diff --git a/.gemini/styleguide.md b/.gemini/styleguide.md index 533ee94bb..acaa392e8 100644 --- a/.gemini/styleguide.md +++ b/.gemini/styleguide.md @@ -39,6 +39,7 @@ Evaluate diffs and static analysis findings from a skeptical maintainer perspect * Declare `provider = google-beta` explicitly on resources and attributes that require the beta provider under the active `versions.tf` constraints, including `google_cloud_run_v2_worker_pool`, `google_kms_autokey_config`, `google_folder_service_identity`, and `google_spanner_instance`. * Prefer compact `object({...})` variables with `optional()` attributes over proliferating scalar variables, omitting explicit defaults on `optional()` when the underlying provider default should apply. * Use `map(...)` collections rather than `list(...)` for multi-instance resources so `for_each` state keys remain stable across insertions and removals, and use deterministic `prefix` tokens rather than random string suffixes for resource naming. +* Name resource, data source, variable, and output labels in snake_case and module labels in kebab-case, as the `terraform_naming_convention` rule in the `.tflint.hcl` file enforces through the `tools/tflint.sh` script, and require a `moved` block for every renamed resource or module so Terraform moves existing state instead of replacing the resource. * Include plan-time `validation` blocks on variables that mirror underlying provider ENUM values. * Never hardcode project IDs, folder IDs, or regions in module or stage code, never set `project`, `region`, or `zone` on `provider "google"` or `provider "google-beta"` blocks, and never use `local-exec` or `remote-exec` provisioners when native Terraform resources or data sources exist. * Preserve safe upstream defaults such as `deletion_protection = coalesce(each.value.deletion_protection, true)` on stateful resources. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e742f926..bb2c0e0ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,6 +58,31 @@ jobs: run: | bash tests/scripts/run_shell_tests.sh + tflint: + name: Terraform Lint + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout Repository + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 + with: + persist-credentials: false + + - name: Set up TFLint + uses: terraform-linters/setup-tflint@6ffdbaa3be476b3431f7275c26966ef32ff60337 # v6.3.2 + with: + tflint_version: v0.64.0 + checksums: cca9d13e2e1d7a2c627af60ff899a3c9b74212899416aeb96ec764d2ef954537 + + - name: Test TFLint Runner + run: | + bash tests/scripts/test_tflint.sh + + - name: Run TFLint + run: | + bash tools/tflint.sh -f compact + python-tests: name: Python Unit Tests & Code Quality runs-on: ubuntu-latest diff --git a/.tflint.hcl b/.tflint.hcl index 16198b068..b68779a09 100644 --- a/.tflint.hcl +++ b/.tflint.hcl @@ -24,3 +24,27 @@ rule "terraform_required_providers" { rule "terraform_required_version" { enabled = false } + +rule "terraform_naming_convention" { + enabled = true + format = "snake_case" + + custom_formats = { + private_snake = { + description = "snake_case with leading _" + regex = "^[_a-z][a-z0-9_]*$" + } + kebab = { + description = "lower kebab case" + regex = "^[a-z][a-z0-9-]*$" + } + } + + locals { + format = "private_snake" + } + + module { + format = "kebab" + } +} diff --git a/blueprints/fedramp-high/access-context-manager/main.tf b/blueprints/fedramp-high/access-context-manager/main.tf index 2add1e2cb..479f4887a 100644 --- a/blueprints/fedramp-high/access-context-manager/main.tf +++ b/blueprints/fedramp-high/access-context-manager/main.tf @@ -12,7 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -module "access_context_manager" { +moved { + from = module.access_context_manager + to = module.access-context-manager +} + +module "access-context-manager" { source = "../../../modules/access-context-manager" project_id = var.main_project_id diff --git a/blueprints/fedramp-high/access-context-manager/outputs.tf b/blueprints/fedramp-high/access-context-manager/outputs.tf index 0c946e571..aa961d750 100644 --- a/blueprints/fedramp-high/access-context-manager/outputs.tf +++ b/blueprints/fedramp-high/access-context-manager/outputs.tf @@ -14,11 +14,11 @@ output "access_levels" { description = "The list of created access levels with their details." - value = module.access_context_manager.access_levels + value = module.access-context-manager.access_levels } output "service_perimeters" { description = "The list of created service perimeters with their details." - value = module.access_context_manager.service_perimeters + value = module.access-context-manager.service_perimeters } diff --git a/blueprints/fedramp-high/cloud-functions/main.tf b/blueprints/fedramp-high/cloud-functions/main.tf index 48d525619..ea510e461 100644 --- a/blueprints/fedramp-high/cloud-functions/main.tf +++ b/blueprints/fedramp-high/cloud-functions/main.tf @@ -64,19 +64,34 @@ resource "google_kms_crypto_key_iam_member" "cloud_storage" { member = each.value } -resource "google_project_iam_member" "artifactregistry_createOnPushWriter" { +moved { + from = google_project_iam_member.artifactregistry_createOnPushWriter + to = google_project_iam_member.artifactregistry_create_on_push_writer +} + +resource "google_project_iam_member" "artifactregistry_create_on_push_writer" { project = var.main_project_id role = "roles/artifactregistry.createOnPushWriter" member = module.service-account-runner.iam_email } -resource "google_project_iam_member" "logging_logWriter" { +moved { + from = google_project_iam_member.logging_logWriter + to = google_project_iam_member.logging_log_writer +} + +resource "google_project_iam_member" "logging_log_writer" { project = var.main_project_id role = "roles/logging.logWriter" member = module.service-account-runner.iam_email } -resource "google_project_iam_member" "storage_objectUser" { +moved { + from = google_project_iam_member.storage_objectUser + to = google_project_iam_member.storage_object_user +} + +resource "google_project_iam_member" "storage_object_user" { project = var.main_project_id role = "roles/storage.objectUser" member = module.service-account-runner.iam_email diff --git a/blueprints/fedramp-high/cloud-functions/outputs.tf b/blueprints/fedramp-high/cloud-functions/outputs.tf index 6fdf55042..2ef2113a2 100644 --- a/blueprints/fedramp-high/cloud-functions/outputs.tf +++ b/blueprints/fedramp-high/cloud-functions/outputs.tf @@ -14,7 +14,7 @@ output "artifact_registry_iam_member" { description = "IAM member assigned to roles/artifactregistry.createOnPushWriter." - value = google_project_iam_member.artifactregistry_createOnPushWriter.member + value = google_project_iam_member.artifactregistry_create_on_push_writer.member } output "bucket" { @@ -34,10 +34,10 @@ output "kms_crypto_key_iam_binding_members" { output "logging_iam_member" { description = "IAM member assigned to roles/logging.logWriter." - value = google_project_iam_member.logging_logWriter.member + value = google_project_iam_member.logging_log_writer.member } output "storage_object_admin_iam_member" { description = "IAM member assigned to roles/storage.objectAdmin." - value = google_project_iam_member.storage_objectUser.member + value = google_project_iam_member.storage_object_user.member } diff --git a/blueprints/fedramp-high/cloud-ids/main.tf b/blueprints/fedramp-high/cloud-ids/main.tf index 348c94ff6..cbc3c46cb 100644 --- a/blueprints/fedramp-high/cloud-ids/main.tf +++ b/blueprints/fedramp-high/cloud-ids/main.tf @@ -12,7 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -resource "google_project_service" "net-host-services" { +moved { + from = google_project_service.net-host-services + to = google_project_service.net_host_services +} + +resource "google_project_service" "net_host_services" { project = var.network_project_id for_each = toset([ "accesscontextmanager.googleapis.com", @@ -45,7 +50,12 @@ data "google_compute_zones" "available" { status = "UP" } -module "cloud_ids" { +moved { + from = module.cloud_ids + to = module.cloud-ids +} + +module "cloud-ids" { source = "../../../modules/intrusion-detection-system" project = var.network_project_id landing_vpc_network = var.network_name @@ -60,5 +70,5 @@ module "cloud_ids" { severity = var.severity packet_mirroring_policy_name = "${var.prefix}-${var.packet_mirroring_policy_name}" - depends_on = [google_project_service.net-host-services] + depends_on = [google_project_service.net_host_services] } \ No newline at end of file diff --git a/blueprints/fedramp-high/cloud-ids/outputs.tf b/blueprints/fedramp-high/cloud-ids/outputs.tf index 078eb456e..4ac9b675c 100644 --- a/blueprints/fedramp-high/cloud-ids/outputs.tf +++ b/blueprints/fedramp-high/cloud-ids/outputs.tf @@ -14,15 +14,15 @@ output "ids_name" { description = "The name of the Cloud IDS instance." - value = module.cloud_ids.ids_name + value = module.cloud-ids.ids_name } output "ids_private_ip_range_name" { description = "The private IP range name for the IDS." - value = module.cloud_ids.ids_private_ip_range_name + value = module.cloud-ids.ids_private_ip_range_name } output "packet_mirroring_policy_name" { description = "The name of the packet mirroring policy." - value = module.cloud_ids.packet_mirroring_policy_name + value = module.cloud-ids.packet_mirroring_policy_name } \ No newline at end of file diff --git a/blueprints/fedramp-high/cloud-run/README.md b/blueprints/fedramp-high/cloud-run/README.md index 55991e849..f67c6d395 100644 --- a/blueprints/fedramp-high/cloud-run/README.md +++ b/blueprints/fedramp-high/cloud-run/README.md @@ -78,5 +78,5 @@ https://console.cloud.google.com/run | name | description | sensitive | |---|---|:---:| | [cloud_run](outputs.tf#L1) | Cloud Run Service that was created. | | -| [service-account](outputs.tf#L6) | Service account that was created to run the Cloud Run Service. | | +| [service_account](outputs.tf#L6) | Service account that was created to run the Cloud Run Service. | | diff --git a/blueprints/fedramp-high/cloud-run/main.tf b/blueprints/fedramp-high/cloud-run/main.tf index 6dc61c517..0a5549461 100644 --- a/blueprints/fedramp-high/cloud-run/main.tf +++ b/blueprints/fedramp-high/cloud-run/main.tf @@ -55,7 +55,12 @@ resource "google_kms_crypto_key_iam_member" "cloud_run_service_agent_kms_permiss member = "serviceAccount:service-${data.google_project.project.number}@serverless-robot-prod.iam.gserviceaccount.com" } -module "cloud_run" { +moved { + from = module.cloud_run + to = module.cloud-run +} + +module "cloud-run" { source = "../../../modules/cloud-run-v2-se/" project_id = var.main_project_id name = var.name diff --git a/blueprints/fedramp-high/cloud-run/outputs.tf b/blueprints/fedramp-high/cloud-run/outputs.tf index 8b9bca30e..34fa2e558 100644 --- a/blueprints/fedramp-high/cloud-run/outputs.tf +++ b/blueprints/fedramp-high/cloud-run/outputs.tf @@ -14,10 +14,10 @@ output "cloud_run" { description = "Cloud Run Service that was created." - value = module.cloud_run + value = module.cloud-run } -output "service-account" { +output "service_account" { description = "Service account that was created to run the Cloud Run Service." value = google_service_account.cloud_run_service_account.email } diff --git a/blueprints/fedramp-high/cloud-scheduler-job/main.tf b/blueprints/fedramp-high/cloud-scheduler-job/main.tf index 22ecc7e72..0b121b20e 100644 --- a/blueprints/fedramp-high/cloud-scheduler-job/main.tf +++ b/blueprints/fedramp-high/cloud-scheduler-job/main.tf @@ -35,7 +35,12 @@ resource "google_kms_crypto_key_iam_member" "pubsub" { depends_on = [google_project_service.cloudscheduler_api] # Ensure API is enabled before IAM } -module "pubsub_job" { +moved { + from = module.pubsub_job + to = module.pubsub-job +} + +module "pubsub-job" { source = "../../../modules/cloud-scheduler" name = var.name description = var.description diff --git a/blueprints/fedramp-high/cloud-scheduler-job/outputs.tf b/blueprints/fedramp-high/cloud-scheduler-job/outputs.tf index 1aee02ad3..118442656 100644 --- a/blueprints/fedramp-high/cloud-scheduler-job/outputs.tf +++ b/blueprints/fedramp-high/cloud-scheduler-job/outputs.tf @@ -14,10 +14,10 @@ output "id" { description = "Job ID." - value = module.pubsub_job.id + value = module.pubsub-job.id } output "state" { description = "Job state." - value = module.pubsub_job.state + value = module.pubsub-job.state } \ No newline at end of file diff --git a/blueprints/fedramp-high/cloud-spanner/main.tf b/blueprints/fedramp-high/cloud-spanner/main.tf index 19deed3bb..976866561 100644 --- a/blueprints/fedramp-high/cloud-spanner/main.tf +++ b/blueprints/fedramp-high/cloud-spanner/main.tf @@ -18,7 +18,12 @@ resource "google_project_service" "spanner_api" { disable_on_destroy = false } -module "cloud_spanner" { +moved { + from = module.cloud_spanner + to = module.cloud-spanner +} + +module "cloud-spanner" { source = "../../../modules/spanner-instance-se" project_id = var.main_project_id edition = var.edition diff --git a/blueprints/fedramp-high/cloud-spanner/outputs.tf b/blueprints/fedramp-high/cloud-spanner/outputs.tf index c6acd03b4..ab5daacf4 100644 --- a/blueprints/fedramp-high/cloud-spanner/outputs.tf +++ b/blueprints/fedramp-high/cloud-spanner/outputs.tf @@ -14,5 +14,5 @@ output "instance" { description = "Cloud spanner instance." - value = module.cloud_spanner + value = module.cloud-spanner } \ No newline at end of file diff --git a/blueprints/fedramp-high/cloud-translation/main.tf b/blueprints/fedramp-high/cloud-translation/main.tf index 3002f87ea..0eecb50bf 100644 --- a/blueprints/fedramp-high/cloud-translation/main.tf +++ b/blueprints/fedramp-high/cloud-translation/main.tf @@ -25,7 +25,12 @@ resource "google_project_service" "translate" { data "google_project" "project" {} -module "input_bucket" { +moved { + from = module.input_bucket + to = module.input-bucket +} + +module "input-bucket" { source = "../../../modules/gcs" project_id = var.main_project_id prefix = var.main_project_id @@ -35,7 +40,12 @@ module "input_bucket" { uniform_bucket_level_access = true } -module "output_bucket" { +moved { + from = module.output_bucket + to = module.output-bucket +} + +module "output-bucket" { source = "../../../modules/gcs" project_id = var.main_project_id prefix = var.main_project_id @@ -61,8 +71,8 @@ module "workflows" { kms_key_self_link = var.kms_key_self_link service_account = google_service_account.workflow_sa.email env_vars = { - input_bucket = "${module.input_bucket.url}/*.txt" - output_bucket = "${module.output_bucket.url}/${var.output_folder}/" + input_bucket = "${module.input-bucket.url}/*.txt" + output_bucket = "${module.output-bucket.url}/${var.output_folder}/" src_lang = var.src_lang target_lang = var.target_lang parent = "projects/${var.main_project_id}/locations/us-central1" diff --git a/blueprints/fedramp-high/cloud-translation/outputs.tf b/blueprints/fedramp-high/cloud-translation/outputs.tf index f55489a13..424d6ee3c 100644 --- a/blueprints/fedramp-high/cloud-translation/outputs.tf +++ b/blueprints/fedramp-high/cloud-translation/outputs.tf @@ -14,12 +14,12 @@ output "input_bucket" { description = "Bucket that takes documents as input." - value = module.input_bucket + value = module.input-bucket } output "output_bucket" { description = "Bucket that stores translated output." - value = module.output_bucket + value = module.output-bucket } output "workflow" { diff --git a/blueprints/fedramp-high/cnap/access_policy.tf b/blueprints/fedramp-high/cnap/access_policy.tf index 860dba95e..e353058c8 100644 --- a/blueprints/fedramp-high/cnap/access_policy.tf +++ b/blueprints/fedramp-high/cnap/access_policy.tf @@ -12,7 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -resource "google_access_context_manager_access_levels" "access-levels" { +moved { + from = google_access_context_manager_access_levels.access-levels + to = google_access_context_manager_access_levels.access_levels +} + +resource "google_access_context_manager_access_levels" "access_levels" { parent = "accessPolicies/${var.access_policy_number}" # Access level for US Region diff --git a/blueprints/fedramp-high/cnap/cloud_ids.tf b/blueprints/fedramp-high/cnap/cloud_ids.tf index 77feae4ad..3bfef0573 100644 --- a/blueprints/fedramp-high/cnap/cloud_ids.tf +++ b/blueprints/fedramp-high/cnap/cloud_ids.tf @@ -14,7 +14,12 @@ * limitations under the License. */ -module "cloud_ids" { +moved { + from = module.cloud_ids + to = module.cloud-ids +} + +module "cloud-ids" { source = "../../../modules/intrusion-detection-system" project = var.network_project_id landing_vpc_network = var.network_name # Duplicate variable (landing_network) @@ -29,5 +34,5 @@ module "cloud_ids" { severity = var.severity packet_mirroring_policy_name = "${var.prefix}-${var.packet_mirroring_policy_name}" - depends_on = [google_project_service.net-host-services] + depends_on = [google_project_service.net_host_services] } \ No newline at end of file diff --git a/blueprints/fedramp-high/cnap/compute_engine.tf b/blueprints/fedramp-high/cnap/compute_engine.tf index 6fe1d4904..16ba2bcc1 100644 --- a/blueprints/fedramp-high/cnap/compute_engine.tf +++ b/blueprints/fedramp-high/cnap/compute_engine.tf @@ -49,7 +49,12 @@ module "cos-demo-config" { run_commands = ["systemctl daemon-reload", "systemctl start demo", ] } -resource "google_compute_region_instance_template" "cos-template" { +moved { + from = google_compute_region_instance_template.cos-template + to = google_compute_region_instance_template.cos_template +} + +resource "google_compute_region_instance_template" "cos_template" { for_each = local.vms project = data.google_project.project.project_id name_prefix = "${var.prefix}-template-${each.key}" @@ -94,7 +99,12 @@ resource "google_compute_region_instance_template" "cos-template" { } } -resource "google_compute_region_health_check" "http-region-health-check" { +moved { + from = google_compute_region_health_check.http-region-health-check + to = google_compute_region_health_check.http_region_health_check +} + +resource "google_compute_region_health_check" "http_region_health_check" { for_each = local.vms project = data.google_project.project.project_id @@ -114,10 +124,10 @@ module "cos-mig" { project_id = data.google_project.project.project_id location = var.region name = "${var.prefix}-cos-${each.key}" - instance_template = google_compute_region_instance_template.cos-template[each.key].self_link + instance_template = google_compute_region_instance_template.cos_template[each.key].self_link target_size = 1 auto_healing_policies = { - health_check = google_compute_region_health_check.http-region-health-check[each.key].self_link + health_check = google_compute_region_health_check.http_region_health_check[each.key].self_link initial_delay_sec = 60 } @@ -165,7 +175,12 @@ module "kms" { } -resource "google_compute_firewall" "allow-app" { +moved { + from = google_compute_firewall.allow-app + to = google_compute_firewall.allow_app +} + +resource "google_compute_firewall" "allow_app" { name = "cnap-app-firewall" network = data.google_compute_network.network.id diff --git a/blueprints/fedramp-high/cnap/load_balancer.tf b/blueprints/fedramp-high/cnap/load_balancer.tf index ce21bca41..f0eff140d 100644 --- a/blueprints/fedramp-high/cnap/load_balancer.tf +++ b/blueprints/fedramp-high/cnap/load_balancer.tf @@ -33,7 +33,7 @@ locals { backends = [{ backend = module.cos-mig[key].group_manager.instance_group }] - health_checks = [google_compute_region_health_check.http-region-health-check[key].self_link, ] + health_checks = [google_compute_region_health_check.http_region_health_check[key].self_link, ] protocol = "HTTP" iap_config = { oauth2_client_id = google_iap_client.project_client.client_id @@ -113,7 +113,12 @@ resource "google_compute_region_ssl_certificate" "default" { } } -resource "google_compute_address" "cnap-ext-ip" { +moved { + from = google_compute_address.cnap-ext-ip + to = google_compute_address.cnap_ext_ip +} + +resource "google_compute_address" "cnap_ext_ip" { name = "cnap-ip" region = var.region address_type = "EXTERNAL" @@ -127,7 +132,7 @@ module "cnap-0-redirect" { vpc = data.google_compute_network.network.self_link region = var.region address = ( - google_compute_address.cnap-ext-ip.id + google_compute_address.cnap_ext_ip.id ) health_check_configs = {} urlmap_config = { @@ -147,7 +152,7 @@ module "cnap-0" { vpc = data.google_compute_network.network.self_link region = var.region address = ( - google_compute_address.cnap-ext-ip.id + google_compute_address.cnap_ext_ip.id ) backend_service_configs = local.backends # with a single serverless NEG the implied default health check is not needed diff --git a/blueprints/fedramp-high/cnap/main.tf b/blueprints/fedramp-high/cnap/main.tf index 92e3e9d0b..a4f56f20d 100644 --- a/blueprints/fedramp-high/cnap/main.tf +++ b/blueprints/fedramp-high/cnap/main.tf @@ -59,7 +59,12 @@ resource "google_project_service" "services" { } -resource "google_project_service" "net-host-services" { +moved { + from = google_project_service.net-host-services + to = google_project_service.net_host_services +} + +resource "google_project_service" "net_host_services" { project = var.network_project_id for_each = toset([ "accesscontextmanager.googleapis.com", diff --git a/blueprints/fedramp-high/dataproc-cluster/main.tf b/blueprints/fedramp-high/dataproc-cluster/main.tf index 69ff9111f..58b935d53 100644 --- a/blueprints/fedramp-high/dataproc-cluster/main.tf +++ b/blueprints/fedramp-high/dataproc-cluster/main.tf @@ -110,7 +110,12 @@ module "gcs" { ] } -module "dataproc_cluster" { +moved { + from = module.dataproc_cluster + to = module.dataproc-cluster +} + +module "dataproc-cluster" { source = "../../../modules/dataproc" project_id = var.main_project_id name = var.dataproc_cluster_name diff --git a/blueprints/fedramp-high/dataproc-cluster/outputs.tf b/blueprints/fedramp-high/dataproc-cluster/outputs.tf index f441c94c1..e68f89230 100644 --- a/blueprints/fedramp-high/dataproc-cluster/outputs.tf +++ b/blueprints/fedramp-high/dataproc-cluster/outputs.tf @@ -19,5 +19,5 @@ output "dataproc_bucket" { output "dataproc_cluster" { description = "Dataproc cluster name." - value = module.dataproc_cluster.name + value = module.dataproc-cluster.name } diff --git a/blueprints/fedramp-high/document-ai/main.tf b/blueprints/fedramp-high/document-ai/main.tf index df27256b4..651fb1234 100644 --- a/blueprints/fedramp-high/document-ai/main.tf +++ b/blueprints/fedramp-high/document-ai/main.tf @@ -50,7 +50,12 @@ resource "google_document_ai_processor_default_version" "processor" { } } -module "input_bucket" { +moved { + from = module.input_bucket + to = module.input-bucket +} + +module "input-bucket" { source = "../../../modules/gcs" project_id = var.main_project_id prefix = var.main_project_id @@ -61,7 +66,12 @@ module "input_bucket" { encryption_key = var.kms_key_name } -module "output_bucket" { +moved { + from = module.output_bucket + to = module.output-bucket +} + +module "output-bucket" { source = "../../../modules/gcs" project_id = var.main_project_id prefix = var.main_project_id @@ -84,8 +94,8 @@ module "workflows" { kms_key_self_link = var.kms_key_name env_vars = { project_id = var.main_project_id - input_bucket = module.input_bucket.url - output_bucket = module.output_bucket.url + input_bucket = module.input-bucket.url + output_bucket = module.output-bucket.url processor_id = google_document_ai_processor.processor.id location = var.region } diff --git a/blueprints/fedramp-high/document-ai/outputs.tf b/blueprints/fedramp-high/document-ai/outputs.tf index f89959784..5d566e750 100644 --- a/blueprints/fedramp-high/document-ai/outputs.tf +++ b/blueprints/fedramp-high/document-ai/outputs.tf @@ -19,12 +19,12 @@ output "id" { output "input_bucket" { description = "Bucket that takes documents as input." - value = module.input_bucket + value = module.input-bucket } output "output_bucket" { description = "Bucket that stores document processor output." - value = module.output_bucket + value = module.output-bucket } output "processor" { diff --git a/blueprints/fedramp-high/gitlab/README.md b/blueprints/fedramp-high/gitlab/README.md index 02137b30e..f8e5e76e5 100644 --- a/blueprints/fedramp-high/gitlab/README.md +++ b/blueprints/fedramp-high/gitlab/README.md @@ -167,7 +167,7 @@ The setup should now be complete and GitLab will now have HTTPS enabled. | name | description | sensitive | |---|---|:---:| -| [gke-cluster](outputs.tf#L1) | Deployed GKE cluster. | ✓ | +| [gke_cluster](outputs.tf#L1) | Deployed GKE cluster. | ✓ | | [lb](outputs.tf#L7) | Application Load Balancer. | ✓ | | [umig](outputs.tf#L13) | Unmanaged instance group. | ✓ | | [vm](outputs.tf#L19) | Deployed VM. | ✓ | diff --git a/blueprints/fedramp-high/gitlab/main.tf b/blueprints/fedramp-high/gitlab/main.tf index d5724c4d0..0e1701dc6 100644 --- a/blueprints/fedramp-high/gitlab/main.tf +++ b/blueprints/fedramp-high/gitlab/main.tf @@ -16,14 +16,19 @@ data "google_project" "project" { project_id = var.project_id } -resource "google_service_account" "gitlab-sa" { +moved { + from = google_service_account.gitlab-sa + to = google_service_account.gitlab_sa +} + +resource "google_service_account" "gitlab_sa" { account_id = var.sa display_name = "gitlab-sa" } resource "google_project_iam_member" "gke_cluster_admin" { project = data.google_project.project.project_id role = "roles/container.admin" - member = "serviceAccount:${google_service_account.gitlab-sa.email}" + member = "serviceAccount:${google_service_account.gitlab_sa.email}" } resource "google_project_service" "storagetransfer_api" { @@ -43,7 +48,7 @@ resource "google_project_iam_member" "compute_agent_subnet_user" { compute_agent = "serviceAccount:service-${data.google_project.project.number}@compute-system.iam.gserviceaccount.com" gke_agent = "serviceAccount:service-${data.google_project.project.number}@container-engine-robot.iam.gserviceaccount.com" cloudservices = "serviceAccount:${data.google_project.project.number}@cloudservices.gserviceaccount.com" - gitlab_sa = "serviceAccount:${google_service_account.gitlab-sa.email}" + gitlab_sa = "serviceAccount:${google_service_account.gitlab_sa.email}" } project = var.net_project role = "roles/compute.networkUser" @@ -55,7 +60,7 @@ resource "google_kms_crypto_key_iam_member" "compute_service_agent_kms_permissio compute_agent = "serviceAccount:service-${data.google_project.project.number}@compute-system.iam.gserviceaccount.com" gke_agent = "serviceAccount:service-${data.google_project.project.number}@container-engine-robot.iam.gserviceaccount.com" cloudservices = "serviceAccount:${data.google_project.project.number}@cloudservices.gserviceaccount.com" - gitlab_sa = "serviceAccount:${google_service_account.gitlab-sa.email}" + gitlab_sa = "serviceAccount:${google_service_account.gitlab_sa.email}" } crypto_key_id = var.kms_key role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" @@ -137,7 +142,7 @@ module "compute-vm" { kms_key_self_link = var.kms_key } service_account = { - email = google_service_account.gitlab-sa.email + email = google_service_account.gitlab_sa.email } metadata = { startup-script = <<-EOT @@ -258,13 +263,18 @@ module "cluster" { depends_on = [google_kms_crypto_key_iam_member.compute_service_agent_kms_permissions, google_project_iam_member.compute_agent_subnet_user, google_project_iam_member.gke_host_agent_use, google_project_iam_member.gke_cluster_admin] } -module "gke_node_pool" { +moved { + from = module.gke_node_pool + to = module.gke-node-pool +} + +module "gke-node-pool" { source = "../../../modules/gke-nodepool" project_id = var.project_id location = var.region cluster_name = var.gke_name service_account = { - email = google_service_account.gitlab-sa.email + email = google_service_account.gitlab_sa.email } name = "nodes" node_count = var.nodepool_node_count diff --git a/blueprints/fedramp-high/gitlab/outputs.tf b/blueprints/fedramp-high/gitlab/outputs.tf index 7c2d96610..a0b159f96 100644 --- a/blueprints/fedramp-high/gitlab/outputs.tf +++ b/blueprints/fedramp-high/gitlab/outputs.tf @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -output "gke-cluster" { +output "gke_cluster" { description = "Deployed GKE cluster." value = module.cluster sensitive = true diff --git a/blueprints/il5/artifact-registry/consumer.tf b/blueprints/il5/artifact-registry/consumer.tf index 864d1f3a3..db5dfea00 100644 --- a/blueprints/il5/artifact-registry/consumer.tf +++ b/blueprints/il5/artifact-registry/consumer.tf @@ -17,7 +17,12 @@ resource "google_service_account" "consumer" { display_name = "Customized service account for consumer" } -resource "google_project_iam_member" "consumer-readonly" { +moved { + from = google_project_iam_member.consumer-readonly + to = google_project_iam_member.consumer_readonly +} + +resource "google_project_iam_member" "consumer_readonly" { project = var.main_project_id role = "roles/artifactregistry.reader" member = google_service_account.consumer.member @@ -66,7 +71,7 @@ module "compute-engine-vm" { { project = var.main_project_id region = var.region - yum_repositories = google_artifact_registry_repository.yum-repos + yum_repositories = google_artifact_registry_repository.yum_repos }, ) block-project-ssh-keys = true # CIS Compliance Benchmark 4.3 diff --git a/blueprints/il5/artifact-registry/main.tf b/blueprints/il5/artifact-registry/main.tf index fd47e8314..2c17608fd 100644 --- a/blueprints/il5/artifact-registry/main.tf +++ b/blueprints/il5/artifact-registry/main.tf @@ -18,7 +18,7 @@ locals { yamldecode(file("data/${f}")) ]...) - docker-registries = merge(google_artifact_registry_repository.docker-repos, { "docker-hub" = google_artifact_registry_repository.docker-hub }) + docker_registries = merge(google_artifact_registry_repository.docker_repos, { "docker-hub" = google_artifact_registry_repository.docker_hub }) } data "google_project" "project" { @@ -53,7 +53,12 @@ resource "google_project_service" "api" { disable_on_destroy = false } -resource "google_artifact_registry_repository" "yum-repos" { +moved { + from = google_artifact_registry_repository.yum-repos + to = google_artifact_registry_repository.yum_repos +} + +resource "google_artifact_registry_repository" "yum_repos" { project = data.google_project.project.project_id location = var.region for_each = local.repositories.yum @@ -77,7 +82,12 @@ resource "google_artifact_registry_repository" "yum-repos" { ] } -resource "google_artifact_registry_repository" "docker-hub" { +moved { + from = google_artifact_registry_repository.docker-hub + to = google_artifact_registry_repository.docker_hub +} + +resource "google_artifact_registry_repository" "docker_hub" { project = data.google_project.project.project_id location = var.region repository_id = "docker-hub" @@ -99,7 +109,12 @@ resource "google_artifact_registry_repository" "docker-hub" { ] } -resource "google_artifact_registry_repository" "docker-repos" { +moved { + from = google_artifact_registry_repository.docker-repos + to = google_artifact_registry_repository.docker_repos +} + +resource "google_artifact_registry_repository" "docker_repos" { project = data.google_project.project.project_id location = var.region for_each = local.repositories.docker @@ -122,7 +137,12 @@ resource "google_artifact_registry_repository" "docker-repos" { ] } -resource "google_artifact_registry_repository" "docker-repos-developer" { +moved { + from = google_artifact_registry_repository.docker-repos-developer + to = google_artifact_registry_repository.docker_repos_developer +} + +resource "google_artifact_registry_repository" "docker_repos_developer" { for_each = var.developer_registries project = data.google_project.project.project_id @@ -145,22 +165,33 @@ resource "google_kms_crypto_key_iam_member" "artifact_registry_crypto_key" { google_project_service_identity.artifact_registry_agent ] } + +moved { + from = google_artifact_registry_repository_iam_binding.writer-permissions + to = google_artifact_registry_repository_iam_binding.writer_permissions +} + # Grant all the writers access to the developer based registries -resource "google_artifact_registry_repository_iam_binding" "writer-permissions" { +resource "google_artifact_registry_repository_iam_binding" "writer_permissions" { for_each = var.developer_registries - project = google_artifact_registry_repository.docker-repos-developer[each.key].project - location = google_artifact_registry_repository.docker-repos-developer[each.key].location - repository = google_artifact_registry_repository.docker-repos-developer[each.key].name + project = google_artifact_registry_repository.docker_repos_developer[each.key].project + location = google_artifact_registry_repository.docker_repos_developer[each.key].location + repository = google_artifact_registry_repository.docker_repos_developer[each.key].name role = "roles/artifactregistry.writer" members = coalesce(each.value.writers, []) } +moved { + from = google_artifact_registry_repository_iam_binding.reader-permissions + to = google_artifact_registry_repository_iam_binding.reader_permissions +} + # Grant all the readers access to the developer based registries -resource "google_artifact_registry_repository_iam_binding" "reader-permissions" { +resource "google_artifact_registry_repository_iam_binding" "reader_permissions" { for_each = var.developer_registries - project = google_artifact_registry_repository.docker-repos-developer[each.key].project - location = google_artifact_registry_repository.docker-repos-developer[each.key].location - repository = google_artifact_registry_repository.docker-repos-developer[each.key].name + project = google_artifact_registry_repository.docker_repos_developer[each.key].project + location = google_artifact_registry_repository.docker_repos_developer[each.key].location + repository = google_artifact_registry_repository.docker_repos_developer[each.key].name role = "roles/artifactregistry.reader" members = coalesce(each.value.readers, []) } diff --git a/blueprints/il5/artifact-registry/outputs.tf b/blueprints/il5/artifact-registry/outputs.tf index 026171bf8..987c66e02 100644 --- a/blueprints/il5/artifact-registry/outputs.tf +++ b/blueprints/il5/artifact-registry/outputs.tf @@ -14,10 +14,10 @@ output "docker_registries" { description = "Docker registries created from the docker-registries.yaml file, with Docker Hub appended." - value = local.docker-registries + value = local.docker_registries } output "yum_repositories" { description = "Yum repositories created from the yum-repos.yaml file." - value = google_artifact_registry_repository.yum-repos + value = google_artifact_registry_repository.yum_repos } diff --git a/blueprints/il5/compute-engine/README.md b/blueprints/il5/compute-engine/README.md index 1dc3d0adf..613f13f0d 100644 --- a/blueprints/il5/compute-engine/README.md +++ b/blueprints/il5/compute-engine/README.md @@ -37,12 +37,12 @@ Compute Engine is an Infrastructure-as-a-Service product offering flexible, self | name | description | sensitive | |---|---|:---:| -| [compute-engine-vm-instance](outputs.tf#L17) | Instance resource. | ✓ | -| [compute-engine-vm-instance-id](outputs.tf#L23) | Fully qualified instance id. | | -| [compute-engine-vm-internal_ip](outputs.tf#L28) | Instance main interface internal IP address. | | -| [compute-engine-vm-internal_ips](outputs.tf#L33) | Instance interfaces internal IP addresses. | | -| [compute-engine-vm-service_account](outputs.tf#L38) | Service account resource. | | -| [compute-engine-vm-service_account_email](outputs.tf#L43) | Service account email. | | +| [compute_engine_vm_instance](outputs.tf#L17) | Instance resource. | ✓ | +| [compute_engine_vm_instance_id](outputs.tf#L23) | Fully qualified instance id. | | +| [compute_engine_vm_internal_ip](outputs.tf#L28) | Instance main interface internal IP address. | | +| [compute_engine_vm_internal_ips](outputs.tf#L33) | Instance interfaces internal IP addresses. | | +| [compute_engine_vm_service_account](outputs.tf#L38) | Service account resource. | | +| [compute_engine_vm_service_account_email](outputs.tf#L43) | Service account email. | | ## Disclaimer - The present GCP Terraform Module in this project is set up and intended to be implemented in either a FedRAMP-High or IL5 (Impact Level 5) environment using the Assured Workloads within the Google Cloud Platform (GCP) organization. @@ -68,13 +68,13 @@ Apply complete! Resources: 13 added, 0 changed, 0 destroyed. Outputs: -compute-engine-vm-instance = -compute-engine-vm-instance-id = "projects/project-name/zones/gcp-zone/instances/instance-name" -compute-engine-vm-internal_ip = "some-ip-address" -compute-engine-vm-internal_ips = [ +compute_engine_vm_instance = +compute_engine_vm_instance_id = "projects/project-name/zones/gcp-zone/instances/instance-name" +compute_engine_vm_internal_ip = "some-ip-address" +compute_engine_vm_internal_ips = [ "some-ip-address", ] -compute-engine-vm-service_account_email = "compute@project-name.iam.gserviceaccount.com" +compute_engine_vm_service_account_email = "compute@project-name.iam.gserviceaccount.com" keyring-id = "projects/project-name/locations/gcp-region/keyRings/keyring-name" keyring-location = "gcp-region" keyring-name = "keyring-name" diff --git a/blueprints/il5/compute-engine/outputs.tf b/blueprints/il5/compute-engine/outputs.tf index e29a2fd58..6e1a93ad1 100644 --- a/blueprints/il5/compute-engine/outputs.tf +++ b/blueprints/il5/compute-engine/outputs.tf @@ -14,33 +14,33 @@ * limitations under the License. */ -output "compute-engine-vm-instance" { +output "compute_engine_vm_instance" { description = "Instance resource." sensitive = true value = try(module.compute-engine-vm.instance) } -output "compute-engine-vm-instance-id" { +output "compute_engine_vm_instance_id" { description = "Fully qualified instance id." value = module.compute-engine-vm.id } -output "compute-engine-vm-internal_ip" { +output "compute_engine_vm_internal_ip" { description = "Instance main interface internal IP address." value = module.compute-engine-vm.internal_ip } -output "compute-engine-vm-internal_ips" { +output "compute_engine_vm_internal_ips" { description = "Instance interfaces internal IP addresses." value = module.compute-engine-vm.internal_ips } -output "compute-engine-vm-service_account" { +output "compute_engine_vm_service_account" { description = "Service account resource." value = module.compute-engine-vm.service_account } -output "compute-engine-vm-service_account_email" { +output "compute_engine_vm_service_account_email" { description = "Service account email." value = module.compute-engine-vm.service_account_email } diff --git a/blueprints/il5/dataflow/README.md b/blueprints/il5/dataflow/README.md index 03301dc6e..a4162fdf1 100644 --- a/blueprints/il5/dataflow/README.md +++ b/blueprints/il5/dataflow/README.md @@ -118,6 +118,6 @@ The Apache Beam SDK for Java has a warning about a bug in the latest version as | name | description | sensitive | |---|---|:---:| -| [dataflow-job](outputs.tf#L1) | Dataflow job. | | -| [gcs-bucket](outputs.tf#L6) | GCS Bucket. | | +| [dataflow_job](outputs.tf#L1) | Dataflow job. | | +| [gcs_bucket](outputs.tf#L6) | GCS Bucket. | | diff --git a/blueprints/il5/dataflow/outputs.tf b/blueprints/il5/dataflow/outputs.tf index fd7d80828..890abebeb 100644 --- a/blueprints/il5/dataflow/outputs.tf +++ b/blueprints/il5/dataflow/outputs.tf @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -output "dataflow-job" { +output "dataflow_job" { description = "Dataflow job." value = google_dataflow_job.job.name } -output "gcs-bucket" { +output "gcs_bucket" { description = "GCS Bucket." value = module.gcs.bucket.name } diff --git a/blueprints/il5/gcs-project/README.md b/blueprints/il5/gcs-project/README.md index b07abb126..e64828d70 100644 --- a/blueprints/il5/gcs-project/README.md +++ b/blueprints/il5/gcs-project/README.md @@ -71,7 +71,7 @@ To see the bucket, browse to [Cloud Storage Bucket](https://console.cloud.google | name | description | type | required | default | |---|---|:---:|:---:|:---:| -| [bucket-name](variables.tf#L24) | Bucket name suffix. | string | ✓ | | +| [bucket_name](variables.tf#L24) | Bucket name suffix. | string | ✓ | | | [core_project_id](variables.tf#L29) | Core Project ID. | string | ✓ | | | [kms_key_name](variables.tf#L34) | The full self-link (projects/../locations/../cryptoKeys/..) of the existing KMS key to use for encryption. | string | ✓ | | | [kms_keyring_name](variables.tf#L39) | Keyring attributes. | string | ✓ | | diff --git a/blueprints/il5/gcs-project/main.tf b/blueprints/il5/gcs-project/main.tf index 7ff10ad89..0316d60bf 100644 --- a/blueprints/il5/gcs-project/main.tf +++ b/blueprints/il5/gcs-project/main.tf @@ -46,7 +46,7 @@ module "gcs" { location = var.region storage_class = var.storage_class encryption_key = data.google_kms_crypto_key.default.id - name = var.bucket-name + name = var.bucket_name # CIS Compliance Benchmark 5.1 public_access_prevention = var.public_access_prevention diff --git a/blueprints/il5/gcs-project/terraform.tfvars.sample b/blueprints/il5/gcs-project/terraform.tfvars.sample index 834a8dea8..8cfbe4ba8 100644 --- a/blueprints/il5/gcs-project/terraform.tfvars.sample +++ b/blueprints/il5/gcs-project/terraform.tfvars.sample @@ -2,7 +2,7 @@ main_project_id = "xxxx-xxxx-xxxx-main-0" core_project_id = "xxxx-xxxx-xxxx-iac-core-0" prefix = "xxxx" -bucket-name = "bucket-name-00" +bucket_name = "bucket-name-00" region = "us-east4" autoclass = true storage_class = "STANDARD" diff --git a/blueprints/il5/gcs-project/variables.tf b/blueprints/il5/gcs-project/variables.tf index 681140478..f64dc6e0b 100644 --- a/blueprints/il5/gcs-project/variables.tf +++ b/blueprints/il5/gcs-project/variables.tf @@ -21,7 +21,7 @@ variable "autoclass" { default = true } -variable "bucket-name" { +variable "bucket_name" { description = "Bucket name suffix." type = string } diff --git a/blueprints/il5/gke-hardened/README.md b/blueprints/il5/gke-hardened/README.md index a836bccbf..7d9b8b506 100644 --- a/blueprints/il5/gke-hardened/README.md +++ b/blueprints/il5/gke-hardened/README.md @@ -72,7 +72,7 @@ The Deployment Steps are outlined in the [Stellar Engine GKE Deployment Guide.]( | [nodepool_service_account_email](outputs.tf#L51) | Service account email. | | | [subnet_regions](outputs.tf#L56) | Map of subnet regions keyed by name. | | | [subnets](outputs.tf#L61) | Subnet resources. | | -| [vpc-network](outputs.tf#L66) | Network resource. | | -| [vpc-subnet_ids](outputs.tf#L71) | Map of subnet IDs keyed by name. | | -| [vpc-subnet_ips](outputs.tf#L76) | Map of subnet address ranges keyed by name. | | +| [vpc_network](outputs.tf#L66) | Network resource. | | +| [vpc_subnet_ids](outputs.tf#L71) | Map of subnet IDs keyed by name. | | +| [vpc_subnet_ips](outputs.tf#L76) | Map of subnet address ranges keyed by name. | | diff --git a/blueprints/il5/gke-hardened/main.tf b/blueprints/il5/gke-hardened/main.tf index 8910b9c8f..b1492cd88 100644 --- a/blueprints/il5/gke-hardened/main.tf +++ b/blueprints/il5/gke-hardened/main.tf @@ -184,7 +184,12 @@ module "cluster" { depends_on = [module.vpc, module.kms] } -module "cluster_nodepool" { +moved { + from = module.cluster_nodepool + to = module.cluster-nodepool +} + +module "cluster-nodepool" { source = "../../../modules/gke-nodepool" project_id = var.main_project_id cluster_name = var.gke_cluster_name @@ -250,7 +255,12 @@ module "compute-vm" { depends_on = [module.cluster] } -resource "google_compute_firewall" "allow-iap" { +moved { + from = google_compute_firewall.allow-iap + to = google_compute_firewall.allow_iap +} + +resource "google_compute_firewall" "allow_iap" { name = "${var.network_name}-allow-iap" description = "Allow IAP for connecting to GKE from bastion host." network = var.network_name @@ -267,7 +277,12 @@ resource "google_compute_firewall" "allow-iap" { depends_on = [module.vpc] } -resource "google_compute_firewall" "allow-local-connect" { +moved { + from = google_compute_firewall.allow-local-connect + to = google_compute_firewall.allow_local_connect +} + +resource "google_compute_firewall" "allow_local_connect" { count = 1 name = "${var.network_name}-allow-local-connect" description = "Allow for connecting to bastion host from local system." diff --git a/blueprints/il5/gke-hardened/outputs.tf b/blueprints/il5/gke-hardened/outputs.tf index 853840c53..c95958184 100644 --- a/blueprints/il5/gke-hardened/outputs.tf +++ b/blueprints/il5/gke-hardened/outputs.tf @@ -54,17 +54,17 @@ output "keyrings_keys" { output "nodepool_id" { description = "Fully qualified nodepool id." - value = module.cluster_nodepool.id + value = module.cluster-nodepool.id } output "nodepool_name" { description = "Nodepool name." - value = module.cluster_nodepool.name + value = module.cluster-nodepool.name } output "nodepool_service_account_email" { description = "Service account email." - value = module.cluster_nodepool.service_account_email + value = module.cluster-nodepool.service_account_email } output "subnet_regions" { @@ -77,17 +77,17 @@ output "subnets" { value = module.vpc.subnets } -output "vpc-network" { +output "vpc_network" { description = "Network resource." value = module.vpc.network } -output "vpc-subnet_ids" { +output "vpc_subnet_ids" { description = "Map of subnet IDs keyed by name." value = module.vpc.subnet_ids } -output "vpc-subnet_ips" { +output "vpc_subnet_ips" { description = "Map of subnet address ranges keyed by name." value = module.vpc.subnet_ips } diff --git a/blueprints/il5/gke/README.md b/blueprints/il5/gke/README.md index 6a886dd4a..455e430ce 100644 --- a/blueprints/il5/gke/README.md +++ b/blueprints/il5/gke/README.md @@ -62,7 +62,7 @@ The present GCP Terraform Module in this project is set up and intended to be im This blueprint creates two node pools by default: `default-pool` and a separate custom node pool (e.g., `gke-nodepool-name-00`). This is an intentional design choice and a GKE best practice. * **`default-pool`**: This pool is created automatically by GKE and is suitable for running system components. By default, this blueprint keeps it. -* **Custom Node Pool**: This pool is created by the `cluster_nodepool` module and is intended for your specific applications. +* **Custom Node Pool**: This pool is created by the `cluster-nodepool` module and is intended for your specific applications. Using separate node pools allows you to optimize performance, security, and cost by running different types of applications on different kinds of machines. Key benefits include: diff --git a/blueprints/il5/gke/main.tf b/blueprints/il5/gke/main.tf index 49296c300..053d964ec 100644 --- a/blueprints/il5/gke/main.tf +++ b/blueprints/il5/gke/main.tf @@ -244,7 +244,12 @@ module "cluster" { ] } -module "cluster_nodepool" { +moved { + from = module.cluster_nodepool + to = module.cluster-nodepool +} + +module "cluster-nodepool" { source = "../../../modules/gke-nodepool" project_id = var.main_project_id cluster_name = module.cluster.name @@ -271,7 +276,12 @@ module "cluster_nodepool" { } # --- Bastion Host --- -module "bastion_vm" { +moved { + from = module.bastion_vm + to = module.bastion-vm +} + +module "bastion-vm" { source = "../../../modules/compute-vm" project_id = var.main_project_id name = var.bastion_vm_name diff --git a/blueprints/il5/gke/outputs.tf b/blueprints/il5/gke/outputs.tf index 3d3e6fd6c..9a4054b4b 100644 --- a/blueprints/il5/gke/outputs.tf +++ b/blueprints/il5/gke/outputs.tf @@ -31,17 +31,17 @@ output "cluster_master_version" { output "nodepool_name" { description = "The name of the additional GKE nodepool." - value = module.cluster_nodepool.name + value = module.cluster-nodepool.name } output "nodepool_id" { description = "The fully qualified ID of the additional GKE nodepool." - value = module.cluster_nodepool.id + value = module.cluster-nodepool.id } output "nodepool_service_account_email" { description = "The service account email used by the additional GKE nodepool." - value = module.cluster_nodepool.service_account_email + value = module.cluster-nodepool.service_account_email } output "gke_cluster_sa_email" { @@ -73,5 +73,5 @@ output "bastion_vm_name" { output "bastion_vm_public_ip" { description = "The public IP address of the bastion Compute Engine VM (if ephemeral public IP is enabled)." - value = try(module.bastion_vm.network_interfaces[0].access_config[0].nat_ip, null) + value = try(module.bastion-vm.network_interfaces[0].access_config[0].nat_ip, null) } diff --git a/blueprints/il5/shielded-vm-project/README.md b/blueprints/il5/shielded-vm-project/README.md index 3459f58aa..8c2775609 100644 --- a/blueprints/il5/shielded-vm-project/README.md +++ b/blueprints/il5/shielded-vm-project/README.md @@ -94,10 +94,10 @@ The apply will take about 1 minute to complete. The Shielded VM be deployed in t | name | description | sensitive | |---|---|:---:| -| [shielded-vm-instance](outputs.tf#L17) | Instance resource. | ✓ | -| [shielded-vm-instance-id](outputs.tf#L23) | Fully qualified instance id. | | -| [shielded-vm-internal_ip](outputs.tf#L28) | Instance main interface internal IP address. | | -| [shielded-vm-internal_ips](outputs.tf#L33) | Instance interfaces internal IP addresses. | | -| [shielded-vm-service_account](outputs.tf#L38) | Service account resource. | | -| [shielded-vm-service_account_email](outputs.tf#L43) | Service account email. | | +| [shielded_vm_instance](outputs.tf#L17) | Instance resource. | ✓ | +| [shielded_vm_instance_id](outputs.tf#L23) | Fully qualified instance id. | | +| [shielded_vm_internal_ip](outputs.tf#L28) | Instance main interface internal IP address. | | +| [shielded_vm_internal_ips](outputs.tf#L33) | Instance interfaces internal IP addresses. | | +| [shielded_vm_service_account](outputs.tf#L38) | Service account resource. | | +| [shielded_vm_service_account_email](outputs.tf#L43) | Service account email. | | diff --git a/blueprints/il5/shielded-vm-project/outputs.tf b/blueprints/il5/shielded-vm-project/outputs.tf index 79347380f..45cae9373 100644 --- a/blueprints/il5/shielded-vm-project/outputs.tf +++ b/blueprints/il5/shielded-vm-project/outputs.tf @@ -14,33 +14,33 @@ * limitations under the License. */ -output "shielded-vm-instance" { +output "shielded_vm_instance" { description = "Instance resource." sensitive = true value = try(module.shielded-vm.instance) } -output "shielded-vm-instance-id" { +output "shielded_vm_instance_id" { description = "Fully qualified instance id." value = module.shielded-vm.id } -output "shielded-vm-internal_ip" { +output "shielded_vm_internal_ip" { description = "Instance main interface internal IP address." value = module.shielded-vm.internal_ip } -output "shielded-vm-internal_ips" { +output "shielded_vm_internal_ips" { description = "Instance interfaces internal IP addresses." value = module.shielded-vm.internal_ips } -output "shielded-vm-service_account" { +output "shielded_vm_service_account" { description = "Service account resource." value = module.shielded-vm.service_account } -output "shielded-vm-service_account_email" { +output "shielded_vm_service_account_email" { description = "Service account email." value = module.shielded-vm.service_account_email } diff --git a/blueprints/stand-alone/vpc-peering-project/main.tf b/blueprints/stand-alone/vpc-peering-project/main.tf index 87f25a773..2d015e4a5 100644 --- a/blueprints/stand-alone/vpc-peering-project/main.tf +++ b/blueprints/stand-alone/vpc-peering-project/main.tf @@ -54,7 +54,12 @@ resource "google_project_service" "compute_api" { } # --- Create VPC Networks --- -module "vpc_networks" { +moved { + from = module.vpc_networks + to = module.vpc-networks +} + +module "vpc-networks" { source = "../../../modules/net-vpc" for_each = local.vpc_configs project_id = each.value.project_id @@ -117,11 +122,11 @@ module "vpc_networks" { module "peering" { source = "../../../modules/net-vpc-peering" prefix = "peer" - local_network = module.vpc_networks["local"].id - peer_network = module.vpc_networks["peer"].id + local_network = module.vpc-networks["local"].id + peer_network = module.vpc-networks["peer"].id # The depends_on block here is necessary because peering resources depend on the Compute API being # enabled in *both* projects before creation. Terraform doesn't implicitly infer this - # dependency from module.vpc_networks. + # dependency from module.vpc-networks. depends_on = [ google_project_service.compute_api ] diff --git a/blueprints/stand-alone/vpc-peering-project/outputs.tf b/blueprints/stand-alone/vpc-peering-project/outputs.tf index 003f5fce0..97cd97b87 100644 --- a/blueprints/stand-alone/vpc-peering-project/outputs.tf +++ b/blueprints/stand-alone/vpc-peering-project/outputs.tf @@ -28,104 +28,104 @@ output "peer_network_peering" { # --- Local VPC Outputs (First VPC created by this blueprint) --- output "local_vpc_network" { description = "The network resource object for the local VPC created by this blueprint." - value = module.vpc_networks["local"].network + value = module.vpc-networks["local"].network } output "local_vpc_network_self_link" { description = "The self-link for the local VPC created by this blueprint." - value = module.vpc_networks["local"].self_link + value = module.vpc-networks["local"].self_link } output "local_vpc_subnet_ids" { description = "A map of subnet IDs keyed by name for the local VPC." - value = module.vpc_networks["local"].subnet_ids + value = module.vpc-networks["local"].subnet_ids } output "local_vpc_subnet_ips" { description = "A map of subnet address ranges keyed by name for the local VPC." - value = module.vpc_networks["local"].subnet_ips + value = module.vpc-networks["local"].subnet_ips } output "local_vpc_subnet_self_links" { description = "A map of subnet self links keyed by name for the local VPC." - value = module.vpc_networks["local"].subnet_self_links + value = module.vpc-networks["local"].subnet_self_links } output "local_vpc_subnet_regions" { description = "A map of subnet regions keyed by name for the local VPC." - value = module.vpc_networks["local"].subnet_regions + value = module.vpc-networks["local"].subnet_regions } # Optional detailed subnet outputs for local VPC output "local_vpc_subnets" { description = "List of subnet resources for the local VPC." - value = module.vpc_networks["local"].subnets + value = module.vpc-networks["local"].subnets } output "local_vpc_subnet_secondary_ranges" { description = "Map of subnet secondary ranges keyed by name for the local VPC." - value = module.vpc_networks["local"].subnet_secondary_ranges + value = module.vpc-networks["local"].subnet_secondary_ranges } output "local_vpc_subnet_ipv6_external_prefixes" { description = "Map of subnet external IPv6 prefixes keyed by name for the local VPC." - value = module.vpc_networks["local"].subnet_ipv6_external_prefixes + value = module.vpc-networks["local"].subnet_ipv6_external_prefixes } output "local_vpc_network_attachment_ids" { description = "IDs of network attachments for the local VPC." - value = module.vpc_networks["local"].network_attachment_ids + value = module.vpc-networks["local"].network_attachment_ids } # --- Peer VPC Outputs (Second VPC created by this blueprint) --- output "peer_vpc_network" { description = "The network resource object for the peer VPC created by this blueprint." - value = module.vpc_networks["peer"].network + value = module.vpc-networks["peer"].network } output "peer_vpc_network_self_link" { description = "The self-link for the peer VPC created by this blueprint." - value = module.vpc_networks["peer"].self_link + value = module.vpc-networks["peer"].self_link } output "peer_vpc_subnet_ids" { description = "A map of subnet IDs keyed by name for the peer VPC." - value = module.vpc_networks["peer"].subnet_ids + value = module.vpc-networks["peer"].subnet_ids } output "peer_vpc_subnet_ips" { description = "A map of subnet address ranges keyed by name for the peer VPC." - value = module.vpc_networks["peer"].subnet_ips + value = module.vpc-networks["peer"].subnet_ips } output "peer_vpc_subnet_self_links" { description = "A map of subnet self links keyed by name for the peer VPC." - value = module.vpc_networks["peer"].subnet_self_links + value = module.vpc-networks["peer"].subnet_self_links } output "peer_vpc_subnet_regions" { description = "A map of subnet regions keyed by name for the peer VPC." - value = module.vpc_networks["peer"].subnet_regions + value = module.vpc-networks["peer"].subnet_regions } # Optional detailed subnet outputs for peer VPC output "peer_vpc_subnets" { description = "List of subnet resources for the peer VPC." - value = module.vpc_networks["peer"].subnets + value = module.vpc-networks["peer"].subnets } output "peer_vpc_subnet_secondary_ranges" { description = "Map of subnet secondary ranges keyed by name for the peer VPC." - value = module.vpc_networks["peer"].subnet_secondary_ranges + value = module.vpc-networks["peer"].subnet_secondary_ranges } output "peer_vpc_subnet_ipv6_external_prefixes" { description = "Map of subnet external IPv6 prefixes keyed by name for the peer VPC." - value = module.vpc_networks["peer"].subnet_ipv6_external_prefixes + value = module.vpc-networks["peer"].subnet_ipv6_external_prefixes } output "peer_vpc_network_attachment_ids" { description = "IDs of network attachments for the peer VPC." - value = module.vpc_networks["peer"].network_attachment_ids + value = module.vpc-networks["peer"].network_attachment_ids } diff --git a/blueprints/third-party-solutions/gitlab/services.tf b/blueprints/third-party-solutions/gitlab/services.tf index abdeee644..d3cb58fb8 100644 --- a/blueprints/third-party-solutions/gitlab/services.tf +++ b/blueprints/third-party-solutions/gitlab/services.tf @@ -76,8 +76,13 @@ resource "google_redis_instance" "cache" { } } +moved { + from = module.gitlab_object_storage + to = module.gitlab-object-storage +} + # https://docs.gitlab.com/ee/administration/object_storage.html#google-cloud-storage-gcs -module "gitlab_object_storage" { +module "gitlab-object-storage" { source = "../../../modules/gcs" for_each = toset(local.gitlab_buckets) project_id = module.project.project_id diff --git a/docs/naming-convention.md b/docs/naming-convention.md index 25792cca2..ec95fd56c 100644 --- a/docs/naming-convention.md +++ b/docs/naming-convention.md @@ -19,6 +19,7 @@ _Throughout this documentation we use example naming and diagrams to show exampl - [IAM Custom Roles](#iam-custom-roles) - [GCS Buckets](#gcs-buckets) - [GCE](#gce) + - [Terraform labels](#terraform-labels) ## Google Cloud Org Domain @@ -235,3 +236,25 @@ GCE naming is: - [ ] _is not_ globally unique - [ ] _is not_ burnable - [ ] _must be_ 1-64 characters + +## Terraform labels + +Terraform block labels follow the upstream Cloud Foundation Fabric convention. The `terraform_naming_convention` rule in the `.tflint.hcl` file enforces it, and CI runs it through the `tools/tflint.sh` script. + +- Resource, data source, variable and output labels use snake_case, such as `google_compute_firewall.allow_iap`. +- Module labels use kebab-case, such as `module.core-log-metrics`. +- Local value names use snake_case. +- A leading underscore marks a block-private intermediate local, such as `_cl_groups` in the `fast/stages-aw/0-bootstrap/checklist.tf` file. + +The convention covers Terraform addresses only. The `name` argument that Google Cloud sees still follows the sections above, so a resource labeled `allow_iap` can create a firewall rule named `allow-iap`. + +Labels form state addresses, so renaming a resource or a module changes its address. Add a `moved` block before every renamed resource or module block, so existing deployments move the state instead of destroying and recreating the resource: + +```hcl +moved { + from = google_compute_firewall.allow-iap + to = google_compute_firewall.allow_iap +} +``` + +Renaming a variable or an output changes the interface that callers and tfvars files use, so the pull request needs a Breaking Changes section with an `upgrade-note`. diff --git a/fast/stages-aw/0-bootstrap/automation.tf b/fast/stages-aw/0-bootstrap/automation.tf index baba1a9e9..df5ca58b4 100644 --- a/fast/stages-aw/0-bootstrap/automation.tf +++ b/fast/stages-aw/0-bootstrap/automation.tf @@ -183,7 +183,12 @@ module "automation-project" { depends_on = [module.organization-logging] } -resource "google_compute_project_metadata" "metadata-automation" { +moved { + from = google_compute_project_metadata.metadata-automation + to = google_compute_project_metadata.metadata_automation +} + +resource "google_compute_project_metadata" "metadata_automation" { project = module.automation-project.project_id metadata = { block-project-ssh-keys = "TRUE" # CIS Compliance Benchmark 4.3 diff --git a/fast/stages-aw/0-bootstrap/billing.tf b/fast/stages-aw/0-bootstrap/billing.tf index 03cc4d192..12e08673a 100644 --- a/fast/stages-aw/0-bootstrap/billing.tf +++ b/fast/stages-aw/0-bootstrap/billing.tf @@ -67,7 +67,12 @@ module "billing-export-project" { depends_on = [module.organization-logging] } -resource "google_compute_project_metadata" "metadata-billing" { +moved { + from = google_compute_project_metadata.metadata-billing + to = google_compute_project_metadata.metadata_billing +} + +resource "google_compute_project_metadata" "metadata_billing" { count = local.billing_mode == "org" ? 1 : 0 project = module.billing-export-project[0].project_id metadata = { diff --git a/fast/stages-aw/0-bootstrap/log-export.tf b/fast/stages-aw/0-bootstrap/log-export.tf index 1e2fe39ef..7df52af1f 100644 --- a/fast/stages-aw/0-bootstrap/log-export.tf +++ b/fast/stages-aw/0-bootstrap/log-export.tf @@ -76,7 +76,12 @@ data "google_logging_project_settings" "log_export" { depends_on = [module.log-export-project] } -resource "google_compute_project_metadata" "metadata-log-export" { +moved { + from = google_compute_project_metadata.metadata-log-export + to = google_compute_project_metadata.metadata_log_export +} + +resource "google_compute_project_metadata" "metadata_log_export" { project = module.log-export-project.project_id metadata = { block-project-ssh-keys = "TRUE" # CIS Compliance Benchmark 4.3 diff --git a/fast/stages-aw/0-bootstrap/log-metric-alerts.tf b/fast/stages-aw/0-bootstrap/log-metric-alerts.tf index 56a5b24bd..a414707a1 100644 --- a/fast/stages-aw/0-bootstrap/log-metric-alerts.tf +++ b/fast/stages-aw/0-bootstrap/log-metric-alerts.tf @@ -29,7 +29,12 @@ locals { ]) } -module "bootstrap_log_metrics" { +moved { + from = module.bootstrap_log_metrics + to = module.bootstrap-log-metrics +} + +module "bootstrap-log-metrics" { source = "../../../modules/cis-log-metrics" for_each = toset(local.bootstrap_projects) @@ -38,11 +43,16 @@ module "bootstrap_log_metrics" { # Alerts require log-metrics to be configure resource "time_sleep" "bootstrap_wait_10_seconds" { - depends_on = [module.bootstrap_log_metrics] + depends_on = [module.bootstrap-log-metrics] create_duration = "10s" } -module "bootstrap_log_alerts" { +moved { + from = module.bootstrap_log_alerts + to = module.bootstrap-log-alerts +} + +module "bootstrap-log-alerts" { source = "../../../modules/cis-log-alerts" for_each = toset(local.bootstrap_projects) diff --git a/fast/stages-aw/1-resman/log-metric-alerts.tf b/fast/stages-aw/1-resman/log-metric-alerts.tf index 61790e8d4..977808859 100644 --- a/fast/stages-aw/1-resman/log-metric-alerts.tf +++ b/fast/stages-aw/1-resman/log-metric-alerts.tf @@ -21,14 +21,24 @@ # CIS Compliance Benchmark 2.10 # CIS Compliance Benchmark 2.11 -module "core_log_metrics" { +moved { + from = module.core_log_metrics + to = module.core-log-metrics +} + +module "core-log-metrics" { source = "../../../modules/cis-log-metrics" for_each = module.tenant-self-iac-projects project = module.tenant-self-iac-projects[each.key].id } -module "main_log_metrics" { +moved { + from = module.main_log_metrics + to = module.main-log-metrics +} + +module "main-log-metrics" { source = "../../../modules/cis-log-metrics" for_each = module.tenant-self-main-projects @@ -37,11 +47,16 @@ module "main_log_metrics" { # Alerts require log-metrics to be configure resource "time_sleep" "resman_wait_10_seconds" { - depends_on = [module.core_log_metrics, module.main_log_metrics] + depends_on = [module.core-log-metrics, module.main-log-metrics] create_duration = "10s" } -module "core_log_alerts" { +moved { + from = module.core_log_alerts + to = module.core-log-alerts +} + +module "core-log-alerts" { source = "../../../modules/cis-log-alerts" for_each = module.tenant-self-iac-projects @@ -57,7 +72,12 @@ module "core_log_alerts" { depends_on = [time_sleep.resman_wait_10_seconds] } -module "main_log_alerts" { +moved { + from = module.main_log_alerts + to = module.main-log-alerts +} + +module "main-log-alerts" { source = "../../../modules/cis-log-alerts" for_each = module.tenant-self-main-projects diff --git a/fast/stages-aw/1-resman/outputs-tenants.tf b/fast/stages-aw/1-resman/outputs-tenants.tf index f260cca5d..f99c02b1f 100644 --- a/fast/stages-aw/1-resman/outputs-tenants.tf +++ b/fast/stages-aw/1-resman/outputs-tenants.tf @@ -61,7 +61,12 @@ locals { # core tfvars and providers -resource "local_file" "tenant-core-tfvars" { +moved { + from = local_file.tenant-core-tfvars + to = local_file.tenant_core_tfvars +} + +resource "local_file" "tenant_core_tfvars" { for_each = var.outputs_location == null ? {} : local.tenant_tfvars file_permission = "0600" filename = ( @@ -70,7 +75,12 @@ resource "local_file" "tenant-core-tfvars" { content = jsonencode(each.value) } -resource "local_file" "tenant-core-providers" { +moved { + from = local_file.tenant-core-providers + to = local_file.tenant_core_providers +} + +resource "local_file" "tenant_core_providers" { for_each = ( var.outputs_location == null ? {} : local.tenant_core_providers ) @@ -81,14 +91,24 @@ resource "local_file" "tenant-core-providers" { content = each.value } -resource "google_storage_bucket_object" "tenant-core-tfvars" { +moved { + from = google_storage_bucket_object.tenant-core-tfvars + to = google_storage_bucket_object.tenant_core_tfvars +} + +resource "google_storage_bucket_object" "tenant_core_tfvars" { for_each = local.tenant_tfvars bucket = var.automation.outputs_bucket name = "tfvars/tenant/${basename(each.key)}.auto.tfvars.json" content = jsonencode(each.value) } -resource "google_storage_bucket_object" "tenant-core-providers" { +moved { + from = google_storage_bucket_object.tenant-core-providers + to = google_storage_bucket_object.tenant_core_providers +} + +resource "google_storage_bucket_object" "tenant_core_providers" { for_each = local.tenant_core_providers bucket = var.automation.outputs_bucket name = "providers/tenant/${basename(each.key)}-providers.tf" @@ -97,7 +117,12 @@ resource "google_storage_bucket_object" "tenant-core-providers" { # tenant tfvars and providers -resource "local_file" "tenant-self-providers" { +moved { + from = local_file.tenant-self-providers + to = local_file.tenant_self_providers +} + +resource "local_file" "tenant_self_providers" { for_each = ( var.outputs_location == null ? {} : local.tenant_self_providers ) @@ -108,14 +133,24 @@ resource "local_file" "tenant-self-providers" { content = each.value } -resource "google_storage_bucket_object" "tenant-self-tfvars" { +moved { + from = google_storage_bucket_object.tenant-self-tfvars + to = google_storage_bucket_object.tenant_self_tfvars +} + +resource "google_storage_bucket_object" "tenant_self_tfvars" { for_each = local.tenant_tfvars bucket = module.tenant-self-iac-gcs-outputs[each.key].name name = "tfvars/${basename(each.key)}.auto.tfvars.json" content = jsonencode(each.value) } -resource "google_storage_bucket_object" "tenant-self-providers" { +moved { + from = google_storage_bucket_object.tenant-self-providers + to = google_storage_bucket_object.tenant_self_providers +} + +resource "google_storage_bucket_object" "tenant_self_providers" { for_each = local.tenant_self_providers bucket = module.tenant-self-iac-gcs-outputs[each.key].name name = "providers/${basename(each.key)}-providers.tf" diff --git a/fast/stages-aw/2-networking-a-fedramp/branch-net-envs.tf b/fast/stages-aw/2-networking-a-fedramp/branch-net-envs.tf index cfea4fcdf..338148699 100644 --- a/fast/stages-aw/2-networking-a-fedramp/branch-net-envs.tf +++ b/fast/stages-aw/2-networking-a-fedramp/branch-net-envs.tf @@ -223,7 +223,12 @@ module "env-dns-peer-landing-root" { } } -resource "google_compute_subnetwork_iam_member" "allow-admin-principals" { +moved { + from = google_compute_subnetwork_iam_member.allow-admin-principals + to = google_compute_subnetwork_iam_member.allow_admin_principals +} + +resource "google_compute_subnetwork_iam_member" "allow_admin_principals" { for_each = local.tenant_subnets_map_of_maps project = module.env-spoke-projects[each.value.env].project_id region = each.value.region diff --git a/fast/stages-aw/2-networking-a-fedramp/connectivity-tests.tf b/fast/stages-aw/2-networking-a-fedramp/connectivity-tests.tf index e4552381a..e3d5ae62d 100644 --- a/fast/stages-aw/2-networking-a-fedramp/connectivity-tests.tf +++ b/fast/stages-aw/2-networking-a-fedramp/connectivity-tests.tf @@ -14,14 +14,19 @@ locals { } -resource "google_network_management_connectivity_test" "landing-test" { +moved { + from = google_network_management_connectivity_test.landing-test + to = google_network_management_connectivity_test.landing_test +} + +resource "google_network_management_connectivity_test" "landing_test" { for_each = var.regions name = "landing-subnet-test-${each.key}" project = module.vdss-host-project.project_id source { - ip_address = google_compute_address.source-addr[each.key].address + ip_address = google_compute_address.source_addr[each.key].address project_id = module.vdss-host-project.project_id network = module.vdss-vpc.id network_type = "GCP_NETWORK" @@ -37,7 +42,12 @@ resource "google_network_management_connectivity_test" "landing-test" { } } -resource "google_compute_address" "source-addr" { +moved { + from = google_compute_address.source-addr + to = google_compute_address.source_addr +} + +resource "google_compute_address" "source_addr" { project = module.vdss-host-project.project_id for_each = var.regions @@ -48,14 +58,19 @@ resource "google_compute_address" "source-addr" { } -resource "google_network_management_connectivity_test" "env-tests" { +moved { + from = google_network_management_connectivity_test.env-tests + to = google_network_management_connectivity_test.env_tests +} + +resource "google_network_management_connectivity_test" "env_tests" { for_each = var.envs_folders name = lower("${each.key}-host-project-test") project = module.env-spoke-projects[each.key].project_id source { - ip_address = google_compute_address.env-source-addrs[each.key].address + ip_address = google_compute_address.env_source_addrs[each.key].address project_id = module.env-spoke-projects[each.key].project_id network = module.env-spoke-vpc[each.key].id network_type = "GCP_NETWORK" @@ -70,7 +85,12 @@ resource "google_network_management_connectivity_test" "env-tests" { env = lower(each.key) } } -resource "google_compute_address" "env-source-addrs" { +moved { + from = google_compute_address.env-source-addrs + to = google_compute_address.env_source_addrs +} + +resource "google_compute_address" "env_source_addrs" { for_each = var.envs_folders project = module.env-spoke-projects[each.key].project_id @@ -93,13 +113,13 @@ resource "google_compute_address" "env-source-addrs" { # project = module.env-spoke-projects[each.key].project_id # source { -# ip_address = google_compute_address.env-source-addrs[each.key].address +# ip_address = google_compute_address.env_source_addrs[each.key].address # project_id = module.env-spoke-projects[each.key].project_id # network = module.env-spoke-vpc[each.key].id # network_type = "GCP_NETWORK" # } # destination { -# ip_address = google_compute_address.env-source-addrs["Prod"].address +# ip_address = google_compute_address.env_source_addrs["Prod"].address # project_id = module.env-spoke-projects["Prod"].project_id # network = module.env-spoke-vpc["Prod"].id # port = 443 diff --git a/fast/stages-aw/2-networking-a-fedramp/net-vdss.tf b/fast/stages-aw/2-networking-a-fedramp/net-vdss.tf index 15db0f38c..cb9d5b7a3 100644 --- a/fast/stages-aw/2-networking-a-fedramp/net-vdss.tf +++ b/fast/stages-aw/2-networking-a-fedramp/net-vdss.tf @@ -50,7 +50,12 @@ module "vdss-host-project" { } } -resource "google_compute_project_metadata" "metadata-vdss-host-project" { +moved { + from = google_compute_project_metadata.metadata-vdss-host-project + to = google_compute_project_metadata.metadata_vdss_host_project +} + +resource "google_compute_project_metadata" "metadata_vdss_host_project" { project = module.vdss-host-project.project_id metadata = { block-project-ssh-keys = true # CIS Compliance Benchmark 4.3 diff --git a/fast/stages-aw/2-networking-b-il5-ngfw/bastion.tf b/fast/stages-aw/2-networking-b-il5-ngfw/bastion.tf index 0d7e5fb40..c77ac9e35 100644 --- a/fast/stages-aw/2-networking-b-il5-ngfw/bastion.tf +++ b/fast/stages-aw/2-networking-b-il5-ngfw/bastion.tf @@ -97,13 +97,13 @@ module "ngfw-ssh-secrets" { ngfw-ssh-private-key = { latest = { enabled = true - data = tls_private_key.ngfw-ssh.private_key_openssh + data = tls_private_key.ngfw_ssh.private_key_openssh } } ngfw-ssh-public-key = { latest = { enabled = true - data = tls_private_key.ngfw-ssh.public_key_openssh + data = tls_private_key.ngfw_ssh.public_key_openssh } } } diff --git a/fast/stages-aw/2-networking-b-il5-ngfw/branch-net-envs.tf b/fast/stages-aw/2-networking-b-il5-ngfw/branch-net-envs.tf index 38dbab8b2..7ffffbcff 100644 --- a/fast/stages-aw/2-networking-b-il5-ngfw/branch-net-envs.tf +++ b/fast/stages-aw/2-networking-b-il5-ngfw/branch-net-envs.tf @@ -223,7 +223,12 @@ module "env-dns-peer-landing-root" { } } -resource "google_compute_subnetwork_iam_member" "allow-admin-principals" { +moved { + from = google_compute_subnetwork_iam_member.allow-admin-principals + to = google_compute_subnetwork_iam_member.allow_admin_principals +} + +resource "google_compute_subnetwork_iam_member" "allow_admin_principals" { for_each = local.tenant_subnets_map_of_maps project = module.env-spoke-projects[each.value.env].project_id region = each.value.region diff --git a/fast/stages-aw/2-networking-b-il5-ngfw/log-metric-alerts.tf b/fast/stages-aw/2-networking-b-il5-ngfw/log-metric-alerts.tf index 87d26cc97..0acc5159a 100644 --- a/fast/stages-aw/2-networking-b-il5-ngfw/log-metric-alerts.tf +++ b/fast/stages-aw/2-networking-b-il5-ngfw/log-metric-alerts.tf @@ -21,12 +21,22 @@ # CIS Compliance Benchmark 2.10 # CIS Compliance Benchmark 2.11 -module "vdss_log_metrics" { +moved { + from = module.vdss_log_metrics + to = module.vdss-log-metrics +} + +module "vdss-log-metrics" { source = "../../../modules/cis-log-metrics" project = module.vdss-host-project.id } -module "spoke_log_metrics" { +moved { + from = module.spoke_log_metrics + to = module.spoke-log-metrics +} + +module "spoke-log-metrics" { source = "../../../modules/cis-log-metrics" for_each = module.env-spoke-projects @@ -35,11 +45,16 @@ module "spoke_log_metrics" { # Alerts require log-metrics to be configure resource "time_sleep" "networking_wait_10_seconds" { - depends_on = [module.vdss_log_metrics, module.spoke_log_metrics] + depends_on = [module.vdss-log-metrics, module.spoke-log-metrics] create_duration = "10s" } -module "vdss_log_alerts" { +moved { + from = module.vdss_log_alerts + to = module.vdss-log-alerts +} + +module "vdss-log-alerts" { source = "../../../modules/cis-log-alerts" project = module.vdss-host-project.id @@ -53,7 +68,12 @@ module "vdss_log_alerts" { depends_on = [time_sleep.networking_wait_10_seconds] } -module "spoke_log_alerts" { +moved { + from = module.spoke_log_alerts + to = module.spoke-log-alerts +} + +module "spoke-log-alerts" { source = "../../../modules/cis-log-alerts" for_each = module.env-spoke-projects diff --git a/fast/stages-aw/2-networking-b-il5-ngfw/net-vdss.tf b/fast/stages-aw/2-networking-b-il5-ngfw/net-vdss.tf index b16347048..fc6d56fbe 100644 --- a/fast/stages-aw/2-networking-b-il5-ngfw/net-vdss.tf +++ b/fast/stages-aw/2-networking-b-il5-ngfw/net-vdss.tf @@ -48,7 +48,12 @@ module "vdss-host-project" { } } -resource "google_compute_project_metadata" "metadata-vdss-host-project" { +moved { + from = google_compute_project_metadata.metadata-vdss-host-project + to = google_compute_project_metadata.metadata_vdss_host_project +} + +resource "google_compute_project_metadata" "metadata_vdss_host_project" { project = module.vdss-host-project.project_id metadata = { block-project-ssh-keys = true # CIS Compliance Benchmark 4.3 @@ -160,7 +165,12 @@ module "dmz-nat-primary" { router_network = module.dmz-vpc.name } -resource "google_compute_route" "mgmt-default" { +moved { + from = google_compute_route.mgmt-default + to = google_compute_route.mgmt_default +} + +resource "google_compute_route" "mgmt_default" { name = "default-route-mgmt" project = module.vdss-host-project.project_id dest_range = "0.0.0.0/0" diff --git a/fast/stages-aw/2-networking-b-il5-ngfw/ngfw.tf b/fast/stages-aw/2-networking-b-il5-ngfw/ngfw.tf index f89e4c38d..2f39d619e 100644 --- a/fast/stages-aw/2-networking-b-il5-ngfw/ngfw.tf +++ b/fast/stages-aw/2-networking-b-il5-ngfw/ngfw.tf @@ -42,7 +42,12 @@ data "google_compute_zones" "available" { depends_on = [module.vdss-host-project] } -resource "tls_private_key" "ngfw-ssh" { +moved { + from = tls_private_key.ngfw-ssh + to = tls_private_key.ngfw_ssh +} + +resource "tls_private_key" "ngfw_ssh" { algorithm = "RSA" rsa_bits = "4096" } @@ -60,7 +65,12 @@ resource "random_password" "salt" { special = false } -resource "google_project_iam_custom_role" "ngfw-custom-role" { +moved { + from = google_project_iam_custom_role.ngfw-custom-role + to = google_project_iam_custom_role.ngfw_custom_role +} + +resource "google_project_iam_custom_role" "ngfw_custom_role" { role_id = "ngfw.appliance" title = "NGFW Appliance" project = module.vdss-host-project.project_id @@ -90,7 +100,7 @@ module "ngfw-service-account" { "roles/compute.viewer" ] } - depends_on = [module.vdss-host-project, google_project_iam_custom_role.ngfw-custom-role] + depends_on = [module.vdss-host-project, google_project_iam_custom_role.ngfw_custom_role] } data "external" "openssl" { @@ -163,12 +173,17 @@ resource "google_storage_bucket_object" "license_folders" { content = " " } -resource "google_storage_bucket_object" "bootstrap-xml" { +moved { + from = google_storage_bucket_object.bootstrap-xml + to = google_storage_bucket_object.bootstrap_xml +} + +resource "google_storage_bucket_object" "bootstrap_xml" { name = "config/bootstrap.xml" for_each = var.regions content = templatefile("./templates/bootstrap.xml.tpl", { password_hash = data.external.openssl.result.hash - ssh_pubkey = tls_private_key.ngfw-ssh.public_key_openssh + ssh_pubkey = tls_private_key.ngfw_ssh.public_key_openssh healthcheck_cidrs = local.cidr_ranges["healthchecks"] iap_cidrs = local.cidr_ranges["iap"] tenants_subnets = { for k, v in var.envs_folders : k => module.env-spoke-vpc[k].subnets[ @@ -180,7 +195,12 @@ resource "google_storage_bucket_object" "bootstrap-xml" { bucket = module.ngfw-bootstrap-bucket[each.key].name } -resource "google_storage_bucket_object" "init-cfg" { +moved { + from = google_storage_bucket_object.init-cfg + to = google_storage_bucket_object.init_cfg +} + +resource "google_storage_bucket_object" "init_cfg" { name = "config/init-cfg.txt" for_each = var.regions @@ -190,7 +210,12 @@ resource "google_storage_bucket_object" "init-cfg" { bucket = module.ngfw-bootstrap-bucket[each.key].name } -resource "google_compute_region_instance_template" "ngfw-template" { +moved { + from = google_compute_region_instance_template.ngfw-template + to = google_compute_region_instance_template.ngfw_template +} + +resource "google_compute_region_instance_template" "ngfw_template" { for_each = var.regions project = module.vdss-host-project.project_id @@ -239,11 +264,11 @@ resource "google_compute_region_instance_template" "ngfw-template" { op-command-modes = "mgmt-interface-swap" dhcp-accept-server-domain = "yes" dhcp-accept-server-hostname = "yes" - ssh-keys = "admin:${tls_private_key.ngfw-ssh.public_key_openssh}" + ssh-keys = "admin:${tls_private_key.ngfw_ssh.public_key_openssh}" serial-port-enable = true serial-port-logging-enable = true vmseries-bootstrap-gce-storagebucket = module.ngfw-bootstrap-bucket[each.key].name - bootstrap-xml-md5 = google_storage_bucket_object.bootstrap-xml[each.key].md5hash # Roll out a new template when our bootstrap.xml file changes + bootstrap-xml-md5 = google_storage_bucket_object.bootstrap_xml[each.key].md5hash # Roll out a new template when our bootstrap.xml file changes } service_account { @@ -277,7 +302,7 @@ module "ngfw-mig" { zones = local.nva_zones[each.key] } - instance_template = google_compute_region_instance_template.ngfw-template[each.key].self_link + instance_template = google_compute_region_instance_template.ngfw_template[each.key].self_link target_size = 2 auto_healing_policies = { initial_delay_sec = 900 diff --git a/fast/stages-aw/3-security/log-metric-alerts.tf b/fast/stages-aw/3-security/log-metric-alerts.tf index cf88df146..9944193e0 100644 --- a/fast/stages-aw/3-security/log-metric-alerts.tf +++ b/fast/stages-aw/3-security/log-metric-alerts.tf @@ -28,7 +28,12 @@ locals { ] } -module "security_log_metrics" { +moved { + from = module.security_log_metrics + to = module.security-log-metrics +} + +module "security-log-metrics" { source = "../../../modules/cis-log-metrics" for_each = toset(local.security_projects) @@ -37,11 +42,16 @@ module "security_log_metrics" { # Alerts require log-metrics to be configure resource "time_sleep" "security_wait_10_seconds" { - depends_on = [module.security_log_metrics] + depends_on = [module.security-log-metrics] create_duration = "10s" } -module "security_log_alerts" { +moved { + from = module.security_log_alerts + to = module.security-log-alerts +} + +module "security-log-alerts" { source = "../../../modules/cis-log-alerts" for_each = toset(local.security_projects) diff --git a/modules/cis-log-alerts/README.md b/modules/cis-log-alerts/README.md index 139bf5bfb..5bced80cc 100644 --- a/modules/cis-log-alerts/README.md +++ b/modules/cis-log-alerts/README.md @@ -21,7 +21,7 @@ This module provisions log-based alerts to satisfy the CIS Google Cloud Computin This module creates a set of required log-based alerts using Cloud Monitoring. It provisions an email notification channel and links it to alert policies based on specific log metrics. ```hcl -module "cis_log_alerts" { +module "cis-log-alerts" { source = "./fabric/modules/cis-log-alerts" project = var.project_id alert_email = "security-alerts@example.com" diff --git a/modules/cis-log-metrics/README.md b/modules/cis-log-metrics/README.md index b8dba06ba..ea9ec0363 100644 --- a/modules/cis-log-metrics/README.md +++ b/modules/cis-log-metrics/README.md @@ -21,7 +21,7 @@ This module creates log-based metrics to satisfy the CIS Google Cloud Computing This module creates the underlying log-based metrics required for CIS compliance alerts. It parses Cloud Logging data to track specific events like project ownership changes, IAM modifications, and network firewall changes. ```hcl -module "cis_log_metrics" { +module "cis-log-metrics" { source = "./fabric/modules/cis-log-metrics" project = var.project_id } diff --git a/modules/cloud-scheduler/README.md b/modules/cloud-scheduler/README.md index b52cd972f..71854bac6 100644 --- a/modules/cloud-scheduler/README.md +++ b/modules/cloud-scheduler/README.md @@ -12,7 +12,7 @@ This module manages the creation of a Cloud Scheduler Job ## Example Usage ### PubSub Job ```hcl -module "pubsub_job" { +module "pubsub-job" { source = "../../../modules/cloud-scheduler" name = "name" description = "description" @@ -30,7 +30,7 @@ module "pubsub_job" { ### HTTP Job ```hcl -module "http_job" { +module "http-job" { source = "../../../modules/cloud-scheduler" name = "name" description = "description" diff --git a/modules/intrusion-detection-system/README.md b/modules/intrusion-detection-system/README.md index dced0cf96..17c1bbf3b 100644 --- a/modules/intrusion-detection-system/README.md +++ b/modules/intrusion-detection-system/README.md @@ -21,7 +21,7 @@ This module implements Cloud Intrusion Detection System (Cloud IDS) resources, i This module provisions a Cloud IDS endpoint and configures a packet mirroring policy to forward traffic from a specific subnet to the IDS endpoint for threat detection. ```hcl -module "intrusion_detection_system" { +module "intrusion-detection-system" { source = "./fabric/modules/intrusion-detection-system" project = var.project_id ids_name = "cloud-ids-endpoint" diff --git a/modules/organization-se/logging.tf b/modules/organization-se/logging.tf index 9e0874c05..801bd5b8d 100644 --- a/modules/organization-se/logging.tf +++ b/modules/organization-se/logging.tf @@ -87,14 +87,24 @@ resource "google_logging_organization_sink" "sink" { ] } -resource "google_storage_bucket_iam_member" "storage-sinks-binding" { +moved { + from = google_storage_bucket_iam_member.storage-sinks-binding + to = google_storage_bucket_iam_member.storage_sinks_binding +} + +resource "google_storage_bucket_iam_member" "storage_sinks_binding" { for_each = local.sink_bindings["storage"] bucket = each.value.destination role = "roles/storage.objectCreator" member = google_logging_organization_sink.sink[each.key].writer_identity } -resource "google_bigquery_dataset_iam_member" "bq-sinks-binding" { +moved { + from = google_bigquery_dataset_iam_member.bq-sinks-binding + to = google_bigquery_dataset_iam_member.bq_sinks_binding +} + +resource "google_bigquery_dataset_iam_member" "bq_sinks_binding" { for_each = local.sink_bindings["bigquery"] project = split("/", each.value.destination)[1] dataset_id = split("/", each.value.destination)[3] @@ -102,7 +112,12 @@ resource "google_bigquery_dataset_iam_member" "bq-sinks-binding" { member = google_logging_organization_sink.sink[each.key].writer_identity } -resource "google_pubsub_topic_iam_member" "pubsub-sinks-binding" { +moved { + from = google_pubsub_topic_iam_member.pubsub-sinks-binding + to = google_pubsub_topic_iam_member.pubsub_sinks_binding +} + +resource "google_pubsub_topic_iam_member" "pubsub_sinks_binding" { for_each = local.sink_bindings["pubsub"] project = split("/", each.value.destination)[1] topic = split("/", each.value.destination)[3] @@ -110,7 +125,12 @@ resource "google_pubsub_topic_iam_member" "pubsub-sinks-binding" { member = google_logging_organization_sink.sink[each.key].writer_identity } -resource "google_project_iam_member" "bucket-sinks-binding" { +moved { + from = google_project_iam_member.bucket-sinks-binding + to = google_project_iam_member.bucket_sinks_binding +} + +resource "google_project_iam_member" "bucket_sinks_binding" { for_each = local.sink_bindings["logging"] project = split("/", each.value.destination)[1] role = "roles/logging.bucketWriter" @@ -123,14 +143,24 @@ resource "google_project_iam_member" "bucket-sinks-binding" { } } -resource "google_project_iam_member" "project-sinks-binding" { +moved { + from = google_project_iam_member.project-sinks-binding + to = google_project_iam_member.project_sinks_binding +} + +resource "google_project_iam_member" "project_sinks_binding" { for_each = local.sink_bindings["project"] project = each.value.destination role = "roles/logging.logWriter" member = google_logging_organization_sink.sink[each.key].writer_identity } -resource "google_logging_organization_exclusion" "logging-exclusion" { +moved { + from = google_logging_organization_exclusion.logging-exclusion + to = google_logging_organization_exclusion.logging_exclusion +} + +resource "google_logging_organization_exclusion" "logging_exclusion" { for_each = var.logging_exclusions name = each.key org_id = local.organization_id_numeric diff --git a/modules/private-service-connect/README.md b/modules/private-service-connect/README.md index e6f6d4441..5daa7b983 100644 --- a/modules/private-service-connect/README.md +++ b/modules/private-service-connect/README.md @@ -15,7 +15,7 @@ The resources created/managed by this module are: Basic usage of this module is as follows: ```hcl -module "private_service_connect" { +module "private-service-connect" { source = "terraform-google-modules/network/google//modules/private-service-connect" project_id = "" diff --git a/modules/private-service-connect/dns.tf b/modules/private-service-connect/dns.tf index 5580181ec..de55f1ced 100644 --- a/modules/private-service-connect/dns.tf +++ b/modules/private-service-connect/dns.tf @@ -84,7 +84,12 @@ module "gcr" { Artifact Registry DNS Zone & records. ***********************************************/ -module "pkg_dev" { +moved { + from = module.pkg_dev + to = module.pkg-dev +} + +module "pkg-dev" { source = "terraform-google-modules/cloud-dns/google" version = "~> 5.0" project_id = var.project_id diff --git a/modules/private-service-connect/outputs.tf b/modules/private-service-connect/outputs.tf index 53a892f3b..712e974af 100644 --- a/modules/private-service-connect/outputs.tf +++ b/modules/private-service-connect/outputs.tf @@ -58,6 +58,6 @@ output "dns_zone_gcr_name" { } output "dns_zone_pkg_dev_name" { - value = module.pkg_dev.name + value = module.pkg-dev.name description = "Name for Managed DNS zone for PKG_DEV" } \ No newline at end of file diff --git a/tests/scripts/run_shell_tests.sh b/tests/scripts/run_shell_tests.sh index 650309469..20aee1144 100755 --- a/tests/scripts/run_shell_tests.sh +++ b/tests/scripts/run_shell_tests.sh @@ -25,6 +25,8 @@ bash "${SCRIPT_DIR}/test_shell_syntax.sh" echo "" bash "${SCRIPT_DIR}/test_common_functions.sh" echo "" +bash "${SCRIPT_DIR}/test_tflint.sh" +echo "" echo "============================================================" echo " All shell script test suites PASSED successfully." diff --git a/tests/scripts/test_tflint.sh b/tests/scripts/test_tflint.sh new file mode 100755 index 000000000..de457324c --- /dev/null +++ b/tests/scripts/test_tflint.sh @@ -0,0 +1,91 @@ +#!/bin/bash +# Copyright 2026 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. + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" + +TEST_COUNT=0 +FAIL_COUNT=0 + +assert_equals() { + local desc="$1" + local expected="$2" + local actual="$3" + TEST_COUNT=$((TEST_COUNT + 1)) + if [[ "$expected" == "$actual" ]]; then + echo " [PASS] ${desc}" + else + echo " [FAIL] ${desc} (expected '$expected', got '$actual')" + FAIL_COUNT=$((FAIL_COUNT + 1)) + fi +} + +echo "==> Running tools/tflint.sh Unit Tests" + +if ! command -v tflint >/dev/null; then + echo " [SKIP] tflint is not installed; the CI tflint job runs these tests." + exit 0 +fi + +TMP="$(mktemp -d)" +trap 'rm -rf "${TMP}"' EXIT + +# Builds a minimal repository that uses the real script and configuration. +mkdir -p "${TMP}/tools" "${TMP}/fast/stage" "${TMP}/blueprints/bp" \ + "${TMP}/modules/project" "${TMP}/modules/own" +cp "${REPO_ROOT}/tools/tflint.sh" "${TMP}/tools/" +cp "${REPO_ROOT}/.tflint.hcl" "${TMP}/" +printf 'resource "null_resource" "good_name" {}\n' >"${TMP}/fast/stage/main.tf" +printf 'module "good-name" {\n source = "../../modules/own"\n}\n' \ + >"${TMP}/blueprints/bp/main.tf" +printf 'resource "null_resource" "own" {}\n' >"${TMP}/modules/own/main.tf" +# modules/project is on the pending list, so its violation is skipped. +printf 'resource "null_resource" "pending-sync" {}\n' \ + >"${TMP}/modules/project/main.tf" + +run() { + local status=0 + bash "${TMP}/tools/tflint.sh" >"${TMP}/out.txt" 2>&1 || status=$? + echo "${status}" +} + +assert_equals "passes when every label follows the convention" "0" "$(run)" +assert_equals "skips the modules that wait for the upstream sync" "0" \ + "$(grep -c 'modules/project' "${TMP}/out.txt" || true)" + +printf 'resource "null_resource" "bad-name" {}\n' >"${TMP}/fast/stage/bad.tf" +assert_equals "fails on a resource label with a dash" "1" "$(run)" +rm "${TMP}/fast/stage/bad.tf" + +printf 'module "bad_name" {\n source = "../../modules/own"\n}\n' \ + >"${TMP}/blueprints/bp/bad.tf" +assert_equals "fails on a module label with an underscore" "1" "$(run)" +rm "${TMP}/blueprints/bp/bad.tf" + +printf 'output "bad-output" {\n value = 1\n}\n' >"${TMP}/modules/own/bad.tf" +assert_equals "fails on an output name with a dash" "1" "$(run)" +rm "${TMP}/modules/own/bad.tf" + +rm -rf "${TMP}/fast" "${TMP}/blueprints" "${TMP}/modules" +mkdir -p "${TMP}/fast" "${TMP}/blueprints" "${TMP}/modules" +assert_equals "fails when no Terraform directory exists" "1" "$(run)" + +echo "" +echo "Summary: ${TEST_COUNT} tests run, ${FAIL_COUNT} failures." +if [[ ${FAIL_COUNT} -gt 0 ]]; then + exit 1 +fi diff --git a/tools/lint.sh b/tools/lint.sh index 2b1438341..528594b04 100755 --- a/tools/lint.sh +++ b/tools/lint.sh @@ -23,6 +23,9 @@ python3 tools/check_boilerplate.py "$PWD" echo -- Terraform format -- terraform fmt -recursive -check -diff "$PWD" +echo -- Terraform lint -- +bash tools/tflint.sh -f compact + echo -- READMEs -- python3 tools/check_documentation.py --no-show-summary modules fast blueprints diff --git a/tools/tflint.sh b/tools/tflint.sh new file mode 100755 index 000000000..acd3f8017 --- /dev/null +++ b/tools/tflint.sh @@ -0,0 +1,94 @@ +#!/bin/bash +# Copyright 2026 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. + +# Runs tflint with the repository's .tflint.hcl on every Terraform directory +# under fast/, blueprints/ and modules/, and fails if any directory reports an +# issue. Extra arguments are passed to tflint, for example `-f compact`. + +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +# Modules synced from upstream Cloud Foundation Fabric before Fabric adopted +# the naming rule in v55.4.0. The upstream sync that #308 tracks brings the +# upstream renames, moved blocks and tflint-ignore annotations, and removes +# this list. +UPSTREAM_PENDING_SYNC=( + modules/billing-account + modules/folder + modules/iam-service-account + modules/ncc-spoke-ra + modules/net-firewall-policy + modules/net-lb-int/recipe-ilb-next-hop + modules/net-vpc-firewall + modules/net-vpn-dynamic + modules/net-vpn-static + modules/organization + modules/project +) + +# Only the naming rule is enforced for now, because the recommended preset +# still reports existing findings. Label names are static, so tflint does not +# need to evaluate module calls, which also avoids evaluation errors in +# blueprints whose variables default to null. +TFLINT_ARGS=( + --config "${REPO_ROOT}/.tflint.hcl" + --only=terraform_naming_convention + --call-module-type=none +) + +is_pending_sync() { + local dir="$1" pending + for pending in "${UPSTREAM_PENDING_SYNC[@]}"; do + if [[ "${dir}" == "${pending}" || "${dir}" == "${pending}"/* ]]; then + return 0 + fi + done + return 1 +} + +command -v tflint >/dev/null || { + echo "tflint not found; install it from https://github.com/terraform-linters/tflint" + exit 1 +} + +cd "${REPO_ROOT}" + +FAILED=0 +TOTAL=0 +while IFS= read -r dir; do + if is_pending_sync "${dir}"; then + continue + fi + TOTAL=$((TOTAL + 1)) + if ! tflint --chdir="${dir}" "${TFLINT_ARGS[@]}" "$@"; then + echo "tflint failed in ${dir}" + FAILED=$((FAILED + 1)) + fi +done < <( + find fast blueprints modules \ + \( -name .git -o -name .terraform -o -name .venv -o -name venv \ + -o -name node_modules -o -name __pycache__ \) -prune \ + -o -type f -name '*.tf' -exec dirname {} + | sort -u +) + +echo "tflint checked ${TOTAL} directories, ${FAILED} failed." +if [[ ${TOTAL} -eq 0 ]]; then + echo "No Terraform directories found." + exit 1 +fi +if [[ ${FAILED} -gt 0 ]]; then + exit 1 +fi