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

Labels/annotations not being imported through terraform import #722

Closed
mixedCase opened this issue Jan 2, 2020 · 4 comments · Fixed by #1253
Closed

Labels/annotations not being imported through terraform import #722

mixedCase opened this issue Jan 2, 2020 · 4 comments · Fixed by #1253
Labels
acknowledged Issue has undergone initial review and is in our work queue. bug help wanted size/M

Comments

@mixedCase
Copy link

mixedCase commented Jan 2, 2020

Running terraform import on a bunch of resources does not import metadata labels nor annotations to state.

Terraform Version

Terraform v0.12.18

  • provider.aws v2.43.0
  • provider.kubernetes v1.10.0

Affected Resource(s)

I just reproduced it with kubernetes_cluster_role, kubernetes_cluster_role_binding, kubernetes_config_map, kubernetes_deployment, kubernetes_namespace, kubernetes_role, kubernetes_role_binding, kubernetes_service and kubernetes_service_account. But I assume it affects all resources with labels in metadata.

Terraform Configuration Files

Partial example:

locals {
  ingress_name = "ingress-nginx"
  ingress_labels = {
    "app.kubernetes.io/name"    = "ingress-nginx"
    "app.kubernetes.io/part-of" = "ingress-nginx"
  }
}

resource "kubernetes_namespace" "ingress_nginx" {
  metadata {
    name   = local.ingress_name
    labels = local.ingress_labels
  }
}

Expected Behavior

Terraform import should've included label and annotation metadata in state.

Actual Behavior

It didn't. JSON screenshot comparing some of the state of one of the resources in the environment where I initially created it, and to the right, the one where I tried to terraform import it:

2020-01-02-15:38:24-screenshot

Steps to Reproduce

Instantiate the resource in one environment, try to import it in another one. Label metadata will be missing.

Important Factoids

Not really important, but just in case it's useful as a testing scenario or w/e: this was found during a refactor where an environment controlled resources that were to be shared with another environment. As a solution, a separate (shared) environment was created and the resources imported to it so that terraform_remote_state could be used in each user environment.

NOTE: This was edited to add annotations after the fact, as I just noticed a resource that missed its annotations as well.

@mixedCase mixedCase changed the title Labels not being imported through terraform import Labels/annotations not being imported through terraform import Jan 2, 2020
@elkbullwinkle
Copy link

I bumped into the same thing, I believe that it's related to the original stand that kubernetes.io labels are ignored, however with a recent change if those have been explicitly defined in the terraform file, these should be respected during import as well, otherwise after importing the resource on the next run it tries to modify the resource with explicitly defined labels, even though they already exist, just missing from the state files.

@jrhouston jrhouston added the acknowledged Issue has undergone initial review and is in our work queue. label Jun 24, 2020
@aareet aareet added the bug label Jul 2, 2020
@DrFaust92
Copy link
Contributor

Maybe we can filter well known labels like as specified here: https://kubernetes.io/docs/reference/kubernetes-api/labels-annotations-taints/ ?

similar to what is proposed here with tolerations #955 (comment)

I opened a PR for tolerations #978

@ixevix
Copy link

ixevix commented Mar 8, 2021

Running into this as well.

Terraform v0.12.29

  • provider.aws v3.30.0
  • provider.kubernetes v2.0.2

@github-actions
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 Jun 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
acknowledged Issue has undergone initial review and is in our work queue. bug help wanted size/M
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants