Enable terraform_naming_convention in tflint (#3930)

* Draft terraform_naming_convention

* Two fast/stages fixes for terraform_naming_convention

* Disable terraform_naming_convention for resources for now

* module fixes for terraform_naming_convention

* tfdoc

* Remove "moved" from recipe and needs-fixing

* Fix moved for spoke_ra

* fix tests

* Use default (snake_case) for resources

* factory.terraform_data.project-preconditions

* First-pass migration of resources + tests

* Fix tests/modules/organization

* Require snake_case for variables; Add annotations for _testing

* permit _fast_debug variable

* Fix net_vpc_factory and net_vpc_firewall tests

* tfdoc addons and recipe

* Fix more tests

* Fix some net-global -> net_global tests

---------

Co-authored-by: Ludovico Magnocavallo <ludomagno@google.com>
This commit is contained in:
Simon Roberts
2026-05-06 16:06:26 +10:00
committed by GitHub
parent ba56d9afbc
commit 26dbaa2d6e
83 changed files with 570 additions and 284 deletions

View File

@@ -14,24 +14,39 @@
* limitations under the License.
*/
resource "google_compute_network_firewall_policy" "net-global" {
moved {
from = google_compute_network_firewall_policy.net-global
to = google_compute_network_firewall_policy.net_global
}
resource "google_compute_network_firewall_policy" "net_global" {
count = !local.use_hierarchical && !local.use_regional ? 1 : 0
project = lookup(local.ctx.project_ids, var.parent_id, var.parent_id)
name = var.name
description = var.description
}
resource "google_compute_network_firewall_policy_association" "net-global" {
moved {
from = google_compute_network_firewall_policy_association.net-global
to = google_compute_network_firewall_policy_association.net_global
}
resource "google_compute_network_firewall_policy_association" "net_global" {
for_each = (
!local.use_hierarchical && !local.use_regional ? var.attachments : {}
)
project = lookup(local.ctx.project_ids, var.parent_id, var.parent_id)
name = "${var.name}-${each.key}"
attachment_target = lookup(local.ctx.networks, each.value, each.value)
firewall_policy = google_compute_network_firewall_policy.net-global[0].name
firewall_policy = google_compute_network_firewall_policy.net_global[0].name
}
resource "google_compute_network_firewall_policy_rule" "net-global" {
moved {
from = google_compute_network_firewall_policy_rule.net-global
to = google_compute_network_firewall_policy_rule.net_global
}
resource "google_compute_network_firewall_policy_rule" "net_global" {
# Terraform's type system barfs in the condition if we use the locals map
for_each = toset(
!local.use_hierarchical && !local.use_regional
@@ -39,7 +54,7 @@ resource "google_compute_network_firewall_policy_rule" "net-global" {
: []
)
project = lookup(local.ctx.project_ids, var.parent_id, var.parent_id)
firewall_policy = google_compute_network_firewall_policy.net-global[0].name
firewall_policy = google_compute_network_firewall_policy.net_global[0].name
rule_name = local.rules[each.key].name
action = local.rules[each.key].action
description = local.rules[each.key].description
@@ -147,7 +162,12 @@ resource "google_compute_network_firewall_policy_rule" "net-global" {
}
}
resource "google_compute_network_firewall_policy_packet_mirroring_rule" "net-global" {
moved {
from = google_compute_network_firewall_policy_packet_mirroring_rule.net-global
to = google_compute_network_firewall_policy_packet_mirroring_rule.net_global
}
resource "google_compute_network_firewall_policy_packet_mirroring_rule" "net_global" {
provider = google-beta
for_each = toset(
!local.use_hierarchical && !local.use_regional
@@ -155,7 +175,7 @@ resource "google_compute_network_firewall_policy_packet_mirroring_rule" "net-glo
: []
)
project = lookup(local.ctx.project_ids, var.parent_id, var.parent_id)
firewall_policy = google_compute_network_firewall_policy.net-global[0].name
firewall_policy = google_compute_network_firewall_policy.net_global[0].name
rule_name = local.mirroring_rules[each.key].name
action = local.mirroring_rules[each.key].action
description = local.mirroring_rules[each.key].description

View File

@@ -14,7 +14,12 @@
* limitations under the License.
*/
resource "google_compute_region_network_firewall_policy" "net-regional" {
moved {
from = google_compute_region_network_firewall_policy.net-regional
to = google_compute_region_network_firewall_policy.net_regional
}
resource "google_compute_region_network_firewall_policy" "net_regional" {
count = !local.use_hierarchical && local.use_regional ? 1 : 0
project = lookup(local.ctx.project_ids, var.parent_id, var.parent_id)
name = var.name
@@ -22,7 +27,12 @@ resource "google_compute_region_network_firewall_policy" "net-regional" {
region = lookup(local.ctx.locations, var.region, var.region)
}
resource "google_compute_region_network_firewall_policy_association" "net-regional" {
moved {
from = google_compute_region_network_firewall_policy_association.net-regional
to = google_compute_region_network_firewall_policy_association.net_regional
}
resource "google_compute_region_network_firewall_policy_association" "net_regional" {
for_each = (
!local.use_hierarchical && local.use_regional ? var.attachments : {}
)
@@ -30,10 +40,15 @@ resource "google_compute_region_network_firewall_policy_association" "net-region
region = lookup(local.ctx.locations, var.region, var.region)
name = "${var.name}-${each.key}"
attachment_target = lookup(local.ctx.networks, each.value, each.value)
firewall_policy = google_compute_region_network_firewall_policy.net-regional[0].name
firewall_policy = google_compute_region_network_firewall_policy.net_regional[0].name
}
resource "google_compute_region_network_firewall_policy_rule" "net-regional" {
moved {
from = google_compute_region_network_firewall_policy_rule.net-regional
to = google_compute_region_network_firewall_policy_rule.net_regional
}
resource "google_compute_region_network_firewall_policy_rule" "net_regional" {
# Terraform's type system barfs in the condition if we use the locals map
for_each = toset(
!local.use_hierarchical && local.use_regional
@@ -42,7 +57,7 @@ resource "google_compute_region_network_firewall_policy_rule" "net-regional" {
)
project = lookup(local.ctx.project_ids, var.parent_id, var.parent_id)
region = lookup(local.ctx.locations, var.region, var.region)
firewall_policy = google_compute_region_network_firewall_policy.net-regional[0].name
firewall_policy = google_compute_region_network_firewall_policy.net_regional[0].name
rule_name = local.rules[each.key].name
action = local.rules[each.key].action
description = local.rules[each.key].description

View File

@@ -21,8 +21,8 @@ output "id" {
? google_compute_firewall_policy.hierarchical[0].id
: (
local.use_regional
? google_compute_region_network_firewall_policy.net-regional[0].id
: google_compute_network_firewall_policy.net-global[0].id
? google_compute_region_network_firewall_policy.net_regional[0].id
: google_compute_network_firewall_policy.net_global[0].id
)
)
}