Skip to content

Commit 963fc98

Browse files
authored
add usgov support and upgrade to v0.12 (#1)
* add usgov support * add data.aws_partition.current.partition
1 parent 4d029ee commit 963fc98

File tree

6 files changed

+27
-25
lines changed

6 files changed

+27
-25
lines changed

examples/complete/init-tf-backend.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ module "tfbackend" {
44
source = "tf-mod/tfbackend/aws"
55
version = "1.0.0"
66

7-
aws_account_id = "${var.aws_account_id}"
8-
bucket_name = "${var.bucket_name}"
9-
dynamodb_table = "${var.dynamodb_table}"
7+
aws_account_id = var.aws_account_id
8+
bucket_name = var.bucket_name
9+
dynamodb_table = var.dynamodb_table
1010
dynamodb_read_capacity = "10"
1111
dynamodb_write_capacity = "10"
1212
}

examples/complete/provider.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ terraform {
33
}
44

55
provider "aws" {
6-
region = "${var.aws_region}"
7-
profile = "${var.aws_profile}"
8-
allowed_account_ids = ["${var.aws_account_id}"]
6+
region = var.aws_region
7+
profile = var.aws_profile
8+
allowed_account_ids = [var.aws_account_id]
99
version = ">= 1.15.0"
1010
}

examples/simple/init-tf-backend.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module "tfbackend" {
44
source = "tf-mod/tfbackend/aws"
55
version = "1.0.0"
66

7-
aws_account_id = "${var.aws_account_id}"
8-
bucket_name = "${var.bucket_name}"
9-
dynamodb_table = "${var.dynamodb_table}"
7+
aws_account_id = var.aws_account_id
8+
bucket_name = var.bucket_name
9+
dynamodb_table = var.dynamodb_table
1010
}

examples/simple/provider.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ terraform {
33
}
44

55
provider "aws" {
6-
region = "${var.aws_region}"
7-
profile = "${var.aws_profile}"
8-
allowed_account_ids = ["${var.aws_account_id}"]
6+
region = var.aws_region
7+
profile = var.aws_profile
8+
allowed_account_ids = [var.aws_account_id]
99
version = ">= 1.15.0"
1010
}

main.tf

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
data "aws_partition" "current" {}
2+
13
# DynamoDB table for lock info storage
24
resource "aws_dynamodb_table" "terraform_lock" {
3-
name = "${var.dynamodb_table}"
4-
read_capacity = "${var.dynamodb_read_capacity}"
5-
write_capacity = "${var.dynamodb_write_capacity}"
5+
name = var.dynamodb_table
6+
read_capacity = var.dynamodb_read_capacity
7+
write_capacity = var.dynamodb_write_capacity
68
hash_key = "LockID"
79

810
attribute {
@@ -20,16 +22,16 @@ resource "aws_dynamodb_table" "terraform_lock" {
2022

2123
# S3 bucket for storing terraform state
2224
resource "aws_s3_bucket" "terraform_state" {
23-
bucket = "${var.bucket_name}"
25+
bucket = var.bucket_name
2426

2527
versioning {
2628
enabled = true
2729
}
2830
}
2931

3032
resource "aws_s3_bucket_policy" "bucket_policy" {
31-
bucket = "${aws_s3_bucket.terraform_state.id}"
32-
policy = "${data.aws_iam_policy_document.bucket_policy.json}"
33+
bucket = aws_s3_bucket.terraform_state.id
34+
policy = data.aws_iam_policy_document.bucket_policy.json
3335
}
3436

3537
data "aws_iam_policy_document" "bucket_policy" {
@@ -40,15 +42,15 @@ data "aws_iam_policy_document" "bucket_policy" {
4042
]
4143

4244
resources = [
43-
"arn:aws:s3:::${var.bucket_name}/*",
44-
"arn:aws:s3:::${var.bucket_name}",
45+
format("arn:%s:s3:::%s/*", data.aws_partition.current.partition, var.bucket_name),
46+
format("arn:%s:s3:::%s", data.aws_partition.current.partition, var.bucket_name),
4547
]
4648

4749
principals {
4850
type = "AWS"
4951

5052
identifiers = [
51-
"arn:aws:iam::${var.aws_account_id}:root",
53+
format("arn:%s:iam::%s:root", data.aws_partition.current.partition, var.aws_account_id)
5254
]
5355
}
5456
}

outputs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
output "bucket_name" {
2-
value = "${aws_s3_bucket.terraform_state.id}"
2+
value = aws_s3_bucket.terraform_state.id
33
}
44

55
output "bucket_arn" {
6-
value = "${aws_s3_bucket.terraform_state.arn}"
6+
value = aws_s3_bucket.terraform_state.arn
77
}
88

99
output "dynamodb_table" {
10-
value = "${aws_dynamodb_table.terraform_lock.id}"
10+
value = aws_dynamodb_table.terraform_lock.id
1111
}
1212

1313
output "dynamodb_table_arn" {
14-
value = "${aws_dynamodb_table.terraform_lock.arn}"
14+
value = aws_dynamodb_table.terraform_lock.arn
1515
}

0 commit comments

Comments
 (0)