-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support setting var.disk_encryption_key for instance templates …
…to enable encryption on all disks (#181)
- Loading branch information
Showing
8 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# instance-template-additional-disks | ||
|
||
This example demonstrates how to use the instance_template module to create | ||
instance templates with encrypted persistent disks. | ||
|
||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| project\_id | The GCP project to use for integration tests | `string` | n/a | yes | | ||
| region | The GCP region to create and test resources in | `string` | `"us-central1"` | no | | ||
| service\_account | Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account. | <pre>object({<br> email = string<br> scopes = set(string)<br> })</pre> | `null` | no | | ||
| subnetwork | The name of the subnetwork create this instance in. | `string` | `""` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| name | Name of the instance templates | | ||
| self\_link | Self-link to the instance template | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
provider "google" { | ||
|
||
project = var.project_id | ||
region = var.region | ||
version = "~> 3.0" | ||
} | ||
|
||
resource "google_kms_key_ring" "keyring" { | ||
name = "keyring-example" | ||
location = "global" | ||
} | ||
|
||
resource "google_kms_crypto_key" "example-key" { | ||
name = "crypto-key-example" | ||
key_ring = google_kms_key_ring.keyring.id | ||
rotation_period = "100000s" | ||
|
||
lifecycle { | ||
prevent_destroy = true | ||
} | ||
} | ||
|
||
module "instance_template" { | ||
source = "../../../modules/instance_template" | ||
project_id = var.project_id | ||
subnetwork = var.subnetwork | ||
service_account = var.service_account | ||
name_prefix = "additional-disks" | ||
|
||
disk_encryption_key = google_kms_crypto_key.example-key.self_link | ||
|
||
additional_disks = [ | ||
{ | ||
disk_name = "disk-0" | ||
device_name = "disk-0" | ||
disk_size_gb = 10 | ||
disk_type = "pd-standard" | ||
auto_delete = "true" | ||
boot = "false" | ||
disk_labels = {} | ||
}, | ||
{ | ||
disk_name = "disk-1" | ||
device_name = "disk-1" | ||
disk_size_gb = 10 | ||
disk_type = "pd-standard" | ||
auto_delete = "true" | ||
boot = "false" | ||
disk_labels = { "foo" : "bar" } | ||
}, | ||
{ | ||
disk_name = "disk-2" | ||
device_name = "disk-2" | ||
disk_size_gb = 10 | ||
disk_type = "pd-standard" | ||
auto_delete = "true" | ||
boot = "false" | ||
disk_labels = { "foo" : "bar" } | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
output "self_link" { | ||
description = "Self-link to the instance template" | ||
value = module.instance_template.self_link | ||
} | ||
|
||
output "name" { | ||
description = "Name of the instance templates" | ||
value = module.instance_template.name | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
variable "project_id" { | ||
description = "The GCP project to use for integration tests" | ||
type = string | ||
} | ||
|
||
variable "region" { | ||
description = "The GCP region to create and test resources in" | ||
type = string | ||
default = "us-central1" | ||
} | ||
|
||
variable "subnetwork" { | ||
description = "The name of the subnetwork create this instance in." | ||
default = "" | ||
} | ||
|
||
variable "service_account" { | ||
default = null | ||
type = object({ | ||
email = string | ||
scopes = set(string) | ||
}) | ||
description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template.html#service_account." | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
terraform { | ||
required_version = ">=0.12.6" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters