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

aws_eip data source missing support for tags #3423

Closed
ghost opened this issue Feb 16, 2018 · 11 comments
Closed

aws_eip data source missing support for tags #3423

ghost opened this issue Feb 16, 2018 · 11 comments
Labels
enhancement Requests to existing resources that expand the functionality or scope. good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@ghost
Copy link

ghost commented Feb 16, 2018

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


Terraform Version

> terraform -v
Terraform v0.11.3
+ provider.aws v1.9.0

Terraform Configuration Files

data "aws_eip" "sample" {
  tags {
		Name ="A valuable IP"
	}
}

Crash Output

Error: data.aws_eip.sample: : invalid or unknown key: tags

Expected Behavior

Terraform would return an IP with a described "Name" tag value

Actual Behavior

Error: data.aws_eip.sample: : invalid or unknown key: tags

Steps to Reproduce

  1. terraform init
  2. terraform apply

References

The same issue was fixed for aws_eip resource just over a month ago at hashicorp/terraform#16993.
Now it is a turn for aws_eip data source

@vpadronblanco
Copy link
Contributor

I am currently studying the issue. I wonder if it is best to have a more general 'filter' (which is part of the API), or just use tags. Any thoughts?

@MaximF
Copy link

MaximF commented Feb 17, 2018 via email

@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. service/ec2 Issues and PRs that pertain to the ec2 service. labels Feb 21, 2018
@Ninir
Copy link
Contributor

Ninir commented Mar 2, 2018

Hey folks,

Just as an input, use of Filters (filter in HCL files) is definitely the way to go here: we already use that in some places like the aws_ami data source, and could use Filter.N from DescribeAddresses as in tag:key=value.
This would be standardised across data sources and would fully rely on the API.

Relying on map of Tags (tags in HCL files) would just confuse users in the end.

@Ninir Ninir added the easy label Mar 2, 2018
@vpadronblanco
Copy link
Contributor

I can leave the tags as complimentary then - something that is available for aws_instance, for example. I saw Richard made some changes to the testing file so once he commits I will commit my changes that accommodate his tests.

@paultyng paultyng added good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. help wanted and removed good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. help wanted labels Mar 5, 2018
@ivankatliarchuk
Copy link

ivankatliarchuk commented Apr 28, 2018

Consistency is nice to have.
However, there is support of both types for example

data "aws_subnet_ids" "this" {
    vpc_id = "${xxxxxxx}"

    tags {
      Visibility  = "xxx"
      Environment = "xxxx"
    }
}

Or

data "aws_vpc" "this" {
  default = false

  filter {
    name   = "state"
    values = ["available"]
  }
}

Its just confusing, when you can use only in one way.
Not terraform related, probably. The filter just by tag is preferred in cloud agnostic world.
Is there is a plan for releasing it anywhere in future?
Cheers.

@whereisaaron
Copy link
Contributor

@tanzwud unfortunately those two syntaxes are also semantically different. They reflect to different tag capabilities for different AWS API calls. The tags approach is a conjunctive test (a=x) AND (b=y). Whereas 'filters' approach (maps to AWS filter.N) approach is disjunctive (a=x or y) OR (b=z).

In my experience the conjunctive tags approach is more useful than filters. When only filters are available I sometime have to fashion special tags to represent right combination of properties for which I want to filter.

@PaulColdren
Copy link

Until this gets implemented, I'm using an external data provider which calls aws directly. Others may find it useful.

We preallocate EIPs with a separate terraform configuration. In our specific use case, we need durable IPs we can share with customers. Keeping them in a separate terraform configuration makes it easier to mutate the underlying infrastructure without needing to take special precautions to avoid inadvertently releasing the EIPs.

This is how we use the preallocated EIPs from our "main" terraform that actually manages the EC2 instances.

main.tf contents:

data "external" "instance-eip" {
  program = ["${path.module}/get_eip.sh"]

  query {
    name        = "tf-${var.preallocated_eip_name}-eip"
    aws_region  = "${var.aws_region}"
    aws_profile = "${var.aws_account_name}"
  }
}

locals {
  eip_alloc_id = "${data.external.instance-eip.result.allocation_id}"
}

get_eip.sh contents:

#!/usr/bin/env bash

set -uex

eval "$(jq -r '@sh "NAME=\(.name) AWS_REGION=\(.aws_region) AWS_PROFILE=\(.aws_profile)"')"

EIP_QUERY_RESPONSE="$(aws ec2 describe-addresses --region $AWS_REGION --filters "Name=tag:Name,Values=$NAME" --profile $AWS_PROFILE)"

ALLOCATION_ID="$(echo ${EIP_QUERY_RESPONSE} | jq -r '.Addresses[0].AllocationId')"

jq -n --arg allocation_id "$ALLOCATION_ID" '{"allocation_id":$allocation_id}'

@bflad bflad closed this as completed in ec0a43c Nov 13, 2018
@bflad bflad added this to the v1.44.0 milestone Nov 13, 2018
@bflad
Copy link
Contributor

bflad commented Nov 13, 2018

Hi folks 👋 Very sorry for the lengthy delays with merging this support, there were a few conflicting pull requests to the same code which needed to get sorted out. Good news is that the following will be supported in version 1.44.0 of the AWS provider, likely releasing later today or tomorrow:

  • Search by filter
  • Search by tags
  • EC2-Classic support

@MaximF
Copy link

MaximF commented Nov 14, 2018

Those are great news, thank you @bflad!

@bflad
Copy link
Contributor

bflad commented Nov 15, 2018

This has been released in version 1.44.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link
Author

ghost commented Apr 2, 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 2, 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. good first issue Call to action for new contributors looking for a place to start. Smaller or straightforward issues. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

No branches or pull requests

8 participants