From b68ac26f4da878452bcc2b17d77368cacd7b6510 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 5 Sep 2018 16:26:42 -0700 Subject: [PATCH] modules/aws/ami: Use implicit provider inheritance Docs in [1], where they say: This approach is recommended in the common case where only a single configuration is needed for each provider across the entire configuration. I didn't know about implicit provider inheritance when I landed the module in b23621fc (modules/aws/ami: Add a new module to get CoreOS AMIs, 2018-07-31, #84). We'll probably drop this module soon as we move to Red Hat CoreOS, but I worked up the change while looking for patterns to follow for a bootstrap module. The module source syntax used in the README is documented in [2,3,4], and means "the modules/aws/ami subdirectory of the github.com/openshift/installer repository cloned over HTTPS". [1]: https://www.terraform.io/docs/modules/usage.html#implicit-provider-inheritance [2]: https://www.terraform.io/docs/configuration/modules.html#source [3]: https://www.terraform.io/docs/modules/sources.html#github [4]: https://www.terraform.io/docs/modules/sources.html#modules-in-package-sub-directories --- modules/aws/ami/README.md | 37 ++++++++++++++++++++++----------- modules/aws/ami/main.tf | 5 ----- modules/aws/ami/variables.tf | 9 -------- modules/aws/master/main.tf | 1 - modules/aws/master/variables.tf | 9 -------- modules/aws/worker/main.tf | 1 - modules/aws/worker/variables.tf | 9 -------- steps/bootstrap/aws/main.tf | 1 - steps/infra/aws/main.tf | 2 -- 9 files changed, 25 insertions(+), 49 deletions(-) diff --git a/modules/aws/ami/README.md b/modules/aws/ami/README.md index 61f43f421e8..1c6072317ba 100644 --- a/modules/aws/ami/README.md +++ b/modules/aws/ami/README.md @@ -1,27 +1,40 @@ # Container Linux AMI Module This [Terraform][] [module][] supports `latest` versions for [Container Linux][container-linux] release channels and returns an appropriate [AMI][]. +It uses [implicit provider inheritance][implicit-provider-inheritance] to access the [AWS provider][AWS-provider]. ## Example -From the module directory: +Set up a `main.tf` with: + +```hcl +provider "aws" { + region = "us-east-1" +} + +module "ami" { + source = "github.com/openshift/installer//modules/aws/ami" +} + +output "ami" { + value = "${module.ami.id}" +} +``` + +You can set `release_channel` and `release_version` if you need a specific Container Linux install. + +Then run: ```console $ terraform init -$ terraform apply --var region=us-east-1 -$ terraform output id -ami-ab6963d4 -$ terraform apply --var region=us-east-1 --var release_channel=alpha -$ terraform output id -ami-985953e7 -$ terraform apply --var region=us-east-2 --var release_channel=alpha --var release_version=1814.0.0 -$ terraform output id -ami-c25f66a7 +$ terraform apply +$ terraform output ami +ami-00cc4337762ba4a52 ``` -When you're done, clean up by removing the `.terraform` directory created by `init` and the `terraform.tfstate*` files created by `apply`. - [AMI]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html +[AWS-provider]: https://www.terraform.io/docs/providers/aws/ [container-linux]: https://coreos.com/os/docs/latest/ +[implicit-provider-inheritance]: https://www.terraform.io/docs/modules/usage.html#implicit-provider-inheritance [module]: https://www.terraform.io/docs/modules/ [Terraform]: https://www.terraform.io/ diff --git a/modules/aws/ami/main.tf b/modules/aws/ami/main.tf index 1593457145e..9c9911d3e97 100644 --- a/modules/aws/ami/main.tf +++ b/modules/aws/ami/main.tf @@ -1,8 +1,3 @@ -provider "aws" { - region = "${var.region}" - version = "1.8.0" -} - locals { ami_owner = "595879546273" arn = "aws" diff --git a/modules/aws/ami/variables.tf b/modules/aws/ami/variables.tf index 5b84b10cdd5..49172b45eb8 100644 --- a/modules/aws/ami/variables.tf +++ b/modules/aws/ami/variables.tf @@ -1,12 +1,3 @@ -variable "region" { - type = "string" - - description = <