Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting ip_address to IPv6 for google_compute_forwarding_rule causes recreation #15916

Assignees
Labels

Comments

@nkinkade
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

$ terraform -v
Terraform v1.5.7
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v4.82.0

Affected Resource(s)

  • google_compute_forwarding_rule

Terraform Configuration Files

resource "google_compute_address" "my_v6_addr" {
  address_type       = "EXTERNAL"
  ipv6_endpoint_type = "NETLB"
  ip_version         = "IPV6"
  name               = "my-v6-addr"
  region             = "us-east1"
  subnetwork         = "my-subnet"
}

resource "google_compute_forwarding_rule" "my_forwarding_rule" {
  all_ports             = true
  backend_service       = google_compute_region_backend_service.my_backend_service.id
  ip_address            = "${google_compute_address.my_ipv6_addr.address}/96"
  ip_protocol           = "L3_DEFAULT"
  ip_version            = "IPV6"
  load_balancing_scheme = "EXTERNAL"
  name                  = "my-forwarding-rule"
  region                = us-east1
  subnetwork            = my-subnet
}

Debug Output

https://gist.github.com/nkinkade/aaccc5ae60d2d3e1b134c9ed24af608c

Panic Output

Expected Behavior

It should be possible to assign the address attribute of a static IPv6 google_compute_address resource as the ip_address argument of google_compute_forwarding_rule without the forwarding rule being recreated on every run of terraform apply, even it nothing has changed.

Actual Behavior

On every run of terraform apply the google_compute_forwarding_rule is recreated, even when nothing has changed about the Terraform configuration.

The underlying issue seems to be that the address field/attribute of an IPv6 google_compute_address resource will use abbreviated IPv6 notation, collapsing all-zero "hextets" and without a prefix value e.g., 2600:1900:4020:31cd:8000::. However, the API appears to expand the ip_address argument (IPAddress field) of a google_compute_forwarding_rule such that the above example IPv6 google_compute_address is stored as 2600:1900:4020:31cd:8000:0:0:0/96. Terraform (or perhaps the API?) sees these as two different addresses/values and wants to recreate the forwarding rule using the abbreviated address value, as stored in the google_compute_address resource. This will happen as many times as you run terraform apply.

Using google_compute_address.my_ipv6_addr.id or google_compute_address.my_ipv6_addr.self_link as the value of ip_address in the forwarding rule creates a similar problem, but more like the one described in #7841.

Details of the created resources as reported by gcloud (abbreviated to relevant fields):

$ gcloud compute addresses describe my-ipv6-address --region us-east1 --project my-project
address: '2600:1900:4020:31cd:8000::'
addressType: EXTERNAL
ipVersion: IPV6
ipv6EndpointType: NETLB
kind: compute#address
prefixLength: 96

$ gcloud compute forwarding-rules describe my-ipv6-fwd-rule --region us-east1 --project my-project
IPAddress: 2600:1900:4020:31cd:8000:0:0:0/96
ipVersion: IPV6
kind: compute#forwardingRule
loadBalancingScheme: EXTERNAL

Steps to Reproduce

  1. Define a regional, static IPv6 google_compute_address resource (e.g., google_compute_address.my_ipv6_addr)
  2. Use ${google_compute_address.my_ipv6_addr.address}/96 as the value of the ip_address argument of a google_compute_forwarding_rule resource.
  3. Run terraform apply... the forwarding rule resources will be recreated.
  4. Run terraform apply ... the forwarding rule resource will be recreated.
  5. [...]

Important Factoids

Nothing special.

References

@nkinkade nkinkade added the bug label Sep 20, 2023
@edwardmedia edwardmedia self-assigned this Sep 20, 2023
@edwardmedia
Copy link
Contributor

edwardmedia commented Sep 20, 2023

Yes, this is a bug

-/+ resource "google_compute_forwarding_rule" "platform_cluster_mig_forwarding_rules_v6" {

      ~ ip_address              = "2600:1900:4020:31cd:8000:0:0:0/96" -> "2600:1900:4020:31cd:8000::/96" # forces replacement
   
        # (5 unchanged attributes hidden)
    }

The diff suppress function needs update

@edwardmedia
Copy link
Contributor

edwardmedia commented Sep 24, 2023

Below format is possible and legit

"2600:1900:4000:1077:8000:0:0:0/96" -> "https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/myaddress" # forces replacement

@nkinkade
Copy link
Author

In my experiments, all of these are accepted by both Terraform and the Google API, but they also all result in the forwarding rule being recreated on every run of terraform {plan,apply}:

  • "${google_compute_address.my_ipv6_addr.address}/96"
  • google_compute_address.my_ipv6_addr.id
  • google_compute_address.my_ipv6_addr.self_link

If I use the .address attribute I have to append "/96", otherwise the Google API rejects the value as invalid.

Copy link

github-actions bot commented Nov 4, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2023
@github-actions github-actions bot added forward/review In review; remove label to forward service/compute-l7-load-balancer labels Jan 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.