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

Interpolation in 'provider =' value for aws_vpc is broken #4845

Closed
pll opened this issue Jan 26, 2016 · 4 comments
Closed

Interpolation in 'provider =' value for aws_vpc is broken #4845

pll opened this issue Jan 26, 2016 · 4 comments
Labels

Comments

@pll
Copy link

pll commented Jan 26, 2016

I would expect this to work:

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

provider "aws" {
  alias = "1"
  region = "us-west-1"
}

provider "aws" {
  alias = "2"
  region = "eu-west-1"
}

resource "aws_vpc" "vpc" {
  count = 3
  provider = "aws.${count.index}"
  cidr_block = "10.${count.index}.0.0/16"
}

Instead, I get:

$ terraform plan 
provider.aws.${lookup(var.regions, count.index)}.region
  The region where AWS operations will take place. Examples
  are us-east-1, us-west-2, etc.

  Default: us-east-1
  Enter a value: 

Even changing it to something like this:

variable "count" {
  default = "1"
}

variable "regions" {
  default = {
     "0" = "east"
     "1" = "west"
     "2" = "eu"
}
provider "aws" {
  alias = "east"
  region = "us-east-1"
}

provider "aws" {
  alias = "west"
  region = "us-west-1"
}

provider "aws" {
  alias = "eu"
  region = "eu-west-1"
}

resource "aws_vpc" "vpc" {
  count = 3
  provider = "aws.${lookup(var.regions, count.index)}"
  cidr_block = "10.${count.index}.0.0/16"
}

fails to work in the same way:

$ terraform plan 
provider.aws.${lookup(var.regions, count.index)}.region
  The region where AWS operations will take place. Examples
  are us-east-1, us-west-2, etc.

  Default: us-east-1
  Enter a value: 

@tobyclemson
Copy link

I also ran into this issue. Is there any workaround?

@Aitem
Copy link

Aitem commented May 5, 2016

+1 Same problem

@apparentlymart apparentlymart added config and removed core labels Nov 7, 2018
@apparentlymart
Copy link
Contributor

Hi all! Sorry for the long silence here.

This seems to be covering the same use-case as #3656, so I'm going to close this out just to consolidate the discussion.

Terraform generally doesn't allow interpolation in the so-called "meta-arguments" because they need to be evaluated during Terraform's graph-building step (in a sense, the "compile" step of the Terraform language) while expressions cannot be evaluated until the graph walk (the "run" step). This is similar to the idea that in many of programming languages you can't use variables in the names of types and functions, because they are something dealt with at compile time rather than at runtime.

However, we would still like to do something about the use-case of choosing a provider, so although it's unlikely to be solved by permitting arbitrary interpolation of provider addresses the issue #3656 is intended to represent the general use-case, with a design still to be determined.

@ghost
Copy link

ghost commented Jul 25, 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 Jul 25, 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

4 participants