From e207928e078014da20bfbcbe753f43b739fea39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Legrand?= Date: Fri, 18 Mar 2022 10:05:51 +0100 Subject: [PATCH] Removing unless variables, using local modules. --- .../network-dashboard/cloud-function/main.py | 3 +- .../network-dashboard/main.tf | 15 +++------ .../network-dashboard/tests/test.tf | 31 ++++++++++--------- .../network-dashboard/tests/variables.tf | 1 - .../network-dashboard/variables.tf | 7 ----- 5 files changed, 24 insertions(+), 33 deletions(-) diff --git a/examples/cloud-operations/network-dashboard/cloud-function/main.py b/examples/cloud-operations/network-dashboard/cloud-function/main.py index 8f9c5458c..0b1e3dff2 100644 --- a/examples/cloud-operations/network-dashboard/cloud-function/main.py +++ b/examples/cloud-operations/network-dashboard/cloud-function/main.py @@ -155,7 +155,8 @@ def create_metric(metric_name, description): for desc in client.list_metric_descriptors(name=MONITORING_PROJECT_LINK): types.append(desc.type) - if metric_link not in types: # If the metric doesn't exist yet, then we create it + # If the metric doesn't exist yet, then we create it + if metric_link not in types: descriptor = ga_metric.MetricDescriptor() descriptor.type = f"custom.googleapis.com/{metric_name}" descriptor.metric_kind = ga_metric.MetricDescriptor.MetricKind.GAUGE diff --git a/examples/cloud-operations/network-dashboard/main.tf b/examples/cloud-operations/network-dashboard/main.tf index bdc94f771..152bb3609 100644 --- a/examples/cloud-operations/network-dashboard/main.tf +++ b/examples/cloud-operations/network-dashboard/main.tf @@ -41,7 +41,7 @@ locals { ################################################ module "project-monitoring" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/project?ref=v14.0.0" + source = "../../../modules/project" name = "monitoring" parent = "organizations/${var.organization_id}" prefix = var.prefix @@ -54,7 +54,7 @@ module "project-monitoring" { ################################################ module "service-account-function" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/iam-service-account?ref=v14.0.0" + source = "../../../modules/iam-service-account" project_id = module.project-monitoring.project_id name = "sa-dash" generate_key = false @@ -81,7 +81,7 @@ module "service-account-function" { ################################################ module "pubsub" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/pubsub?ref=v14.0.0" + source = "../../../modules/pubsub" project_id = module.project-monitoring.project_id name = "network-dashboard-pubsub" subscriptions = { @@ -104,16 +104,11 @@ resource "google_cloud_scheduler_job" "job" { } } -# Random ID to re-deploy the Cloud Function with every Terraform run -resource "random_pet" "random" { - length = 1 -} - module "cloud-function" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/cloud-function?ref=v14.0.0" + source = "../../../modules/cloud-function" project_id = module.project-monitoring.project_id name = "network-dashboard-cloud-function" - bucket_name = "network-dashboard-bucket-${random_pet.random.id}" + bucket_name = "network-dashboard-bucket" bucket_config = { location = var.region lifecycle_delete_age = null diff --git a/examples/cloud-operations/network-dashboard/tests/test.tf b/examples/cloud-operations/network-dashboard/tests/test.tf index ad03d9de1..9e4677262 100644 --- a/examples/cloud-operations/network-dashboard/tests/test.tf +++ b/examples/cloud-operations/network-dashboard/tests/test.tf @@ -22,7 +22,7 @@ resource "google_folder" "test-net-dash" { ##### Creating host projects, VPCs, service projects ##### module "project-hub" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/project?ref=v14.0.0" + source = "../../../../modules/project" name = "test-host-hub" parent = google_folder.test-net-dash.name prefix = var.prefix @@ -36,7 +36,7 @@ module "project-hub" { } module "vpc-hub" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-vpc?ref=v14.0.0" + source = "../../../../modules/net-vpc" project_id = module.project-hub.project_id name = "vpc-hub" subnets = [ @@ -50,7 +50,7 @@ module "vpc-hub" { } module "project-svc-hub" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/project?ref=v14.0.0" + source = "../../../../modules/project" parent = google_folder.test-net-dash.name billing_account = var.billing_account prefix = var.prefix @@ -60,11 +60,12 @@ module "project-svc-hub" { shared_vpc_service_config = { attach = true host_project = module.project-hub.project_id + service_identity_iam = {} } } module "project-prod" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/project?ref=v14.0.0" + source = "../../../../modules/project" name = "test-host-prod" parent = google_folder.test-net-dash.name prefix = var.prefix @@ -78,7 +79,7 @@ module "project-prod" { } module "vpc-prod" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-vpc?ref=v14.0.0" + source = "../../../../modules/net-vpc" project_id = module.project-prod.project_id name = "vpc-prod" subnets = [ @@ -92,7 +93,7 @@ module "vpc-prod" { } module "project-svc-prod" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/project?ref=v14.0.0" + source = "../../../../modules/project" parent = google_folder.test-net-dash.name billing_account = var.billing_account prefix = var.prefix @@ -102,11 +103,12 @@ module "project-svc-prod" { shared_vpc_service_config = { attach = true host_project = module.project-prod.project_id + service_identity_iam = {} } } module "project-dev" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/project?ref=v14.0.0" + source = "../../../../modules/project" name = "test-host-dev" parent = google_folder.test-net-dash.name prefix = var.prefix @@ -120,7 +122,7 @@ module "project-dev" { } module "vpc-dev" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-vpc?ref=v14.0.0" + source = "../../../../modules/net-vpc" project_id = module.project-dev.project_id name = "vpc-dev" subnets = [ @@ -134,7 +136,7 @@ module "vpc-dev" { } module "project-svc-dev" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/project?ref=v14.0.0" + source = "../../../../modules/project" parent = google_folder.test-net-dash.name billing_account = var.billing_account prefix = var.prefix @@ -144,32 +146,33 @@ module "project-svc-dev" { shared_vpc_service_config = { attach = true host_project = module.project-dev.project_id + service_identity_iam = {} } } ##### Creating VPC peerings ##### module "hub-to-prod-peering" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-vpc?ref=v14.0.0-peering" + source = "../../../../modules/net-vpc-peering" local_network = module.vpc-hub.self_link peer_network = module.vpc-prod.self_link } module "prod-to-hub-peering" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-vpc?ref=v14.0.0-peering" + source = "../../../../modules/net-vpc-peering" local_network = module.vpc-prod.self_link peer_network = module.vpc-hub.self_link depends_on = [module.hub-to-prod-peering] } module "hub-to-dev-peering" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-vpc?ref=v14.0.0-peering" + source = "../../../../modules/net-vpc-peering" local_network = module.vpc-hub.self_link peer_network = module.vpc-dev.self_link } module "dev-to-hub-peering" { - source = "github.com/GoogleCloudPlatform/cloud-foundation-fabric//modules/net-vpc?ref=v14.0.0-peering" + source = "../../../../modules/net-vpc-peering" local_network = module.vpc-dev.self_link peer_network = module.vpc-hub.self_link depends_on = [module.hub-to-dev-peering] @@ -205,7 +208,7 @@ resource "google_compute_instance" "test-vm-prod2" { machine_type = "f1-micro" zone = var.zone - tags = ["${var.region}"] + tags = [var.region] boot_disk { initialize_params { diff --git a/examples/cloud-operations/network-dashboard/tests/variables.tf b/examples/cloud-operations/network-dashboard/tests/variables.tf index c1833b7e1..5339712c2 100644 --- a/examples/cloud-operations/network-dashboard/tests/variables.tf +++ b/examples/cloud-operations/network-dashboard/tests/variables.tf @@ -24,7 +24,6 @@ variable "billing_account" { variable "prefix" { description = "Customer name to use as prefix for resources' naming" - default = "net-dash" } variable "project_vm_services" { diff --git a/examples/cloud-operations/network-dashboard/variables.tf b/examples/cloud-operations/network-dashboard/variables.tf index b3b0c23e3..7170a513f 100644 --- a/examples/cloud-operations/network-dashboard/variables.tf +++ b/examples/cloud-operations/network-dashboard/variables.tf @@ -24,13 +24,6 @@ variable "billing_account" { variable "prefix" { description = "Customer name to use as prefix for resources' naming" - default = "net-dash" -} - -# Not used for now as I am creating the monitoring project in my main.tf file -variable "monitoring_project_id" { - type = string - description = "ID of the monitoring project, where the Cloud Function and dashboards will be deployed." } # TODO: support folder instead of a list of projects?