terraform-google-modules / terraform-google-network

Sets up a new VPC network on Google Cloud
https://registry.terraform.io/modules/terraform-google-modules/network/google
Apache License 2.0
411 stars 1.23k forks source link

Migration path from (firewall) rules to ingress/egress_rules #560

Closed oliverboehme-ida closed 2 months ago

oliverboehme-ida commented 3 months ago

TL;DR

The field rules in firewall-rules module is marked "deprecated". But what is the clean way of transitioning rules to the new fields (ingress_rules, egress_rules) without destroying/re-applying them all?

Terraform Resources

https://github.com/terraform-google-modules/terraform-google-network/tree/master/modules/firewall-rules

Additional information

After painfully re-writing all rules separately to be included in ingress_rules and egress_rules, I found no non-destructive way of transitioning them in Terraform state.

Moved block does not work because the "old" resource "rules" is still existing. Import block does not work because it assumes the resources are not contained in the state (thus destroying the "real" resources too) Manually tf importing has the same effect.

Destroying and re-creating all is too risky.

What now?

oliverboehme-ida commented 3 months ago

CC @imrannayer

oliverboehme-ida commented 2 months ago

For anyone who is interested, I solved it like this: