Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Tags in Instance, Inst Temp, Inst Vol Attmnt #3993

Merged
merged 1 commit into from
Sep 9, 2022

Conversation

SunithaGudisagarIBM
Copy link
Collaborator

@SunithaGudisagarIBM SunithaGudisagarIBM commented Aug 27, 2022

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates OR Closes #0000

Output from acceptance testing:

$ make testacc TEST=./ibm/service/vpc TESTARGS='-run=TestAccIBMISInstanceTemplate_WithVolumeAttachmentUserTag'
$ make testacc TEST=./ibm/service/vpc TESTARGS='-run=TestAccIBMISInstance_bootVolumeUserTags'
$ make testacc TEST=./ibm/service/vpc TESTARGS='-run=TestAccIBMISInstanceVolumeAttachment_userTag'
resource "ibm_is_instance" "testacc_instance" {
  name    = "sunitha-instance-new"
  image   = "r134-c31deded-722d-4950-9d05-862fecb831b1"
  profile = "cx2-2x4"
  boot_volume {
    size = 220
    tags = ["tag-0", "tag-1"]
  }
  primary_network_interface {
    subnet = "0716-4b83a399-a222-4736-a0e0-44cd802a7e64"
  }
  user_data = "a"
  vpc       = "r134-060fbfe6-4d0f-47b0-b9c5-94da8e719e22"
  zone      = "us-south-1"
  keys      = ["r134-8ddfdc65-73ac-48e1-864b-870f29bd35ca"]
}

