Skip to content

Commit e4fc47a

Browse files
authored
Normalize prefix handling in blueprints (GoogleCloudPlatform#1003)
1 parent d16affd commit e4fc47a

File tree

98 files changed

+502
-351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+502
-351
lines changed

CONTRIBUTING.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ module "project" {
209209
]
210210
}
211211
iam = {
212-
"roles/editor" = [
212+
"roles/editor" = [
213213
"serviceAccount:${module.project.service_accounts.cloud_services}"
214214
]
215215
}
@@ -236,7 +236,7 @@ module "project" {
236236
source = "./modules/project"
237237
name = "project-example"
238238
iam = {
239-
"roles/editor" = [
239+
"roles/editor" = [
240240
"serviceAccount:${module.project.service_accounts.cloud_services}"
241241
]
242242
}
@@ -543,16 +543,16 @@ locals {
543543

544544
#### The `prefix` variable
545545

546-
If you would like to use a "prefix" variable for resource names, please keep its definition consistent across all code:
546+
If you would like to use a "prefix" variable for resource names, please keep its definition consistent across all modules:
547547
```hcl
548548
# variables.tf
549549
variable "prefix" {
550550
description = "Optional prefix used for resource names."
551551
type = string
552552
default = null
553553
validation {
554-
condition = var.prefix != ""
555-
error_message = "Prefix can not be empty, please use null instead."
554+
condition = var.prefix != ""
555+
error_message = "Prefix cannot be empty, please use null instead."
556556
}
557557
}
558558
@@ -562,6 +562,18 @@ locals {
562562
}
563563
```
564564

565+
For blueprints the prefix is mandatory:
566+
```hcl
567+
variable "prefix" {
568+
description = "Prefix used for resource names."
569+
type = string
570+
validation {
571+
condition = var.prefix != ""
572+
error_message = "Prefix cannot be empty."
573+
}
574+
}
575+
```
576+
565577
### Interacting with checks, tests and tools
566578

567579
Our modules are designed for composition and live in a monorepo together with several end-to-end blueprints, so it was inevitable that over time we found ways of ensuring that a change does not break consumers.

blueprints/cloud-operations/adfs/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ Once done testing, you can clean up resources by running `terraform destroy`.
5454
|---|---|:---:|:---:|:---:|
5555
| [ad_dns_domain_name](variables.tf#L15) | AD DNS domain name. | <code>string</code> || |
5656
| [adfs_dns_domain_name](variables.tf#L26) | ADFS DNS domain name. | <code>string</code> || |
57-
| [project_id](variables.tf#L79) | Host project ID. | <code>string</code> || |
57+
| [prefix](variables.tf#L64) | Prefix used for resource names. | <code>string</code> || |
58+
| [project_id](variables.tf#L82) | Host project ID. | <code>string</code> || |
5859
| [ad_ip_cidr_block](variables.tf#L20) | Managed AD IP CIDR block. | <code>string</code> | | <code>&#34;10.0.0.0&#47;24&#34;</code> |
5960
| [disk_size](variables.tf#L31) | Disk size. | <code>number</code> | | <code>50</code> |
6061
| [disk_type](variables.tf#L37) | Disk type. | <code>string</code> | | <code>&#34;pd-ssd&#34;</code> |
6162
| [image](variables.tf#L43) | Image. | <code>string</code> | | <code>&#34;projects&#47;windows-cloud&#47;global&#47;images&#47;family&#47;windows-2022&#34;</code> |
6263
| [instance_type](variables.tf#L49) | Instance type. | <code>string</code> | | <code>&#34;n1-standard-2&#34;</code> |
6364
| [network_config](variables.tf#L55) | Network configuration | <code title="object&#40;&#123;&#10; network &#61; string&#10; subnet &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
64-
| [prefix](variables.tf#L64) | Prefix for the resources created. | <code>string</code> | | <code>null</code> |
65-
| [project_create](variables.tf#L70) | Parameters for the creation of the new project. | <code title="object&#40;&#123;&#10; billing_account_id &#61; string&#10; parent &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
66-
| [region](variables.tf#L84) | Region. | <code>string</code> | | <code>&#34;europe-west1&#34;</code> |
67-
| [subnet_ip_cidr_block](variables.tf#L90) | Subnet IP CIDR block. | <code>string</code> | | <code>&#34;10.0.1.0&#47;28&#34;</code> |
68-
| [zone](variables.tf#L96) | Zone. | <code>string</code> | | <code>&#34;europe-west1-c&#34;</code> |
65+
| [project_create](variables.tf#L73) | Parameters for the creation of the new project. | <code title="object&#40;&#123;&#10; billing_account_id &#61; string&#10; parent &#61; string&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
66+
| [region](variables.tf#L87) | Region. | <code>string</code> | | <code>&#34;europe-west1&#34;</code> |
67+
| [subnet_ip_cidr_block](variables.tf#L93) | Subnet IP CIDR block. | <code>string</code> | | <code>&#34;10.0.1.0&#47;28&#34;</code> |
68+
| [zone](variables.tf#L99) | Zone. | <code>string</code> | | <code>&#34;europe-west1-c&#34;</code> |
6969

7070
## Outputs
7171

blueprints/cloud-operations/adfs/main.tf

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
locals {
16-
prefix = (var.prefix == null || var.prefix == "") ? "" : "${var.prefix}-"
17-
}
18-
1915
module "project" {
2016
source = "../../../modules/project"
2117
billing_account = (
@@ -41,7 +37,7 @@ module "vpc" {
4137
count = var.network_config == null ? 1 : 0
4238
source = "../../../modules/net-vpc"
4339
project_id = module.project.project_id
44-
name = "${local.prefix}vpc"
40+
name = "${var.prefix}-vpc"
4541
subnets = [
4642
{
4743
ip_cidr_range = var.subnet_ip_cidr_block
@@ -98,7 +94,7 @@ module "server" {
9894

9995
module "glb" {
10096
source = "../../../modules/net-glb"
101-
name = "${local.prefix}glb"
97+
name = "${var.prefix}-glb"
10298
project_id = module.project.project_id
10399

104100
https = true

blueprints/cloud-operations/adfs/variables.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ variable "network_config" {
6262
}
6363

6464
variable "prefix" {
65-
description = "Prefix for the resources created."
65+
description = "Prefix used for resource names."
6666
type = string
67-
default = null
67+
validation {
68+
condition = var.prefix != ""
69+
error_message = "Prefix cannot be empty."
70+
}
6871
}
6972

7073
variable "project_create" {

blueprints/cloud-operations/dns-shared-vpc/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ Note that Terraform 0.13 at least is required due to the use of `for_each` with
2626
|---|---|:---:|:---:|:---:|
2727
| [billing_account_id](variables.tf#L17) | Billing account associated with the GCP Projects that will be created for each team. | <code>string</code> || |
2828
| [folder_id](variables.tf#L28) | Folder ID in which DNS projects will be created. | <code>string</code> || |
29-
| [shared_vpc_link](variables.tf#L48) | Shared VPC self link, used for DNS peering. | <code>string</code> || |
29+
| [prefix](variables.tf#L33) | Prefix used for resource names. | <code>string</code> || |
30+
| [shared_vpc_link](variables.tf#L51) | Shared VPC self link, used for DNS peering. | <code>string</code> || |
3031
| [dns_domain](variables.tf#L22) | DNS domain under which each application team DNS domain will be created. | <code>string</code> | | <code>&#34;example.org&#34;</code> |
31-
| [prefix](variables.tf#L33) | Customer name to use as prefix for resources' naming. | <code>string</code> | | <code>&#34;test-dns&#34;</code> |
32-
| [project_services](variables.tf#L39) | Service APIs enabled by default. | <code>list&#40;string&#41;</code> | | <code title="&#91;&#10; &#34;compute.googleapis.com&#34;,&#10; &#34;dns.googleapis.com&#34;,&#10;&#93;">&#91;&#8230;&#93;</code> |
33-
| [teams](variables.tf#L53) | List of application teams requiring their own Cloud DNS instance. | <code>list&#40;string&#41;</code> | | <code title="&#91;&#10; &#34;team1&#34;,&#10; &#34;team2&#34;,&#10;&#93;">&#91;&#8230;&#93;</code> |
32+
| [project_services](variables.tf#L42) | Service APIs enabled by default. | <code>list&#40;string&#41;</code> | | <code title="&#91;&#10; &#34;compute.googleapis.com&#34;,&#10; &#34;dns.googleapis.com&#34;,&#10;&#93;">&#91;&#8230;&#93;</code> |
33+
| [teams](variables.tf#L56) | List of application teams requiring their own Cloud DNS instance. | <code>list&#40;string&#41;</code> | | <code title="&#91;&#10; &#34;team1&#34;,&#10; &#34;team2&#34;,&#10;&#93;">&#91;&#8230;&#93;</code> |
3434

3535
## Outputs
3636

blueprints/cloud-operations/dns-shared-vpc/examples/shared-vpc-example/variables.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ variable "billing_account" {
5050
}
5151

5252
variable "prefix" {
53-
description = "Customer name to use as prefix for resources' naming."
54-
default = "test-dns"
53+
description = "Prefix used for resource names."
54+
type = string
55+
validation {
56+
condition = var.prefix != ""
57+
error_message = "Prefix cannot be empty."
58+
}
5559
}
5660

5761
variable "dns_domain" {

blueprints/cloud-operations/dns-shared-vpc/variables.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ variable "folder_id" {
3131
}
3232

3333
variable "prefix" {
34-
description = "Customer name to use as prefix for resources' naming."
34+
description = "Prefix used for resource names."
3535
type = string
36-
default = "test-dns"
36+
validation {
37+
condition = var.prefix != ""
38+
error_message = "Prefix cannot be empty."
39+
}
3740
}
3841

3942
variable "project_services" {

blueprints/cloud-operations/network-dashboard/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ If you are interested in this and/or would like to contribute, please contact le
9292
| [billing_account](variables.tf#L17) | The ID of the billing account to associate this project with | <code></code> | ✓ | |
9393
| [monitored_projects_list](variables.tf#L36) | ID of the projects to be monitored (where limits and quotas data will be pulled) | <code>list&#40;string&#41;</code> | ✓ | |
9494
| [organization_id](variables.tf#L46) | The organization id for the associated services | <code></code> | ✓ | |
95-
| [prefix](variables.tf#L50) | Customer name to use as prefix for monitoring project | <code></code> | ✓ | |
95+
| [prefix](variables.tf#L50) | Prefix used for resource names. | <code>string</code> | ✓ | |
9696
| [cf_version](variables.tf#L21) | Cloud Function version 2nd Gen or 1st Gen. Possible options: 'V1' or 'V2'.Use CFv2 if your Cloud Function timeouts after 9 minutes. By default it is using CFv1. | <code></code> | | <code>V1</code> |
9797
| [monitored_folders_list](variables.tf#L30) | ID of the projects to be monitored (where limits and quotas data will be pulled) | <code>list&#40;string&#41;</code> | | <code>&#91;&#93;</code> |
9898
| [monitoring_project_id](variables.tf#L41) | Monitoring project where the dashboard will be created and the solution deployed; a project will be created if set to empty string | <code></code> | | |
99-
| [project_monitoring_services](variables.tf#L54) | Service APIs enabled in the monitoring project if it will be created. | <code></code> | | <code title="&#91;&#10; &#34;artifactregistry.googleapis.com&#34;,&#10; &#34;cloudasset.googleapis.com&#34;,&#10; &#34;cloudbilling.googleapis.com&#34;,&#10; &#34;cloudbuild.googleapis.com&#34;,&#10; &#34;cloudfunctions.googleapis.com&#34;,&#10; &#34;cloudresourcemanager.googleapis.com&#34;,&#10; &#34;cloudscheduler.googleapis.com&#34;,&#10; &#34;compute.googleapis.com&#34;,&#10; &#34;iam.googleapis.com&#34;,&#10; &#34;iamcredentials.googleapis.com&#34;,&#10; &#34;logging.googleapis.com&#34;,&#10; &#34;monitoring.googleapis.com&#34;,&#10; &#34;pubsub.googleapis.com&#34;,&#10; &#34;run.googleapis.com&#34;,&#10; &#34;servicenetworking.googleapis.com&#34;,&#10; &#34;serviceusage.googleapis.com&#34;,&#10; &#34;storage-component.googleapis.com&#34;&#10;&#93;">&#91;&#8230;&#93;</code> |
100-
| [region](variables.tf#L76) | Region used to deploy the cloud functions and scheduler | <code></code> | | <code>europe-west1</code> |
101-
| [schedule_cron](variables.tf#L81) | Cron format schedule to run the Cloud Function. Default is every 10 minutes. | <code></code> | | <code>&#42;&#47;10 &#42; &#42; &#42; &#42;</code> |
99+
| [project_monitoring_services](variables.tf#L59) | Service APIs enabled in the monitoring project if it will be created. | <code></code> | | <code title="&#91;&#10; &#34;artifactregistry.googleapis.com&#34;,&#10; &#34;cloudasset.googleapis.com&#34;,&#10; &#34;cloudbilling.googleapis.com&#34;,&#10; &#34;cloudbuild.googleapis.com&#34;,&#10; &#34;cloudfunctions.googleapis.com&#34;,&#10; &#34;cloudresourcemanager.googleapis.com&#34;,&#10; &#34;cloudscheduler.googleapis.com&#34;,&#10; &#34;compute.googleapis.com&#34;,&#10; &#34;iam.googleapis.com&#34;,&#10; &#34;iamcredentials.googleapis.com&#34;,&#10; &#34;logging.googleapis.com&#34;,&#10; &#34;monitoring.googleapis.com&#34;,&#10; &#34;pubsub.googleapis.com&#34;,&#10; &#34;run.googleapis.com&#34;,&#10; &#34;servicenetworking.googleapis.com&#34;,&#10; &#34;serviceusage.googleapis.com&#34;,&#10; &#34;storage-component.googleapis.com&#34;&#10;&#93;">&#91;&#8230;&#93;</code> |
100+
| [region](variables.tf#L81) | Region used to deploy the cloud functions and scheduler | <code></code> | | <code>europe-west1</code> |
101+
| [schedule_cron](variables.tf#L86) | Cron format schedule to run the Cloud Function. Default is every 10 minutes. | <code></code> | | <code>&#42;&#47;10 &#42; &#42; &#42; &#42;</code> |
102102
103103
<!-- END TFDOC -->

blueprints/cloud-operations/network-dashboard/cloud-function/metrics/limits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def count_effective_limit(config, project_id, network_dict, usage_metric_name,
187187
for peered_network in network_dict['peerings']:
188188
if 'usage' not in peered_network:
189189
print(
190-
f"Can not add metrics for peered network in projects/{project_id} as no usage metrics exist due to missing permissions"
190+
f"Cannot add metrics for peered network in projects/{project_id} as no usage metrics exist due to missing permissions"
191191
)
192192
continue
193193
peering_group_usage += peered_network['usage']

blueprints/cloud-operations/network-dashboard/tests/variables.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ variable "billing_account" {
2323
}
2424

2525
variable "prefix" {
26-
description = "Customer name to use as prefix for resources' naming"
26+
description = "Prefix used for resource names."
27+
type = string
28+
validation {
29+
condition = var.prefix != ""
30+
error_message = "Prefix cannot be empty."
31+
}
2732
}
2833

2934
variable "project_vm_services" {

0 commit comments

Comments
 (0)