Skip to content

Commit

Permalink
Merge pull request #39 from scalefactory/provider_passing
Browse files Browse the repository at this point in the history
Pass default aws provider explicitly
  • Loading branch information
word authored Aug 17, 2021
2 parents 84266b3 + 1964ace commit 21c7704
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 6 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
= Changelog

== 1.6.0

* fix: pass the default AWS provider explicitly from tfctl generated configuration.
This fixes provider inheritance issues when using multiple providers which
was introduced in 1.3.0. You may need to add a terraform block with
`required_provides` to your profiles if you don't have it defined already.
Terraform will warn about this during `init`. Here's an example block:

----
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
----

== 1.5.0

* feat: support for setting default tags at AWS provider level. (Thanks @patrickli)
Expand Down
4 changes: 4 additions & 0 deletions examples/control_tower/modules/s3-bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ resource aws_s3_bucket bucket {
bucket = var.name
acl = "private"
}

output "arn" {
value = aws_s3_bucket.bucket.arn
}
9 changes: 8 additions & 1 deletion examples/control_tower/profiles/example-profile/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
resource "random_pet" "bucket_prefix" {
}

module "bucket" {
source = "../../modules/s3-bucket"
name = "${local.account_id}-${local.account["data"]["example_bucket_name"]}"
name = "${random_pet.bucket_prefix.id}-${local.account["data"]["example_bucket_name"]}"
}

output "bucket_arn" {
value = module.bucket.arn
}
7 changes: 7 additions & 0 deletions examples/control_tower/profiles/example-profile/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
4 changes: 2 additions & 2 deletions examples/control_tower/profiles/example-profile/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ variable "config" {

locals {
config = jsondecode(var.config)
account_id = "${data.aws_caller_identity.current.account_id}"
account_id = data.aws_caller_identity.current.account_id
# get account configuration from tfctl config
account = [ for account in local.config["accounts"]: account if account["id"] == local.account_id ][0]
account = [for account in local.config["accounts"] : account if account["id"] == local.account_id][0]
}
7 changes: 5 additions & 2 deletions lib/tfctl/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ def make(account:, config:)
profile_block = {
'module' => {
profile => {
'source' => "../../../profiles/#{profile}",
'config' => '${var.config}',
'source' => "../../../profiles/#{profile}",
'config' => '${var.config}',
'providers' => {
'aws' => 'aws',
},
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion lib/tfctl/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Tfctl
VERSION = '1.5.0'
VERSION = '1.6.0'
end

0 comments on commit 21c7704

Please sign in to comment.