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

terraform should warn when unexpected attributes are in required_providers #26160

Closed
francisferrell opened this issue Sep 8, 2020 · 6 comments · Fixed by #26184
Closed

terraform should warn when unexpected attributes are in required_providers #26160

francisferrell opened this issue Sep 8, 2020 · 6 comments · Fixed by #26184
Labels
enhancement v0.13 Issues (primarily bugs) reported against v0.13 releases

Comments

@francisferrell
Copy link

francisferrell commented Sep 8, 2020

I'm just getting spun up with vanilla terraform for a personal project after using terragrunt at work. I think I've got it configured correctly, but maybe I made a mistake. I think this is a bug in terraform, not in the aws provider, because a trivial sample works on 0.12.29 but the behavior regresses on 0.13.2.

I have the region configured in the tf and as the region in the AWS profile config. I therefore expect to not be prompted for the region.

Terraform Version

Terraform v0.13.2
+ provider registry.terraform.io/hashicorp/aws v3.5.0

Terraform Configuration Files

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "3.5.0"
      profile = "terraform"
      region = "us-east-1"
    }
  }

  backend "s3" {
    profile = "terraform"
    region = "us-east-1"
    bucket = "terraform-francisferrell"
    key = "terraform.tfstate"
    dynamodb_table = "terraform-francisferrell"
  }
}


resource "aws_s3_bucket" "foo" {
}
 ~ $ cat ~/.aws/config
[profile francis]
region = us-east-1
cli_pager =
[profile terraform]
region = us-east-1
cli_pager =
 ~ $ env | grep AWS
AWS_DEFAULT_PROFILE=francis

Debug Output

Crash Output

Expected Behavior

A plan

Actual Behavior

provider.aws.region
  The region where AWS operations will take place. Examples
  are us-east-1, us-west-2, etc.

  Enter a value:

Steps to Reproduce

  1. terraform init
  2. terraform plan

Additional Context

References

@francisferrell francisferrell added bug new new issue not yet triaged labels Sep 8, 2020
@francisferrell
Copy link
Author

For comparison, the following produces the expected result. Same AWS profile configuration and env is in effect here.

Terraform Version

Terraform v0.12.29
+ provider.aws v3.5.0

Your version of Terraform is out of date! The latest version
is 0.13.2. You can update by downloading from https://www.terraform.io/downloads.html

Terraform Configuration Files

provider "aws" {
  version = "3.5.0"
  profile = "terraform"
  region = "us-east-1"
}

terraform {
  backend "s3" {
    profile = "terraform"
    region = "us-east-1"
    bucket = "terraform-francisferrell"
    key = "terraform.tfstate"
    dynamodb_table = "terraform-francisferrell"
  }
}

resource "aws_s3_bucket" "foo" {
}

@mildwonkey
Copy link
Contributor

hi @francisferrell !

The required_providers setting is only used to set the version and source for a provider - you still need your provider configuration block:

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "3.5.0"
    }
  }

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

  backend "s3" {
    profile = "terraform"
    region = "us-east-1"
    bucket = "terraform-francisferrell"
    key = "terraform.tfstate"
    dynamodb_table = "terraform-francisferrell"
  }
}


resource "aws_s3_bucket" "foo" {
}

When I originally wrote this, I omitted any error message for unexpected attributes in a required_providers setting (like "region" in your first example) for backwards compatibility (0.12 accepted the new required_providers syntax but ignored anything other than "version"), but if this confusion comes up frequently we can change that.

I am going to re-title and re-label this as an enhancement, specifically to add a warning when unexpected attributes show up in required_providers. Thanks for reporting it, and I'm sorry for the confusion!

@mildwonkey mildwonkey changed the title terraform prompts for provider.aws.region after upgrading to 0.13.2 terraform should warn when unexpected attributes are in required_providers Sep 8, 2020
@mildwonkey mildwonkey added enhancement v0.13 Issues (primarily bugs) reported against v0.13 releases and removed bug new new issue not yet triaged labels Sep 8, 2020
@bflad
Copy link
Member

bflad commented Sep 8, 2020

@francisferrell
Copy link
Author

francisferrell commented Sep 8, 2020

@mildwonkey got it, thanks for clarifying. I'll give it a try tonight and verify that it works like expected.

I think I was confused by the way the docs present it (https://registry.terraform.io/providers/hashicorp/aws/latest/docs). In the docs for the aws provider, when I click on the USE PROVIDER button and get the popup, the two forms are presented in a way that seems mutually exclusive:

Terraform 0.13 [Latest]

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "3.5.0"
    }
  }
}

vs:

Terraform <= 0.12

provider "aws" {
  version = "3.5.0"
}

Then, in the body of that document, right at the top, is this example:

# Configure the AWS Provider
provider "aws" {
  version = "~> 3.0"
  region  = "us-east-1"
}

Not knowing better, I interpret this as a holdover from 0.12.x that hasn't yet been updated for the new 0.13.x syntax, so I dutifully migrate the entire provider section into the aws section inside required_providers.

Maybe there's some other documentation somewhere else that explains how providers in general are configured and how 0.13 introduces a split of the provider version into a separate block form the provider's own parameters. But, looking at https://www.terraform.io/docs/backends/config.html and https://www.terraform.io/docs/providers/index.html there are no mentions of required_providers in either.

@francisferrell
Copy link
Author

@mildwonkey as written this gives:

Error: Unsupported block type

  on main.tf line 10, in terraform:
  10: provider "aws" {

Blocks of type "provider" are not expected here.

I put provider "aws" { ... } in its own top-level block adjacent to, instead of inside of, terraform { ... }.

That got my issue sorted out. I got a complete plan/apply/destroy cycle working as expected with no prompts for region. Thanks for pointing me in the right direction.

Here's the full tf for reference

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "3.5.0"
    }
  }

  backend "s3" {
    profile = "terraform"
    region = "us-east-1"
    bucket = "terraform-francisferrell"
    key = "terraform.tfstate"
    dynamodb_table = "terraform-francisferrell"
  }
}


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


resource "aws_s3_bucket" "foo" {
}

@ghost
Copy link

ghost commented Oct 13, 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 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 as resolved and limited conversation to collaborators Oct 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement v0.13 Issues (primarily bugs) reported against v0.13 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants