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

Lookup of AMIs by region in atlas_artifact ? #4239

Closed
steve-jansen opened this issue Dec 9, 2015 · 6 comments
Closed

Lookup of AMIs by region in atlas_artifact ? #4239

steve-jansen opened this issue Dec 9, 2015 · 6 comments
Labels

Comments

@steve-jansen
Copy link
Contributor

Hi Hashicorp,

Following up on #2731, how does one lookup an atlas_artifact AMI by AWS region?

@ravbaba posted in #732:

ami = "${lookup(atlas_artifact.mesos-master.metadata_full, concat("region-", var.region))}"

But this raises an error like:

Error running plan: 1 error(s) occurred:

* lookup: lookup in 'B780EEEC-B661-4EB8-8236-A01737AD98B6' failed to find 'region.us-east-1' in:

${lookup(atlas_artifact.mesos-master.metadata_full, concat("region.", var.region))}

Is Atlas/AMI lookup possible via some other means now?

Cheers,
Steve

@pstengel
Copy link

This is the workaround I'm currently using:

resource "aws_instance" "controller" {
  ami = "${element(split(",", atlas_artifact.controller.metadata_full.ami_id), index(split(",", atlas_artifact.controller.metadata_full.region), var.region))}"
  ...

It's long and ugly and we definitely need a better way, but it works for now. 😄

@stack72
Copy link
Contributor

stack72 commented Jul 27, 2016

Hi @steve-jansen

Sorry this has taken so long to reply to - there is a backlog of issues that I am working my way through right now. Can you have a look and tell me if the new data_sources work will help here?

https://github.com/hashicorp/terraform/blob/master/website/source/docs/providers/atlas/d/artifact.html.markdown

This is already available in 0.7.0-RC3

thanks

Paul

@stack72 stack72 added the waiting-response An issue/pull request is waiting for a response from the community label Jul 27, 2016
@steve-jansen
Copy link
Contributor Author

Hi @stack72

No worries, we found ways to workaround the challenge here, which includes #7365.

The data_sources are great. Not sure they solve this specific issue here, which is that metadata_full doesn't seem to behave like a proper map, which breaks the lookup function when trying to lookup an AMI by region.

Cheers,
Steve

@mootpt
Copy link
Contributor

mootpt commented Sep 12, 2016

@steve-jansen

I have some success with:

variable "region" { default = "us-east-1" }

data "atlas_artifact" "foo" {
        name          = "ptr/foo"
        type          = "amazon.ami"
}

output "ami_id" {
        value = "${lookup(data.atlas_artifact.foo.metadata_full, "region-${var.region}")}"
}

but maybe I am missing the requirements? Why the use of concat? Concat no longer works with strings, just lists.

@steve-jansen
Copy link
Contributor Author

@mootpt looks great! Thanks for sharing. Closing this issue.

🍻

@ghost
Copy link

ghost commented Aug 16, 2019

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.

@ghost ghost locked and limited conversation to collaborators Aug 16, 2019
@ghost ghost removed the waiting-response An issue/pull request is waiting for a response from the community label Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants