Skip to content

Commit

Permalink
Merge pull request #632 from terraform-providers/b-reset-tag-found-flag
Browse files Browse the repository at this point in the history
Find tag changes when first tag is changed
  • Loading branch information
bill-rich authored Oct 11, 2018
2 parents 22226ed + d43a726 commit d842397
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
94 changes: 94 additions & 0 deletions vsphere/resource_vsphere_folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,42 @@ func TestAccResourceVSphereFolder_modifyTags(t *testing.T) {
})
}

func TestAccResourceVSphereFolder_modifyTagsMultiStage(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccResourceVSphereFolderExists(false),
Steps: []resource.TestStep{
{
Config: testAccResourceVSphereFolderConfigTag(),
Check: resource.ComposeTestCheckFunc(
testAccResourceVSphereFolderExists(true),
testAccResourceVSphereFolderHasName(testAccResourceVSphereFolderConfigExpectedName),
testAccResourceVSphereFolderHasType(folder.VSphereFolderTypeVM),
),
},
{
Config: testAccResourceVSphereFolderConfigAllTag(),
Check: resource.ComposeTestCheckFunc(
testAccResourceVSphereFolderExists(true),
testAccResourceVSphereFolderHasName(testAccResourceVSphereFolderConfigExpectedName),
testAccResourceVSphereFolderHasType(folder.VSphereFolderTypeVM),
),
},
{
Config: testAccResourceVSphereFolderConfigMultiTag(),
Check: resource.ComposeTestCheckFunc(
testAccResourceVSphereFolderExists(true),
testAccResourceVSphereFolderHasName(testAccResourceVSphereFolderConfigExpectedName),
testAccResourceVSphereFolderHasType(folder.VSphereFolderTypeVM),
),
},
},
})
}

func TestAccResourceVSphereFolder_customAttributes(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down Expand Up @@ -756,6 +792,64 @@ resource "vsphere_folder" "folder" {
)
}

func testAccResourceVSphereFolderConfigAllTag() string {
return fmt.Sprintf(`
variable "datacenter" {
default = "%s"
}
variable "folder_name" {
default = "%s"
}
variable "folder_type" {
default = "%s"
}
variable "extra_tags" {
default = [
"terraform-test-thing1",
"terraform-test-thing2",
]
}
data "vsphere_datacenter" "dc" {
name = "${var.datacenter}"
}
resource "vsphere_tag_category" "terraform-test-category" {
name = "terraform-test-tag-category"
cardinality = "MULTIPLE"
associable_types = [
"Folder",
]
}
resource "vsphere_tag" "terraform-test-tag" {
name = "terraform-test-tag"
category_id = "${vsphere_tag_category.terraform-test-category.id}"
}
resource "vsphere_tag" "terraform-test-tags-alt" {
count = "${length(var.extra_tags)}"
name = "${var.extra_tags[count.index]}"
category_id = "${vsphere_tag_category.terraform-test-category.id}"
}
resource "vsphere_folder" "folder" {
path = "${var.folder_name}"
type = "${var.folder_type}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
tags = ["${vsphere_tag.terraform-test-tag.id}", "${vsphere_tag.terraform-test-tags-alt.*.id}"]
}
`,
os.Getenv("VSPHERE_DATACENTER"),
testAccResourceVSphereFolderConfigExpectedName,
folder.VSphereFolderTypeVM,
)
}

func testAccResourceVSphereFolderConfigMultiTag() string {
return fmt.Sprintf(`
variable "datacenter" {
Expand Down
1 change: 1 addition & 0 deletions vsphere/tags_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func (p *tagDiffProcessor) diff(a, b []string) []string {
if !found {
c = append(c, v1)
}
found = false
}
return c
}
Expand Down

0 comments on commit d842397

Please sign in to comment.