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

Can't use tags attribute data sources #853

Closed
artburkart opened this issue Jun 14, 2017 · 2 comments · Fixed by #1706
Closed

Can't use tags attribute data sources #853

artburkart opened this issue Jun 14, 2017 · 2 comments · Fixed by #1706
Labels
enhancement Requests to existing resources that expand the functionality or scope.

Comments

@artburkart
Copy link
Contributor

artburkart commented Jun 14, 2017

Terraform Version

$ terraform -v
Terraform v0.9.8

Affected Resource(s)

Please list the resources as a list, for example:

  • aws_instance
  • aws_ebs_volume
  • possibly others? didn't check

I guess I should mention it might be a problem across providers depending on whether other providers use similar tag implementations.

Terraform Configuration Files

I've made a gist with a README here: https://gist.github.com/artburkart/5916ea45390bf2050e1f97f15c9a7dcd

I'll also paste my configs here:

provider "aws" {
  region = "us-east-1"
}

data "aws_instance" "dummy" {
  instance_id = "i-3c6e8abc"
}

variable "use_null_resource" {
  default = 0
}

resource "null_resource" "null" {
  triggers {
    Name = "foo"
  }
}

resource "aws_instance" "instance" {
  ami                    = "${data.aws_instance.dummy.ami}"
  instance_type          = "${data.aws_instance.dummy.instance_type}"
  subnet_id              = "${data.aws_instance.dummy.subnet_id}"
  vpc_security_group_ids = ["${data.aws_instance.dummy.vpc_security_group_ids}"]
  # tags                   = "${var.use_null_resource == 0 ? data.aws_instance.dummy.tags : null_resource.null.triggers}"
  # tags                   = "${data.aws_instance.dummy.tags}"
  tags                   = "${null_resource.null.triggers}"
}

data "aws_ebs_volume" "dummy" {
  most_recent = true
}

resource "aws_ebs_volume" "ebs_vol" {
  availability_zone = "us-east-1"
  size              = 40
  # tags              = "${var.use_null_resource == 0 ? data.aws_ebs_volume.dummy.tags : null_resource.null.triggers}"
  # tags              = "${data.aws_ebs_volume.dummy.tags}"
  tags              = "${null_resource.null.triggers}"
}

Debug Output

I'll provide some upon request, but I think the snippet I provided should be sufficient for reproduction and the output isn't too helpful, since there aren't any API issues here.

Expected Behavior

I should be able to write this:

  tags = "${data.aws_instance.dummy.tags}"

Actual Behavior

Because the tags on the data source are interpreted as a list of maps, they're not compatible with the tags attribute as defined.

Steps to Reproduce

  1. terraform plan

Important Factoids

Nothing atypical about setup. It's not an AWS account-related conundrum. One thing worth noting is that no matter how I try accessing the values of the tags in the data.aws_instance.dummy.tags field, I get the length of the list back.

For example:

"${data.aws_instance.dummy.tags.*} => "5"
"${data.aws_instance.dummy.tags.0} => "5"
"${data.aws_instance.dummy.tags.0.Name} => "5"

I think this has something to do with terraform not unpacking the value correctly when creating the data source, so it ends up not being compatible with the aws_instance resource because terraform doesn't play nicely with lists of maps.

I don't know go very well, but I think this problem might have something to do with terraform converting a set of hashes to a list of hashes in this file: https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/data_source_aws_common_schema.go#L21-L33

References

I was told to open this issue here: hashicorp/terraform#2042 (comment)

@radeksimko radeksimko added the enhancement Requests to existing resources that expand the functionality or scope. label Jun 16, 2017
@Ninir
Copy link
Contributor

Ninir commented Aug 4, 2017

Hey @artburkart

I think this is something we can do by updating the code & adding a schema migration. Will check how we can do that soon :)

@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
enhancement Requests to existing resources that expand the functionality or scope.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants