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

google_secret_manager_secret in for_each loop returns Error 400: Secret must be provided. #11395

Closed
nikkatalnikov opened this issue Apr 1, 2022 · 6 comments

Comments

@nikkatalnikov
Copy link

nikkatalnikov commented Apr 1, 2022

Affected Resource(s)

  • google_secret_manager_secret

Trying to create multiple secrets from the JSON collection:

resource "google_secret_manager_secret" "secret-general" {
  project       = "modern-project-123"
  for_each      = local.general_secrets
  secret_id     = each.key

  replication {
    automatic = false
  }
}

resource "google_secret_manager_secret_version" "secret-version-general" {
  for_each      = google_secret_manager_secret.secret-general
  secret        = each.value.name
  secret_data   = local.general_secrets[each.key]
}

And getting an error

│ Error: Error creating Secret: googleapi: Error 400: Secret must be provided.
│ 
│   with google_secret_manager_secret.secret-general["API_KEY"],
│   on 02-general-secrets.tf line 1, in resource "google_secret_manager_secret" "secret-general":
│    1: resource "google_secret_manager_secret" "secret-general" {
│ 

Env:

Terraform v1.1.2 on darwin_amd64
provider registry.terraform.io/hashicorp/google v4.15.0

Is that a bug or what am i doing wrong? Thank you!

b/301412033

@nikkatalnikov
Copy link
Author

I found that it works with

  replication {
    automatic = true
  }

but why?

@rileykarson
Copy link
Collaborator

rileykarson commented Apr 5, 2022

The error message received from the API is confusing if that solves it- my guess is that either automatic must be true, or self_managed must be set w/ at least one replicas option defined.

Does a configuration like the following work?

resource "google_secret_manager_secret" "secret-general" {
  project       = "modern-project-123"
  for_each      = local.general_secrets
  secret_id     = each.key

  replication {
    user_managed {
      replicas {
        location = "us-central1"
      }
      replicas {
        location = "us-east1"
      }
    }
  }
}

resource "google_secret_manager_secret_version" "secret-version-general" {
  for_each      = google_secret_manager_secret.secret-general
  secret        = each.value.name
  secret_data   = local.general_secrets[each.key]
}

@nikkatalnikov
Copy link
Author

@rileykarson
I can confirm it works if replication is set like in your example

@nikkatalnikov
Copy link
Author

probably it worth to fix an error message to resolve the issue?

@github-actions github-actions bot added service/secretmanager forward/review In review; remove label to forward labels Aug 17, 2023
@edwardmedia edwardmedia removed the forward/review In review; remove label to forward label Sep 20, 2023
@slevenick
Copy link
Collaborator

Fixed in 5.0+

Copy link

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 Apr 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants