Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for cluster labels #81

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Then perform the following commands on the root folder:

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
<<<<<<< HEAD
| description | The description of the cluster | string | `""` | no |
| horizontal\_pod\_autoscaling | Enable horizontal pod autoscaling addon | string | `"true"` | no |
| http\_load\_balancing | Enable httpload balancer addon | string | `"true"` | no |
Expand Down Expand Up @@ -127,6 +128,7 @@ Then perform the following commands on the root folder:
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. Defaults to the compute engine default service account. May also specify `create` to automatically create a cluster-specific service account | string | `""` | no |
| stub\_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | map | `<map>` | no |
| subnetwork | The subnetwork to host the cluster in (required) | string | n/a | yes |
| cluster_resource_labels | Map containing cluster labels. Maximum of 64 labels | map | `<map>` | no |
| zones | The zones to host the cluster in (optional if regional cluster / required if zonal) | list | `<list>` | no |

## Outputs
Expand Down
1 change: 1 addition & 0 deletions autogen/cluster_regional.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ resource "google_container_cluster" "primary" {
name = "${var.name}"
description = "${var.description}"
project = "${var.project_id}"
resource_labels = "${var.cluster_resource_labels}"

region = "${var.region}"
additional_zones = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"]
Expand Down
1 change: 1 addition & 0 deletions autogen/cluster_zonal.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ resource "google_container_cluster" "zonal_primary" {
name = "${var.name}"
description = "${var.description}"
project = "${var.project_id}"
resource_labels = "${var.cluster_resource_labels}"

zone = "${var.zones[0]}"
additional_zones = ["${slice(var.zones,1,length(var.zones))}"]
Expand Down
8 changes: 8 additions & 0 deletions autogen/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ variable "description" {
default = ""
}

variable "cluster_resource_labels" {
type = "map"
description = "Map containing cluster labels. Maximum of 64 labels"

default = {
}
}

variable "regional" {
description = "Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!)"
default = true
Expand Down
1 change: 1 addition & 0 deletions cluster_regional.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ resource "google_container_cluster" "primary" {
name = "${var.name}"
description = "${var.description}"
project = "${var.project_id}"
resource_labels = "${var.cluster_resource_labels}"

region = "${var.region}"
additional_zones = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"]
Expand Down
1 change: 1 addition & 0 deletions cluster_zonal.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ resource "google_container_cluster" "zonal_primary" {
name = "${var.name}"
description = "${var.description}"
project = "${var.project_id}"
resource_labels = "${var.cluster_resource_labels}"

zone = "${var.zones[0]}"
additional_zones = ["${slice(var.zones,1,length(var.zones))}"]
Expand Down
10 changes: 10 additions & 0 deletions examples/simple_regional/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ variable "ip_range_services" {
variable "compute_engine_service_account" {
description = "Service account to associate to the nodes in the cluster"
}

variable "cluster_resource_labels" {
type = "map"
description = "Map containing cluster labels. Maximum of 64 labels"

default = {
created-by = "terraform"
}

}
1 change: 1 addition & 0 deletions examples/simple_regional_private/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This example illustrates how to create a simple private cluster.
| project\_id | The project ID to host the cluster in | string | n/a | yes |
| region | The region to host the cluster in | string | n/a | yes |
| subnetwork | The subnetwork to host the cluster in | string | n/a | yes |
| cluster_resource_labels | Map containing cluster labels. Maximum of 64 labels | map | `<map>` | no |

## Outputs

Expand Down
9 changes: 9 additions & 0 deletions examples/simple_regional_private/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,12 @@ variable "ip_range_services" {
variable "compute_engine_service_account" {
description = "Service account to associate to the nodes in the cluster"
}

variable "cluster_resource_labels" {
type = "map"
description = "Map containing cluster labels. Maximum of 64 labels"

default = {
}

}
1 change: 1 addition & 0 deletions examples/simple_zonal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This example illustrates how to create a simple cluster.
| region | The region to host the cluster in | string | n/a | yes |
| subnetwork | The subnetwork to host the cluster in | string | n/a | yes |
| zones | The zone to host the cluster in (required if is a zonal cluster) | list | n/a | yes |
| cluster_name_suffix | A suffix to append to the default cluster name | string | `` | no |

## Outputs

Expand Down
9 changes: 9 additions & 0 deletions examples/simple_zonal/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ variable "ip_range_pods" {
variable "ip_range_services" {
description = "The secondary ip range to use for pods"
}

variable "cluster_resource_labels" {
type = "map"
description = "Map containing cluster labels. Maximum of 64 labels"

default = {
}

}
1 change: 1 addition & 0 deletions examples/simple_zonal_private/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This example illustrates how to create a simple private cluster.
| region | The region to host the cluster in | string | n/a | yes |
| subnetwork | The subnetwork to host the cluster in | string | n/a | yes |
| zones | The zone to host the cluster in (required if is a zonal cluster) | list | n/a | yes |
| cluster_name_suffix | A suffix to append to the default cluster name | string | `` | no |

## Outputs

Expand Down
9 changes: 9 additions & 0 deletions examples/simple_zonal_private/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ variable "ip_range_services" {
variable "compute_engine_service_account" {
description = "Service account to associate to the nodes in the cluster"
}

variable "cluster_resource_labels" {
type = "map"
description = "Map containing cluster labels. Maximum of 64 labels"

default = {
}

}
1 change: 1 addition & 0 deletions modules/private-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Then perform the following commands on the root folder:
| service\_account | The service account to default running nodes as if not overridden in `node_pools`. Defaults to the compute engine default service account. May also specify `create` to automatically create a cluster-specific service account | string | `""` | no |
| stub\_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | map | `<map>` | no |
| subnetwork | The subnetwork to host the cluster in (required) | string | n/a | yes |
| cluster_resource_labels | Map containing cluster labels. Maximum of 64 labels | map | `<map>` | no |
| zones | The zones to host the cluster in (optional if regional cluster / required if zonal) | list | `<list>` | no |

## Outputs
Expand Down
1 change: 1 addition & 0 deletions modules/private-cluster/cluster_regional.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ resource "google_container_cluster" "primary" {
name = "${var.name}"
description = "${var.description}"
project = "${var.project_id}"
resource_labels = "${var.cluster_resource_labels}"

region = "${var.region}"
additional_zones = ["${coalescelist(compact(var.zones), sort(random_shuffle.available_zones.result))}"]
Expand Down
1 change: 1 addition & 0 deletions modules/private-cluster/cluster_zonal.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ resource "google_container_cluster" "zonal_primary" {
name = "${var.name}"
description = "${var.description}"
project = "${var.project_id}"
resource_labels = "${var.cluster_resource_labels}"

zone = "${var.zones[0]}"
additional_zones = ["${slice(var.zones,1,length(var.zones))}"]
Expand Down
2 changes: 1 addition & 1 deletion modules/private-cluster/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ output "node_pools_versions" {
output "service_account" {
description = "The service account to default running nodes as if not overridden in `node_pools`."
value = "${local.service_account}"
}
}
8 changes: 8 additions & 0 deletions modules/private-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ variable "description" {
default = ""
}

variable "cluster_resource_labels" {
type = "map"
description = "Map containing cluster labels. Maximum of 64 labels"

default = {
}
}

variable "regional" {
description = "Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!)"
default = true
Expand Down
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ output "node_pools_versions" {
output "service_account" {
description = "The service account to default running nodes as if not overridden in `node_pools`."
value = "${local.service_account}"
}
}
1 change: 1 addition & 0 deletions test/ci/simple-regional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ params:
COMPUTE_ENGINE_SERVICE_ACCOUNT: ""
REGION: "us-east4"
ZONES: '["us-east4-a", "us-east4-b", "us-east4-c"]'
CLUSTER_RESOURCE_LABELS: 'cluster_resource_labels={ created-by = "terraform" }'
1 change: 1 addition & 0 deletions test/ci_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ setup_environment() {
export TF_VAR_credentials_path_relative="../shared/credentials.json"
export TF_VAR_region="$REGION"
export TF_VAR_zones="$ZONES"
export TF_VAR_cluster_resource_labels="$CLUSTER_RESOURCE_LABELS"
export TF_VAR_compute_engine_service_account="$COMPUTE_ENGINE_SERVICE_ACCOUNT"
}

Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/shared/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ variable "zones" {
variable "compute_engine_service_account" {
description = "The email address of the service account to associate with the GKE cluster"
}

variable "cluster_resource_labels" {
type = "map"
description = "Map containing cluster labels. Maximum of 64 labels"
}
4 changes: 4 additions & 0 deletions test/fixtures/simple_regional/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ module "example" {
ip_range_pods = "${google_compute_subnetwork.main.secondary_ip_range.0.range_name}"
ip_range_services = "${google_compute_subnetwork.main.secondary_ip_range.1.range_name}"
compute_engine_service_account = "${var.compute_engine_service_account}"

cluster_resource_labels = {
created-by = "terraform"
}
}
10 changes: 10 additions & 0 deletions test/integration/simple_regional/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
},
})
end

it "has cluster resource labels" do
expect(data['resourceLabels']).to eq({
"created-by" => "terraform",
})
end
end

describe "default node pool" do
Expand Down Expand Up @@ -138,6 +144,10 @@
)
end





it "has the expected network tags" do
expect(node_pools).to include(
including(
Expand Down
8 changes: 8 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ variable "description" {
default = ""
}

variable "cluster_resource_labels" {
type = "map"
description = "Map containing cluster labels. Maximum of 64 labels"

default = {
}
}

variable "regional" {
description = "Whether is a regional cluster (zonal cluster if set false. WARNING: changing this after cluster creation is destructive!)"
default = true
Expand Down