-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Terraform Version, Provider Version and Kubernetes Version
Terraform version: 1.1.9
Kubernetes provider version: 2.11.0
Kubernetes version: 1.22.5
Affected Resource(s)
- kubernetes_manifest
Terraform Configuration Files
resource "kubernetes_manifest" "serviceaccount_default" {
manifest = {
"apiVersion" = "v1"
"imagePullSecrets" = [
{
"name" = "default-dockercfg-k5mph"
},
]
"kind" = "ServiceAccount"
"metadata" = {
"name" = "default"
"namespace" = "default"
}
"secrets" = [
{
"name" = "default-token-hrxnz"
},
{
"name" = "default-dockercfg-k5mph"
},
]
}
}
Steps to Reproduce
- Create Terraform manifest file
sa-default.tf
:
resource "kubernetes_manifest" "serviceaccount_default" {
manifest = {
"apiVersion" = "v1"
"imagePullSecrets" = [
{
"name" = "default-dockercfg-k5mph"
},
]
"kind" = "ServiceAccount"
"metadata" = {
"name" = "default"
"namespace" = "default"
}
"secrets" = [
{
"name" = "default-token-hrxnz"
},
{
"name" = "default-dockercfg-k5mph"
},
]
}
}
- Import terraform resource
kubernetes_manifest.serviceaccount_default
:
terraform import kubernetes_manifest.serviceaccount_default "apiVersion=v1,kind=ServiceAccount,name=default,namespace=default"
- Terraform plan/apply:
terraform plan
or
terraform apply
Expected Behavior
What should have happened?
Terrafom should update in-place resource.
Actual Behavior
When importing a kubernetes resource with terraform import
command and then executing terraform apply
, the kubernetes will be replaced (delete and recreate) instead of updated.
We can see apiVersion, Kind and Name are added despite the fact that the fields have not been modified and have the same name which causes to the creation of the object and not the update
It seems the normal behavior for all terraform resources from #1593 issue. Recreation is the default behavior when apiVersion, Kind or Name changed. When importing a kubernetes manifest resource with this command terraform import kubernetes_manifest.secret_sample "apiVersion=v1,kind=Secret,namespace=default,name=sample" the fields apiVersion, Kind or Name are systematically added despite the fact that they do not change.
Important Factoids
-
Downgrading to
v2.8.0
of the provider results in the correct expected behavior. -
Importing resource with provider version >2.8.0 results re-creation of the resource
-
Importing resource with provider version <=2.8.0 works as expected - resource is updated in-place
References
- imported
kubernetes_manifest
resources are replaced on next apply #1679 importedkubernetes_manifest
resources are replaced on next apply #1679 - Force new resource when changing apiVersion or Kind #1593 Force new resource when changing apiVersion or Kind #1593
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment