Skip to content
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

Get 'value' of particular tag 'key' of aws resource. #1423

Closed
hashibot opened this issue Aug 15, 2017 · 10 comments · Fixed by #1706
Closed

Get 'value' of particular tag 'key' of aws resource. #1423

hashibot opened this issue Aug 15, 2017 · 10 comments · Fixed by #1706
Labels
breaking-change Introduces a breaking change in current functionality; usually deferred to the next major release. bug Addresses a defect in current functionality.

Comments

@hashibot
Copy link

hashibot commented Aug 15, 2017

This issue was originally opened by @dspatil as hashicorp/terraform#15814. It was migrated here as a result of the provider split. The original body of the issue is below.


I want to get a 'value' of particular tag 'key' of aws resource. (say 'aws_ami')
Using the latest terraform version. (Terraform v0.10.0)

Here is data source.

data "aws_ami" "web" {  
  filter {  
    name   = "state"  
    values = ["available"]  
  }  
  filter {  
    name   = "tag:Name"  
    values = ["Hello"]  
  }  
  most_recent = true    
}

Now, I am able to get all the tags associated with above resource as

"${data.aws_ami.web.tags}"

But, I want to get the 'value' of particular 'key' from that returned list. (say 'value' of key 'key1')
Is there a way to achieve this?

Below article explains some syntax. (like tags.#.key)
But its not working.
https://www.terraform.io/docs/providers/aws/d/ami.html#tags-key

Getting below error.

Failed to load root config module: Error loading modules: module compute: Error loading .terraform\modules\c46c475f0ca1e50cfe8501b3ff5285a6\compute.tf: Error reading config for output tags: parse error at 1:25: expected "}" but found invalid sequence "#"

Can anyone help me out?

@hashibot hashibot added the documentation Introduces or discusses updates to documentation. label Aug 15, 2017
@coingraham
Copy link
Contributor

Can someone explain how this configuration is supposed to work? Here's what I have:

data "aws_ami" "my_ami" {
  filter {
    name   = "name"
    values = ["my-ami-image"]
  }
}
output "ami_information" {
  value = "${data.aws_ami.my_ami.tags}"
}

Which produces the following output:

○ → terraform apply
data.aws_ami.my_ami: Refreshing state...
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
ami_information = [
    {
        key = terraform,
        value = test
    }
]

I've updated the terraform output line with the following tests:
value = "${data.aws_ami.my_ami.#.tags}" example straight from the docs. Fails.
value = "${data.aws_ami.my_ami.0.tags}" just a guess. Returns nothing.
value = "${data.aws_ami.my_ami.tags["terraform]}" example from the previous issue. Returns nothing.

Tested with both terraform 8.8 and 9.11

@apparentlymart apparentlymart added bug Addresses a defect in current functionality. and removed documentation Introduces or discusses updates to documentation. labels Aug 16, 2017
@apparentlymart
Copy link
Contributor

Hi @dspatil, @coingraham,

In my previous reply in the other issue I'd forgotten that (due to a historical mistake) the tags on this data source are not exported in the same way as on others: they are a list of objects with "key" and "value" rather than a map as I expected.

I think there was another bug open for this somewhere but since I wasn't able to find it I've just retagged this one as being a bug to represent that. The current formulation of the tags is not usable, so we should see about changing it to be a map like on other resources. (This will technically be a breaking change, but given that the current version is not actually usable -- since there's no way to actually select a single item -- I'd assume that currently usage of this attribute is pretty rare.)

@dspatil
Copy link

dspatil commented Aug 21, 2017

Hi @apparentlymart

Thanks for the updates.
So any timeline by when this will be fixed?

@apparentlymart apparentlymart added the breaking-change Introduces a breaking change in current functionality; usually deferred to the next major release. label Aug 22, 2017
@apparentlymart
Copy link
Contributor

Hi @dspatil,

I'm afraid we're not able to commit to particular timelines since our development process is not schedule-driven.

I've added the breaking-change label here, which will remind us next time we're planning a major release to take a look at this issue; we'd need to save it for a major release so we can warn users about the potential impact, even though it's small. We don't have any major releases of the AWS provider planned at this time, but when we do we'll look at all of the labels with this tag.

If someone has the time and motivation to work on this, we'd be happy to review a PR for it, though as noted we'd need to delay merging it until we're preparing for the next major release.

@Ninir
Copy link
Contributor

Ninir commented Aug 22, 2017

Hi folks,

I agree on the breaking-change label, which should imply a change for a major version, but since it is simply broken at the moment, what would you think of just merging when ready?

This looks to impact every data sources as far as I see.

It seems "easy" & "fast" to fix, but probably missing something for a first-sight check... ! 😅

@dspatil
Copy link

dspatil commented Aug 22, 2017

@apparentlymart ,
Thanks for the updates.

@Ninir
Copy link
Contributor

Ninir commented Aug 23, 2017

@apparentlymart You were probably remembering about this one #853

@drewsonne
Copy link
Contributor

drewsonne commented Sep 25, 2017

@apparentlymart If I were to give this a shot (I've written another provider, so I think I'm comfortable enough). Would you be happy with me changing the tags attribute from the schema.TypeSet to schema.TypeMapand rather than using the shared dataSourceTags func just use map[string]interface{} with the tags around here? Or would you want to maintain the existing shared functionality of dataSourceTags(...)?

@Ninir
Copy link
Contributor

Ninir commented Sep 27, 2017

Hey @drewsonne

I threw a PR for that a week ago: #1706, which fixes multiple data sources.

Tell me what you think on the PR :)

@ghost
Copy link

ghost commented Apr 10, 2020

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. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking-change Introduces a breaking change in current functionality; usually deferred to the next major release. bug Addresses a defect in current functionality.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants