@@ -594,3 +594,121 @@ resource "tfe_workspace_settings" "test" {
594
594
}
595
595
`
596
596
}
597
+
598
+ func TestAccTFEWorkspaceSettings_preservesWorkspaceTagsOnFirstApply (t * testing.T ) {
599
+ rInt := rand .New (rand .NewSource (time .Now ().UnixNano ())).Int ()
600
+
601
+ configStep := fmt .Sprintf (`
602
+ resource "tfe_organization" "test" {
603
+ name = "tst-tfeprovider-%d"
604
+
605
+ }
606
+
607
+ resource "tfe_project" "test" {
608
+ organization = tfe_organization.test.name
609
+ name = "tfe-provider-test-%d"
610
+ tags = { projectTag = "valueA" }
611
+ }
612
+
613
+ resource "tfe_workspace" "test" {
614
+ name = "tfe-provider-test-workspace-%d"
615
+ organization = tfe_organization.test.name
616
+ project_id = tfe_project.test.id
617
+ tags = { app = "web" } # workspace-level tag
618
+ }
619
+
620
+ resource "tfe_workspace_settings" "test" {
621
+ workspace_id = tfe_workspace.test.id
622
+ }
623
+ ` , rInt , rInt , rInt )
624
+
625
+ resource .Test (t , resource.TestCase {
626
+ PreCheck : func () { testAccPreCheck (t ) },
627
+ ProtoV6ProviderFactories : testAccMuxedProviders ,
628
+ Steps : []resource.TestStep {
629
+ {
630
+ Config : configStep ,
631
+ Check : resource .ComposeTestCheckFunc (
632
+ resource .TestCheckResourceAttr ("tfe_workspace_settings.test" , "effective_tags.%" , "2" ),
633
+ resource .TestCheckResourceAttr ("tfe_workspace_settings.test" , "effective_tags.projectTag" , "valueA" ),
634
+ resource .TestCheckResourceAttr ("tfe_workspace_settings.test" , "effective_tags.app" , "web" ),
635
+ ),
636
+ },
637
+ },
638
+ })
639
+ }
640
+
641
+ func TestAccTFEWorkspaceSettings_explicitEmptyClearsWorkspaceTags (t * testing.T ) {
642
+ rInt := rand .New (rand .NewSource (time .Now ().UnixNano ())).Int ()
643
+
644
+ configStep1 := fmt .Sprintf (`
645
+ resource "tfe_organization" "test" {
646
+ name = "tst-tfeprovider-%d"
647
+
648
+ }
649
+
650
+ resource "tfe_project" "test" {
651
+ organization = tfe_organization.test.name
652
+ name = "tfe-provider-test-%d"
653
+ tags = { projectTag = "valueA" }
654
+ }
655
+
656
+ resource "tfe_workspace" "test" {
657
+ name = "tfe-provider-test-workspace-%d"
658
+ organization = tfe_organization.test.name
659
+ project_id = tfe_project.test.id
660
+ tags = { app = "web" } # workspace-level tag
661
+ }
662
+
663
+ resource "tfe_workspace_settings" "test" {
664
+ workspace_id = tfe_workspace.test.id
665
+ }
666
+ ` , rInt , rInt , rInt )
667
+
668
+ configStep2 := fmt .Sprintf (`
669
+ resource "tfe_organization" "test" {
670
+ name = "tst-tfeprovider-%d"
671
+
672
+ }
673
+
674
+ resource "tfe_project" "test" {
675
+ organization = tfe_organization.test.name
676
+ name = "tfe-provider-test-%d"
677
+ tags = { projectTag = "valueA" }
678
+ }
679
+
680
+ resource "tfe_workspace" "test" {
681
+ name = "tfe-provider-test-workspace-%d"
682
+ organization = tfe_organization.test.name
683
+ project_id = tfe_project.test.id
684
+ }
685
+
686
+ resource "tfe_workspace_settings" "test" {
687
+ workspace_id = tfe_workspace.test.id
688
+ tags = {}
689
+ }
690
+ ` , rInt , rInt , rInt )
691
+
692
+ resource .Test (t , resource.TestCase {
693
+ PreCheck : func () { testAccPreCheck (t ) },
694
+ ProtoV6ProviderFactories : testAccMuxedProviders ,
695
+ Steps : []resource.TestStep {
696
+ {
697
+ Config : configStep1 ,
698
+ Check : resource .ComposeTestCheckFunc (
699
+ resource .TestCheckResourceAttr ("tfe_workspace_settings.test" , "effective_tags.%" , "2" ),
700
+ resource .TestCheckResourceAttr ("tfe_workspace_settings.test" , "effective_tags.projectTag" , "valueA" ),
701
+ resource .TestCheckResourceAttr ("tfe_workspace_settings.test" , "effective_tags.app" , "web" ),
702
+ ),
703
+ },
704
+ {
705
+ Config : configStep2 ,
706
+ Check : resource .ComposeTestCheckFunc (
707
+ resource .TestCheckResourceAttr ("tfe_workspace_settings.test" , "effective_tags.%" , "1" ),
708
+ resource .TestCheckResourceAttr ("tfe_workspace_settings.test" , "effective_tags.projectTag" , "valueA" ),
709
+ resource .TestCheckNoResourceAttr ("tfe_workspace_settings.test" , "effective_tags.app" ),
710
+ ),
711
+ },
712
+ },
713
+ })
714
+ }
0 commit comments