Skip to content

Commit b452196

Browse files
authored
Merge pull request #55 from taylorludwig/feature/47-advanced-container-options
show how to use advanced container options with example
2 parents b7ddc6b + 93c5bb7 commit b452196

File tree

40 files changed

+466
-90
lines changed

40 files changed

+466
-90
lines changed

.kitchen.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ suites:
4040
backend: local
4141
controls:
4242
- gce
43+
- name: "instance_with_advanced_options"
44+
driver:
45+
name: "terraform"
46+
command_timeout: 1800
47+
root_module_directory: test/fixtures/instance_with_advanced_options
48+
verifier:
49+
name: terraform
50+
color: false
51+
systems:
52+
- name: system
53+
backend: local
54+
controls:
55+
- gce
4356
- name: "instance_with_attached_disk"
4457
driver:
4558
name: "terraform"

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Extending the adopted spec, each change should have a link to its corresponding
88

99
## [Unreleased]
1010

11+
### Added
12+
13+
- Example for showing advanced container options [#55]
14+
1115
## [2.0.0] - 2019-12-13
1216

1317
### Added
@@ -88,6 +92,7 @@ Extending the adopted spec, each change should have a link to its corresponding
8892
[0.2.0]: https://github.com/terraform-google-modules/terraform-google-container-vm/compare/v0.1.1...v0.2.0
8993
[0.1.1]: https://github.com/terraform-google-modules/terraform-google-container-vm/compare/v0.1.0...v0.1.1
9094

95+
[#55]: https://github.com/terraform-google-modules/terraform-google-container-vm/pull/55
9196
[#57]: https://github.com/terraform-google-modules/terraform-google-container-vm/pull/57
9297
[#54]: https://github.com/terraform-google-modules/terraform-google-container-vm/pull/54
9398
[#48]: https://github.com/terraform-google-modules/terraform-google-container-vm/pull/48

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This module is meant for use with Terraform 0.12. If you need a Terraform 0.11.x
1313
```hcl
1414
module "gce-container" {
1515
source = "github.com/terraform-google-modules/terraform-google-container-vm"
16-
version = "0.1.0"
16+
version = "2.0.0"
1717
1818
container = {
1919
image="gcr.io/google-samples/hello-app:1.0"
@@ -95,6 +95,42 @@ Then perform the following commands on the root folder:
9595

9696
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
9797

98+
## Container Options
99+
100+
Advanced container options, as described [here](https://cloud.google.com/compute/docs/containers/configuring-options-to-run-containers), can be passed in as part of the `container` map.
101+
102+
The `instance_with_advanced_options` example also demonstrates this.
103+
104+
```hcl
105+
module "gce-advanced-container" {
106+
source = "github.com/terraform-google-modules/terraform-google-container-vm"
107+
version = "2.0.0"
108+
109+
container = {
110+
image = "busybox"
111+
command = [
112+
"tail"
113+
]
114+
args = [
115+
"-f",
116+
"/dev/null"
117+
]
118+
securityContext = {
119+
privileged : true
120+
}
121+
tty : true
122+
env = [
123+
{
124+
name = "EXAMPLE"
125+
value = "VAR"
126+
}
127+
]
128+
}
129+
130+
restart_policy = "OnFailure"
131+
}
132+
```
133+
98134
## Requirements
99135
### Terraform plugins
100136
- [Terraform](https://www.terraform.io/downloads.html) 0.10.x
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform.tfvars
2+
.terraform
3+
terraform.tfstate.d
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Instance with Advanced Options
2+
3+
This example illustrates how to deploy a container to a Google Compute Engine instance in GCP with advanced options.
4+
5+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6+
## Inputs
7+
8+
| 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 |
16+
17+
## Outputs
18+
19+
| Name | Description |
20+
|------|-------------|
21+
| container | The container metadata provided to the module |
22+
| instance\_name | The deployed instance name |
23+
| ipv4 | The public IP address of the deployed instance |
24+
| vm\_container\_label | The instance label containing container configuration |
25+
| volumes | The volume metadata provided to the module |
26+
27+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
28+
29+
## Running
30+
31+
To provision this example, run the following from within this directory:
32+
33+
- `terraform init` to get plugins
34+
- `terraform plan` to dry-run the infrastructure changes
35+
- `terraform apply` to apply the infrastructure changes
36+
- `terraform destroy` to tear down the created infrastructure
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
provider "google" {
18+
}
19+
20+
locals {
21+
instance_name = format("%s-%s", var.instance_name, substr(md5(module.gce-advanced-container.container.image), 0, 8))
22+
}
23+
24+
module "gce-advanced-container" {
25+
source = "../../"
26+
27+
container = {
28+
image = "busybox"
29+
command = [
30+
"tail"
31+
]
32+
args = [
33+
"-f",
34+
"/dev/null"
35+
]
36+
securityContext = {
37+
privileged : true
38+
}
39+
tty : true
40+
env = [
41+
{
42+
name = "EXAMPLE"
43+
value = "VAR"
44+
}
45+
]
46+
}
47+
48+
restart_policy = "OnFailure"
49+
}
50+
51+
resource "google_compute_instance" "vm" {
52+
project = var.project_id
53+
name = local.instance_name
54+
machine_type = "n1-standard-1"
55+
zone = var.zone
56+
57+
boot_disk {
58+
initialize_params {
59+
image = module.gce-advanced-container.source_image
60+
}
61+
}
62+
63+
network_interface {
64+
subnetwork_project = var.subnetwork_project
65+
subnetwork = var.subnetwork
66+
access_config {}
67+
}
68+
69+
tags = ["container-vm-example"]
70+
71+
metadata = {
72+
gce-container-declaration = module.gce-advanced-container.metadata_value
73+
}
74+
75+
labels = {
76+
container-vm = module.gce-advanced-container.vm_container_label
77+
}
78+
79+
service_account {
80+
email = var.client_email
81+
scopes = [
82+
"https://www.googleapis.com/auth/cloud-platform",
83+
]
84+
}
85+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "vm_container_label" {
18+
description = "The instance label containing container configuration"
19+
value = module.gce-advanced-container.vm_container_label
20+
}
21+
22+
output "container" {
23+
description = "The container metadata provided to the module"
24+
value = module.gce-advanced-container.container
25+
}
26+
27+
output "volumes" {
28+
description = "The volume metadata provided to the module"
29+
value = module.gce-advanced-container.volumes
30+
}
31+
32+
output "instance_name" {
33+
description = "The deployed instance name"
34+
value = local.instance_name
35+
}
36+
37+
output "ipv4" {
38+
description = "The public IP address of the deployed instance"
39+
value = google_compute_instance.vm.network_interface.0.access_config.0.nat_ip
40+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
variable "project_id" {
18+
description = "The project ID to deploy resources into"
19+
}
20+
21+
variable "subnetwork_project" {
22+
description = "The project ID where the desired subnetwork is provisioned"
23+
}
24+
25+
variable "subnetwork" {
26+
description = "The name of the subnetwork to deploy instances into"
27+
}
28+
29+
variable "instance_name" {
30+
description = "The desired name to assign to the deployed instance"
31+
default = "container-vm-advanced-options"
32+
}
33+
34+
variable "zone" {
35+
description = "The GCP zone to deploy instances into"
36+
type = string
37+
}
38+
39+
variable "client_email" {
40+
description = "Service account email address"
41+
type = string
42+
default = ""
43+
}

examples/instance_with_attached_disk/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ This example illustrates how to deploy and expose a container to a Google Comput
1414
| instance\_name | The desired name to assign to the deployed instance | string | `"disk-instance-vm-test"` | no |
1515
| machine\_type | The GCP machine type to deploy | string | n/a | yes |
1616
| project\_id | The project ID to deploy resource into | string | n/a | yes |
17-
| region | The GCP region to deploy instances into | string | `"us-east4"` | no |
1817
| restart\_policy | The desired Docker restart policy for the deployed image | string | n/a | yes |
1918
| subnetwork | The name of the subnetwork to deploy instances into | string | n/a | yes |
2019
| subnetwork\_project | The project ID where the desired subnetwork is provisioned | string | n/a | yes |
21-
| zone | The GCP zone to deploy instances into | string | `"us-east4-b"` | no |
20+
| zone | The GCP zone to deploy instances into | string | n/a | yes |
2221

2322
## Outputs
2423

@@ -29,11 +28,8 @@ This example illustrates how to deploy and expose a container to a Google Comput
2928
| http\_port | The port on which the HTTP service is exposed |
3029
| instance\_name | The deployed instance name |
3130
| ipv4 | The public IP address of the deployed instance |
32-
| project\_id | The project ID resources were deployed into |
33-
| region | The region the GCE instance was deployed into |
3431
| vm\_container\_label | The instance label containing container configuration |
3532
| volumes | The volume metadata provided to the module |
36-
| zone | The zone the GCE instance was deployed into |
3733

3834
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
3935

examples/instance_with_attached_disk/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
provider "google" {
18-
region = var.region
1918
}
2019

2120
locals {

examples/instance_with_attached_disk/outputs.tf

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
output "project_id" {
18-
description = "The project ID resources were deployed into"
19-
value = var.project_id
20-
}
21-
22-
output "region" {
23-
description = "The region the GCE instance was deployed into"
24-
value = var.region
25-
}
26-
27-
output "zone" {
28-
description = "The zone the GCE instance was deployed into"
29-
value = var.zone
30-
}
31-
3217
output "vm_container_label" {
3318
description = "The instance label containing container configuration"
3419
value = module.gce-container.vm_container_label

examples/instance_with_attached_disk/variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,8 @@ variable "machine_type" {
4747
description = "The GCP machine type to deploy"
4848
}
4949

50-
variable "region" {
51-
description = "The GCP region to deploy instances into"
52-
default = "us-east4"
53-
}
54-
5550
variable "zone" {
5651
description = "The GCP zone to deploy instances into"
57-
default = "us-east4-b"
5852
}
5953

6054
variable "additional_metadata" {

examples/managed_instance_group/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ This example requires that some python libraries be installed, as outlined in `r
1818
| mig\_name | The desired name to assign to the deployed managed instance group | string | `"mig-test"` | no |
1919
| network | The GCP network | string | `"mig-net"` | no |
2020
| project\_id | The project ID to deploy resource into | string | n/a | yes |
21-
| region | The GCP region to deploy instances into | string | `"us-east4"` | no |
21+
| region | The GCP region to deploy instances into | string | n/a | yes |
2222
| service\_account | | object | `<map>` | no |
2323
| subnetwork | The name of the subnetwork to deploy instances into | string | `"mig-subnet"` | no |
24-
| zone | The GCP zone to deploy instances into | string | `"us-east4-b"` | no |
24+
| zone | The GCP zone to deploy instances into | string | n/a | yes |
2525

2626
## Outputs
2727

@@ -30,11 +30,8 @@ This example requires that some python libraries be installed, as outlined in `r
3030
| container | The container metadata provided to the module |
3131
| http\_address | The IP address on which the HTTP service is exposed |
3232
| http\_port | The port on which the HTTP service is exposed |
33-
| project\_id | The project ID resources were deployed into |
34-
| region | The region the GCE instance was deployed into |
3533
| vm\_container\_label | The instance label containing container configuration |
3634
| volumes | The volume metadata provided to the module |
37-
| zone | The zone the GCE instance was deployed into |
3835

3936
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
4037

0 commit comments

Comments
 (0)