resource "ibm_is_instance_volume_attachment" "testacc_att" {
  instance = ibm_is_instance.testacc_instance.id

  name     = "volume-attachment"
  profile  = "custom"
  capacity = 20
  iops     = 600
  tags     = ["tag-sunitha","test"]

  delete_volume_on_instance_delete = true
  volume_name                      = "sunitha-volume-inst-vol-attmnt"
}
sunitha@dhcp-9-239-8-182 vpc-ibm-lb-config % terraform apply -auto-approve
ibm_is_instance.testacc_instance: Refreshing state... [id=0716_c8a9c7f3-bbec-4994-87f1-21096566acd6]
ibm_is_instance_volume_attachment.testacc_att: Refreshing state... [id=0716_c8a9c7f3-bbec-4994-87f1-21096566acd6/0716-9bd05fef-6920-48f7-8c50-a9cea3d47ade]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # ibm_is_instance_volume_attachment.testacc_att will be updated in-place
  ~ resource "ibm_is_instance_volume_attachment" "testacc_att" {
        id                                 = "0716_c8a9c7f3-bbec-4994-87f1-21096566acd6/0716-9bd05fef-6920-48f7-8c50-a9cea3d47ade"
        name                               = "volume-attachment"
      ~ tags                               = [
          + "test",
            # (1 unchanged element hidden)
        ]
        # (15 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
ibm_is_instance_volume_attachment.testacc_att: Modifying... [id=0716_c8a9c7f3-bbec-4994-87f1-21096566acd6/0716-9bd05fef-6920-48f7-8c50-a9cea3d47ade]
ibm_is_instance_volume_attachment.testacc_att: Still modifying... [id=0716_c8a9c7f3-bbec-4994-87f1-21096566ac...6-9bd05fef-6920-48f7-8c50-a9cea3d47ade, 10s elapsed]
ibm_is_instance_volume_attachment.testacc_att: Still modifying... [id=0716_c8a9c7f3-bbec-4994-87f1-21096566ac...6-9bd05fef-6920-48f7-8c50-a9cea3d47ade, 20s elapsed]
ibm_is_instance_volume_attachment.testacc_att: Modifications complete after 27s [id=0716_c8a9c7f3-bbec-4994-87f1-21096566acd6/0716-9bd05fef-6920-48f7-8c50-a9cea3d47ade]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

screen1

screen2

screen3

data "ibm_is_instance_template" "instance_template_data" {
name = "cli-tpl-1"
}
data "ibm_is_instance_templates" "instance_templates_data" {
}

screen5

screen4

@SunithaGudisagarIBM SunithaGudisagarIBM marked this pull request as ready for review August 27, 2022 11:20
@SunithaGudisagarIBM
Copy link
Collaborator Author

@hkantare we have reviewed internally this feature please find the PR ibm-vpc#162 here.. Can you please review and merge this PR...

@@ -597,6 +614,9 @@ func dataSourceIBMISInstanceTemplateRead(context context.Context, d *schema.Reso
volProfInst := volProfIntf.(*vpcv1.VolumeProfileIdentity)
bootVol[isInstanceTemplateBootProfile] = volProfInst.Name
}
if instance.BootVolumeAttachment.Volume.UserTags != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check if any
instance.BootVolumeAttachment != nil && instance.BootVolumeAttachment.Volume != nil && instance.BootVolumeAttachment.Volume.UserTags != nil ..just to eliminate possibility of nil pointer expection

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the nill checks have happened in the above if lines..

		if instance.BootVolumeAttachment != nil {
			bootVolList := make([]map[string]interface{}, 0)
			bootVol := map[string]interface{}{}

			bootVol[isInstanceTemplateDeleteVol] = *instance.BootVolumeAttachment.DeleteVolumeOnInstanceDelete
			if instance.BootVolumeAttachment.Volume != nil {
				volumeIntf := instance.BootVolumeAttachment.Volume
				bootVol[isInstanceTemplateName] = volumeIntf.Name
				bootVol[isInstanceTemplateVol] = volumeIntf.Name
				bootVol[isInstanceTemplateBootSize] = volumeIntf.Capacity
				if instance.BootVolumeAttachment.Volume.Profile != nil {
					volProfIntf := instance.BootVolumeAttachment.Volume.Profile
					volProfInst := volProfIntf.(*vpcv1.VolumeProfileIdentity)
					bootVol[isInstanceTemplateBootProfile] = volProfInst.Name
				}
				if instance.BootVolumeAttachment.Volume.UserTags != nil {
					bootVol[isInstanceTemplateBootVolumeTags] = instance.BootVolumeAttachment.Volume.UserTags
				}
			}
			bootVolList = append(bootVolList, bootVol)
			d.Set(isInstanceTemplateBootVolumeAttachment, bootVolList)
		}

isInstanceTemplateVolAttTags: {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why forcenew to true we don't have update support?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No harini, other fields in the same block has the same structure.
https://pages.github.ibm.com/vpc/vpc-spec-artifacts/branch/master/public/2022-03-29.html#/Instances/update_instance_template

						isInstanceTemplateVolAttVolPrototype: {
							Type:     schema.TypeList,
							MaxItems: 1,
							MinItems: 1,
							Optional: true,
							ForceNew: true,
							Elem: &schema.Resource{
								Schema: map[string]*schema.Schema{
									isInstanceTemplateVolAttVolIops: {
										Type:        schema.TypeInt,
										Optional:    true,
										ForceNew:    true,
										Description: "The maximum I/O operations per second (IOPS) for the volume.",
									},
.
.
..
.
.

									isInstanceTemplateVolAttTags: {
										Type:        schema.TypeSet,
										Optional:    true,
										ForceNew:    true,
										Elem:        &schema.Schema{Type: schema.TypeString, ValidateFunc: validate.InvokeValidator("ibm_is_volume", "tags")},
										Set:         flex.ResourceIBMVPCHash,
										Description: "UserTags for the volume instance",
									},
								},
							},
						},

@@ -437,6 +448,14 @@ func ResourceIBMISInstanceTemplate() *schema.Resource {
Optional: true,
Computed: true,
},
isInstanceTemplateBootVolumeTags: {
Type: schema.TypeSet,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have update support here?

Copy link
Collaborator Author

@SunithaGudisagarIBM SunithaGudisagarIBM Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://pages.github.ibm.com/vpc/vpc-spec-artifacts/branch/master/public/2022-03-29.html#/Instances/update_instance_template
We dont have update support here.. which is similar behaviour with the other fields.

ibm/service/vpc/resource_ibm_is_instance_template.go Outdated Show resolved Hide resolved
@hkantare
Copy link
Collaborator

hkantare commented Sep 8, 2022

Test existing basic testcases also and share the results

@SunithaGudisagarIBM
Copy link
Collaborator Author

make testacc TEST=./ibm/service/vpc TESTARGS='-run=TestAccIBMISInstance_basic'
make testacc TEST=./ibm/service/vpc TESTARGS='-run=TestAccIBMISInstanceTemplate_basic'
make testacc TEST=./ibm/service/vpc TESTARGS='-run=TestAccIBMISInstanceVolumeAttachment_basic'

Screenshot 2022-09-08 at 6 35 33 PM

Screenshot 2022-09-08 at 6 39 09 PM

Screenshot 2022-09-08 at 6 49 48 PM

@hkantare hkantare merged commit 7c33674 into IBM-Cloud:master Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants