-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
aws_db_instance: Downcase "engine" for RDS #2745
Conversation
Learned this one the hard way on my own stuff. Figured I'd submit a quick patch once I was able to isolate the bug :-). |
Thanks for submitting this @ctiwald! I'm curious, you mention being unable to simply write lowercase to the state file, were you doing this manually, or using a |
@catsby: manually. Wasn't aware of the state function but I'm certain that'll do it. I'll resubmit tomorrow. |
29afc8e
to
060c868
Compare
@catsby -- updated to use the StateFunc. Also fixed a bug in the acc tests, and injected a mixed-case config into the acc tests to ensure the new state func works. Runs green for me now. |
I agree this is a problem, but I'm not overly happy with the proposed solution. AWS APIs sometimes are magic (in a negative way) - especially when changing uppercase to lowercase. I don't think that Terraform should behave the same way. Why not use the |
@radeksimko -- In the end, I'm somewhat indifferent about the implementation here. I started by throwing an error (without the ValidateFunc, notably), then moved to StateFunc, and I could move it back. For what it's worth, though, I completely agree: The AWS APIs are magical, inconsistent, and in many ways incoherent. The rules that apply to one service don't apply to another, and it's completely obvious they were designed in isolation, by teams with different rules, guidelines, and product managers. As a user of terraform, one of the things I like about TF is that it keeps it simple. I'd personally rather Terraform hide AWS's terrible design than proxy it forward, forcing me, the TF user, to memorize a slew of inconsistent and odd validations. I'm totally on board with validating truly invalid input, but this isn't invalid input, it's just input that creates an inconsistent state on
I'm totally willing to defer to you and @catsby here. In the end, I'm pretty indifferent about this particular case. But for what it's worth, I think it'd be great if TF allowed me to reduce my mental model of "random crap I have to know to use AWS" by silently taking care of stuff like this. |
Well, it may be valid based on the docs, but in reality you cannot create an RDS instance with uppercase engine because it will always be lowercased, so effectively it's invalid - the API just makes invalid input valid again. :) I'm letting @catsby to decide here. I just think that there are benefits of keeping attribute values inside Terraform code close to the reality. |
Sure. I'm fine with whatever you guys decide. Just let me know and I'll modify the PR accordingly. |
Valid points on both sides.
Unfortunately, That said, and assuming that adding a I don't want Terraform to do a lot of magic for users either, but I think we're in a corner here and need to compromise. Does that sound reasonable? |
@catsby -- I'm totally up for the compromise. Do note however that with the current bug, if they're using an uppercase plan, they are, in fact, going to get a new database with each The I'm happy to implement whichever solution you all like. |
I think the |
@catsby -- in that case you can merge this right now pending review. That is what this PR implements in its most recent round. |
engine_version = "5.6.21" | ||
instance_class = "db.t1.micro" | ||
name = "baz" | ||
security_group_names = ["default"] |
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.
Are you running this in a Classic env? I get an error when trying to create in a VPC. If possible, please remove this.
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.
Ah yeah, except I'm not specifically opting into it. AWS just must default me there. One moment.
Amazon accepts mixed-case engines, but only returns lowercase. Without the proper StateFunc, every apply of a mixed-case engine will result in a new db instance. Standardize on lowercase.
060c868
to
4f085ba
Compare
Updated, @catsby. I'm running an environment that defaults to EC2 Classic, which caused the tests to fail for me. |
aws_db_instance: Downcase "engine" for RDS
Thanks @ctiwald ! |
Thanks @radeksimko too, for the discussion / suggestions |
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. |
If we don't, then mixed case engines (e.g. "MySQL") will force a rebuild
of the db_instance on every apply.
Unfortunately, we can't simply write lowercase to the state file. The
engine property forces a new instance when a diff is detected. This
solution, while not perfect, protects the user from themselves.