-
Notifications
You must be signed in to change notification settings - Fork 368
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
feat: create service account as part of instance template module #475
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# instance-template-simple | ||
|
||
This is a simple, minimal example of how to use the instance_template module. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| enable\_nested\_virtualization | Defines whether the instance should have nested virtualization enabled. | `bool` | `false` | no | | ||
| labels | Labels, provided as a map | `map(string)` | n/a | yes | | ||
| 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 | | ||
| subnetwork | The name of the subnetwork create this instance in. | `string` | `""` | no | | ||
| tags | Network tags, provided as a list | `list(string)` | n/a | yes | | ||
| threads\_per\_core | The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1. | `string` | `null` | 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 --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
provider "google" { | ||
|
||
project = var.project_id | ||
region = var.region | ||
} | ||
|
||
resource "google_compute_address" "ip_address" { | ||
name = "external-ip" | ||
} | ||
|
||
locals { | ||
access_config = { | ||
nat_ip = google_compute_address.ip_address.address | ||
network_tier = "PREMIUM" | ||
} | ||
} | ||
|
||
module "instance_template" { | ||
source = "../../../modules/instance_template" | ||
|
||
project_id = var.project_id | ||
region = var.region | ||
subnetwork = var.subnetwork | ||
stack_type = "IPV4_ONLY" | ||
name_prefix = "simple" | ||
tags = var.tags | ||
labels = var.labels | ||
access_config = [local.access_config] | ||
enable_nested_virtualization = var.enable_nested_virtualization | ||
threads_per_core = var.threads_per_core | ||
} |
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 | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* 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 "tags" { | ||
type = list(string) | ||
description = "Network tags, provided as a list" | ||
} | ||
|
||
variable "labels" { | ||
type = map(string) | ||
description = "Labels, provided as a map" | ||
} | ||
|
||
variable "enable_nested_virtualization" { | ||
type = bool | ||
description = "Defines whether the instance should have nested virtualization enabled." | ||
default = false | ||
} | ||
|
||
variable "threads_per_core" { | ||
type = string | ||
description = "The number of threads per physical core. To disable simultaneous multithreading (SMT) set this to 1." | ||
default = null | ||
} | ||
Comment on lines
+24
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets hard code all of these in the example |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,6 +328,25 @@ variable "service_account" { | |
scopes = optional(set(string), ["cloud-platform"]) | ||
}) | ||
description = "Service account to attach to the instance. See https://www.terraform.io/docs/providers/google/r/compute_instance_template#service_account." | ||
default = null | ||
} | ||
|
||
variable "create_new_service_account" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: lets name as |
||
type = object({ | ||
enabled = bool | ||
scopes = set(string) | ||
}) | ||
description = "Create a new service account to attach to the instance. This is alternate to providing the service_account input variable." | ||
default = { | ||
enabled = true | ||
scopes = ["cloud-platform"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's generally not needed to use scope. For this functiality I would recommend changing logic to just use |
||
} | ||
} | ||
|
||
variable "service_account_project_roles" { | ||
type = list(string) | ||
description = "Roles to grant to the newly created cloud run SA in specified project. Should be used with create_service_account set to true and no input for service_account" | ||
default = [] | ||
} | ||
|
||
########################### | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: update