-
Notifications
You must be signed in to change notification settings - Fork 388
feat: add confidential computing example #421
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
Merged
apeabody
merged 5 commits into
terraform-google-modules:master
from
arthurlapertosa:confidential-complete
Sep 9, 2024
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ffa0033
feat: add confidential computing example
arthurlapertosa 103fb77
code review fixes
arthurlapertosa e93ae34
Merge branch 'master' into confidential-complete
arthurlapertosa 6af2ab3
fix lint
arthurlapertosa 8db92a9
code review changes
arthurlapertosa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,28 @@ | ||
# confidential computing vm | ||
|
||
This is an example of a vm creation with confidential computing, encrypted disk | ||
using a Cloud HSM key and a custom service account with cloud-platform scope. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| key | Key name. | `string` | n/a | yes | | ||
| keyring | Keyring name. | `string` | n/a | yes | | ||
| location | Location for the resources (keyring, key, network, etc.). | `string` | `"us"` | no | | ||
| project\_id | The Google Cloud project ID. | `string` | n/a | yes | | ||
| region | The GCP region to create and test resources in. | `string` | `"us-central1"` | no | | ||
| subnetwork | The subnetwork selflink to host the compute instances in. | `string` | n/a | yes | | ||
| suffix | A suffix to be used as an identifier for resources. (e.g., suffix for KMS Key, Keyring). | `string` | `""` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| instance\_self\_link | Self-link for compute instance. | | ||
| name | Name of the instance templates. | | ||
| self\_link | Self-link to the instance template. | | ||
| suffix | Suffix used as an identifier for resources. | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
arthurlapertosa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or 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,90 @@ | ||
/** | ||
* Copyright 2024 Google LLC | ||
arthurlapertosa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* 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. | ||
*/ | ||
|
||
locals { | ||
default_suffix = var.suffix == "" ? random_string.suffix.result : "${random_string.suffix.result}-${var.suffix}" | ||
key_name = "${var.key}-${local.default_suffix}" | ||
} | ||
|
||
resource "random_string" "suffix" { | ||
length = 4 | ||
special = false | ||
upper = false | ||
} | ||
|
||
module "kms" { | ||
source = "terraform-google-modules/kms/google" | ||
version = "2.3.0" | ||
|
||
keyring = "${var.keyring}-${local.default_suffix}" | ||
location = var.location | ||
project_id = var.project_id | ||
keys = [local.key_name] | ||
purpose = "ENCRYPT_DECRYPT" | ||
key_protection_level = "HSM" | ||
prevent_destroy = false | ||
} | ||
|
||
resource "google_service_account" "default" { | ||
arthurlapertosa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
project = var.project_id | ||
account_id = "confidential-compute-sa" | ||
display_name = "Custom SA for confidential VM Instance" | ||
} | ||
|
||
data "google_project" "project" { | ||
project_id = var.project_id | ||
} | ||
|
||
resource "google_kms_crypto_key_iam_binding" "crypto_key" { | ||
crypto_key_id = module.kms.keys[local.key_name] | ||
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" | ||
members = [ | ||
"serviceAccount:service-${data.google_project.project.number}@compute-system.iam.gserviceaccount.com", | ||
] | ||
} | ||
|
||
module "instance_template" { | ||
source = "../../modules/instance_template" | ||
|
||
region = var.region | ||
project_id = var.project_id | ||
subnetwork = var.subnetwork | ||
|
||
name_prefix = "confidential-encrypted-template" | ||
source_image_project = "ubuntu-os-cloud" | ||
source_image = "ubuntu-2004-lts" | ||
machine_type = "n2d-standard-2" | ||
min_cpu_platform = "AMD Milan" | ||
enable_confidential_vm = true | ||
confidential_instance_type = "SEV" | ||
|
||
service_account = { | ||
email = google_service_account.default.email | ||
scopes = ["cloud-platform"] | ||
} | ||
disk_encryption_key = module.kms.keys[local.key_name] | ||
} | ||
|
||
module "compute_instance" { | ||
source = "terraform-google-modules/vm/google//modules/compute_instance" | ||
version = "~> 11.0" | ||
|
||
region = var.region | ||
subnetwork = var.subnetwork | ||
hostname = "confidential-encrypted-instance" | ||
instance_template = module.instance_template.self_link | ||
deletion_protection = false | ||
} |
This file contains hidden or 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,36 @@ | ||
/** | ||
* Copyright 2024 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 | ||
} | ||
|
||
output "instance_self_link" { | ||
description = "Self-link for compute instance." | ||
value = module.compute_instance.instances_self_links[0] | ||
} | ||
|
||
output "suffix" { | ||
description = "Suffix used as an identifier for resources." | ||
value = local.default_suffix | ||
} |
This file contains hidden or 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,53 @@ | ||
/** | ||
* Copyright 2024 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 Google Cloud project ID." | ||
type = string | ||
} | ||
|
||
variable "region" { | ||
description = "The GCP region to create and test resources in." | ||
type = string | ||
default = "us-central1" | ||
} | ||
|
||
variable "subnetwork" { | ||
description = "The subnetwork selflink to host the compute instances in." | ||
type = string | ||
} | ||
|
||
variable "location" { | ||
description = "Location for the resources (keyring, key, network, etc.)." | ||
type = string | ||
default = "us" | ||
} | ||
|
||
variable "suffix" { | ||
description = "A suffix to be used as an identifier for resources. (e.g., suffix for KMS Key, Keyring)." | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "keyring" { | ||
description = "Keyring name." | ||
type = string | ||
} | ||
|
||
variable "key" { | ||
description = "Key name." | ||
type = string | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
/** | ||
* Copyright 2024 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. | ||
*/ | ||
|
||
module "confidential_computing" { | ||
source = "../../../examples/confidential_computing" | ||
project_id = var.project_id | ||
region = "us-central1" | ||
subnetwork = google_compute_subnetwork.main.self_link | ||
keyring = "key-ring-test" | ||
key = "key-test" | ||
} |
This file contains hidden or 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 @@ | ||
../shared/network.tf |
This file contains hidden or 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,40 @@ | ||
/** | ||
* Copyright 2024 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.confidential_computing.self_link | ||
} | ||
|
||
output "name" { | ||
description = "Name of the instance templates." | ||
value = module.confidential_computing.name | ||
} | ||
|
||
output "instance_self_link" { | ||
description = "Self-link for compute instance" | ||
arthurlapertosa marked this conversation as resolved.
Show resolved
Hide resolved
arthurlapertosa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
value = module.confidential_computing.instance_self_link | ||
} | ||
|
||
output "project_id" { | ||
description = "The GCP project to use for integration tests." | ||
value = var.project_id | ||
} | ||
|
||
output "suffix" { | ||
description = "Suffix used as an identifier for resources." | ||
value = module.confidential_computing.suffix | ||
} |
This file contains hidden or 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,20 @@ | ||
/** | ||
* Copyright 2024 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 | ||
} |
This file contains hidden or 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 2024 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.13" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.