mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-01 16:21:06 +00:00
Added ability to configure resource labels on a GKE cluster
This commit is contained in:
parent
43cccf3e2c
commit
e14aa8bf39
@ -461,6 +461,12 @@ func resourceContainerCluster() *schema.Resource {
|
|||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
ValidateFunc: validation.CIDRNetwork(28, 28),
|
ValidateFunc: validation.CIDRNetwork(28, 28),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"resource_labels": {
|
||||||
|
Type: schema.TypeMap,
|
||||||
|
Optional: true,
|
||||||
|
Elem: schema.TypeString,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -638,6 +644,10 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v, ok := d.GetOk("resource_labels"); ok {
|
||||||
|
cluster.ResourceLabels = v.(map[string]string)
|
||||||
|
}
|
||||||
|
|
||||||
req := &containerBeta.CreateClusterRequest{
|
req := &containerBeta.CreateClusterRequest{
|
||||||
Cluster: cluster,
|
Cluster: cluster,
|
||||||
}
|
}
|
||||||
@ -787,6 +797,7 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
|
|||||||
|
|
||||||
d.Set("private_cluster", cluster.PrivateCluster)
|
d.Set("private_cluster", cluster.PrivateCluster)
|
||||||
d.Set("master_ipv4_cidr_block", cluster.MasterIpv4CidrBlock)
|
d.Set("master_ipv4_cidr_block", cluster.MasterIpv4CidrBlock)
|
||||||
|
d.Set("resource_labels", cluster.ResourceLabels)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -1143,6 +1154,31 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
|
|||||||
d.SetPartial("pod_security_policy_config")
|
d.SetPartial("pod_security_policy_config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if d.HasChange("resource_labels") {
|
||||||
|
resourceLabels := d.Get("resource_labels").(map[string]string)
|
||||||
|
|
||||||
|
req := &containerBeta.SetLabelsRequest{
|
||||||
|
ResourceLabels: resourceLabels,
|
||||||
|
}
|
||||||
|
updateF := func() error {
|
||||||
|
name := containerClusterFullName(project, location, clusterName)
|
||||||
|
op, err := config.clientContainerBeta.Projects.Locations.Clusters.SetResourceLabels(name, req).Do()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait until it's updated
|
||||||
|
return containerSharedOperationWait(config, op, project, location, "updating GKE resource labels", timeoutInMinutes, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call update serially.
|
||||||
|
if err := lockedCall(lockKey, updateF); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
d.SetPartial("resource_labels")
|
||||||
|
}
|
||||||
|
|
||||||
if d.HasChange("remove_default_node_pool") && d.Get("remove_default_node_pool").(bool) {
|
if d.HasChange("remove_default_node_pool") && d.Get("remove_default_node_pool").(bool) {
|
||||||
name := fmt.Sprintf("%s/nodePools/%s", containerClusterFullName(project, location, clusterName), "default-pool")
|
name := fmt.Sprintf("%s/nodePools/%s", containerClusterFullName(project, location, clusterName), "default-pool")
|
||||||
op, err := config.clientContainerBeta.Projects.Locations.Clusters.NodePools.Delete(name).Do()
|
op, err := config.clientContainerBeta.Projects.Locations.Clusters.NodePools.Delete(name).Do()
|
||||||
|
@ -1160,6 +1160,27 @@ func TestAccContainerCluster_sharedVpc(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccContainerCluster_withResourceLabels(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccContainerCluster_withResourceLabels(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ResourceName: "google_container_cluster.with_resource_labels",
|
||||||
|
ImportStateIdPrefix: "us-central1-a/",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateVerify: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckContainerClusterDestroy(s *terraform.State) error {
|
func testAccCheckContainerClusterDestroy(s *terraform.State) error {
|
||||||
config := testAccProvider.Meta().(*Config)
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
@ -2229,3 +2250,18 @@ resource "google_container_cluster" "shared_vpc_cluster" {
|
|||||||
]
|
]
|
||||||
}`, projectName, org, billingId, projectName, org, billingId, acctest.RandString(10), acctest.RandString(10), name)
|
}`, projectName, org, billingId, projectName, org, billingId, acctest.RandString(10), acctest.RandString(10), name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccContainerCluster_withResourceLabels() string {
|
||||||
|
testId := acctest.RandString(10)
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "google_container_cluster" "with_resource_labels" {
|
||||||
|
name = "tf-cluster-resourcelabel-test-%s"
|
||||||
|
zone = "us-central1-a"
|
||||||
|
initial_node_count = 1
|
||||||
|
|
||||||
|
resource_labels {
|
||||||
|
created-by = "terraform"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`, testId)
|
||||||
|
}
|
||||||
|
@ -172,6 +172,8 @@ output "cluster_ca_certificate" {
|
|||||||
|
|
||||||
* `remove_default_node_pool` - (Optional) If true, deletes the default node pool upon cluster creation.
|
* `remove_default_node_pool` - (Optional) If true, deletes the default node pool upon cluster creation.
|
||||||
|
|
||||||
|
* `resource_labels` - (Optional) The GCE resource labels (key/value pairs) to be applied to the cluster.
|
||||||
|
|
||||||
* `subnetwork` - (Optional) The name or self_link of the Google Compute Engine subnetwork in
|
* `subnetwork` - (Optional) The name or self_link of the Google Compute Engine subnetwork in
|
||||||
which the cluster's instances are launched.
|
which the cluster's instances are launched.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user