Skip to content

Commit be4bad0

Browse files
committed
chore: updating and adding some outputs
1 parent 42931dd commit be4bad0

4 files changed

Lines changed: 37 additions & 20 deletions

File tree

modules/remote_state/data.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,24 @@ data "aws_caller_identity" "current" {}
44

55
## Lookup current region
66
data "aws_region" "current" {}
7+
8+
## Retrieve the remote state
9+
data "terraform_remote_state" "this" {
10+
backend = "s3"
11+
12+
config = {
13+
bucket = local.tf_state_bucket
14+
key = local.tf_state_key
15+
16+
## We can assume via the web identity token if it is provided
17+
assume_role_with_web_identity = var.web_identity_token_file != null ? {
18+
role_arn = local.role_arn
19+
web_identity_token_file = var.web_identity_token_file
20+
} : null
21+
22+
## We can assume via the reader role if no web identity token is provided
23+
assume_role = var.web_identity_token_file == null ? {
24+
role_arn = local.role_arn
25+
} : null
26+
}
27+
}

modules/remote_state/locals.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ locals {
77
region = coalesce(var.region, data.aws_region.current.name)
88

99
## Terraform state bucket name
10-
tf_state_bucket = format("%s-%s", local.account, local.region)
10+
tf_state_bucket = format("%s-%s-tfstate", local.account, local.region)
11+
12+
## Terraform state bucket key
13+
tf_state_key = format("%s.tfstate", var.repository)
1114

1215
## Remote state role
1316
role_arn = var.reader_role != null ? format("arn:aws:iam::%s:role/%s", local.account, var.reader_role) : format("arn:aws:iam::%s:role/%s-sr", local.account, var.repository)

modules/remote_state/main.tf

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1 @@
1-
data "terraform_remote_state" "this" {
2-
backend = "s3"
31

4-
config = {
5-
bucket = format("%s-tfstate", local.tf_state_bucket)
6-
key = format("%s.tfstate", var.repository)
7-
8-
## We can assume via the web identity token if it is provided
9-
assume_role_with_web_identity = var.web_identity_token_file != null ? {
10-
role_arn = local.role_arn
11-
web_identity_token_file = var.web_identity_token_file
12-
} : null
13-
14-
## We can assume via the reader role if no web identity token is provided
15-
assume_role = var.web_identity_token_file == null ? {
16-
role_arn = local.role_arn
17-
} : null
18-
}
19-
}

modules/remote_state/outputs.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
output "outputs" {
2-
value = data.terraform_remote_state.this.outputs
2+
description = "The outputs from the terraform_remote_state data source."
3+
value = data.terraform_remote_state.this.outputs
4+
}
5+
6+
output "bucket_name" {
7+
description = "The name of the S3 bucket where the Terraform state is stored."
8+
value = local.tf_state_bucket
9+
}
10+
11+
output "bucket_key" {
12+
description = "The key of the S3 bucket where the Terraform state is stored."
13+
value = local.tf_state_key
314
}

0 commit comments

Comments
 (0)