Skip to content

Commit 2a0db2b

Browse files
authored
Update account component (cloudposse/terraform-aws-components#295)
* Update `account` component * Update `account` component * Update `account` component * Update `account` component * Update `account` component * Update components
1 parent e327ebe commit 2a0db2b

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

src/tfstate-context.tf

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
variable "tfstate_assume_role" {
2+
type = bool
3+
description = "Set to false to use the caller's role to access the Terraform remote state"
4+
default = true
5+
}
6+
7+
variable "tfstate_existing_role_arn" {
8+
type = string
9+
description = "The ARN of the existing IAM Role to access the Terraform remote state. If not provided and `remote_state_assume_role` is `true`, a role will be constructed from `remote_state_role_arn_template`"
10+
default = ""
11+
}
12+
13+
variable "tfstate_account_id" {
14+
type = string
15+
default = ""
16+
description = "The ID of the account where the Terraform remote state backend is provisioned"
17+
}
18+
19+
variable "tfstate_role_arn_template" {
20+
type = string
21+
default = "arn:aws:iam::%s:role/%s-%s-%s-%s"
22+
description = "IAM Role ARN template for accessing the Terraform remote state"
23+
}
24+
25+
variable "tfstate_role_environment_name" {
26+
type = string
27+
default = "gbl"
28+
description = "The name of the environment for Terraform state IAM role"
29+
}
30+
31+
variable "tfstate_role_stage_name" {
32+
type = string
33+
default = "root"
34+
description = "The name of the stage for Terraform state IAM role"
35+
}
36+
37+
variable "tfstate_bucket_environment_name" {
38+
type = string
39+
default = ""
40+
description = "The name of the environment for Terraform state bucket"
41+
}
42+
43+
variable "tfstate_bucket_stage_name" {
44+
type = string
45+
default = "root"
46+
description = "The name of the stage for Terraform state bucket"
47+
}
48+
49+
variable "tfstate_role_name" {
50+
type = string
51+
default = "terraform"
52+
description = "IAM Role name for accessing the Terraform remote state"
53+
}
54+
55+
locals {
56+
tfstate_access_role_arn = var.tfstate_assume_role ? (
57+
(var.tfstate_existing_role_arn != null && var.tfstate_existing_role_arn != "") ? var.tfstate_existing_role_arn : (
58+
format(var.tfstate_role_arn_template,
59+
var.tfstate_account_id,
60+
module.this.namespace,
61+
var.tfstate_role_environment_name,
62+
var.tfstate_role_stage_name,
63+
var.tfstate_role_name
64+
)
65+
)
66+
) : null
67+
68+
tfstate_bucket = "${module.this.namespace}-${var.tfstate_bucket_environment_name}-${var.tfstate_bucket_stage_name}-tfstate"
69+
tfstate_dynamodb_table = "${module.this.namespace}-${var.tfstate_bucket_environment_name}-${var.tfstate_bucket_stage_name}-tfstate-lock"
70+
}

0 commit comments

Comments
 (0)