-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
SQL Database Instance does not have attribute ip_address.0.ip_address
#912
Comments
I can get to the "why was it implemented that way?" questions tomorrow, but for now- is it possible to just output the working value and then when you're trying to use it in a resource, grab the value you need from the list of maps? (does that make sense? I can try to come up with a sample config if not) |
When this instance has a count of 1, we want to grab the value of it's ip address and expose it as a terraform output. It's possible to get that value when the instance is present, but we haven't yet found a way to make the output "empty" so that terraform does not fail. If we know the instance is there, we tired to say |
It seems like the combination of splat syntax + nested map attributes is hard for terraform to follow. We tried splitting it into multiple small local vars: (This code might be a little off, I checked out the changes and am trying to remember one of dozens of things we tried 😄.)
And this will fail when the count is 0. |
This is obviously only breaking us since the |
Ah, ok. In that case I'd recommend filing an issue in the core repository: github.com/hashicorp/terraform, since even though you're using the Google provider, the actual problem could have happened with any of them if they followed this pattern. Probably best to make a note that you filed here first and I sent you there, so they don't try to send you back here. As for why we use a nested resource for ip addresses, that's just to mirror what the GCP API gives us: https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances. Since that documentation makes it sound like there could be more than one value in the list, we allow for more than one value in Terraform as well. |
Thanks Dana! Will do! |
@rosbo Would it be possible to re-open this issue as there is something that can be done in this provider that would fix the issue and also be convenient for users? The suggestion is from this comment: hashicorp/terraform#17048 (comment)
|
Oh. I missed that part. Reopening. |
@danawillow Would you be interested in a PR that added a |
Going to close this since the above PR got merged! |
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 👉 [email protected]. Thanks! |
Terraform Version
Terraform v0.11.1
Affected Resource(s)
Terraform Configuration Files
Debug Output
Expected & Actual Behavior
If I were to change the output value to:
I get:
I expect that in the former version of the output syntax (as is specified in the docs), it would print
35.184.66.76
and not an error that the attribute is not available. I additionally expect the output not to cause an error when the instance was not created.It seems that trying to use the splat syntax and asking for nested attributes (conditionally) is not possible in terraform. If there is a single ip address assigned, why does the attribute have to be gathered by indexing with
ip_address.0.ip_address
? Could the instance have a single, non-nested attribute for returning the address?Other Attempts
Using the
element
syntax is not possible asmaster.*.ip_address
will return a nested map and not a flat list. We can flatten this list withflatten(google_sql_database_instance.master.*.ip_address)
but this is a list of maps and so we cannot select the first map withelement()
. We can'telement(concat(flatten(...), list(SOMETHING)))
because you need to concat the flatted list with another list of maps.list()
only takes strings.We cannot do conditionals because they are not lazily evaluated and for the case where the instance is not created (
count == 0
), it still tries to get attributes.Steps to Reproduce
terraform apply
The text was updated successfully, but these errors were encountered: