-
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
Any Way to Check If Resource or Data Has Attributes? #17881
Comments
Hi @hippothewild! Sorry for this strange behavior, and for the late response. We've been working on some significant changes to how Terraform deals with configuration and provider results in preparation for the forthcoming v0.12.0 release. One of the changes in that release is that when a provider declares an attribute in its schema but does not set a value for it then it should appear in expressions has having the value However, when I tried this in the v0.12.0-alpha1 prerelease build I saw that there is some sort of issue still remaining here. I simplified the example configuration a little just to avoid the need for those template files: provider "aws" {
region = "us-east-1"
}
variable "image_index" {
default = "d"
}
locals {
image_name = {
a = "ami-ed14c790" # Windows Server 2016
b = "ami-1853ac65" # Amazon Linux 2017.09.1
}
}
data "aws_ami" "ec2_ami" {
most_recent = true
filter {
name = "image-id"
values = ["${lookup(local.image_name, var.image_index, local.image_name["a"])}"]
}
}
data "template_file" "ec2_userdata" {
template = data.aws_ami.ec2_ami.platform == "windows" ? "windows" : "linux"
} It worked as expected with the Windows AMI, as before:
...but sadly after switching to the Linux AMI I see a new error, rather than success:
This error suggests that I'm going to mark this issue as being part of the v0.12.0 milestone so we'll look at it again before final release and fix this remaining problem and make this work correctly. Once this is fixed, the template should render as |
Hi @apparentlymart , Me and my team will happily be waiting for release of v0.12.0 which has lots of changes and improvements. Thank you so much for addressing the issue and telling about the future plan! |
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. |
Terraform Version
Terraform Configuration Files
Expected Behavior
data.aws_ami.ec2_ami
should have attributeplatform
Actual Behavior
For non-windows image like
ami-1853ac65
,data.aws_ami.ec2_ami
does not have attributeplatform
.Steps to Reproduce
Copy the configuration code to empty directory, and
Additional Context
The document says that some values are not always set, and the implementation also suppresses attributes that doesn't returned by AWS query.
However, to prevent different behavior depending on the data source, it should be able to have empty value(
""
) for the nontrivial attributes, or Terraform should have a way to check existence of attribute on resources and data variables.The text was updated successfully, but these errors were encountered: