terraform-provider-google icon indicating copy to clipboard operation
terraform-provider-google copied to clipboard

google_alloydb_cluster throws error when psc_config or network_config values are passed using dynamic block

Open imrannayer opened this issue 8 months ago • 9 comments

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 a user, that user is claiming responsibility for the issue.
  • Customers working with a Google Technical Account Manager or Customer Engineer can ask them to reach out internally to expedite investigation and resolution of this issue.

Terraform Version & Provider Version(s)

Terraform v1.7.5 on darwin_amd64

  • provider registry.terraform.io/hashicorp/google v5.34.0

Affected Resource(s)

google_alloydb_cluster

Terraform Configuration

variable "network_self_link" {
  description = "Network ID where the AlloyDb cluster will be deployed. If network_self_link is set then psc_enabled should be set to false"
  type        = string
  default     = null
}

variable "psc_enabled" {
  type        = bool
  description = "Create an instance that allows connections from Private Service Connect endpoints to the instance. If psc_enabled is set to true, then network_self_link should be set to null"
  default     = true
}

resource "google_alloydb_cluster" "default" {
  cluster_id   = "cluster-us-central1-psc"
  cluster_type = "PRIMARY"
  location     = "us-central1"
  project      = "ci-alloy-db-1-859a"

  dynamic "network_config" {
    for_each = var.network_self_link == null ? [] : ["network_config"]
    content {
      network            = var.network_self_link
      allocated_ip_range = local.allocated_ip_range
    }
  }

  dynamic "psc_config" {
    for_each = var.psc_enabled ? ["psc_enabled"] : []
    content {
      psc_enabled = var.psc_enabled
    }
  }

}

OR

variable "network_self_link" {
  description = "Network ID where the AlloyDb cluster will be deployed. If network_self_link is set then psc_enabled should be set to false"
  type        = string
  default     = "projects/ci-alloy-db-1-859a/global/networks/deleteme-network"
}

variable "psc_enabled" {
  type        = bool
  description = "Create an instance that allows connections from Private Service Connect endpoints to the instance. If psc_enabled is set to true, then network_self_link should be set to null"
  default     = false
}

resource "google_alloydb_cluster" "default" {
  cluster_id   = "cluster-us-central1-psc"
  cluster_type = "PRIMARY"
  location     = "us-central1"
  project      = "ci-alloy-db-1-859a"

  dynamic "network_config" {
    for_each = var.network_self_link == null ? [] : ["network_config"]
    content {
      network            = var.network_self_link
    }
  }

  dynamic "psc_config" {
    for_each = var.psc_enabled ? ["psc_enabled"] : []
    content {
      psc_enabled = var.psc_enabled
    }
  }
}

Debug Output

https://gist.github.com/imrannayer/c2ca657e5ba4a731febf15949f8e7acb

Expected Behavior

It should work fine as the value of psc_config.0.psc_enabled is provided

Actual Behavior

getting following error

│ Error: Invalid combination of arguments
│
│   with google_alloydb_cluster.default,
│   on main.tf line 46, in resource "google_alloydb_cluster" "default":
│   46: resource "google_alloydb_cluster" "default" {
│
│ "network": one of `network,network_config.0.network,psc_config.0.psc_enabled` must be specified

Steps to reproduce

  1. terraform apply

Important Factoids

No response

References

No response

b/349388135

imrannayer avatar Jun 18 '24 19:06 imrannayer