@@ -57,6 +57,43 @@ func TestAccContainerCluster_basic(t *testing.T) {
57
57
})
58
58
}
59
59
60
+ func TestAccContainerCluster_resourceManagerTags (t * testing.T ) {
61
+ t .Parallel ()
62
+
63
+ pid := envvar .GetTestProjectFromEnv ()
64
+
65
+ randomSuffix := acctest .RandString (t , 10 )
66
+ clusterName := fmt .Sprintf ("tf-test-cluster-%s" , randomSuffix )
67
+
68
+ networkName := acctest .BootstrapSharedTestNetwork (t , "gke-cluster" )
69
+ subnetworkName := acctest .BootstrapSubnet (t , "gke-cluster" , networkName )
70
+
71
+ acctest .VcrTest (t , resource.TestCase {
72
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
73
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
74
+ ExternalProviders : map [string ]resource.ExternalProvider {
75
+ "time" : {},
76
+ },
77
+ CheckDestroy : testAccCheckContainerClusterDestroyProducer (t ),
78
+ Steps : []resource.TestStep {
79
+ {
80
+ Config : testAccContainerCluster_resourceManagerTags (pid , clusterName , networkName , subnetworkName , randomSuffix ),
81
+ Check : resource .ComposeTestCheckFunc (
82
+ resource .TestCheckResourceAttrSet ("google_container_cluster.primary" , "self_link" ),
83
+ resource .TestCheckResourceAttrSet ("google_container_cluster.primary" , "node_config.0.resource_manager_tags.%" ),
84
+ ),
85
+ },
86
+ {
87
+ ResourceName : "google_container_cluster.primary" ,
88
+ ImportStateId : fmt .Sprintf ("us-central1-a/%s" , clusterName ),
89
+ ImportState : true ,
90
+ ImportStateVerify : true ,
91
+ ImportStateVerifyIgnore : []string {"min_master_version" , "deletion_protection" },
92
+ },
93
+ },
94
+ })
95
+ }
96
+
60
97
func TestAccContainerCluster_networkingModeRoutes (t * testing.T ) {
61
98
t .Parallel ()
62
99
@@ -3805,11 +3842,11 @@ func testAccContainerCluster_withIncompatibleMasterVersionNodeVersion(name strin
3805
3842
resource "google_container_cluster" "gke_cluster" {
3806
3843
name = "%s"
3807
3844
location = "us-central1"
3808
-
3845
+
3809
3846
min_master_version = "1.10.9-gke.5"
3810
3847
node_version = "1.10.6-gke.11"
3811
3848
initial_node_count = 1
3812
-
3849
+
3813
3850
}
3814
3851
` , name )
3815
3852
}
@@ -5824,7 +5861,7 @@ resource "google_container_cluster" "with_autoprovisioning" {
5824
5861
min_master_version = data.google_container_engine_versions.central1a.latest_master_version
5825
5862
initial_node_count = 1
5826
5863
deletion_protection = false
5827
-
5864
+
5828
5865
network = "%s"
5829
5866
subnetwork = "%s"
5830
5867
@@ -8095,7 +8132,7 @@ resource "google_compute_resource_policy" "policy" {
8095
8132
resource "google_container_cluster" "cluster" {
8096
8133
name = "%s"
8097
8134
location = "us-central1-a"
8098
-
8135
+
8099
8136
node_pool {
8100
8137
name = "%s"
8101
8138
initial_node_count = 2
@@ -8196,3 +8233,86 @@ func testAccContainerCluster_additional_pod_ranges_config(name string, nameCount
8196
8233
}
8197
8234
` , name , name , name , aprc )
8198
8235
}
8236
+
8237
+ func testAccContainerCluster_resourceManagerTags (projectID , clusterName , networkName , subnetworkName , randomSuffix string ) string {
8238
+ return fmt .Sprintf (`
8239
+ data "google_project" "project" {
8240
+ project_id = "%[1]s"
8241
+ }
8242
+
8243
+ resource "google_project_iam_binding" "tagHoldAdmin" {
8244
+ project = "%[1]s"
8245
+ role = "roles/resourcemanager.tagHoldAdmin"
8246
+ members = [
8247
+ "serviceAccount:service-${data.google_project.project.number}@container-engine-robot.iam.gserviceaccount.com",
8248
+ ]
8249
+ }
8250
+
8251
+ resource "google_project_iam_binding" "tagUser" {
8252
+ project = "%[1]s"
8253
+ role = "roles/resourcemanager.tagUser"
8254
+ members = [
8255
+ "serviceAccount:service-${data.google_project.project.number}@container-engine-robot.iam.gserviceaccount.com",
8256
+ "serviceAccount:${data.google_project.project.number}@cloudservices.gserviceaccount.com",
8257
+ ]
8258
+
8259
+ depends_on = [google_project_iam_binding.tagHoldAdmin]
8260
+ }
8261
+
8262
+ resource "time_sleep" "wait_120_seconds" {
8263
+ create_duration = "120s"
8264
+
8265
+ depends_on = [
8266
+ google_project_iam_binding.tagHoldAdmin,
8267
+ google_project_iam_binding.tagUser
8268
+ ]
8269
+ }
8270
+
8271
+ resource "google_tags_tag_key" "key" {
8272
+ parent = "projects/%[1]s"
8273
+ short_name = "foobarbaz-%[2]s"
8274
+ description = "For foo/bar resources"
8275
+ purpose = "GCE_FIREWALL"
8276
+ purpose_data = {
8277
+ network = "%[1]s/%[4]s"
8278
+ }
8279
+ }
8280
+
8281
+ resource "google_tags_tag_value" "value" {
8282
+ parent = "tagKeys/${google_tags_tag_key.key.name}"
8283
+ short_name = "foo-%[2]s"
8284
+ description = "For foo resources"
8285
+ }
8286
+
8287
+ data "google_container_engine_versions" "uscentral1a" {
8288
+ location = "us-central1-a"
8289
+ }
8290
+
8291
+ resource "google_container_cluster" "primary" {
8292
+ name = "%[3]s"
8293
+ location = "us-central1-a"
8294
+ min_master_version = data.google_container_engine_versions.uscentral1a.release_channel_latest_version["STABLE"]
8295
+ initial_node_count = 1
8296
+
8297
+ node_config {
8298
+ machine_type = "n1-standard-1" // can't be e2 because of local-ssd
8299
+ disk_size_gb = 15
8300
+
8301
+ resource_manager_tags = {
8302
+ "tagKeys/${google_tags_tag_key.key.name}" = "tagValues/${google_tags_tag_value.value.name}"
8303
+ }
8304
+ }
8305
+
8306
+ deletion_protection = false
8307
+ network = "%[4]s"
8308
+ subnetwork = "%[5]s"
8309
+
8310
+ timeouts {
8311
+ create = "30m"
8312
+ update = "40m"
8313
+ }
8314
+
8315
+ depends_on = [time_sleep.wait_120_seconds]
8316
+ }
8317
+ ` , projectID , randomSuffix , clusterName , networkName , subnetworkName )
8318
+ }
0 commit comments