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

Error: key "ssh-keys" already present in metadata for project in GCP #6440

Closed
vikas4cloud opened this issue May 21, 2020 · 5 comments
Closed

Comments

@vikas4cloud
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 v0.12.24

  • provider.google v3.11.0

Affected Resource(s)

  • google_XXXXX
    Terraform v0.12.24
  • provider.google v3.11.0

Terraform Configuration Files

main.tf
resource "google_compute_project_metadata_item" "username" {
  key   = "ssh-keys"
  value = var.users
}

variables.tf
variable "users" {}

Debug Output

Panic Output

Error: key "ssh-keys" already present in metadata for project

google_compute_project_metadata_item.username: Creating...
Error: key "ssh-keys" already present in metadata for project "solid-ridge-266407". Use terraform import to manage it with Terraform
on main.tf line 1, in resource "google_compute_project_metadata_item" "username":
1: resource "google_compute_project_metadata_item" "username" {

Expected Behavior

Expecting to add the provided key to the metadata/sshKeys
https://console.cloud.google.com/compute/metadata/sshKeys

Actual Behavior

its replacing the previous sshKeys its not appending

it should append as well as should not delete the previous terraform apply

Steps to Reproduce

  1. add users key in terraform.tfvars file
  2. terraform apply

Important Factoids

References

  • #0000
@ghost ghost added bug labels May 21, 2020
@vikas4cloud vikas4cloud changed the title Error: key "ssh-keys" already present in metadata for project Error: key "ssh-keys" already present in metadata for project in GCP May 21, 2020
@edwardmedia edwardmedia self-assigned this May 21, 2020
@edwardmedia
Copy link
Contributor

edwardmedia commented May 21, 2020

@vikas4cloud This is expected behavior, If you have already created the metadata using other methods, Terraform does not have knowledge about it, and then will not overwrite it. That is why you have to create the state by calling terraform import before you can let Terraform to manage it. Also the metadata is a pair of key/value. It does not support multiple values for a key as you mentioned append. Does this make sense to you?

@vikas4cloud
Copy link
Author

@edwardmedia Thanks for your message let assume its a expected behavior of terraform then how to add more keys

as well as i have added the 2 keys (first time) with terraform only

scenario 1 if i want to add another 2 keys how can i add keys ??
my use case is i want to add 2 more new keys to metadata (2 already added via same terraform script)so after execution of terraform it should have to be 2 new and 2 old keys in metadata total 4

scenario 2 - if i am adding 2 new keys via terraform script its replacing old keys and adding only new 2 keys

working scenario 3 if i will keep all previous keys and appending the 2 more new keys then its adding but keeping all keys for adding new key is not a good practice for me.

can u let is know if this is a expected behiver than how can we achieve (adding more keys)

we would not like to use import as our jenkins jobs have same mechanism(init-plan-apply) for Iac

@ghost ghost removed the waiting-response label May 25, 2020
@edwardmedia edwardmedia added question and removed bug labels May 26, 2020
@edwardmedia
Copy link
Contributor

@vikas4cloud you may use below way or Terraform dynamic blocks feature to create multiple keys. Keep in mind, if you have already had keys that were created through non-Terraform methods, you have to run terraform import first before you can use Terraform to manage all keys.

resource "google_compute_project_metadata_item" "item1" {
  key   = "key1"
  value = "value1"
}
resource "google_compute_project_metadata_item" "item2" {
  key   = "key2"
  value = "value2"
}

@edwardmedia
Copy link
Contributor

@vikas4cloud I am closing this issue at this moment. Please feel free to reopen it if you still have related questions

@ghost
Copy link

ghost commented Jul 2, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Jul 2, 2020
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

2 participants