Skip to content

Conversation

@rtb-major
Copy link

This is a breaking change as it changes the way TF sees it's resources.

The reason of this change is simple, currently when you create a config of consumer_quotas like this:

    {
      service = "bigquery.googleapis.com"
      metric  = urlencode("bigquery.googleapis.com/quota/query/usage")
      limit   = urlencode("/d/project")
      dimensions = {}
      value = "100000"
    },    {
      service = "bigquery.googleapis.com"
      metric  = urlencode("bigquery.googleapis.com/quota/query/usage")
      limit   = urlencode("/d/project/user")
      dimensions = {}
      value = "100000"
    }
    ]

So you want to override quota both for project and project/user limit, then after you run terrafrom plan you get an error:

  │ Error: Duplicate object key
  │ 
  │   on .terraform/modules/projects/modules/quota_manager/main.tf line 18, in locals:
  │   18:   consumer_quotas = { for index, quota in var.consumer_quotas : "${quota.service}-${quota.metric}" => quota }
  │     ├────────────────
  │     │ quota.metric is "bigquery.googleapis.com%2Fquota%2Fquery%2Fusage"
  │     │ quota.service is "bigquery.googleapis.com"
  │ 
  │ Two different items produced the key
  │ "bigquery.googleapis.com-bigquery.googleapis.com%2Fquota%2Fquery%2Fusage"
  │ in this 'for' expression. If duplicates are expected, use the ellipsis
  │ (...) after the value expression to enable grouping by key.

This change fixes this issue and potentially other similar when you want to set up different limit for same quota/metric.

Proposed change is to change variable name from "quota-metric" value to "metric-limit" not for "qouta-metric-limit" as metric always consists of quota value plus quota name, ie:
quota = "bigquery.googleapis.com"
metric = "bigquery.googleapis.com%2Fquota%2Fquery%2Fusage"

@rtb-major rtb-major requested review from a team and imrannayer as code owners October 27, 2025 07:38
Copy link
Member

@bharathkkb bharathkkb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @rtb-major

@bharathkkb bharathkkb changed the title fix: change consumer quotas variable format to prevent "Duplicate object key" TF Error fix!: change consumer quotas variable format to prevent "Duplicate object key" TF Error Nov 18, 2025
@bharathkkb
Copy link
Member

/gcbrun

rtb-major and others added 2 commits November 19, 2025 18:00
I'am not going argue about that, personaly I like simpler solutions. But maybe there will be some "edge case" where my proposition won't be working

Co-authored-by: Bharath KKB <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants