@@ -4325,3 +4325,137 @@ func testAccCheckIBMISInstanceConfigWithProfileAndBandwidth(vpcname, subnetname,
43254325 wait_before_delete = false
43264326 }` , vpcname , subnetname , acc .ISZoneName , acc .ISCIDR , sshname , publicKey , name , acc .IsImage , profile , bandwidth , prefix , acc .ISZoneName )
43274327}
4328+
4329+ // volume tags
4330+
4331+ func TestAccIBMISInstance_volumeTags (t * testing.T ) {
4332+ var instance string
4333+ prefix := fmt .Sprintf ("tf-inst-%d" , acctest .RandIntRange (10 , 100 ))
4334+ vpcname := fmt .Sprintf ("%s-vpc" , prefix )
4335+ name := fmt .Sprintf ("%s-instance" , prefix )
4336+ subnetname := fmt .Sprintf ("%s-subnet" , prefix )
4337+ sshname := fmt .Sprintf ("%s-ssh" , prefix )
4338+ dataVolumeName := fmt .Sprintf ("%s-data-volume" , prefix )
4339+
4340+ publicKey := strings .TrimSpace (`
4341+ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBEGGaXOYllPYQE+Qj8MiRo7DOJK9j7K8OQE9VWL5VjZ terraform-test-key
4342+ ` )
4343+
4344+ resource .Test (t , resource.TestCase {
4345+ PreCheck : func () { acc .TestAccPreCheck (t ) },
4346+ Providers : acc .TestAccProviders ,
4347+ CheckDestroy : testAccCheckIBMISInstanceDestroy ,
4348+ Steps : []resource.TestStep {
4349+ {
4350+ Config : testAccCheckIBMISInstanceVolumeTagsConfig (prefix , vpcname , subnetname , sshname , publicKey , name , dataVolumeName ),
4351+ Check : resource .ComposeTestCheckFunc (
4352+ testAccCheckIBMISInstanceExists ("ibm_is_instance.testacc_instance" , instance ),
4353+ // Instance checks
4354+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "name" , name ),
4355+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "profile" , "bx2-2x8" ),
4356+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "zone" , acc .ISZoneName ),
4357+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "tags.#" , "1" ),
4358+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "tags.0" , "tagged:byuser" ),
4359+
4360+ // Volume prototype checks
4361+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "volume_prototypes.#" , "1" ),
4362+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "volume_prototypes.0.volume_name" , dataVolumeName ),
4363+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "volume_prototypes.0.volume_capacity" , "141" ),
4364+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "volume_prototypes.0.volume_profile" , "general-purpose" ),
4365+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "volume_prototypes.0.delete_volume_on_instance_delete" , "true" ),
4366+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "volume_prototypes.0.volume_tags.#" , "1" ),
4367+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "volume_prototypes.0.volume_tags.0" , "tagged:byuser" ),
4368+
4369+ // Boot volume checks
4370+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "boot_volume.#" , "1" ),
4371+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "boot_volume.0.tags.#" , "1" ),
4372+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "boot_volume.0.tags.0" , "tagged:byuser" ),
4373+ resource .TestCheckResourceAttrSet ("ibm_is_instance.testacc_instance" , "boot_volume.0.volume_id" ),
4374+
4375+ // Primary network attachment checks
4376+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "primary_network_attachment.#" , "1" ),
4377+ resource .TestCheckResourceAttr ("ibm_is_instance.testacc_instance" , "primary_network_attachment.0.name" , fmt .Sprintf ("%s-pna" , prefix )),
4378+ resource .TestCheckResourceAttrSet ("ibm_is_instance.testacc_instance" , "primary_network_attachment.0.virtual_network_interface.0.subnet" ),
4379+
4380+ // Data source checks for boot volume tags
4381+ resource .TestCheckResourceAttr ("data.ibm_is_volume.boot" , "tags.0" , "tagged:byuser" ),
4382+ // Data source checks for data volume tags
4383+ resource .TestCheckResourceAttr ("data.ibm_is_volume.data" , "tags.0" , "tagged:byuser" ),
4384+ ),
4385+ },
4386+ },
4387+ })
4388+ }
4389+
4390+ func testAccCheckIBMISInstanceVolumeTagsConfig (prefix , vpcname , subnetname , sshname , publicKey , name , dataVolumeName string ) string {
4391+ return fmt .Sprintf (`
4392+ # VPC Infrastructure
4393+ resource "ibm_is_vpc" "is_vpc" {
4394+ name = "%s"
4395+ }
4396+
4397+ resource "ibm_is_subnet" "is_subnet" {
4398+ name = "%s"
4399+ vpc = ibm_is_vpc.is_vpc.id
4400+ total_ipv4_address_count = 64
4401+ zone = "%s"
4402+ }
4403+
4404+ # Data sources
4405+ data "ibm_is_image" "is_image" {
4406+ name = "ibm-ubuntu-20-04-6-minimal-amd64-6"
4407+ }
4408+
4409+ # SSH Key
4410+ resource "ibm_is_ssh_key" "is_key" {
4411+ name = "%s"
4412+ public_key = "%s"
4413+ type = "ed25519"
4414+ }
4415+
4416+ # Instance with tagged volumes
4417+ resource "ibm_is_instance" "testacc_instance" {
4418+ name = "%s"
4419+ image = data.ibm_is_image.is_image.id
4420+ profile = "bx2-2x8"
4421+
4422+ primary_network_attachment {
4423+ name = "%s-pna"
4424+ virtual_network_interface {
4425+ subnet = ibm_is_subnet.is_subnet.id
4426+ }
4427+ }
4428+
4429+ # Boot volume with tags
4430+ boot_volume {
4431+ tags = ["tagged:byuser"]
4432+ }
4433+
4434+ # Data volume with tags
4435+ volume_prototypes {
4436+ name = "%s"
4437+ delete_volume_on_instance_delete = true
4438+ volume_name = "%s"
4439+ volume_capacity = 141
4440+ volume_profile = "general-purpose"
4441+ volume_tags = ["tagged:byuser"]
4442+ }
4443+
4444+ vpc = ibm_is_vpc.is_vpc.id
4445+ zone = ibm_is_subnet.is_subnet.zone
4446+ keys = [ibm_is_ssh_key.is_key.id]
4447+ wait_before_delete = false
4448+
4449+ tags = ["tagged:byuser"]
4450+ }
4451+
4452+ # Data sources to verify volume tags
4453+ data "ibm_is_volume" "boot" {
4454+ identifier = ibm_is_instance.testacc_instance.boot_volume.0.volume_id
4455+ }
4456+
4457+ data "ibm_is_volume" "data" {
4458+ name = ibm_is_instance.testacc_instance.volume_prototypes.0.volume_name
4459+ }
4460+ ` , vpcname , subnetname , acc .ISZoneName , sshname , publicKey , name , prefix , dataVolumeName , dataVolumeName )
4461+ }
0 commit comments