Skip to content

Commit d68f6b4

Browse files
authored
Merge branch 'master' into master
2 parents c522daa + 2e544f2 commit d68f6b4

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99

1010
## [1.1.1] - 2019-10-25
11-
1211
### Fixed
1312

1413
- Fix bug with `distribution_policy_zones` forcing permadiff. [#37]
@@ -18,9 +17,9 @@ project adheres to [Semantic Versioning](http://semver.org/).
1817
### Added
1918

2019
- Added variable `project_id`. [#26]
21-
2220
- `preemptible_and_regular_instance_templates` submodule. [#18]
23-
- `mig_with_percent` submodule. [#18]
21+
- `mig_with_percent` submodule. [#19]
22+
- Support for shielded VMs. [#38]
2423

2524
## [1.0.0] - 2019-07-31
2625

@@ -44,13 +43,16 @@ project adheres to [Semantic Versioning](http://semver.org/).
4443
- `instance_template`, `mig`, and `umig` modules
4544
- examples, basic tests and fixtures for all modules
4645

47-
[Unreleased]: https://github.com/terraform-google-modules/terraform-google-vm/compare/v1.0.0...HEAD
46+
[Unreleased]: https://github.com/terraform-google-modules/terraform-google-vm/compare/v1.1.0...HEAD
47+
[1.1.0]: https://github.com/terraform-google-modules/terraform-google-vm/compare/v1.0.0...v1.1.0
4848
[1.0.0]: https://github.com/terraform-google-modules/terraform-google-vm/compare/v0.2.0...v1.0.0
4949
[0.2.0]: https://github.com/terraform-google-modules/terraform-google-vm/compare/v0.1.0...v0.2.0
5050
[0.1.0]: https://github.com/terraform-google-modules/terraform-google-vm/releases/tag/v0.1.0
5151
[#10]: https://github.com/terraform-google-modules/terraform-google-vm/pull/10
5252
[#14]: https://github.com/terraform-google-modules/terraform-google-vm/pull/14
5353
[#16]: https://github.com/terraform-google-modules/terraform-google-vm/pull/16
5454
[#18]: https://github.com/terraform-google-modules/terraform-google-vm/pull/18
55+
[#19]: https://github.com/terraform-google-modules/terraform-google-vm/pull/19
5556
[#26]: https://github.com/terraform-google-modules/terraform-google-vm/pull/26
5657
[#37]: https://github.com/terraform-google-modules/terraform-google-vm/pull/37
58+
[#38]: https://github.com/terraform-google-modules/terraform-google-vm/pull/38

modules/instance_template/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
2020
| can\_ip\_forward | Enable IP forwarding, for NAT instances for example | string | `"false"` | no |
2121
| disk\_size\_gb | Boot disk size in GB | string | `"100"` | no |
2222
| disk\_type | Boot disk type, can be either pd-ssd, local-ssd, or pd-standard | string | `"pd-standard"` | no |
23+
| enable\_shielded\_vm | Whether to enable the Shielded VM configuration on the instance. Note that the instance image must support Shielded VMs. See https://cloud.google.com/compute/docs/images | string | `"false"` | no |
2324
| labels | Labels, provided as a map | map(string) | `<map>` | no |
2425
| machine\_type | Machine type to create, e.g. n1-standard-1 | string | `"n1-standard-1"` | no |
2526
| metadata | Metadata, provided as a map | map(string) | `<map>` | no |
@@ -28,9 +29,10 @@ See the [simple](../../examples/instance_template/simple) for a usage example.
2829
| preemptible | Allow the instance to be preempted | bool | `"false"` | no |
2930
| project\_id | The GCP project ID | string | `"null"` | no |
3031
| service\_account | Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account. | object | n/a | yes |
32+
| shielded\_instance\_config | Not used unless enable_shielded_vm is true. Shielded VM configuration for the instance. | object | `<map>` | no |
3133
| source\_image | Source disk image. If neither source_image nor source_image_family is specified, defaults to the latest public CentOS image. | string | `""` | no |
32-
| source\_image\_family | Source image family. If neither source_image nor source_image_family is specified, defaults to the latest public CentOS image. | string | `""` | no |
33-
| source\_image\_project | Project where the source image comes from | string | `""` | no |
34+
| source\_image\_family | Source image family. If neither source_image nor source_image_family is specified, defaults to the latest public CentOS image. | string | `"centos-7"` | no |
35+
| source\_image\_project | Project where the source image comes from. The default project contains images that support Shielded VMs if desired | string | `"gce-uefi-images"` | no |
3436
| startup\_script | User startup script to run when instances spin up | string | `""` | no |
3537
| subnetwork | The name of the subnetwork to attach this interface to. The subnetwork must exist in the same region this instance will be created in. Either network or subnetwork must be provided. | string | `""` | no |
3638
| subnetwork\_project | The ID of the project in which the subnetwork belongs. If it is not provided, the provider project is used. | string | `""` | no |

modules/instance_template/main.tf

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ locals {
4343
]
4444

4545
all_disks = concat(local.boot_disk, var.additional_disks)
46+
47+
# NOTE: Even if all the shielded_instance_config values are false, if the
48+
# config block exists and an unsupported image is chosen, the apply will fail
49+
# so we use a single-value array with the default value to initialize the block
50+
# only if it is enabled.
51+
shielded_vm_configs = var.enable_shielded_vm ? [true] : []
4652
}
4753

4854
####################
@@ -80,6 +86,7 @@ resource "google_compute_instance_template" "tpl" {
8086
}
8187
}
8288
}
89+
8390
dynamic "service_account" {
8491
for_each = [var.service_account]
8592
content {
@@ -98,9 +105,18 @@ resource "google_compute_instance_template" "tpl" {
98105
create_before_destroy = "true"
99106
}
100107

101-
// scheduling must have automatic_restart be false when preemptible is true.
108+
# scheduling must have automatic_restart be false when preemptible is true.
102109
scheduling {
103110
preemptible = var.preemptible
104111
automatic_restart = ! var.preemptible
105112
}
113+
114+
dynamic "shielded_instance_config" {
115+
for_each = local.shielded_vm_configs
116+
content {
117+
enable_secure_boot = lookup(var.shielded_instance_config, "enable_secure_boot", shielded_instance_config.value)
118+
enable_vtpm = lookup(var.shielded_instance_config, "enable_vtpm", shielded_instance_config.value)
119+
enable_integrity_monitoring = lookup(var.shielded_instance_config, "enable_integrity_monitoring", shielded_instance_config.value)
120+
}
121+
}
106122
}

modules/instance_template/variables.tf

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ variable "source_image" {
6363

6464
variable "source_image_family" {
6565
description = "Source image family. If neither source_image nor source_image_family is specified, defaults to the latest public CentOS image."
66-
default = ""
66+
default = "centos-7"
6767
}
6868

6969
variable "source_image_project" {
70-
description = "Project where the source image comes from"
71-
default = ""
70+
description = "Project where the source image comes from. The default project contains images that support Shielded VMs if desired"
71+
default = "gce-uefi-images"
7272
}
7373

7474
variable "disk_size_gb" {
@@ -141,3 +141,26 @@ variable "service_account" {
141141
})
142142
description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account."
143143
}
144+
145+
###########################
146+
# Shielded VMs
147+
###########################
148+
variable "enable_shielded_vm" {
149+
default = false
150+
description = "Whether to enable the Shielded VM configuration on the instance. Note that the instance image must support Shielded VMs. See https://cloud.google.com/compute/docs/images"
151+
}
152+
153+
variable "shielded_instance_config" {
154+
description = "Not used unless enable_shielded_vm is true. Shielded VM configuration for the instance."
155+
type = object({
156+
enable_secure_boot = bool
157+
enable_vtpm = bool
158+
enable_integrity_monitoring = bool
159+
})
160+
161+
default = {
162+
enable_secure_boot = true
163+
enable_vtpm = true
164+
enable_integrity_monitoring = true
165+
}
166+
}

0 commit comments

Comments
 (0)