From 836c098d7419c10252869b64ddd6eb6a4f2aae74 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Mon, 12 Aug 2024 10:20:33 -0500 Subject: [PATCH 01/20] crn-network attributes and args --- go.mod | 2 +- go.sum | 4 ++-- .../power/data_source_ibm_pi_network.go | 13 ++++++++++++ .../power/data_source_ibm_pi_networks.go | 6 ++++++ .../data_source_ibm_pi_public_network.go | 6 ++++++ ibm/service/power/ibm_pi_constants.go | 2 ++ ibm/service/power/resource_ibm_pi_network.go | 20 +++++++++++++++++-- .../resource_ibm_pi_network_port_attach.go | 12 ++++++++++- 8 files changed, 59 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 9331c5dfe6..532529b7a3 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.22.5 require ( github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 - github.com/IBM-Cloud/power-go-client v1.7.0 + github.com/IBM-Cloud/power-go-client v1.8.0-beta5 github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca github.com/IBM/appconfiguration-go-admin-sdk v0.3.0 github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f diff --git a/go.sum b/go.sum index 5db19a9fe9..159416c5b7 100644 --- a/go.sum +++ b/go.sum @@ -118,8 +118,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be/go.mod h1:/7h github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 h1:f2Erqfea1dKpaTFagTJM6W/wnD3JGq/Vn9URh8nuRwk= github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY= github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs= -github.com/IBM-Cloud/power-go-client v1.7.0 h1:/GuGwPMTKoCZACfnwt7b6wKr4v32q1VO1AMFGNETRN4= -github.com/IBM-Cloud/power-go-client v1.7.0/go.mod h1:9izycYAmNQ+NAdVPXDC3fHYxqWLjlR2YiwqKYveMv5Y= +github.com/IBM-Cloud/power-go-client v1.8.0-beta5 h1:23FxbCYsE4vqBMAQO/8tkksmFu57oXSITVFcyRVgtpg= +github.com/IBM-Cloud/power-go-client v1.8.0-beta5/go.mod h1:oAkZiHX25cmr2Yun5V0q6CpnUemegvSrpcEy/oQcjzU= github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw= github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4= github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs= diff --git a/ibm/service/power/data_source_ibm_pi_network.go b/ibm/service/power/data_source_ibm_pi_network.go index 2835514f90..2808c04350 100644 --- a/ibm/service/power/data_source_ibm_pi_network.go +++ b/ibm/service/power/data_source_ibm_pi_network.go @@ -48,6 +48,11 @@ func DataSourceIBMPINetwork() *schema.Resource { Description: "The CIDR of the network.", Type: schema.TypeString, }, + Attr_CRN: { + Computed: true, + Description: "The CRN of the network.", + Type: schema.TypeString, + }, Attr_DNS: { Computed: true, Description: "The DNS Servers for the network.", @@ -91,6 +96,12 @@ func DataSourceIBMPINetwork() *schema.Resource { Description: "The percentage of IP addresses used.", Type: schema.TypeFloat, }, + Attr_UserTags: { + Computed: true, + Description: "List of user specified tags for the network.", + Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, + }, Attr_VLanID: { Computed: true, Description: "The VLAN ID that the network is connected to.", @@ -122,6 +133,7 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met if networkdata.Cidr != nil { d.Set(Attr_CIDR, networkdata.Cidr) } + d.Set(Attr_CRN, networkdata.Crn) if len(networkdata.DNSServers) > 0 { d.Set(Attr_DNS, networkdata.DNSServers) } @@ -140,6 +152,7 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met if networkdata.IPAddressMetrics.Utilization != nil { d.Set(Attr_UsedIPPercent, networkdata.IPAddressMetrics.Utilization) } + d.Set(Attr_UserTags, networkdata.UserTags) if networkdata.VlanID != nil { d.Set(Attr_VLanID, networkdata.VlanID) } diff --git a/ibm/service/power/data_source_ibm_pi_networks.go b/ibm/service/power/data_source_ibm_pi_networks.go index 75d9fc6964..79118083d4 100644 --- a/ibm/service/power/data_source_ibm_pi_networks.go +++ b/ibm/service/power/data_source_ibm_pi_networks.go @@ -38,6 +38,11 @@ func DataSourceIBMPINetworks() *schema.Resource { Description: "The network communication configuration option of the network (for satellite locations only).", Type: schema.TypeString, }, + Attr_CRN: { + Computed: true, + Description: "The CRN of the network.", + Type: schema.TypeString, + }, Attr_DhcpManaged: { Computed: true, Description: "Indicates if the network DHCP Managed.", @@ -107,6 +112,7 @@ func flattenNetworks(list []*models.NetworkReference) []map[string]interface{} { for _, i := range list { l := map[string]interface{}{ Attr_AccessConfig: i.AccessConfig, + Attr_CRN: i.Crn, Attr_DhcpManaged: i.DhcpManaged, Attr_Href: *i.Href, Attr_MTU: i.Mtu, diff --git a/ibm/service/power/data_source_ibm_pi_public_network.go b/ibm/service/power/data_source_ibm_pi_public_network.go index ef8195c964..0502723a73 100644 --- a/ibm/service/power/data_source_ibm_pi_public_network.go +++ b/ibm/service/power/data_source_ibm_pi_public_network.go @@ -26,6 +26,11 @@ func DataSourceIBMPIPublicNetwork() *schema.Resource { }, // Attributes + Attr_CRN: { + Computed: true, + Description: "CRN of public network.", + Type: schema.TypeString, + }, Attr_Name: { Computed: true, Description: "The name of the network.", @@ -63,6 +68,7 @@ func dataSourceIBMPIPublicNetworkRead(ctx context.Context, d *schema.ResourceDat } d.SetId(*networkdata.Networks[0].NetworkID) + d.Set(Attr_CRN, networkdata.Networks[0].Crn) if networkdata.Networks[0].Name != nil { d.Set(Attr_Name, networkdata.Networks[0].Name) } diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 6f3fff8509..58844b2289 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -85,6 +85,7 @@ const ( Arg_SysType = "pi_sys_type" Arg_TargetStorageTier = "pi_target_storage_tier" Arg_UserData = "pi_user_data" + Arg_UserTags = "pi_user_tags" Arg_VirtualCoresAssigned = "pi_virtual_cores_assigned" Arg_VirtualOpticalDevice = "pi_virtual_optical_device" Arg_VolumeCloneName = "pi_volume_clone_name" @@ -371,6 +372,7 @@ const ( Attr_UsedIPPercent = "used_ip_percent" Attr_UsedMemory = "used_memory" Attr_UserIPAddress = "user_ip_address" + Attr_UserTags = "user_tags" Attr_VCPUs = "vcpus" Attr_Vendor = "vendor" Attr_VirtualCoresAssigned = "virtual_cores_assigned" diff --git a/ibm/service/power/resource_ibm_pi_network.go b/ibm/service/power/resource_ibm_pi_network.go index 5842599a2b..20ba7a0beb 100644 --- a/ibm/service/power/resource_ibm_pi_network.go +++ b/ibm/service/power/resource_ibm_pi_network.go @@ -122,8 +122,20 @@ func ResourceIBMPINetwork() *schema.Resource { }, }, }, + Arg_UserTags: { + Description: "List of user specified tags.", + Elem: &schema.Schema{Type: schema.TypeString}, + ForceNew: true, + Optional: true, + Type: schema.TypeList, + }, //Computed Attributes + Attr_CRN: { + Computed: true, + Description: "CRN of network.", + Type: schema.TypeString, + }, "network_id": { Type: schema.TypeString, Computed: true, @@ -158,7 +170,10 @@ func resourceIBMPINetworkCreate(ctx context.Context, d *schema.ResourceData, met body.DNSServers = networkdns } } - + if tags, ok := d.GetOk(Arg_UserTags); ok { + userTags := flex.ExpandStringList(tags.([]interface{})) + body.UserTags = userTags + } if v, ok := d.GetOk(helpers.PINetworkJumbo); ok { body.Jumbo = v.(bool) } @@ -242,7 +257,7 @@ func resourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, meta if err != nil { return diag.FromErr(err) } - + d.Set(Attr_CRN, networkdata.Crn) d.Set("network_id", networkdata.NetworkID) d.Set(helpers.PINetworkCidr, networkdata.Cidr) d.Set(helpers.PINetworkDNS, networkdata.DNSServers) @@ -266,6 +281,7 @@ func resourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, meta } } d.Set(helpers.PINetworkIPAddressRange, ipRangesMap) + d.Set(Arg_UserTags, networkdata.UserTags) return nil } diff --git a/ibm/service/power/resource_ibm_pi_network_port_attach.go b/ibm/service/power/resource_ibm_pi_network_port_attach.go index e0e342e15a..c829938bb2 100644 --- a/ibm/service/power/resource_ibm_pi_network_port_attach.go +++ b/ibm/service/power/resource_ibm_pi_network_port_attach.go @@ -63,6 +63,13 @@ func ResourceIBMPINetworkPortAttach() *schema.Resource { ForceNew: true, Computed: true, }, + Arg_UserTags: { + Description: "List of user specified tags.", + Elem: &schema.Schema{Type: schema.TypeString}, + ForceNew: true, + Optional: true, + Type: schema.TypeList, + }, //Computed Attributes "macaddress": { @@ -101,7 +108,10 @@ func resourceIBMPINetworkPortAttachCreate(ctx context.Context, d *schema.Resourc ipaddress := v.(string) nwportBody.IPAddress = ipaddress } - + if tags, ok := d.GetOk(Arg_UserTags); ok { + userTags := flex.ExpandStringList(tags.([]interface{})) + nwportBody.UserTags = userTags + } nwportattachBody := &models.NetworkPortUpdate{ Description: &description, PvmInstanceID: &instanceID, From b07287a9c0d66c21911a4a6716e9987fa33f98e5 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Tue, 13 Aug 2024 11:12:52 -0500 Subject: [PATCH 02/20] Update documentation --- website/docs/d/pi_network.html.markdown | 2 ++ website/docs/d/pi_networks.html.markdown | 1 + website/docs/d/pi_public_network.html.markdown | 1 + website/docs/r/pi_network.html.markdown | 2 ++ website/docs/r/pi_network_port_attach.html.markdown | 1 + 5 files changed, 7 insertions(+) diff --git a/website/docs/d/pi_network.html.markdown b/website/docs/d/pi_network.html.markdown index 30635fd315..a90e06f551 100644 --- a/website/docs/d/pi_network.html.markdown +++ b/website/docs/d/pi_network.html.markdown @@ -43,6 +43,7 @@ In addition to all argument reference list, you can access the following attribu - `access_config` - (String) The network communication configuration option of the network (for satellite locations only). - `available_ip_count` - (Float) The total number of IP addresses that you have in your network. - `cidr` - (String) The CIDR of the network. +- `crn` - (String) CRN of the network. - `dns`- (Set) The DNS Servers for the network. - `gateway` - (String) The network gateway that is attached to your network. - `id` - (String) The ID of the network. @@ -51,4 +52,5 @@ In addition to all argument reference list, you can access the following attribu - `type` - (String) The type of network. - `used_ip_count` - (Float) The number of used IP addresses. - `used_ip_percent` - (Float) The percentage of IP addresses used. +- `user_tags` - (List) List of user tags associated with the network. - `vlan_id` - (String) The VLAN ID that the network is connected to. diff --git a/website/docs/d/pi_networks.html.markdown b/website/docs/d/pi_networks.html.markdown index 4461cacd9a..9afa1ef986 100644 --- a/website/docs/d/pi_networks.html.markdown +++ b/website/docs/d/pi_networks.html.markdown @@ -42,6 +42,7 @@ In addition to all argument reference list, you can access the following attribu Nested scheme for `networks`: - `access_config` - (String) The network communication configuration option of the network (for satellite locations only). + - `crn` - (String) CRN of the network. - `dhcp_managed` - (Boolean) Indicates if the network DHCP Managed. - `href` - (String) The hyper link of a network. - `mtu` - (Boolean) Maximum Transmission Unit option of the network. diff --git a/website/docs/d/pi_public_network.html.markdown b/website/docs/d/pi_public_network.html.markdown index 097d94ce6a..705c3fb769 100644 --- a/website/docs/d/pi_public_network.html.markdown +++ b/website/docs/d/pi_public_network.html.markdown @@ -39,6 +39,7 @@ Review the argument references that you can specify for your data source. ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. +- `crn` - (String) CRN of the public network. - `id` - (String) The ID of the network. - `name` - (String) The name of the network. - `type` - (String) The type of VLAN that the network is connected to. diff --git a/website/docs/r/pi_network.html.markdown b/website/docs/r/pi_network.html.markdown index b74018f7c4..189c4b57e6 100644 --- a/website/docs/r/pi_network.html.markdown +++ b/website/docs/r/pi_network.html.markdown @@ -72,11 +72,13 @@ Review the argument references that you can specify for your resource. - `pi_network_jumbo` - (Deprecated, Optional, Bool) MTU Jumbo option of the network (for multi-zone locations only). - `pi_network_mtu` - (Optional, Integer) Maximum Transmission Unit option of the network, min size = 1450 & max size = 9000. - `pi_network_access_config` - (Optional, String) The network communication configuration option of the network (for satellite locations only). +- `pi_user_tags` - (Optional, List) List of user tags for the network. ## Attribute reference In addition to all argument reference list, you can access the following attribute reference after your resource is created. +- `crn` - (String) CRN of the network. - `id` - (String) The unique identifier of the network. The ID is composed of `/`. - `network_id` - (String) The unique identifier of the network. - `vlan_id` - (Integer) The ID of the VLAN that your network is attached to. diff --git a/website/docs/r/pi_network_port_attach.html.markdown b/website/docs/r/pi_network_port_attach.html.markdown index b12d5b2a7f..036b613b7f 100644 --- a/website/docs/r/pi_network_port_attach.html.markdown +++ b/website/docs/r/pi_network_port_attach.html.markdown @@ -54,6 +54,7 @@ Review the argument references that you can specify for your resource. - `pi_network_name` - (Required, String) The network ID or name. - `pi_network_port_description` - (Optional, String) The description for the Network Port. - `pi_network_port_ipaddress` - (Optional, String) The requested ip address of this port. +- `pi_user_tags` - (Optional, List) List of user tags for the port. ## Attribute reference In addition to all argument reference list, you can access the following attribute reference after your resource is created. From f14d30276cb3fc0b7afd82bb64df8b0b58efa188 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Tue, 13 Aug 2024 12:00:21 -0500 Subject: [PATCH 03/20] Fix on network datasource --- ibm/service/power/data_source_ibm_pi_network.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ibm/service/power/data_source_ibm_pi_network.go b/ibm/service/power/data_source_ibm_pi_network.go index 2808c04350..994e179f44 100644 --- a/ibm/service/power/data_source_ibm_pi_network.go +++ b/ibm/service/power/data_source_ibm_pi_network.go @@ -152,7 +152,9 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met if networkdata.IPAddressMetrics.Utilization != nil { d.Set(Attr_UsedIPPercent, networkdata.IPAddressMetrics.Utilization) } - d.Set(Attr_UserTags, networkdata.UserTags) + if len(networkdata.UserTags) > 0 { + d.Set(Attr_UserTags, networkdata.UserTags) + } if networkdata.VlanID != nil { d.Set(Attr_VLanID, networkdata.VlanID) } From 66be521ffeb98e085aab8dc361bba52f619081f4 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Thu, 15 Aug 2024 11:30:37 -0500 Subject: [PATCH 04/20] Add tests for crn and user tags --- .../power/data_source_ibm_pi_network_test.go | 4 +- .../power/data_source_ibm_pi_networks_test.go | 4 +- .../data_source_ibm_pi_public_network_test.go | 4 +- .../power/resource_ibm_pi_network_test.go | 71 +++++++++++++++---- 4 files changed, 66 insertions(+), 17 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_network_test.go b/ibm/service/power/data_source_ibm_pi_network_test.go index c4c09fa58c..cb3d00a828 100644 --- a/ibm/service/power/data_source_ibm_pi_network_test.go +++ b/ibm/service/power/data_source_ibm_pi_network_test.go @@ -13,6 +13,7 @@ import ( ) func TestAccIBMPINetworkDataSource_basic(t *testing.T) { + networkRes := "data.ibm_pi_network.testacc_ds_network" resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -20,7 +21,8 @@ func TestAccIBMPINetworkDataSource_basic(t *testing.T) { { Config: testAccCheckIBMPINetworkDataSourceConfig(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_pi_network.testacc_ds_network", "id"), + resource.TestCheckResourceAttrSet(networkRes, "id"), + resource.TestCheckResourceAttrSet(networkRes, "crn"), ), }, }, diff --git a/ibm/service/power/data_source_ibm_pi_networks_test.go b/ibm/service/power/data_source_ibm_pi_networks_test.go index 3235db2a64..09a78095df 100644 --- a/ibm/service/power/data_source_ibm_pi_networks_test.go +++ b/ibm/service/power/data_source_ibm_pi_networks_test.go @@ -13,6 +13,7 @@ import ( ) func TestAccIBMPINetworksDataSource_basic(t *testing.T) { + networksResData := "data.ibm_pi_networks.testacc_ds_networks" resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -20,7 +21,8 @@ func TestAccIBMPINetworksDataSource_basic(t *testing.T) { { Config: testAccCheckIBMPINetworksDataSourceConfig(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_pi_networks.testacc_ds_networks", "id"), + resource.TestCheckResourceAttrSet(networksResData, "id"), + resource.TestCheckResourceAttrSet(networksResData, "networks.0.crn"), ), }, }, diff --git a/ibm/service/power/data_source_ibm_pi_public_network_test.go b/ibm/service/power/data_source_ibm_pi_public_network_test.go index 3ac39c13a6..3673b32cc4 100644 --- a/ibm/service/power/data_source_ibm_pi_public_network_test.go +++ b/ibm/service/power/data_source_ibm_pi_public_network_test.go @@ -13,6 +13,7 @@ import ( ) func TestAccIBMPIPublicNetworkDataSource_basic(t *testing.T) { + publicNetworkResData := "data.ibm_pi_public_network.testacc_ds_public_network" resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -20,7 +21,8 @@ func TestAccIBMPIPublicNetworkDataSource_basic(t *testing.T) { { Config: testAccCheckIBMPIPublicNetworkDataSourceConfig(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("data.ibm_pi_public_network.testacc_ds_public_network", "id"), + resource.TestCheckResourceAttrSet(publicNetworkResData, "id"), + resource.TestCheckResourceAttrSet(publicNetworkResData, "crn"), ), }, }, diff --git a/ibm/service/power/resource_ibm_pi_network_test.go b/ibm/service/power/resource_ibm_pi_network_test.go index cc55a7af24..d5ec068253 100644 --- a/ibm/service/power/resource_ibm_pi_network_test.go +++ b/ibm/service/power/resource_ibm_pi_network_test.go @@ -21,6 +21,7 @@ import ( func TestAccIBMPINetworkbasic(t *testing.T) { name := fmt.Sprintf("tf-pi-network-%d", acctest.RandIntRange(10, 100)) + networkRes := "ibm_pi_network.power_networks" resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, Providers: acc.TestAccProviders, @@ -29,25 +30,24 @@ func TestAccIBMPINetworkbasic(t *testing.T) { { Config: testAccCheckIBMPINetworkConfig(name), Check: resource.ComposeTestCheckFunc( - testAccCheckIBMPINetworkExists("ibm_pi_network.power_networks"), - resource.TestCheckResourceAttr( - "ibm_pi_network.power_networks", "pi_network_name", name), - resource.TestCheckResourceAttrSet("ibm_pi_network.power_networks", "id"), - resource.TestCheckResourceAttrSet("ibm_pi_network.power_networks", "pi_gateway"), - resource.TestCheckResourceAttrSet("ibm_pi_network.power_networks", "pi_ipaddress_range.#"), + testAccCheckIBMPINetworkExists(networkRes), + resource.TestCheckResourceAttr(networkRes, "pi_network_name", name), + resource.TestCheckResourceAttrSet(networkRes, "crn"), + resource.TestCheckResourceAttrSet(networkRes, "id"), + resource.TestCheckResourceAttrSet(networkRes, "pi_gateway"), + resource.TestCheckResourceAttrSet(networkRes, "pi_ipaddress_range.#"), ), }, { Config: testAccCheckIBMPINetworkConfigUpdateDNS(name), Check: resource.ComposeTestCheckFunc( - testAccCheckIBMPINetworkExists("ibm_pi_network.power_networks"), - resource.TestCheckResourceAttr( - "ibm_pi_network.power_networks", "pi_network_name", name), - resource.TestCheckResourceAttr( - "ibm_pi_network.power_networks", "pi_dns.#", "1"), - resource.TestCheckResourceAttrSet("ibm_pi_network.power_networks", "id"), - resource.TestCheckResourceAttrSet("ibm_pi_network.power_networks", "pi_gateway"), - resource.TestCheckResourceAttrSet("ibm_pi_network.power_networks", "pi_ipaddress_range.#"), + testAccCheckIBMPINetworkExists(networkRes), + resource.TestCheckResourceAttr(networkRes, "pi_network_name", name), + resource.TestCheckResourceAttrSet(networkRes, "crn"), + resource.TestCheckResourceAttr(networkRes, "pi_dns.#", "1"), + resource.TestCheckResourceAttrSet(networkRes, "id"), + resource.TestCheckResourceAttrSet(networkRes, "pi_gateway"), + resource.TestCheckResourceAttrSet(networkRes, "pi_ipaddress_range.#"), ), }, }, @@ -156,6 +156,27 @@ func TestAccIBMPINetworkDHCPbasic(t *testing.T) { }, }) } +func TestAccIBMPINetworkusertags(t *testing.T) { + name := fmt.Sprintf("tf-pi-network-%d", acctest.RandIntRange(10, 100)) + networkRes := "ibm_pi_network.power_networks" + userTagsString := `["env:dev","test_tag"]` + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMPINetworkDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMPINetworkConfigUserTags(name, userTagsString), + Check: resource.ComposeTestCheckFunc( + testAccCheckIBMPINetworkExists(networkRes), + resource.TestCheckResourceAttr(networkRes, "pi_user_tags.#", "2"), + resource.TestCheckResourceAttr(networkRes, "pi_user_tags.0", "env:test"), + resource.TestCheckResourceAttr(networkRes, "pi_user_tags.1", "test_tag"), + ), + }, + }, + }) +} func testAccCheckIBMPINetworkDestroy(s *terraform.State) error { sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession() @@ -296,3 +317,25 @@ func testAccCheckIBMPINetworkConfigGatewayDHCPUpdateDNS(name string) string { } `, acc.Pi_cloud_instance_id, name) } + +func testAccCheckIBMPINetworkConfigUserTags(name string, userTagsString string) string { + return fmt.Sprintf(` + data "ibm_pi_network" "power_networks_data" { + pi_cloud_instance_id = "%[1]s" + pi_network_name = ibm_pi_network.power_networks.pi_network_name + } + + resource "ibm_pi_network" "power_networks" { + pi_network_name = "%[2]s" + pi_cloud_instance_id = "%[1]s" + pi_network_type = "vlan" + pi_cidr = "192.168.17.0/24" + pi_gateway = "192.168.17.2" + pi_ipaddress_range { + pi_ending_ip_address = "192.168.17.254" + pi_starting_ip_address = "192.168.17.3" + } + pi_user_tags = %[3]s + } + `, acc.Pi_cloud_instance_id, name, userTagsString) +} From 7dc9d3102be0cd7802b4309929a992c2bf0e3ceb Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Mon, 19 Aug 2024 12:56:21 -0500 Subject: [PATCH 05/20] Cleanup and test fixes --- ibm/service/power/resource_ibm_pi_network.go | 1 - ibm/service/power/resource_ibm_pi_network_test.go | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_network.go b/ibm/service/power/resource_ibm_pi_network.go index 20ba7a0beb..efc2dab805 100644 --- a/ibm/service/power/resource_ibm_pi_network.go +++ b/ibm/service/power/resource_ibm_pi_network.go @@ -281,7 +281,6 @@ func resourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, meta } } d.Set(helpers.PINetworkIPAddressRange, ipRangesMap) - d.Set(Arg_UserTags, networkdata.UserTags) return nil } diff --git a/ibm/service/power/resource_ibm_pi_network_test.go b/ibm/service/power/resource_ibm_pi_network_test.go index d5ec068253..c8fc034f1c 100644 --- a/ibm/service/power/resource_ibm_pi_network_test.go +++ b/ibm/service/power/resource_ibm_pi_network_test.go @@ -159,6 +159,7 @@ func TestAccIBMPINetworkDHCPbasic(t *testing.T) { func TestAccIBMPINetworkusertags(t *testing.T) { name := fmt.Sprintf("tf-pi-network-%d", acctest.RandIntRange(10, 100)) networkRes := "ibm_pi_network.power_networks" + networkResData := "data.ibm_pi_network.power_networks_data" userTagsString := `["env:dev","test_tag"]` resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -169,9 +170,9 @@ func TestAccIBMPINetworkusertags(t *testing.T) { Config: testAccCheckIBMPINetworkConfigUserTags(name, userTagsString), Check: resource.ComposeTestCheckFunc( testAccCheckIBMPINetworkExists(networkRes), - resource.TestCheckResourceAttr(networkRes, "pi_user_tags.#", "2"), - resource.TestCheckResourceAttr(networkRes, "pi_user_tags.0", "env:test"), - resource.TestCheckResourceAttr(networkRes, "pi_user_tags.1", "test_tag"), + resource.TestCheckResourceAttr(networkResData, "user_tags.#", "2"), + resource.TestCheckResourceAttr(networkResData, "user_tags.0", "env:test"), + resource.TestCheckResourceAttr(networkResData, "user_tags.1", "test_tag"), ), }, }, From eb3d792cda1284b13d031dd58f372875fdb73ddd Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Thu, 22 Aug 2024 09:37:33 -0500 Subject: [PATCH 06/20] Fixes from code review --- ibm/service/power/resource_ibm_pi_network.go | 5 +++-- ibm/service/power/resource_ibm_pi_network_port_attach.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_network.go b/ibm/service/power/resource_ibm_pi_network.go index efc2dab805..21d2aabc18 100644 --- a/ibm/service/power/resource_ibm_pi_network.go +++ b/ibm/service/power/resource_ibm_pi_network.go @@ -171,8 +171,9 @@ func resourceIBMPINetworkCreate(ctx context.Context, d *schema.ResourceData, met } } if tags, ok := d.GetOk(Arg_UserTags); ok { - userTags := flex.ExpandStringList(tags.([]interface{})) - body.UserTags = userTags + if len(tags.([]interface{})) > 0 { + body.UserTags = flex.ExpandStringList(tags.([]interface{})) + } } if v, ok := d.GetOk(helpers.PINetworkJumbo); ok { body.Jumbo = v.(bool) diff --git a/ibm/service/power/resource_ibm_pi_network_port_attach.go b/ibm/service/power/resource_ibm_pi_network_port_attach.go index c829938bb2..88272f6ec3 100644 --- a/ibm/service/power/resource_ibm_pi_network_port_attach.go +++ b/ibm/service/power/resource_ibm_pi_network_port_attach.go @@ -109,8 +109,9 @@ func resourceIBMPINetworkPortAttachCreate(ctx context.Context, d *schema.Resourc nwportBody.IPAddress = ipaddress } if tags, ok := d.GetOk(Arg_UserTags); ok { - userTags := flex.ExpandStringList(tags.([]interface{})) - nwportBody.UserTags = userTags + if len(tags.([]interface{})) > 0 { + nwportBody.UserTags = flex.ExpandStringList(tags.([]interface{})) + } } nwportattachBody := &models.NetworkPortUpdate{ Description: &description, From 8ae7fb3f47af38caf2e8a929a5dc102cf242b595 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Thu, 22 Aug 2024 10:48:05 -0500 Subject: [PATCH 07/20] Add Crn checks --- ibm/service/power/data_source_ibm_pi_network.go | 4 +++- ibm/service/power/data_source_ibm_pi_networks.go | 5 ++++- ibm/service/power/data_source_ibm_pi_public_network.go | 4 +++- ibm/service/power/resource_ibm_pi_network.go | 4 +++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_network.go b/ibm/service/power/data_source_ibm_pi_network.go index 994e179f44..6569e4f4a2 100644 --- a/ibm/service/power/data_source_ibm_pi_network.go +++ b/ibm/service/power/data_source_ibm_pi_network.go @@ -133,7 +133,9 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met if networkdata.Cidr != nil { d.Set(Attr_CIDR, networkdata.Cidr) } - d.Set(Attr_CRN, networkdata.Crn) + if networkdata.Crn != "" { + d.Set(Attr_CRN, networkdata.Crn) + } if len(networkdata.DNSServers) > 0 { d.Set(Attr_DNS, networkdata.DNSServers) } diff --git a/ibm/service/power/data_source_ibm_pi_networks.go b/ibm/service/power/data_source_ibm_pi_networks.go index 79118083d4..456504b09e 100644 --- a/ibm/service/power/data_source_ibm_pi_networks.go +++ b/ibm/service/power/data_source_ibm_pi_networks.go @@ -112,7 +112,6 @@ func flattenNetworks(list []*models.NetworkReference) []map[string]interface{} { for _, i := range list { l := map[string]interface{}{ Attr_AccessConfig: i.AccessConfig, - Attr_CRN: i.Crn, Attr_DhcpManaged: i.DhcpManaged, Attr_Href: *i.Href, Attr_MTU: i.Mtu, @@ -121,6 +120,10 @@ func flattenNetworks(list []*models.NetworkReference) []map[string]interface{} { Attr_Type: *i.Type, Attr_VLanID: *i.VlanID, } + + if i.Crn != "" { + l[Attr_CRN] = i.Crn + } result = append(result, l) } return result diff --git a/ibm/service/power/data_source_ibm_pi_public_network.go b/ibm/service/power/data_source_ibm_pi_public_network.go index 0502723a73..12f30612f3 100644 --- a/ibm/service/power/data_source_ibm_pi_public_network.go +++ b/ibm/service/power/data_source_ibm_pi_public_network.go @@ -68,7 +68,9 @@ func dataSourceIBMPIPublicNetworkRead(ctx context.Context, d *schema.ResourceDat } d.SetId(*networkdata.Networks[0].NetworkID) - d.Set(Attr_CRN, networkdata.Networks[0].Crn) + if networkdata.Networks[0].Crn != "" { + d.Set(Attr_CRN, networkdata.Networks[0].Crn) + } if networkdata.Networks[0].Name != nil { d.Set(Attr_Name, networkdata.Networks[0].Name) } diff --git a/ibm/service/power/resource_ibm_pi_network.go b/ibm/service/power/resource_ibm_pi_network.go index 21d2aabc18..de15c094ad 100644 --- a/ibm/service/power/resource_ibm_pi_network.go +++ b/ibm/service/power/resource_ibm_pi_network.go @@ -258,7 +258,9 @@ func resourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, meta if err != nil { return diag.FromErr(err) } - d.Set(Attr_CRN, networkdata.Crn) + if networkdata.Crn != "" { + d.Set(Attr_CRN, networkdata.Crn) + } d.Set("network_id", networkdata.NetworkID) d.Set(helpers.PINetworkCidr, networkdata.Cidr) d.Set(helpers.PINetworkDNS, networkdata.DNSServers) From d2c8f95c6fefe2155521445cd8dbb323787fc4a2 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Mon, 26 Aug 2024 14:19:38 -0500 Subject: [PATCH 08/20] Description and documentation updates --- ibm/service/power/data_source_ibm_pi_network.go | 4 ++-- ibm/service/power/data_source_ibm_pi_networks.go | 2 +- ibm/service/power/data_source_ibm_pi_public_network.go | 2 +- ibm/service/power/resource_ibm_pi_network.go | 4 ++-- ibm/service/power/resource_ibm_pi_network_port_attach.go | 2 +- website/docs/d/pi_network.html.markdown | 4 ++-- website/docs/d/pi_networks.html.markdown | 2 +- website/docs/d/pi_public_network.html.markdown | 2 +- website/docs/r/pi_network.html.markdown | 4 ++-- website/docs/r/pi_network_port_attach.html.markdown | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_network.go b/ibm/service/power/data_source_ibm_pi_network.go index 6569e4f4a2..f799ed8196 100644 --- a/ibm/service/power/data_source_ibm_pi_network.go +++ b/ibm/service/power/data_source_ibm_pi_network.go @@ -50,7 +50,7 @@ func DataSourceIBMPINetwork() *schema.Resource { }, Attr_CRN: { Computed: true, - Description: "The CRN of the network.", + Description: "The CRN of this resource.", Type: schema.TypeString, }, Attr_DNS: { @@ -98,7 +98,7 @@ func DataSourceIBMPINetwork() *schema.Resource { }, Attr_UserTags: { Computed: true, - Description: "List of user specified tags for the network.", + Description: "The user tags associated with this resource.", Elem: &schema.Schema{Type: schema.TypeString}, Type: schema.TypeList, }, diff --git a/ibm/service/power/data_source_ibm_pi_networks.go b/ibm/service/power/data_source_ibm_pi_networks.go index 456504b09e..b1ce19e6da 100644 --- a/ibm/service/power/data_source_ibm_pi_networks.go +++ b/ibm/service/power/data_source_ibm_pi_networks.go @@ -40,7 +40,7 @@ func DataSourceIBMPINetworks() *schema.Resource { }, Attr_CRN: { Computed: true, - Description: "The CRN of the network.", + Description: "The CRN of this resource.", Type: schema.TypeString, }, Attr_DhcpManaged: { diff --git a/ibm/service/power/data_source_ibm_pi_public_network.go b/ibm/service/power/data_source_ibm_pi_public_network.go index 12f30612f3..04af881a3c 100644 --- a/ibm/service/power/data_source_ibm_pi_public_network.go +++ b/ibm/service/power/data_source_ibm_pi_public_network.go @@ -28,7 +28,7 @@ func DataSourceIBMPIPublicNetwork() *schema.Resource { // Attributes Attr_CRN: { Computed: true, - Description: "CRN of public network.", + Description: "The CRN of this resource.", Type: schema.TypeString, }, Attr_Name: { diff --git a/ibm/service/power/resource_ibm_pi_network.go b/ibm/service/power/resource_ibm_pi_network.go index de15c094ad..d4816bed8e 100644 --- a/ibm/service/power/resource_ibm_pi_network.go +++ b/ibm/service/power/resource_ibm_pi_network.go @@ -123,7 +123,7 @@ func ResourceIBMPINetwork() *schema.Resource { }, }, Arg_UserTags: { - Description: "List of user specified tags.", + Description: "The user tags associated with this resource.", Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true, Optional: true, @@ -133,7 +133,7 @@ func ResourceIBMPINetwork() *schema.Resource { //Computed Attributes Attr_CRN: { Computed: true, - Description: "CRN of network.", + Description: "The CRN of this resource.", Type: schema.TypeString, }, "network_id": { diff --git a/ibm/service/power/resource_ibm_pi_network_port_attach.go b/ibm/service/power/resource_ibm_pi_network_port_attach.go index 88272f6ec3..4dbec57d96 100644 --- a/ibm/service/power/resource_ibm_pi_network_port_attach.go +++ b/ibm/service/power/resource_ibm_pi_network_port_attach.go @@ -64,7 +64,7 @@ func ResourceIBMPINetworkPortAttach() *schema.Resource { Computed: true, }, Arg_UserTags: { - Description: "List of user specified tags.", + Description: "The user tags associated with this resource.", Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true, Optional: true, diff --git a/website/docs/d/pi_network.html.markdown b/website/docs/d/pi_network.html.markdown index a90e06f551..e99d0d601e 100644 --- a/website/docs/d/pi_network.html.markdown +++ b/website/docs/d/pi_network.html.markdown @@ -43,7 +43,7 @@ In addition to all argument reference list, you can access the following attribu - `access_config` - (String) The network communication configuration option of the network (for satellite locations only). - `available_ip_count` - (Float) The total number of IP addresses that you have in your network. - `cidr` - (String) The CIDR of the network. -- `crn` - (String) CRN of the network. +- `crn` - (String) The CRN of this resource. - `dns`- (Set) The DNS Servers for the network. - `gateway` - (String) The network gateway that is attached to your network. - `id` - (String) The ID of the network. @@ -52,5 +52,5 @@ In addition to all argument reference list, you can access the following attribu - `type` - (String) The type of network. - `used_ip_count` - (Float) The number of used IP addresses. - `used_ip_percent` - (Float) The percentage of IP addresses used. -- `user_tags` - (List) List of user tags associated with the network. +- `user_tags` - (List) The user tags associated with this resource. - `vlan_id` - (String) The VLAN ID that the network is connected to. diff --git a/website/docs/d/pi_networks.html.markdown b/website/docs/d/pi_networks.html.markdown index 9afa1ef986..4230592156 100644 --- a/website/docs/d/pi_networks.html.markdown +++ b/website/docs/d/pi_networks.html.markdown @@ -42,7 +42,7 @@ In addition to all argument reference list, you can access the following attribu Nested scheme for `networks`: - `access_config` - (String) The network communication configuration option of the network (for satellite locations only). - - `crn` - (String) CRN of the network. + - `crn` - (String) The CRN of this resource. - `dhcp_managed` - (Boolean) Indicates if the network DHCP Managed. - `href` - (String) The hyper link of a network. - `mtu` - (Boolean) Maximum Transmission Unit option of the network. diff --git a/website/docs/d/pi_public_network.html.markdown b/website/docs/d/pi_public_network.html.markdown index 705c3fb769..f1ecb789ac 100644 --- a/website/docs/d/pi_public_network.html.markdown +++ b/website/docs/d/pi_public_network.html.markdown @@ -39,7 +39,7 @@ Review the argument references that you can specify for your data source. ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. -- `crn` - (String) CRN of the public network. +- `crn` - (String) The CRN of this resource. - `id` - (String) The ID of the network. - `name` - (String) The name of the network. - `type` - (String) The type of VLAN that the network is connected to. diff --git a/website/docs/r/pi_network.html.markdown b/website/docs/r/pi_network.html.markdown index 189c4b57e6..5f0bdd7c45 100644 --- a/website/docs/r/pi_network.html.markdown +++ b/website/docs/r/pi_network.html.markdown @@ -72,13 +72,13 @@ Review the argument references that you can specify for your resource. - `pi_network_jumbo` - (Deprecated, Optional, Bool) MTU Jumbo option of the network (for multi-zone locations only). - `pi_network_mtu` - (Optional, Integer) Maximum Transmission Unit option of the network, min size = 1450 & max size = 9000. - `pi_network_access_config` - (Optional, String) The network communication configuration option of the network (for satellite locations only). -- `pi_user_tags` - (Optional, List) List of user tags for the network. +- `pi_user_tags` - (Optional, List) The user tags associated with this resource. ## Attribute reference In addition to all argument reference list, you can access the following attribute reference after your resource is created. -- `crn` - (String) CRN of the network. +- `crn` - (String) The CRN of this resource. - `id` - (String) The unique identifier of the network. The ID is composed of `/`. - `network_id` - (String) The unique identifier of the network. - `vlan_id` - (Integer) The ID of the VLAN that your network is attached to. diff --git a/website/docs/r/pi_network_port_attach.html.markdown b/website/docs/r/pi_network_port_attach.html.markdown index 036b613b7f..c20fd5db84 100644 --- a/website/docs/r/pi_network_port_attach.html.markdown +++ b/website/docs/r/pi_network_port_attach.html.markdown @@ -54,7 +54,7 @@ Review the argument references that you can specify for your resource. - `pi_network_name` - (Required, String) The network ID or name. - `pi_network_port_description` - (Optional, String) The description for the Network Port. - `pi_network_port_ipaddress` - (Optional, String) The requested ip address of this port. -- `pi_user_tags` - (Optional, List) List of user tags for the port. +- `pi_user_tags` - (Optional, List) The user tags associated with this resource. ## Attribute reference In addition to all argument reference list, you can access the following attribute reference after your resource is created. From f1e781424fe768434653533d344821bfa5d168a0 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Tue, 27 Aug 2024 10:39:22 -0500 Subject: [PATCH 09/20] Remove crn from tests --- ibm/service/power/data_source_ibm_pi_network_test.go | 1 - ibm/service/power/data_source_ibm_pi_networks_test.go | 1 - ibm/service/power/data_source_ibm_pi_public_network_test.go | 1 - ibm/service/power/resource_ibm_pi_network_test.go | 2 -- 4 files changed, 5 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_network_test.go b/ibm/service/power/data_source_ibm_pi_network_test.go index cb3d00a828..9cb5fa3c72 100644 --- a/ibm/service/power/data_source_ibm_pi_network_test.go +++ b/ibm/service/power/data_source_ibm_pi_network_test.go @@ -22,7 +22,6 @@ func TestAccIBMPINetworkDataSource_basic(t *testing.T) { Config: testAccCheckIBMPINetworkDataSourceConfig(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(networkRes, "id"), - resource.TestCheckResourceAttrSet(networkRes, "crn"), ), }, }, diff --git a/ibm/service/power/data_source_ibm_pi_networks_test.go b/ibm/service/power/data_source_ibm_pi_networks_test.go index 09a78095df..2d53f2e73b 100644 --- a/ibm/service/power/data_source_ibm_pi_networks_test.go +++ b/ibm/service/power/data_source_ibm_pi_networks_test.go @@ -22,7 +22,6 @@ func TestAccIBMPINetworksDataSource_basic(t *testing.T) { Config: testAccCheckIBMPINetworksDataSourceConfig(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(networksResData, "id"), - resource.TestCheckResourceAttrSet(networksResData, "networks.0.crn"), ), }, }, diff --git a/ibm/service/power/data_source_ibm_pi_public_network_test.go b/ibm/service/power/data_source_ibm_pi_public_network_test.go index 3673b32cc4..3062b232de 100644 --- a/ibm/service/power/data_source_ibm_pi_public_network_test.go +++ b/ibm/service/power/data_source_ibm_pi_public_network_test.go @@ -22,7 +22,6 @@ func TestAccIBMPIPublicNetworkDataSource_basic(t *testing.T) { Config: testAccCheckIBMPIPublicNetworkDataSourceConfig(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(publicNetworkResData, "id"), - resource.TestCheckResourceAttrSet(publicNetworkResData, "crn"), ), }, }, diff --git a/ibm/service/power/resource_ibm_pi_network_test.go b/ibm/service/power/resource_ibm_pi_network_test.go index c8fc034f1c..6915d11421 100644 --- a/ibm/service/power/resource_ibm_pi_network_test.go +++ b/ibm/service/power/resource_ibm_pi_network_test.go @@ -32,7 +32,6 @@ func TestAccIBMPINetworkbasic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckIBMPINetworkExists(networkRes), resource.TestCheckResourceAttr(networkRes, "pi_network_name", name), - resource.TestCheckResourceAttrSet(networkRes, "crn"), resource.TestCheckResourceAttrSet(networkRes, "id"), resource.TestCheckResourceAttrSet(networkRes, "pi_gateway"), resource.TestCheckResourceAttrSet(networkRes, "pi_ipaddress_range.#"), @@ -43,7 +42,6 @@ func TestAccIBMPINetworkbasic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckIBMPINetworkExists(networkRes), resource.TestCheckResourceAttr(networkRes, "pi_network_name", name), - resource.TestCheckResourceAttrSet(networkRes, "crn"), resource.TestCheckResourceAttr(networkRes, "pi_dns.#", "1"), resource.TestCheckResourceAttrSet(networkRes, "id"), resource.TestCheckResourceAttrSet(networkRes, "pi_gateway"), From 1e98450ae2e29b1482e473844d509c7cc6e3aca2 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Wed, 28 Aug 2024 09:48:58 -0500 Subject: [PATCH 10/20] Change user tags description --- ibm/service/power/data_source_ibm_pi_network.go | 2 +- ibm/service/power/resource_ibm_pi_network.go | 2 +- ibm/service/power/resource_ibm_pi_network_port_attach.go | 2 +- website/docs/d/pi_network.html.markdown | 2 +- website/docs/r/pi_network.html.markdown | 2 +- website/docs/r/pi_network_port_attach.html.markdown | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_network.go b/ibm/service/power/data_source_ibm_pi_network.go index f799ed8196..ead08f2824 100644 --- a/ibm/service/power/data_source_ibm_pi_network.go +++ b/ibm/service/power/data_source_ibm_pi_network.go @@ -98,7 +98,7 @@ func DataSourceIBMPINetwork() *schema.Resource { }, Attr_UserTags: { Computed: true, - Description: "The user tags associated with this resource.", + Description: "The user tags attached to this resource.", Elem: &schema.Schema{Type: schema.TypeString}, Type: schema.TypeList, }, diff --git a/ibm/service/power/resource_ibm_pi_network.go b/ibm/service/power/resource_ibm_pi_network.go index d4816bed8e..18dc4a736b 100644 --- a/ibm/service/power/resource_ibm_pi_network.go +++ b/ibm/service/power/resource_ibm_pi_network.go @@ -123,7 +123,7 @@ func ResourceIBMPINetwork() *schema.Resource { }, }, Arg_UserTags: { - Description: "The user tags associated with this resource.", + Description: "The user tags attached to this resource.", Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true, Optional: true, diff --git a/ibm/service/power/resource_ibm_pi_network_port_attach.go b/ibm/service/power/resource_ibm_pi_network_port_attach.go index 4dbec57d96..ee3a9d5139 100644 --- a/ibm/service/power/resource_ibm_pi_network_port_attach.go +++ b/ibm/service/power/resource_ibm_pi_network_port_attach.go @@ -64,7 +64,7 @@ func ResourceIBMPINetworkPortAttach() *schema.Resource { Computed: true, }, Arg_UserTags: { - Description: "The user tags associated with this resource.", + Description: "The user tags attached to this resource.", Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true, Optional: true, diff --git a/website/docs/d/pi_network.html.markdown b/website/docs/d/pi_network.html.markdown index e99d0d601e..f99d3fc238 100644 --- a/website/docs/d/pi_network.html.markdown +++ b/website/docs/d/pi_network.html.markdown @@ -52,5 +52,5 @@ In addition to all argument reference list, you can access the following attribu - `type` - (String) The type of network. - `used_ip_count` - (Float) The number of used IP addresses. - `used_ip_percent` - (Float) The percentage of IP addresses used. -- `user_tags` - (List) The user tags associated with this resource. +- `user_tags` - (List) The user tags attached to this resource. - `vlan_id` - (String) The VLAN ID that the network is connected to. diff --git a/website/docs/r/pi_network.html.markdown b/website/docs/r/pi_network.html.markdown index 5f0bdd7c45..e8ece20e93 100644 --- a/website/docs/r/pi_network.html.markdown +++ b/website/docs/r/pi_network.html.markdown @@ -72,7 +72,7 @@ Review the argument references that you can specify for your resource. - `pi_network_jumbo` - (Deprecated, Optional, Bool) MTU Jumbo option of the network (for multi-zone locations only). - `pi_network_mtu` - (Optional, Integer) Maximum Transmission Unit option of the network, min size = 1450 & max size = 9000. - `pi_network_access_config` - (Optional, String) The network communication configuration option of the network (for satellite locations only). -- `pi_user_tags` - (Optional, List) The user tags associated with this resource. +- `pi_user_tags` - (Optional, List) The user tags attached to this resource. ## Attribute reference diff --git a/website/docs/r/pi_network_port_attach.html.markdown b/website/docs/r/pi_network_port_attach.html.markdown index c20fd5db84..e55c6badc4 100644 --- a/website/docs/r/pi_network_port_attach.html.markdown +++ b/website/docs/r/pi_network_port_attach.html.markdown @@ -54,7 +54,7 @@ Review the argument references that you can specify for your resource. - `pi_network_name` - (Required, String) The network ID or name. - `pi_network_port_description` - (Optional, String) The description for the Network Port. - `pi_network_port_ipaddress` - (Optional, String) The requested ip address of this port. -- `pi_user_tags` - (Optional, List) The user tags associated with this resource. +- `pi_user_tags` - (Optional, List) The user tags attached to this resource. ## Attribute reference In addition to all argument reference list, you can access the following attribute reference after your resource is created. From 2b4c68536c87ace457eab1a38e9adc19bd93ecef Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Wed, 4 Sep 2024 15:57:20 -0500 Subject: [PATCH 11/20] Remove user tags test --- .../power/resource_ibm_pi_network_test.go | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_network_test.go b/ibm/service/power/resource_ibm_pi_network_test.go index 6915d11421..226a15f1ce 100644 --- a/ibm/service/power/resource_ibm_pi_network_test.go +++ b/ibm/service/power/resource_ibm_pi_network_test.go @@ -154,28 +154,6 @@ func TestAccIBMPINetworkDHCPbasic(t *testing.T) { }, }) } -func TestAccIBMPINetworkusertags(t *testing.T) { - name := fmt.Sprintf("tf-pi-network-%d", acctest.RandIntRange(10, 100)) - networkRes := "ibm_pi_network.power_networks" - networkResData := "data.ibm_pi_network.power_networks_data" - userTagsString := `["env:dev","test_tag"]` - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.TestAccPreCheck(t) }, - Providers: acc.TestAccProviders, - CheckDestroy: testAccCheckIBMPINetworkDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckIBMPINetworkConfigUserTags(name, userTagsString), - Check: resource.ComposeTestCheckFunc( - testAccCheckIBMPINetworkExists(networkRes), - resource.TestCheckResourceAttr(networkResData, "user_tags.#", "2"), - resource.TestCheckResourceAttr(networkResData, "user_tags.0", "env:test"), - resource.TestCheckResourceAttr(networkResData, "user_tags.1", "test_tag"), - ), - }, - }, - }) -} func testAccCheckIBMPINetworkDestroy(s *terraform.State) error { sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession() @@ -316,25 +294,3 @@ func testAccCheckIBMPINetworkConfigGatewayDHCPUpdateDNS(name string) string { } `, acc.Pi_cloud_instance_id, name) } - -func testAccCheckIBMPINetworkConfigUserTags(name string, userTagsString string) string { - return fmt.Sprintf(` - data "ibm_pi_network" "power_networks_data" { - pi_cloud_instance_id = "%[1]s" - pi_network_name = ibm_pi_network.power_networks.pi_network_name - } - - resource "ibm_pi_network" "power_networks" { - pi_network_name = "%[2]s" - pi_cloud_instance_id = "%[1]s" - pi_network_type = "vlan" - pi_cidr = "192.168.17.0/24" - pi_gateway = "192.168.17.2" - pi_ipaddress_range { - pi_ending_ip_address = "192.168.17.254" - pi_starting_ip_address = "192.168.17.3" - } - pi_user_tags = %[3]s - } - `, acc.Pi_cloud_instance_id, name, userTagsString) -} From 7f8de0f91277309d6418a6d6f2754c0a895dcdb3 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Wed, 4 Sep 2024 16:41:11 -0500 Subject: [PATCH 12/20] Remove gateway from network satellite tests --- ibm/service/power/resource_ibm_pi_network_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_network_test.go b/ibm/service/power/resource_ibm_pi_network_test.go index 226a15f1ce..98fac89171 100644 --- a/ibm/service/power/resource_ibm_pi_network_test.go +++ b/ibm/service/power/resource_ibm_pi_network_test.go @@ -100,7 +100,6 @@ func TestAccIBMPINetworkGatewaybasicSatellite(t *testing.T) { testAccCheckIBMPINetworkExists("ibm_pi_network.power_networks"), resource.TestCheckResourceAttr( "ibm_pi_network.power_networks", "pi_network_name", name), - resource.TestCheckResourceAttrSet("ibm_pi_network.power_networks", "pi_gateway"), resource.TestCheckResourceAttrSet("ibm_pi_network.power_networks", "id"), resource.TestCheckResourceAttrSet("ibm_pi_network.power_networks", "pi_ipaddress_range.#"), ), @@ -111,8 +110,6 @@ func TestAccIBMPINetworkGatewaybasicSatellite(t *testing.T) { testAccCheckIBMPINetworkExists("ibm_pi_network.power_networks"), resource.TestCheckResourceAttr( "ibm_pi_network.power_networks", "pi_network_name", name), - resource.TestCheckResourceAttr( - "ibm_pi_network.power_networks", "pi_gateway", "192.168.17.2"), resource.TestCheckResourceAttr( "ibm_pi_network.power_networks", "pi_ipaddress_range.0.pi_ending_ip_address", "192.168.17.254"), resource.TestCheckResourceAttr( @@ -261,7 +258,6 @@ func testAccCheckIBMPINetworkConfigGatewayUpdateDNS(name string) string { pi_network_name = "%s" pi_network_type = "vlan" pi_dns = ["127.0.0.1"] - pi_gateway = "192.168.17.2" pi_cidr = "192.168.17.0/24" pi_ipaddress_range { pi_ending_ip_address = "192.168.17.254" From 648deccb189a564ce0da60fdde5491e0d1aba5e9 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Thu, 5 Sep 2024 22:25:00 -0500 Subject: [PATCH 13/20] Remove user tags from data sources --- ibm/service/power/data_source_ibm_pi_network.go | 9 --------- website/docs/d/pi_network.html.markdown | 1 - 2 files changed, 10 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_network.go b/ibm/service/power/data_source_ibm_pi_network.go index ead08f2824..0b6e9ce31a 100644 --- a/ibm/service/power/data_source_ibm_pi_network.go +++ b/ibm/service/power/data_source_ibm_pi_network.go @@ -96,12 +96,6 @@ func DataSourceIBMPINetwork() *schema.Resource { Description: "The percentage of IP addresses used.", Type: schema.TypeFloat, }, - Attr_UserTags: { - Computed: true, - Description: "The user tags attached to this resource.", - Elem: &schema.Schema{Type: schema.TypeString}, - Type: schema.TypeList, - }, Attr_VLanID: { Computed: true, Description: "The VLAN ID that the network is connected to.", @@ -154,9 +148,6 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met if networkdata.IPAddressMetrics.Utilization != nil { d.Set(Attr_UsedIPPercent, networkdata.IPAddressMetrics.Utilization) } - if len(networkdata.UserTags) > 0 { - d.Set(Attr_UserTags, networkdata.UserTags) - } if networkdata.VlanID != nil { d.Set(Attr_VLanID, networkdata.VlanID) } diff --git a/website/docs/d/pi_network.html.markdown b/website/docs/d/pi_network.html.markdown index f99d3fc238..317d0a1c4b 100644 --- a/website/docs/d/pi_network.html.markdown +++ b/website/docs/d/pi_network.html.markdown @@ -52,5 +52,4 @@ In addition to all argument reference list, you can access the following attribu - `type` - (String) The type of network. - `used_ip_count` - (Float) The number of used IP addresses. - `used_ip_percent` - (Float) The percentage of IP addresses used. -- `user_tags` - (List) The user tags attached to this resource. - `vlan_id` - (String) The VLAN ID that the network is connected to. From 0de1cea2fc347bedf3a29cc9bfa748fb311d99dd Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Thu, 5 Sep 2024 22:43:54 -0500 Subject: [PATCH 14/20] Remove user tags attribute from constants --- ibm/service/power/ibm_pi_constants.go | 1 - 1 file changed, 1 deletion(-) diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 58844b2289..248ca86d86 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -372,7 +372,6 @@ const ( Attr_UsedIPPercent = "used_ip_percent" Attr_UsedMemory = "used_memory" Attr_UserIPAddress = "user_ip_address" - Attr_UserTags = "user_tags" Attr_VCPUs = "vcpus" Attr_Vendor = "vendor" Attr_VirtualCoresAssigned = "virtual_cores_assigned" From 00d1ba674f9825225347afcc4b1a9ea29ee67c9a Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Mon, 16 Sep 2024 11:12:40 -0500 Subject: [PATCH 15/20] Upgrade to beta-16 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 532529b7a3..b2157c2004 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.22.5 require ( github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 - github.com/IBM-Cloud/power-go-client v1.8.0-beta5 + github.com/IBM-Cloud/power-go-client v1.8.0-beta16 github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca github.com/IBM/appconfiguration-go-admin-sdk v0.3.0 github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f diff --git a/go.sum b/go.sum index 159416c5b7..ad777f9c74 100644 --- a/go.sum +++ b/go.sum @@ -118,8 +118,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be/go.mod h1:/7h github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 h1:f2Erqfea1dKpaTFagTJM6W/wnD3JGq/Vn9URh8nuRwk= github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY= github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs= -github.com/IBM-Cloud/power-go-client v1.8.0-beta5 h1:23FxbCYsE4vqBMAQO/8tkksmFu57oXSITVFcyRVgtpg= -github.com/IBM-Cloud/power-go-client v1.8.0-beta5/go.mod h1:oAkZiHX25cmr2Yun5V0q6CpnUemegvSrpcEy/oQcjzU= +github.com/IBM-Cloud/power-go-client v1.8.0-beta16 h1:rIMQsPxmsWA5lFGcliQxKGSKwdLjtJg8lDRM7bn2Z04= +github.com/IBM-Cloud/power-go-client v1.8.0-beta16/go.mod h1:oAkZiHX25cmr2Yun5V0q6CpnUemegvSrpcEy/oQcjzU= github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw= github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4= github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs= From eb935f682d5f102e0a03ae83b64430e51e2f3f52 Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Fri, 20 Sep 2024 11:35:37 -0500 Subject: [PATCH 16/20] Upgrade SDK to v1.8.1 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b2157c2004..a784b178ad 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.22.5 require ( github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 - github.com/IBM-Cloud/power-go-client v1.8.0-beta16 + github.com/IBM-Cloud/power-go-client v1.8.1 github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca github.com/IBM/appconfiguration-go-admin-sdk v0.3.0 github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f diff --git a/go.sum b/go.sum index ad777f9c74..6e1a9cdfea 100644 --- a/go.sum +++ b/go.sum @@ -118,8 +118,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20240719075425-078fcb3a55be/go.mod h1:/7h github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 h1:f2Erqfea1dKpaTFagTJM6W/wnD3JGq/Vn9URh8nuRwk= github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY= github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs= -github.com/IBM-Cloud/power-go-client v1.8.0-beta16 h1:rIMQsPxmsWA5lFGcliQxKGSKwdLjtJg8lDRM7bn2Z04= -github.com/IBM-Cloud/power-go-client v1.8.0-beta16/go.mod h1:oAkZiHX25cmr2Yun5V0q6CpnUemegvSrpcEy/oQcjzU= +github.com/IBM-Cloud/power-go-client v1.8.1 h1:tx1aPJmIQrNru1MD1VHGNasGx3eRIs0zzPZ0KvdFQrg= +github.com/IBM-Cloud/power-go-client v1.8.1/go.mod h1:N4RxrsMUvBQjSQ/qPk0iMZ8zK+fZPRTnHi/gTaASw0g= github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw= github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4= github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs= From 4fa8422064fc1decabfddd9083323795c6720b8e Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Tue, 24 Sep 2024 10:46:18 -0500 Subject: [PATCH 17/20] change list to set --- ibm/service/power/resource_ibm_pi_network.go | 7 ++++--- ibm/service/power/resource_ibm_pi_network_port_attach.go | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_network.go b/ibm/service/power/resource_ibm_pi_network.go index 18dc4a736b..188e17529f 100644 --- a/ibm/service/power/resource_ibm_pi_network.go +++ b/ibm/service/power/resource_ibm_pi_network.go @@ -127,7 +127,8 @@ func ResourceIBMPINetwork() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true, Optional: true, - Type: schema.TypeList, + Set: schema.HashString, + Type: schema.TypeSet, }, //Computed Attributes @@ -171,8 +172,8 @@ func resourceIBMPINetworkCreate(ctx context.Context, d *schema.ResourceData, met } } if tags, ok := d.GetOk(Arg_UserTags); ok { - if len(tags.([]interface{})) > 0 { - body.UserTags = flex.ExpandStringList(tags.([]interface{})) + if len(flex.FlattenSet(tags.(*schema.Set))) > 0 { + body.UserTags = flex.FlattenSet(tags.(*schema.Set)) } } if v, ok := d.GetOk(helpers.PINetworkJumbo); ok { diff --git a/ibm/service/power/resource_ibm_pi_network_port_attach.go b/ibm/service/power/resource_ibm_pi_network_port_attach.go index ee3a9d5139..73efa23c8c 100644 --- a/ibm/service/power/resource_ibm_pi_network_port_attach.go +++ b/ibm/service/power/resource_ibm_pi_network_port_attach.go @@ -68,7 +68,8 @@ func ResourceIBMPINetworkPortAttach() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, ForceNew: true, Optional: true, - Type: schema.TypeList, + Set: schema.HashString, + Type: schema.TypeSet, }, //Computed Attributes @@ -109,8 +110,8 @@ func resourceIBMPINetworkPortAttachCreate(ctx context.Context, d *schema.Resourc nwportBody.IPAddress = ipaddress } if tags, ok := d.GetOk(Arg_UserTags); ok { - if len(tags.([]interface{})) > 0 { - nwportBody.UserTags = flex.ExpandStringList(tags.([]interface{})) + if len(flex.FlattenSet(tags.(*schema.Set))) > 0 { + nwportBody.UserTags = flex.FlattenSet(tags.(*schema.Set)) } } nwportattachBody := &models.NetworkPortUpdate{ From d28a492f5d648ca4b6ef5dc37f543574da603e3d Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Tue, 1 Oct 2024 12:02:38 -0500 Subject: [PATCH 18/20] Add read and update user tags --- .../power/data_source_ibm_pi_network.go | 14 ++++++ .../power/data_source_ibm_pi_networks.go | 18 ++++++- ibm/service/power/ibm_pi_constants.go | 2 + ibm/service/power/resource_ibm_pi_network.go | 16 ++++++- .../power/resource_ibm_pi_network_test.go | 48 +++++++++++++++++++ website/docs/d/pi_network.html.markdown | 1 + website/docs/d/pi_networks.html.markdown | 1 + 7 files changed, 97 insertions(+), 3 deletions(-) diff --git a/ibm/service/power/data_source_ibm_pi_network.go b/ibm/service/power/data_source_ibm_pi_network.go index 0b6e9ce31a..dec8dab0cc 100644 --- a/ibm/service/power/data_source_ibm_pi_network.go +++ b/ibm/service/power/data_source_ibm_pi_network.go @@ -5,10 +5,12 @@ package power import ( "context" + "log" "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/power-go-client/helpers" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -96,6 +98,13 @@ func DataSourceIBMPINetwork() *schema.Resource { Description: "The percentage of IP addresses used.", Type: schema.TypeFloat, }, + Attr_UserTags: { + Computed: true, + Description: "List of user tags attached to the resource.", + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + Type: schema.TypeSet, + }, Attr_VLanID: { Computed: true, Description: "The VLAN ID that the network is connected to.", @@ -129,6 +138,11 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met } if networkdata.Crn != "" { d.Set(Attr_CRN, networkdata.Crn) + tags, err := flex.GetGlobalTagsUsingCRN(meta, string(networkdata.Crn), "", UserTagType) + if err != nil { + log.Printf("Error on get of pi network (%s) user_tags: %s", *networkdata.NetworkID, err) + } + d.Set(Attr_UserTags, tags) } if len(networkdata.DNSServers) > 0 { d.Set(Attr_DNS, networkdata.DNSServers) diff --git a/ibm/service/power/data_source_ibm_pi_networks.go b/ibm/service/power/data_source_ibm_pi_networks.go index b1ce19e6da..db5c3ed5c2 100644 --- a/ibm/service/power/data_source_ibm_pi_networks.go +++ b/ibm/service/power/data_source_ibm_pi_networks.go @@ -5,10 +5,12 @@ package power import ( "context" + "log" "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/power-go-client/power/models" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -73,6 +75,13 @@ func DataSourceIBMPINetworks() *schema.Resource { Description: "The type of network.", Type: schema.TypeString, }, + Attr_UserTags: { + Computed: true, + Description: "List of user tags attached to the resource.", + Elem: &schema.Schema{Type: schema.TypeString}, + Set: schema.HashString, + Type: schema.TypeSet, + }, Attr_VLanID: { Computed: true, Description: "The VLAN ID that the network is connected to.", @@ -102,12 +111,12 @@ func dataSourceIBMPINetworksRead(ctx context.Context, d *schema.ResourceData, me var clientgenU, _ = uuid.GenerateUUID() d.SetId(clientgenU) - d.Set(Attr_Networks, flattenNetworks(networkdata.Networks)) + d.Set(Attr_Networks, flattenNetworks(networkdata.Networks, meta)) return nil } -func flattenNetworks(list []*models.NetworkReference) []map[string]interface{} { +func flattenNetworks(list []*models.NetworkReference, meta interface{}) []map[string]interface{} { result := make([]map[string]interface{}, 0, len(list)) for _, i := range list { l := map[string]interface{}{ @@ -123,6 +132,11 @@ func flattenNetworks(list []*models.NetworkReference) []map[string]interface{} { if i.Crn != "" { l[Attr_CRN] = i.Crn + tags, err := flex.GetGlobalTagsUsingCRN(meta, string(i.Crn), "", UserTagType) + if err != nil { + log.Printf("Error on get of pi network (%s) user_tags: %s", *i.NetworkID, err) + } + l[Attr_UserTags] = tags } result = append(result, l) } diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 248ca86d86..52d828de19 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -372,6 +372,7 @@ const ( Attr_UsedIPPercent = "used_ip_percent" Attr_UsedMemory = "used_memory" Attr_UserIPAddress = "user_ip_address" + Attr_UserTags = "user_tags" Attr_VCPUs = "vcpus" Attr_Vendor = "vendor" Attr_VirtualCoresAssigned = "virtual_cores_assigned" @@ -444,6 +445,7 @@ const ( Shared = "shared" Soft = "soft" Suffix = "suffix" + UserTagType = "user" Vlan = "vlan" vSCSI = "vSCSI" Warning = "WARNING" diff --git a/ibm/service/power/resource_ibm_pi_network.go b/ibm/service/power/resource_ibm_pi_network.go index 188e17529f..d89b6ee74a 100644 --- a/ibm/service/power/resource_ibm_pi_network.go +++ b/ibm/service/power/resource_ibm_pi_network.go @@ -125,7 +125,6 @@ func ResourceIBMPINetwork() *schema.Resource { Arg_UserTags: { Description: "The user tags attached to this resource.", Elem: &schema.Schema{Type: schema.TypeString}, - ForceNew: true, Optional: true, Set: schema.HashString, Type: schema.TypeSet, @@ -261,6 +260,11 @@ func resourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, meta } if networkdata.Crn != "" { d.Set(Attr_CRN, networkdata.Crn) + tags, err := flex.GetGlobalTagsUsingCRN(meta, string(networkdata.Crn), "", UserTagType) + if err != nil { + log.Printf("Error on get of pi network (%s) pi_user_tags: %s", *networkdata.NetworkID, err) + } + d.Set(Arg_UserTags, tags) } d.Set("network_id", networkdata.NetworkID) d.Set(helpers.PINetworkCidr, networkdata.Cidr) @@ -329,6 +333,16 @@ func resourceIBMPINetworkUpdate(ctx context.Context, d *schema.ResourceData, met } } + if d.HasChange(Arg_UserTags) { + if crn, ok := d.GetOk(Attr_CRN); ok { + oldList, newList := d.GetChange(Arg_UserTags) + err := flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, crn.(string), "", UserTagType) + if err != nil { + log.Printf("Error on update of pi network (%s) pi_user_tags: %s", networkID, err) + } + } + } + return resourceIBMPINetworkRead(ctx, d, meta) } diff --git a/ibm/service/power/resource_ibm_pi_network_test.go b/ibm/service/power/resource_ibm_pi_network_test.go index 98fac89171..b62dac6513 100644 --- a/ibm/service/power/resource_ibm_pi_network_test.go +++ b/ibm/service/power/resource_ibm_pi_network_test.go @@ -152,6 +152,43 @@ func TestAccIBMPINetworkDHCPbasic(t *testing.T) { }) } +func TestAccIBMPINetworkUserTags(t *testing.T) { + name := fmt.Sprintf("tf-pi-network-%d", acctest.RandIntRange(10, 100)) + networkRes := "ibm_pi_network.power_networks" + userTagsString := `["env:dev","test_tag"]` + userTagsStringUpdated := `["env:dev","test_tag","test_tag2"]` + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMPINetworkDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMPINetworkUserTagsConfig(name, userTagsString), + Check: resource.ComposeTestCheckFunc( + testAccCheckIBMPINetworkExists(networkRes), + resource.TestCheckResourceAttr(networkRes, "pi_network_name", name), + resource.TestCheckResourceAttrSet(networkRes, "id"), + resource.TestCheckResourceAttr(networkRes, "pi_user_tags.#", "2"), + resource.TestCheckTypeSetElemAttr(networkRes, "pi_user_tags.*", "env:dev"), + resource.TestCheckTypeSetElemAttr(networkRes, "pi_user_tags.*", "test_tag"), + ), + }, + { + Config: testAccCheckIBMPINetworkUserTagsConfig(name, userTagsStringUpdated), + Check: resource.ComposeTestCheckFunc( + testAccCheckIBMPINetworkExists(networkRes), + resource.TestCheckResourceAttr(networkRes, "pi_network_name", name), + resource.TestCheckResourceAttrSet(networkRes, "id"), + resource.TestCheckResourceAttr(networkRes, "pi_user_tags.#", "3"), + resource.TestCheckTypeSetElemAttr(networkRes, "pi_user_tags.*", "env:dev"), + resource.TestCheckTypeSetElemAttr(networkRes, "pi_user_tags.*", "test_tag"), + resource.TestCheckTypeSetElemAttr(networkRes, "pi_user_tags.*", "test_tag2"), + ), + }, + }, + }) +} + func testAccCheckIBMPINetworkDestroy(s *terraform.State) error { sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession() if err != nil { @@ -290,3 +327,14 @@ func testAccCheckIBMPINetworkConfigGatewayDHCPUpdateDNS(name string) string { } `, acc.Pi_cloud_instance_id, name) } + +func testAccCheckIBMPINetworkUserTagsConfig(name string, userTagsString string) string { + return fmt.Sprintf(` + resource "ibm_pi_network" "power_networks" { + pi_cloud_instance_id = "%s" + pi_network_name = "%s" + pi_network_type = "pub-vlan" + pi_user_tags = %s + } + `, acc.Pi_cloud_instance_id, name, userTagsString) +} diff --git a/website/docs/d/pi_network.html.markdown b/website/docs/d/pi_network.html.markdown index 317d0a1c4b..befcce7a1c 100644 --- a/website/docs/d/pi_network.html.markdown +++ b/website/docs/d/pi_network.html.markdown @@ -52,4 +52,5 @@ In addition to all argument reference list, you can access the following attribu - `type` - (String) The type of network. - `used_ip_count` - (Float) The number of used IP addresses. - `used_ip_percent` - (Float) The percentage of IP addresses used. +- `user_tags` - (List) List of user tags attached to the resource. - `vlan_id` - (String) The VLAN ID that the network is connected to. diff --git a/website/docs/d/pi_networks.html.markdown b/website/docs/d/pi_networks.html.markdown index 4230592156..2b030d6165 100644 --- a/website/docs/d/pi_networks.html.markdown +++ b/website/docs/d/pi_networks.html.markdown @@ -49,4 +49,5 @@ In addition to all argument reference list, you can access the following attribu - `name` - (String) The name of a network. - `network_id` - (String) The ID of the network. - `type` - (String) The type of network. + - `user_tags` - (List) List of user tags attached to the resource. - `vlan_id` - (String) The VLAN ID that the network is connected to. From c7600314a6c0863049fc49ab7194b415afbb2ace Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Tue, 1 Oct 2024 17:34:48 -0500 Subject: [PATCH 19/20] Add user tags update to create --- ibm/service/power/resource_ibm_pi_network.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ibm/service/power/resource_ibm_pi_network.go b/ibm/service/power/resource_ibm_pi_network.go index d89b6ee74a..f21b29da35 100644 --- a/ibm/service/power/resource_ibm_pi_network.go +++ b/ibm/service/power/resource_ibm_pi_network.go @@ -239,6 +239,16 @@ func resourceIBMPINetworkCreate(ctx context.Context, d *schema.ResourceData, met return diag.FromErr(err) } + if _, ok := d.GetOk(Arg_UserTags); ok { + if networkResponse.Crn != "" { + oldList, newList := d.GetChange(Arg_UserTags) + err := flex.UpdateGlobalTagsUsingCRN(oldList, newList, meta, string(networkResponse.Crn), "", UserTagType) + if err != nil { + log.Printf("Error on update of pi snapshot (%s) pi_user_tags during creation: %s", networkID, err) + } + } + } + return resourceIBMPINetworkRead(ctx, d, meta) } From ab5e103c1d15dbb45c7d5970975410001b021bbd Mon Sep 17 00:00:00 2001 From: Alexander Kita Date: Thu, 3 Oct 2024 11:23:51 -0500 Subject: [PATCH 20/20] Remove length check from user tags argument --- ibm/service/power/resource_ibm_pi_network.go | 4 +--- ibm/service/power/resource_ibm_pi_network_port_attach.go | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/ibm/service/power/resource_ibm_pi_network.go b/ibm/service/power/resource_ibm_pi_network.go index f21b29da35..3670aa3d10 100644 --- a/ibm/service/power/resource_ibm_pi_network.go +++ b/ibm/service/power/resource_ibm_pi_network.go @@ -171,9 +171,7 @@ func resourceIBMPINetworkCreate(ctx context.Context, d *schema.ResourceData, met } } if tags, ok := d.GetOk(Arg_UserTags); ok { - if len(flex.FlattenSet(tags.(*schema.Set))) > 0 { - body.UserTags = flex.FlattenSet(tags.(*schema.Set)) - } + body.UserTags = flex.FlattenSet(tags.(*schema.Set)) } if v, ok := d.GetOk(helpers.PINetworkJumbo); ok { body.Jumbo = v.(bool) diff --git a/ibm/service/power/resource_ibm_pi_network_port_attach.go b/ibm/service/power/resource_ibm_pi_network_port_attach.go index 73efa23c8c..99bb5adb05 100644 --- a/ibm/service/power/resource_ibm_pi_network_port_attach.go +++ b/ibm/service/power/resource_ibm_pi_network_port_attach.go @@ -110,9 +110,7 @@ func resourceIBMPINetworkPortAttachCreate(ctx context.Context, d *schema.Resourc nwportBody.IPAddress = ipaddress } if tags, ok := d.GetOk(Arg_UserTags); ok { - if len(flex.FlattenSet(tags.(*schema.Set))) > 0 { - nwportBody.UserTags = flex.FlattenSet(tags.(*schema.Set)) - } + nwportBody.UserTags = flex.FlattenSet(tags.(*schema.Set)) } nwportattachBody := &models.NetworkPortUpdate{ Description: &description,