-
Notifications
You must be signed in to change notification settings - Fork 113
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
Add import support to consul_key_prefix
#78
Add import support to consul_key_prefix
#78
Conversation
`consul_key_prefix` protect operators against unwanted key deletions by requiring the choosen path to be empty. While this is a nice default behavior, it can be intrusive to force it. This change makes add import support to `consul_key_prefix` so the operator can manually initialize Terraform state and override the default behavior. Close hashicorp#77
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is intended, but the behavior here is a little bit strange to me:
https://gist.github.com/pearkes/2da3d298119b7148d3e216e315d6bd49
I feel like that terraform apply
should be a no-op change, and not show a diff. What do you think, is this expected behavior?
I see three possibilities to handle this case:
I think 3. is the best solution, the least susceptible to surprise the user. It would still be a very good improvement for #77. What do you think about it? |
I agree 3 is the right choice there! Is there existing examples of this "import validation" in other providers? If that is a common UX lets do that. |
I made some research, none of https://github.com/terraform-providers/terraform-provider-github, https://github.com/terraform-providers/terraform-provider-aws/ or https://github.com/terraform-providers/terraform-provider-google do this. They either just use the Here's an example with
I still think it may be good idea though, Consul often store configuration that services will auto-reload on changes, a mistake can be costly, especially if those keys were not terraformed before as it may require to fetch them from backup. |
Interesting wonderful research @remilapeyre. With that being said I'm okay with 1 which I believe is the current approach, but also if you want to pursue 3 I'd also be okay with it! |
I suspect that one of the reasons that this not currently checked by any provider may be that they are not usually to diff and check states by hand. I think they may do it more if it were automatic, a new boolean attribute This boolean could be checked on https://github.com/hashicorp/terraform/blob/50e2b1856e211dc9dfd80a51d4f7e4af0bdd0f28/helper/schema/provider.go#L358 to abort the import if it would not result on a no-op change. If provider designers need a more customizable, two booleans could be used This could be useful for stateful resources, if I want to import a RDS database it's not to get it destroyed right away, having an import resulting in a destroy-recreate for such resources is probably a user error. If we want to let the user override The best way to know whether this would be useful would be to ask other provider writers, what do you think? |
If you wanted to prevent destruction via the config to be safe you can code it that way: resource "aws_instance" "test" {
lifecycle {
prevent_destroy = true
}
ami = "ami-0f9e7e8867f55fd8e"
instance_type = "t2.micro"
} |
consul_key_prefix
protect operators against unwanted key deletions byrequiring the choosen path to be empty.
While this is a nice default behavior, it can be intrusive to force it.
This change makes add import support to
consul_key_prefix
so theoperator can manually initialize Terraform state and override the default
behavior.
Close #77