@@ -57,11 +57,27 @@ func TestAccContainerNodePool_resourceManagerTags(t *testing.T) {
57
57
t .Parallel ()
58
58
pid := envvar .GetTestProjectFromEnv ()
59
59
60
- randomSuffix := acctest .RandString (t , 10 )
61
- clusterName := fmt .Sprintf ("tf-test-cluster-%s" , randomSuffix )
62
-
63
60
networkName := acctest .BootstrapSharedTestNetwork (t , "gke-cluster" )
64
- subnetworkName := acctest .BootstrapSubnet (t , "gke-cluster" , networkName )
61
+ tagData := map [string ]interface {}{
62
+ "purpose" : "GCE_FIREWALL" ,
63
+ "purpose_data" : map [string ]interface {}{
64
+ "network" : pid + "/" + networkName ,
65
+ },
66
+ }
67
+ tagKey1 := acctest .BootstrapSharedTestProjectTagKey (t , "resourceManagerTags1" , tagData )
68
+ tagKey2 := acctest .BootstrapSharedTestProjectTagKey (t , "resourceManagerTags2" , tagData )
69
+
70
+ context := map [string ]interface {}{
71
+ "pid" : pid ,
72
+ "org" : envvar .GetTestOrgFromEnv (t ),
73
+ "network" : networkName ,
74
+ "subnet" : acctest .BootstrapSubnet (t , "gke-cluster" , networkName ),
75
+ "tagKey1" : tagKey1 ,
76
+ "tagValue1" : acctest .BootstrapSharedTestProjectTagValue (t , "resourceManagerTags1" , tagKey1 ),
77
+ "tagKey2" : tagKey2 ,
78
+ "tagValue2" : acctest .BootstrapSharedTestProjectTagValue (t , "resourceManagerTags2" , tagKey2 ),
79
+ "random_suffix" : acctest .RandString (t , 10 ),
80
+ }
65
81
66
82
bootstrapGkeTagManagerServiceAgents (t )
67
83
@@ -74,7 +90,7 @@ func TestAccContainerNodePool_resourceManagerTags(t *testing.T) {
74
90
CheckDestroy : testAccCheckContainerClusterDestroyProducer (t ),
75
91
Steps : []resource.TestStep {
76
92
{
77
- Config : testAccContainerNodePool_resourceManagerTags (pid , clusterName , networkName , subnetworkName , randomSuffix ),
93
+ Config : testAccContainerNodePool_resourceManagerTags (context ),
78
94
Check : resource .ComposeTestCheckFunc (
79
95
resource .TestCheckResourceAttrSet ("google_container_node_pool.primary_nodes" , "node_config.0.resource_manager_tags.%" ),
80
96
),
@@ -86,7 +102,7 @@ func TestAccContainerNodePool_resourceManagerTags(t *testing.T) {
86
102
ImportStateVerifyIgnore : []string {"min_master_version" , "cluster" },
87
103
},
88
104
{
89
- Config : testAccContainerNodePool_resourceManagerTagsUpdate1 (pid , clusterName , networkName , subnetworkName , randomSuffix ),
105
+ Config : testAccContainerNodePool_resourceManagerTagsUpdate1 (context ),
90
106
Check : resource .ComposeTestCheckFunc (
91
107
resource .TestCheckResourceAttrSet ("google_container_node_pool.primary_nodes" , "node_config.0.resource_manager_tags.%" ),
92
108
),
@@ -98,7 +114,7 @@ func TestAccContainerNodePool_resourceManagerTags(t *testing.T) {
98
114
ImportStateVerifyIgnore : []string {"min_master_version" , "cluster" },
99
115
},
100
116
{
101
- Config : testAccContainerNodePool_resourceManagerTagsUpdate2 (pid , clusterName , networkName , subnetworkName , randomSuffix ),
117
+ Config : testAccContainerNodePool_resourceManagerTagsUpdate2 (context ),
102
118
},
103
119
{
104
120
ResourceName : "google_container_node_pool.primary_nodes" ,
@@ -4653,52 +4669,18 @@ resource "google_container_node_pool" "without_confidential_boot_disk" {
4653
4669
` , cluster , networkName , subnetworkName , np )
4654
4670
}
4655
4671
4656
- func testAccContainerNodePool_resourceManagerTags (projectID , clusterName , networkName , subnetworkName , randomSuffix string ) string {
4657
- return fmt . Sprintf (`
4672
+ func testAccContainerNodePool_resourceManagerTags (context map [ string ] interface {} ) string {
4673
+ return acctest . Nprintf (`
4658
4674
data "google_project" "project" {
4659
- project_id = "%[1]s"
4660
- }
4661
-
4662
- resource "google_tags_tag_key" "key1" {
4663
- parent = "projects/%[1]s"
4664
- short_name = "foobarbaz1-%[2]s"
4665
- description = "For foo/bar1 resources"
4666
- purpose = "GCE_FIREWALL"
4667
- purpose_data = {
4668
- network = "%[1]s/%[4]s"
4669
- }
4670
- }
4671
-
4672
- resource "google_tags_tag_value" "value1" {
4673
- parent = google_tags_tag_key.key1.id
4674
- short_name = "foo1-%[2]s"
4675
- description = "For foo1 resources"
4676
- }
4677
-
4678
- resource "google_tags_tag_key" "key2" {
4679
- parent = "projects/%[1]s"
4680
- short_name = "foobarbaz2-%[2]s"
4681
- description = "For foo/bar2 resources"
4682
- purpose = "GCE_FIREWALL"
4683
- purpose_data = {
4684
- network = "%[1]s/%[4]s"
4685
- }
4686
-
4687
- depends_on = [google_tags_tag_key.key1]
4688
- }
4689
-
4690
- resource "google_tags_tag_value" "value2" {
4691
- parent = google_tags_tag_key.key2.id
4692
- short_name = "foo2-%[2]s"
4693
- description = "For foo2 resources"
4675
+ project_id = "%{pid}"
4694
4676
}
4695
4677
4696
4678
data "google_container_engine_versions" "uscentral1a" {
4697
4679
location = "us-central1-a"
4698
4680
}
4699
4681
4700
4682
resource "google_container_cluster" "primary" {
4701
- name = "%[3]s "
4683
+ name = "tf-test-cluster-%{random_suffix} "
4702
4684
location = "us-central1-a"
4703
4685
min_master_version = data.google_container_engine_versions.uscentral1a.release_channel_latest_version["STABLE"]
4704
4686
@@ -4709,8 +4691,8 @@ resource "google_container_cluster" "primary" {
4709
4691
initial_node_count = 1
4710
4692
4711
4693
deletion_protection = false
4712
- network = "%[4]s "
4713
- subnetwork = "%[5]s "
4694
+ network = "%{network} "
4695
+ subnetwork = "%{subnet} "
4714
4696
4715
4697
timeouts {
4716
4698
create = "30m"
@@ -4732,59 +4714,25 @@ resource "google_container_node_pool" "primary_nodes" {
4732
4714
disk_size_gb = 15
4733
4715
4734
4716
resource_manager_tags = {
4735
- (google_tags_tag_key.key1.id) = google_tags_tag_value.value1.id
4717
+ "%{pid}/%{tagKey1}" = "%{tagValue1}"
4736
4718
}
4737
4719
}
4738
4720
}
4739
- ` , projectID , randomSuffix , clusterName , networkName , subnetworkName )
4721
+ ` , context )
4740
4722
}
4741
4723
4742
- func testAccContainerNodePool_resourceManagerTagsUpdate1 (projectID , clusterName , networkName , subnetworkName , randomSuffix string ) string {
4743
- return fmt . Sprintf (`
4724
+ func testAccContainerNodePool_resourceManagerTagsUpdate1 (context map [ string ] interface {} ) string {
4725
+ return acctest . Nprintf (`
4744
4726
data "google_project" "project" {
4745
- project_id = "%[1]s"
4746
- }
4747
-
4748
- resource "google_tags_tag_key" "key1" {
4749
- parent = "projects/%[1]s"
4750
- short_name = "foobarbaz1-%[2]s"
4751
- description = "For foo/bar1 resources"
4752
- purpose = "GCE_FIREWALL"
4753
- purpose_data = {
4754
- network = "%[1]s/%[4]s"
4755
- }
4756
- }
4757
-
4758
- resource "google_tags_tag_value" "value1" {
4759
- parent = google_tags_tag_key.key1.id
4760
- short_name = "foo1-%[2]s"
4761
- description = "For foo1 resources"
4762
- }
4763
-
4764
- resource "google_tags_tag_key" "key2" {
4765
- parent = "projects/%[1]s"
4766
- short_name = "foobarbaz2-%[2]s"
4767
- description = "For foo/bar2 resources"
4768
- purpose = "GCE_FIREWALL"
4769
- purpose_data = {
4770
- network = "%[1]s/%[4]s"
4771
- }
4772
-
4773
- depends_on = [google_tags_tag_key.key1]
4774
- }
4775
-
4776
- resource "google_tags_tag_value" "value2" {
4777
- parent = google_tags_tag_key.key2.id
4778
- short_name = "foo2-%[2]s"
4779
- description = "For foo2 resources"
4727
+ project_id = "%{pid}"
4780
4728
}
4781
4729
4782
4730
data "google_container_engine_versions" "uscentral1a" {
4783
4731
location = "us-central1-a"
4784
4732
}
4785
4733
4786
4734
resource "google_container_cluster" "primary" {
4787
- name = "%[3]s "
4735
+ name = "tf-test-cluster-%{random_suffix} "
4788
4736
location = "us-central1-a"
4789
4737
min_master_version = data.google_container_engine_versions.uscentral1a.release_channel_latest_version["STABLE"]
4790
4738
@@ -4795,8 +4743,8 @@ resource "google_container_cluster" "primary" {
4795
4743
initial_node_count = 1
4796
4744
4797
4745
deletion_protection = false
4798
- network = "%[4]s "
4799
- subnetwork = "%[5]s "
4746
+ network = "%{network} "
4747
+ subnetwork = "%{subnet} "
4800
4748
4801
4749
timeouts {
4802
4750
create = "30m"
@@ -4818,60 +4766,26 @@ resource "google_container_node_pool" "primary_nodes" {
4818
4766
disk_size_gb = 15
4819
4767
4820
4768
resource_manager_tags = {
4821
- (google_tags_tag_key.key1.id) = google_tags_tag_value.value1.id
4822
- (google_tags_tag_key.key2.id) = google_tags_tag_value.value2.id
4769
+ "%{pid}/%{tagKey1}" = "%{tagValue1}"
4770
+ "%{pid}/%{tagKey2}" = "%{tagValue2}"
4823
4771
}
4824
4772
}
4825
4773
}
4826
- ` , projectID , randomSuffix , clusterName , networkName , subnetworkName )
4774
+ ` , context )
4827
4775
}
4828
4776
4829
- func testAccContainerNodePool_resourceManagerTagsUpdate2 (projectID , clusterName , networkName , subnetworkName , randomSuffix string ) string {
4830
- return fmt . Sprintf (`
4777
+ func testAccContainerNodePool_resourceManagerTagsUpdate2 (context map [ string ] interface {} ) string {
4778
+ return acctest . Nprintf (`
4831
4779
data "google_project" "project" {
4832
- project_id = "%[1]s"
4833
- }
4834
-
4835
- resource "google_tags_tag_key" "key1" {
4836
- parent = "projects/%[1]s"
4837
- short_name = "foobarbaz1-%[2]s"
4838
- description = "For foo/bar1 resources"
4839
- purpose = "GCE_FIREWALL"
4840
- purpose_data = {
4841
- network = "%[1]s/%[4]s"
4842
- }
4843
- }
4844
-
4845
- resource "google_tags_tag_value" "value1" {
4846
- parent = google_tags_tag_key.key1.id
4847
- short_name = "foo1-%[2]s"
4848
- description = "For foo1 resources"
4849
- }
4850
-
4851
- resource "google_tags_tag_key" "key2" {
4852
- parent = "projects/%[1]s"
4853
- short_name = "foobarbaz2-%[2]s"
4854
- description = "For foo/bar2 resources"
4855
- purpose = "GCE_FIREWALL"
4856
- purpose_data = {
4857
- network = "%[1]s/%[4]s"
4858
- }
4859
-
4860
- depends_on = [google_tags_tag_key.key1]
4861
- }
4862
-
4863
- resource "google_tags_tag_value" "value2" {
4864
- parent = google_tags_tag_key.key2.id
4865
- short_name = "foo2-%[2]s"
4866
- description = "For foo2 resources"
4780
+ project_id = "%{pid}"
4867
4781
}
4868
4782
4869
4783
data "google_container_engine_versions" "uscentral1a" {
4870
4784
location = "us-central1-a"
4871
4785
}
4872
4786
4873
4787
resource "google_container_cluster" "primary" {
4874
- name = "%[3]s "
4788
+ name = "tf-test-cluster-%{random_suffix} "
4875
4789
location = "us-central1-a"
4876
4790
min_master_version = data.google_container_engine_versions.uscentral1a.release_channel_latest_version["STABLE"]
4877
4791
@@ -4882,8 +4796,8 @@ resource "google_container_cluster" "primary" {
4882
4796
initial_node_count = 1
4883
4797
4884
4798
deletion_protection = false
4885
- network = "%[4]s "
4886
- subnetwork = "%[5]s "
4799
+ network = "%{network} "
4800
+ subnetwork = "%{subnet} "
4887
4801
4888
4802
timeouts {
4889
4803
create = "30m"
@@ -4905,7 +4819,7 @@ resource "google_container_node_pool" "primary_nodes" {
4905
4819
disk_size_gb = 15
4906
4820
}
4907
4821
}
4908
- ` , projectID , randomSuffix , clusterName , networkName , subnetworkName )
4822
+ ` , context )
4909
4823
}
4910
4824
4911
4825
func TestAccContainerNodePool_privateRegistry (t * testing.T ) {
0 commit comments