Terraform-aws-eks: Open PR to remove providers from module

Created on 29 Aug 2018  路  5Comments  路  Source: terraform-aws-modules/terraform-aws-eks

I have issues

I'm submitting a...

  • [ ] bug report
  • [X] feature request
  • [ ] support request
  • [ ] kudos, thank you, warm fuzzy

What is the current behavior?

Currently, because of providers defined at the module level, you cannot delete the module to remove your infrastructure. Conversely, you have to use commands to remove items from the state file before you can delete. See #108

Per these 2 issues, it seems after terraform 0.11 these providers should no longer be in modules.
https://github.com/hashicorp/terraform/issues/16824
https://github.com/hashicorp/terraform/issues/17928

If this is a bug, how to reproduce? Please include a code sample if relevvant.

User Terraform > 0.11 and add the module to create infra, after the apply remove the code, you will get error.

What's the expected behavior?

All infra in this module is deleted.

Are you able to fix this problem and submit a PR? Link here if you have already.

Yes, but don't have permissions to contribute. eg create branch for a PR.

Environment details

  • Affected module version: terraform-aws-eks
  • OS: N/A
  • Terraform version: v0.11.7

Any other relevant info

Something like this should fix the issues, I tested locally and it works on my machine.

provider "null" {
  version = "~> 1.0"
  alias = "default"
}

provider "template" {
  version = "~> 1.0"
  alias = "default"
}

module "eks" {
  source                     = terraform-aws-modules/eks/aws"
  cluster_name          = "development"
  subnets                   = "${module.vpc_app.private_subnets}"
  tags                         = "${map("Environment", "${var.stage}")}"
  vpc_id                      = "${module.vpc_app.vpc_id}"
  manage_aws_auth   = false

  providers = {
    aws = "aws.default"
    null = "null.default"
    template = "template.default"
  }
}

Next __remove__ these lines from main.tf

...
- provider "null" {}
- provider "template" {}

Most helpful comment

Is this really standard practice now? We need to pass providers into every module?

No.

The primary provider instance does not need an alias specified. You only need to use alias if you are dealing with multiple instances of the same provider (e.g. default aws provider is in us-east-1 and you also want to add DR resources in us-west-2).

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

provider "aws" {
  region = "us-east-2"
  alias  = "dr"
}

The default provider is automatically passed through to modules for their use.

Setting version on providers is not required but is recommended best practice.

It is recommended best practice not to define providers within modules. It is really frustrating from a module provider's PoV as you cannot specify the minimum compatible provider version. This has caused confusion in the community VPC module a few times when e.g. the new tags-on-EIPs feature was used.

Removing null and template should not be a breaking change. Users will get a warning that they should add a provider block with version when doing terraform init

Chris's example is better written as:

provider "null" {
  version = "~> 1.0"
}

provider "template" {
  version = "~> 1.0"
}

module "eks" {
  source          = "terraform-aws-modules/eks/aws"
  cluster_name    = "development"
  subnets         = "${module.vpc_app.private_subnets}"
  tags            = "${map("Environment", "${var.stage}")}"
  vpc_id          = "${module.vpc_app.vpc_id}"
  manage_aws_auth = false
}

All 5 comments

Is this really standard practice now? We need to pass providers into every module?

Is this really standard practice now? We need to pass providers into every module?

No.

The primary provider instance does not need an alias specified. You only need to use alias if you are dealing with multiple instances of the same provider (e.g. default aws provider is in us-east-1 and you also want to add DR resources in us-west-2).

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

provider "aws" {
  region = "us-east-2"
  alias  = "dr"
}

The default provider is automatically passed through to modules for their use.

Setting version on providers is not required but is recommended best practice.

It is recommended best practice not to define providers within modules. It is really frustrating from a module provider's PoV as you cannot specify the minimum compatible provider version. This has caused confusion in the community VPC module a few times when e.g. the new tags-on-EIPs feature was used.

Removing null and template should not be a breaking change. Users will get a warning that they should add a provider block with version when doing terraform init

Chris's example is better written as:

provider "null" {
  version = "~> 1.0"
}

provider "template" {
  version = "~> 1.0"
}

module "eks" {
  source          = "terraform-aws-modules/eks/aws"
  cluster_name    = "development"
  subnets         = "${module.vpc_app.private_subnets}"
  tags            = "${map("Environment", "${var.stage}")}"
  vpc_id          = "${module.vpc_app.vpc_id}"
  manage_aws_auth = false
}

Removing null and template should not be a breaking change.

Alright, let's do that now. I'll make a PR.

PR is now merged so I'll close this issue.

Was this page helpful?
0 / 5 - 0 ratings