Skip to content

Commit 5e69eaf

Browse files
cloud-foundation-botJamesDuncanNzbharathkkb
authored
feat!: add Terraform 0.13 constraint and module attribution (#70)
* feat!: add Terraform 0.13 constraint and module attribution * Multiple Updates to support move to 0.13 Updated Inspec tests for two examples. Updated versions for managed_instance_group example + sample for using the http-lb. Updated version for project factory in test setup Co-authored-by: James Duncan <[email protected]> Co-authored-by: Bharath KKB <[email protected]>
1 parent 3e26ace commit 5e69eaf

File tree

24 files changed

+350
-179
lines changed

24 files changed

+350
-179
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Make will use bash instead of sh
1919
SHELL := /usr/bin/env bash
2020

21-
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.12.0
21+
DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 0.13
2222
DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
2323
REGISTRY_URL := gcr.io/cloud-foundation-cicd
2424

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ This module handles the generation of metadata for [deploying containers on GCE
55
This module itself does not launch an instance or managed instance group. It simply generates the necessary metadata to create an instance or MIG yourself. Examples of using this module can be found in the [examples/](examples) directory.
66

77
## Compatibility
8-
9-
This module is meant for use with Terraform 0.12. If you need a Terraform 0.11.x-compatible version of this module, the last released version intended for Terraform 0.11.x is [0.3.0].
8+
This module is meant for use with Terraform 0.13. If you haven't
9+
[upgraded](https://www.terraform.io/upgrade-guides/0-13.html) and need a Terraform
10+
0.12.x-compatible version of this module, the last released version
11+
intended for Terraform 0.12.x is [v2.0.0](https://registry.terraform.io/modules/terraform-google-modules/-container-vm/google/v2.0.0).
1012

1113
## Usage
1214

@@ -73,12 +75,12 @@ Then perform the following commands on the root folder:
7375
## Inputs
7476

7577
| Name | Description | Type | Default | Required |
76-
|------|-------------|:----:|:-----:|:-----:|
77-
| container | A description of the container to deploy | any | `<map>` | no |
78-
| cos\_image\_family | The COS image family to use (eg: stable, beta, or dev) | string | `"stable"` | no |
79-
| cos\_image\_name | Name of a specific COS image to use instead of the latest cos family image | string | `"null"` | no |
80-
| restart\_policy | The restart policy for a Docker container. Defaults to `OnFailure` | string | `"OnFailure"` | no |
81-
| volumes | A set of Docker Volumes to configure | any | `<list>` | no |
78+
|------|-------------|------|---------|:--------:|
79+
| container | A description of the container to deploy | `any` | <pre>{<br> "command": "ls",<br> "image": "gcr.io/google-containers/busybox"<br>}</pre> | no |
80+
| cos\_image\_family | The COS image family to use (eg: stable, beta, or dev) | `string` | `"stable"` | no |
81+
| cos\_image\_name | Name of a specific COS image to use instead of the latest cos family image | `string` | `null` | no |
82+
| restart\_policy | The restart policy for a Docker container. Defaults to `OnFailure` | `string` | `"OnFailure"` | no |
83+
| volumes | A set of Docker Volumes to configure | `any` | `[]` | no |
8284

8385
## Outputs
8486

@@ -89,8 +91,8 @@ Then perform the following commands on the root folder:
8991
| metadata\_key | The key to assign `metadata_value` to, so container information is attached to the instance |
9092
| metadata\_value | The generated container configuration |
9193
| restart\_policy | The restart policy provided |
92-
| source\_image | The self_link to the COS image to use for the GCE instance. Equivalent to container_vm.self_link |
93-
| vm\_container\_label | The COS version to deploy to the instance. To be used as the value for the `vm_container_label_key` label key. Equivalent to container_vm.name |
94+
| source\_image | The self\_link to the COS image to use for the GCE instance. Equivalent to container\_vm.self\_link |
95+
| vm\_container\_label | The COS version to deploy to the instance. To be used as the value for the `vm_container_label_key` label key. Equivalent to container\_vm.name |
9496
| vm\_container\_label\_key | The label key for the COS version deployed to the instance |
9597
| volumes | The volume definition provided |
9698

@@ -134,7 +136,7 @@ module "gce-advanced-container" {
134136

135137
## Requirements
136138
### Terraform plugins
137-
- [Terraform](https://www.terraform.io/downloads.html) 0.10.x
139+
- [Terraform](https://www.terraform.io/downloads.html) >= 0.13.0
138140
- [terraform-provider-google](https://github.com/terraform-providers/terraform-provider-google) plugin v1.8.0
139141

140142
### Python Libraries

build/int.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ tags:
3838
- 'integration'
3939
substitutions:
4040
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
41-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.12.0'
41+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.13'

build/lint.cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ tags:
2121
- 'lint'
2222
substitutions:
2323
_DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
24-
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.12.0'
24+
_DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '0.13'

examples/instance_with_advanced_options/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ This example illustrates how to deploy a container to a Google Compute Engine in
66
## Inputs
77

88
| Name | Description | Type | Default | Required |
9-
|------|-------------|:----:|:-----:|:-----:|
10-
| client\_email | Service account email address | string | `""` | no |
11-
| instance\_name | The desired name to assign to the deployed instance | string | `"container-vm-advanced-options"` | no |
12-
| project\_id | The project ID to deploy resources into | string | n/a | yes |
13-
| subnetwork | The name of the subnetwork to deploy instances into | string | n/a | yes |
14-
| subnetwork\_project | The project ID where the desired subnetwork is provisioned | string | n/a | yes |
15-
| zone | The GCP zone to deploy instances into | string | n/a | yes |
9+
|------|-------------|------|---------|:--------:|
10+
| client\_email | Service account email address | `string` | `""` | no |
11+
| instance\_name | The desired name to assign to the deployed instance | `string` | `"container-vm-advanced-options"` | no |
12+
| project\_id | The project ID to deploy resources into | `any` | n/a | yes |
13+
| subnetwork | The name of the subnetwork to deploy instances into | `any` | n/a | yes |
14+
| subnetwork\_project | The project ID where the desired subnetwork is provisioned | `any` | n/a | yes |
15+
| zone | The GCP zone to deploy instances into | `string` | n/a | yes |
1616

1717
## Outputs
1818

examples/instance_with_attached_disk/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ This example illustrates how to deploy and expose a container to a Google Comput
66
## Inputs
77

88
| Name | Description | Type | Default | Required |
9-
|------|-------------|:----:|:-----:|:-----:|
10-
| additional\_metadata | Additional metadata to attach to the instance | map(string) | `<map>` | no |
11-
| client\_email | Service account email address | string | `""` | no |
12-
| image | The Docker image to deploy to GCE instances | string | n/a | yes |
13-
| image\_port | The port the image exposes for HTTP requests | string | n/a | yes |
14-
| instance\_name | The desired name to assign to the deployed instance | string | `"disk-instance-vm-test"` | no |
15-
| machine\_type | The GCP machine type to deploy | string | n/a | yes |
16-
| project\_id | The project ID to deploy resource into | string | n/a | yes |
17-
| restart\_policy | The desired Docker restart policy for the deployed image | string | n/a | yes |
18-
| subnetwork | The name of the subnetwork to deploy instances into | string | n/a | yes |
19-
| subnetwork\_project | The project ID where the desired subnetwork is provisioned | string | n/a | yes |
20-
| zone | The GCP zone to deploy instances into | string | n/a | yes |
9+
|------|-------------|------|---------|:--------:|
10+
| additional\_metadata | Additional metadata to attach to the instance | `map(string)` | `{}` | no |
11+
| client\_email | Service account email address | `string` | `""` | no |
12+
| image | The Docker image to deploy to GCE instances | `any` | n/a | yes |
13+
| image\_port | The port the image exposes for HTTP requests | `any` | n/a | yes |
14+
| instance\_name | The desired name to assign to the deployed instance | `string` | `"disk-instance-vm-test"` | no |
15+
| machine\_type | The GCP machine type to deploy | `any` | n/a | yes |
16+
| project\_id | The project ID to deploy resource into | `any` | n/a | yes |
17+
| restart\_policy | The desired Docker restart policy for the deployed image | `any` | n/a | yes |
18+
| subnetwork | The name of the subnetwork to deploy instances into | `any` | n/a | yes |
19+
| subnetwork\_project | The project ID where the desired subnetwork is provisioned | `any` | n/a | yes |
20+
| zone | The GCP zone to deploy instances into | `any` | n/a | yes |
2121

2222
## Outputs
2323

examples/instance_with_config_file/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ This example illustrates how to deploy and expose a container to a Google Comput
66
## Inputs
77

88
| Name | Description | Type | Default | Required |
9-
|------|-------------|:----:|:-----:|:-----:|
10-
| additional\_metadata | Additional metadata to attach to the instance | map(string) | `<map>` | no |
11-
| client\_email | Service account email address | string | `""` | no |
12-
| cos\_image\_name | The forced COS image to use instead of latest | string | `"cos-stable-77-12371-89-0"` | no |
13-
| instance\_name | The desired name to assign to the deployed instance | string | `"hello-world-container-vm"` | no |
14-
| project\_id | The project ID to deploy resources into | string | n/a | yes |
15-
| subnetwork | The name of the subnetwork to deploy instances into | string | n/a | yes |
16-
| subnetwork\_project | The project ID where the desired subnetwork is provisioned | string | n/a | yes |
17-
| zone | The GCP zone to deploy instances into | string | n/a | yes |
9+
|------|-------------|------|---------|:--------:|
10+
| additional\_metadata | Additional metadata to attach to the instance | `map(string)` | `{}` | no |
11+
| client\_email | Service account email address | `string` | `""` | no |
12+
| cos\_image\_name | The forced COS image to use instead of latest | `string` | `"cos-stable-77-12371-89-0"` | no |
13+
| instance\_name | The desired name to assign to the deployed instance | `string` | `"hello-world-container-vm"` | no |
14+
| project\_id | The project ID to deploy resources into | `any` | n/a | yes |
15+
| subnetwork | The name of the subnetwork to deploy instances into | `any` | n/a | yes |
16+
| subnetwork\_project | The project ID where the desired subnetwork is provisioned | `any` | n/a | yes |
17+
| zone | The GCP zone to deploy instances into | `string` | n/a | yes |
1818

1919
## Outputs
2020

examples/instance_with_config_file/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
provider "google" {
1818
project = var.project_id
19-
version = "~> 2.20"
19+
version = "~> 3.53"
2020
}
2121

2222
provider "template" {

examples/managed_instance_group/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ This example requires that some python libraries be installed, as outlined in `r
1010
## Inputs
1111

1212
| Name | Description | Type | Default | Required |
13-
|------|-------------|:----:|:-----:|:-----:|
14-
| additional\_metadata | Additional metadata to attach to the instance | map | `<map>` | no |
15-
| image | The Docker image to deploy to GCE instances | string | `"gcr.io/google-samples/hello-app:1.0"` | no |
16-
| image\_port | The port the image exposes for HTTP requests | number | `"8080"` | no |
17-
| mig\_instance\_count | The number of instances to place in the managed instance group | string | `"2"` | no |
18-
| mig\_name | The desired name to assign to the deployed managed instance group | string | `"mig-test"` | no |
19-
| network | The GCP network | string | `"mig-net"` | no |
20-
| project\_id | The project ID to deploy resource into | string | n/a | yes |
21-
| region | The GCP region to deploy instances into | string | n/a | yes |
22-
| service\_account | | object | `<map>` | no |
23-
| subnetwork | The name of the subnetwork to deploy instances into | string | `"mig-subnet"` | no |
24-
| zone | The GCP zone to deploy instances into | string | n/a | yes |
13+
|------|-------------|------|---------|:--------:|
14+
| additional\_metadata | Additional metadata to attach to the instance | `map(any)` | `{}` | no |
15+
| image | The Docker image to deploy to GCE instances | `string` | `"gcr.io/google-samples/hello-app:1.0"` | no |
16+
| image\_port | The port the image exposes for HTTP requests | `number` | `8080` | no |
17+
| mig\_instance\_count | The number of instances to place in the managed instance group | `string` | `"2"` | no |
18+
| mig\_name | The desired name to assign to the deployed managed instance group | `string` | `"mig-test"` | no |
19+
| network | The GCP network | `string` | `"mig-net"` | no |
20+
| project\_id | The project ID to deploy resource into | `string` | n/a | yes |
21+
| region | The GCP region to deploy instances into | `string` | n/a | yes |
22+
| service\_account | n/a | <pre>object({<br> email = string,<br> scopes = list(string)<br> })</pre> | <pre>{<br> "email": "",<br> "scopes": [<br> "cloud-platform"<br> ]<br>}</pre> | no |
23+
| subnetwork | The name of the subnetwork to deploy instances into | `string` | `"mig-subnet"` | no |
24+
| zone | The GCP zone to deploy instances into | `string` | n/a | yes |
2525

2626
## Outputs
2727

examples/managed_instance_group/main.tf

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ locals {
2424
}
2525
provider "google" {
2626
project = var.project_id
27-
version = "~> 2.7.0"
27+
version = "~> 3.53.0"
2828
}
2929
provider "google-beta" {
3030
project = var.project_id
31-
version = "~> 2.7.0"
31+
version = "~> 3.53.0"
3232
}
3333
module "gce-container" {
3434
source = "../../"
@@ -63,7 +63,7 @@ module "cloud-nat" {
6363
}
6464
module "mig_template" {
6565
source = "terraform-google-modules/vm/google//modules/instance_template"
66-
version = "~> 1.0.0"
66+
version = "~> 6.0"
6767
network = google_compute_network.default.self_link
6868
subnetwork = google_compute_subnetwork.default.self_link
6969
service_account = var.service_account
@@ -81,7 +81,7 @@ module "mig_template" {
8181
}
8282
module "mig" {
8383
source = "terraform-google-modules/vm/google//modules/mig"
84-
version = "~> 1.0.0"
84+
version = "~> 6.0"
8585
instance_template = module.mig_template.self_link
8686
region = var.region
8787
hostname = var.network
@@ -97,32 +97,68 @@ module "mig" {
9797
}
9898
module "http-lb" {
9999
source = "GoogleCloudPlatform/lb-http/google"
100-
version = "~> 2.0"
100+
version = "~> 4.5"
101101

102-
project = var.project_id
103-
name = "${var.mig_name}-lb"
102+
project = var.project_id
103+
name = "${var.mig_name}-lb"
104+
target_tags = local.target_tags
104105
firewall_networks = [
105106
google_compute_network.default.self_link
106107
]
107-
target_tags = local.target_tags
108+
108109
backends = {
109-
"0" = [
110-
{
111-
group = module.mig.instance_group
112-
balancing_mode = null
113-
capacity_scaler = null
114-
description = null
115-
max_connections = null
116-
max_connections_per_instance = null
117-
max_rate = null
118-
max_rate_per_instance = null
119-
max_utilization = null
110+
default = {
111+
description = null
112+
protocol = "HTTP"
113+
port = 80
114+
port_name = "http"
115+
timeout_sec = 30
116+
connection_draining_timeout_sec = null
117+
enable_cdn = false
118+
security_policy = null
119+
session_affinity = null
120+
affinity_cookie_ttl_sec = null
121+
custom_request_headers = null
122+
123+
health_check = {
124+
check_interval_sec = null
125+
timeout_sec = null
126+
healthy_threshold = null
127+
unhealthy_threshold = null
128+
request_path = "/"
129+
port = 80
130+
host = null
131+
logging = null
120132
}
121-
]
133+
134+
log_config = {
135+
enable = false
136+
sample_rate = null
137+
}
138+
139+
groups = [
140+
{
141+
group = module.mig.instance_group
142+
balancing_mode = null
143+
capacity_scaler = null
144+
description = null
145+
max_connections = null
146+
max_connections_per_instance = null
147+
max_connections_per_endpoint = null
148+
max_rate = null
149+
max_rate_per_instance = null
150+
max_rate_per_endpoint = null
151+
max_utilization = null
152+
}
153+
]
154+
155+
iap_config = {
156+
enable = false
157+
oauth2_client_id = ""
158+
oauth2_client_secret = ""
159+
}
160+
}
122161
}
123-
backend_params = [
124-
"/,http,${var.image_port},30",
125-
]
126162
}
127163
resource "google_compute_firewall" "lb-to-instances" {
128164
name = "${var.mig_name}-firewall-lb-to-instances"

examples/managed_instance_group/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ variable "network" {
6666
}
6767

6868
variable "additional_metadata" {
69-
type = map
69+
type = map(any)
7070
description = "Additional metadata to attach to the instance"
7171
default = {}
7272
}

examples/simple_instance/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ This example illustrates how to deploy a container to a Google Compute Engine in
66
## Inputs
77

88
| Name | Description | Type | Default | Required |
9-
|------|-------------|:----:|:-----:|:-----:|
10-
| client\_email | Service account email address | string | `""` | no |
11-
| cos\_image\_name | The forced COS image to use instead of latest | string | `"cos-stable-77-12371-89-0"` | no |
12-
| instance\_name | The desired name to assign to the deployed instance | string | `"hello-world-container-vm"` | no |
13-
| project\_id | The project ID to deploy resources into | string | n/a | yes |
14-
| subnetwork | The name of the subnetwork to deploy instances into | string | n/a | yes |
15-
| subnetwork\_project | The project ID where the desired subnetwork is provisioned | string | n/a | yes |
16-
| zone | The GCP zone to deploy instances into | string | n/a | yes |
9+
|------|-------------|------|---------|:--------:|
10+
| client\_email | Service account email address | `string` | `""` | no |
11+
| cos\_image\_name | The forced COS image to use instead of latest | `string` | `"cos-stable-77-12371-89-0"` | no |
12+
| instance\_name | The desired name to assign to the deployed instance | `string` | `"hello-world-container-vm"` | no |
13+
| project\_id | The project ID to deploy resources into | `any` | n/a | yes |
14+
| subnetwork | The name of the subnetwork to deploy instances into | `any` | n/a | yes |
15+
| subnetwork\_project | The project ID where the desired subnetwork is provisioned | `any` | n/a | yes |
16+
| zone | The GCP zone to deploy instances into | `string` | n/a | yes |
1717

1818
## Outputs
1919

0 commit comments

Comments
 (0)