@@ -59,6 +59,52 @@ func testAccCheckIBMPINetworkAddressGroupConfigBasic(name string) string {
5959 ` , acc .Pi_cloud_instance_id , name )
6060}
6161
62+ func TestAccIBMPINetworkAddressGroupUserTags (t * testing.T ) {
63+ name := fmt .Sprintf ("tf-nag-name-%d" , acctest .RandIntRange (10 , 100 ))
64+ nagRes := "ibm_pi_network_address_group.network_address_group"
65+ userTagsString := `["env:dev", "test_tag"]`
66+ userTagsStringUpdated := `["env:dev", "test_tag", "ibm"]`
67+ resource .Test (t , resource.TestCase {
68+ PreCheck : func () { acc .TestAccPreCheck (t ) },
69+ Providers : acc .TestAccProviders ,
70+ CheckDestroy : testAccCheckIBMPINetworkAddressGroupDestroy ,
71+ Steps : []resource.TestStep {
72+ {
73+ Config : testAccCheckIBMPINetworkAddressGroupConfigUserTags (name , userTagsString ),
74+ Check : resource .ComposeAggregateTestCheckFunc (
75+ testAccCheckIBMPINetworkAddressGroupExists (nagRes ),
76+ resource .TestCheckResourceAttrSet (nagRes , power .Attr_ID ),
77+ resource .TestCheckResourceAttrSet (nagRes , power .Attr_CRN ),
78+ resource .TestCheckResourceAttr (nagRes , power .Arg_UserTags + ".#" , "2" ),
79+ resource .TestCheckTypeSetElemAttr (nagRes , power .Arg_UserTags + ".*" , "env:dev" ),
80+ resource .TestCheckTypeSetElemAttr (nagRes , power .Arg_UserTags + ".*" , "test_tag" ),
81+ ),
82+ },
83+ {
84+ Config : testAccCheckIBMPINetworkAddressGroupConfigUserTags (name , userTagsStringUpdated ),
85+ Check : resource .ComposeAggregateTestCheckFunc (
86+ resource .TestCheckResourceAttrSet (nagRes , power .Attr_ID ),
87+ resource .TestCheckResourceAttrSet (nagRes , power .Attr_CRN ),
88+ resource .TestCheckResourceAttr (nagRes , power .Arg_UserTags + ".#" , "3" ),
89+ resource .TestCheckTypeSetElemAttr (nagRes , power .Arg_UserTags + ".*" , "env:dev" ),
90+ resource .TestCheckTypeSetElemAttr (nagRes , power .Arg_UserTags + ".*" , "test_tag" ),
91+ resource .TestCheckTypeSetElemAttr (nagRes , power .Arg_UserTags + ".*" , "ibm" ),
92+ ),
93+ },
94+ },
95+ })
96+ }
97+
98+ func testAccCheckIBMPINetworkAddressGroupConfigUserTags (name string , userTagsString string ) string {
99+ return fmt .Sprintf (`
100+ resource "ibm_pi_network_address_group" "network_address_group" {
101+ pi_cloud_instance_id = "%[1]s"
102+ pi_name = "%[2]s"
103+ pi_user_tags = %[3]s
104+ }
105+ ` , acc .Pi_cloud_instance_id , name , userTagsString )
106+ }
107+
62108func testAccCheckIBMPINetworkAddressGroupExists (n string ) resource.TestCheckFunc {
63109
64110 return func (s * terraform.State ) error {
0 commit comments