Skip to content

fix!: change consumer quotas variable format to prevent "Duplicate object key" TF Error#1014

Open
mmajor-rtbh wants to merge 7 commits intoterraform-google-modules:mainfrom
mmajor-rtbh:change_consumer_quotas_variable_format
Open

fix!: change consumer quotas variable format to prevent "Duplicate object key" TF Error#1014
mmajor-rtbh wants to merge 7 commits intoterraform-google-modules:mainfrom
mmajor-rtbh:change_consumer_quotas_variable_format

Conversation

@mmajor-rtbh
Copy link
Copy Markdown

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"

@mmajor-rtbh mmajor-rtbh requested review from a team and imrannayer as code owners October 27, 2025 07:38
Copy link
Copy Markdown
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

Comment thread modules/quota_manager/main.tf Outdated
@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
Copy Markdown
Member

/gcbrun

mmajor-rtbh and others added 4 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 <bharathkrishnakb@gmail.com>
@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions Bot added the Stale label Feb 21, 2026
@github-actions github-actions Bot closed this Mar 1, 2026
@mmajor-rtbh
Copy link
Copy Markdown
Author

hey, 5 months has passed and no one can look into this, is this repo live or not ?

@bharathkkb bharathkkb reopened this Apr 10, 2026
@bharathkkb
Copy link
Copy Markdown
Member

/gcbrun

@github-actions github-actions Bot removed the Stale label Apr 10, 2026
@mmajor-rtbh
Copy link
Copy Markdown
Author

bump

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