Skip to content

Commit 477c7e0

Browse files
committed
Remove unused policies and variables for state locking
Since we are using terraform's native s3 state locking (#1476) we no longer need have dynamodb tables or the permissions associated with it
1 parent 7a4c1f8 commit 477c7e0

13 files changed

Lines changed: 28 additions & 154 deletions

File tree

infra/deployments/deploy/engineer-access/roles.tf

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ module "users" {
33
}
44

55
module "engineer_access" {
6-
source = "../../../modules/engineer-access"
7-
admins = module.users.with_role["deploy_admin"]
8-
support = module.users.with_role["deploy_support"]
9-
readonly = module.users.with_role["deploy_readonly"]
10-
env_name = "deploy"
11-
environment_type = "deploy"
12-
codestar_connection_arn = var.codestar_connection_arn
13-
dynamodb_state_file_locks_table_arn = "arn:aws:dynamodb::${var.deploy_account_id}:table/*"
14-
allow_ecs_task_usage = false
15-
allow_rds_data_api_access = false
6+
source = "../../../modules/engineer-access"
7+
admins = module.users.with_role["deploy_admin"]
8+
support = module.users.with_role["deploy_support"]
9+
readonly = module.users.with_role["deploy_readonly"]
10+
env_name = "deploy"
11+
environment_type = "deploy"
12+
codestar_connection_arn = var.codestar_connection_arn
13+
allow_ecs_task_usage = false
14+
allow_rds_data_api_access = false
1615

1716
# Pentesters may not have GDS domains so our pattern using the 'users' module
1817
# doesn't necessarily work.

infra/deployments/forms/account/deployer-access.tf

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
locals {
2-
# The user research account uses an underscore for environment type
3-
# and a dash for environment name. This is a bug fix to get the user-research
4-
# account Terraform working again while we determine what impact changing
5-
# the values will have.
6-
dynamodb_table_name = (var.environment_type == "user_research" ?
7-
"govuk-forms-user-research-tfstate-locking" :
8-
"govuk-forms-${var.environment_type}-tfstate-locking")
9-
}
101
module "deployer_access" {
11-
source = "../../../modules/deployer-access"
12-
environment_name = var.environment_name
13-
environment_type = replace(var.environment_type, "_", "-") # See comment about dynamodb table name
14-
account_id = var.aws_account_id
15-
deploy_account_id = var.deploy_account_id
16-
hosted_zone_id = aws_route53_zone.public.id
17-
codestar_connection_arn = var.codestar_connection_arn
18-
dynamodb_state_file_locks_table_arn = "arn:aws:dynamodb:eu-west-2:${var.aws_account_id}:table/*"
2+
source = "../../../modules/deployer-access"
3+
environment_name = var.environment_name
4+
environment_type = replace(var.environment_type, "_", "-") # The user research account uses an underscore for environment type and a dash for environment name
5+
account_id = var.aws_account_id
6+
deploy_account_id = var.deploy_account_id
7+
hosted_zone_id = aws_route53_zone.public.id
8+
codestar_connection_arn = var.codestar_connection_arn
199

2010
depends_on = [aws_route53_zone.public]
2111
}

infra/deployments/forms/account/engineer-access.tf

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ module "users" {
33
}
44

55
module "engineer_access" {
6-
source = "../../../modules/engineer-access"
7-
env_name = var.account_name
8-
environment_type = var.environment_type
9-
admins = module.users.with_role["${var.environment_type}_admin"]
10-
support = module.users.with_role["${var.environment_type}_support"]
11-
readonly = module.users.with_role["${var.environment_type}_readonly"]
12-
pentesters = var.pentester_email_addresses
13-
pentester_cidrs = var.pentester_cidr_ranges
14-
vpn = var.require_vpn_to_access
15-
codestar_connection_arn = var.codestar_connection_arn
16-
dynamodb_state_file_locks_table_arn = "arn:aws:dynamodb:eu-west-2:${var.aws_account_id}:table/*"
17-
allow_rds_data_api_access = true
18-
allow_ecs_task_usage = true
6+
source = "../../../modules/engineer-access"
7+
env_name = var.account_name
8+
environment_type = var.environment_type
9+
admins = module.users.with_role["${var.environment_type}_admin"]
10+
support = module.users.with_role["${var.environment_type}_support"]
11+
readonly = module.users.with_role["${var.environment_type}_readonly"]
12+
pentesters = var.pentester_email_addresses
13+
pentester_cidrs = var.pentester_cidr_ranges
14+
vpn = var.require_vpn_to_access
15+
codestar_connection_arn = var.codestar_connection_arn
16+
allow_rds_data_api_access = true
17+
allow_ecs_task_usage = true
1918
}

infra/deployments/forms/account/init-state-bucket/main.tf

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,12 @@ variable "bucket_name" {
99
description = "The name to give to the S3 bucket. Standard S3 bucket naming rules apply."
1010
}
1111

12-
variable "dynamodb_table" {
13-
type = string
14-
description = "The name to give to the DynamoDB table that will be used for state file locking."
15-
default = "tmp"
16-
}
17-
1812
module "state_bucket" {
1913
source = "../../../../modules/state-bucket"
2014

2115
bucket_name = var.bucket_name
2216
}
2317

24-
resource "aws_dynamodb_table" "state_locking_table" {
25-
#checkov:skip=CKV_AWS_28:we don't need point in time recovery on this table
26-
#checkov:skip=CKV_AWS_119:we don't require encryption on this table
27-
name = var.dynamodb_table
28-
hash_key = "LockID"
29-
billing_mode = "PAY_PER_REQUEST"
30-
31-
attribute {
32-
name = "LockID"
33-
type = "S"
34-
}
35-
}
3618

3719
output "bucket_name" {
3820
value = module.state_bucket.bucket_name

infra/deployments/forms/account/inputs.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ variable "bucket" {
2424
nullable = false
2525
}
2626

27-
variable "dynamodb_table" {
28-
description = "Name of the DynamoDB table used for state file locking. This is named to match the key in the S3 type backend"
29-
type = string
30-
nullable = false
31-
default = "tmp"
32-
}
33-
3427
variable "environment_name" {
3528
description = "The name of the environment. This is distinct from the environment type, but is likely to share the same name in cases like production or staging."
3629
type = string

infra/deployments/forms/inputs.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ variable "bucket" {
5454
nullable = false
5555
}
5656

57-
variable "dynamodb_table" {
58-
description = "Name of the DynamoDB table used for state file locking. This is named to match the key in the S3 type backend"
59-
type = string
60-
nullable = false
61-
default = "tmp"
62-
}
63-
6457
variable "dlq_arn" {
6558
description = "The ARN of the dead letter queue for paused pipeline detection"
6659
type = string

infra/deployments/integration/account/engineer-access.tf

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ module "support_role" {
5151
email = "${each.value}@digital.cabinet-office.gov.uk"
5252
role_suffix = "support"
5353
iam_policy_arns = [
54-
aws_iam_policy.lock_state_files.id
5554
]
5655
ip_restrictions = local.ip_restrictions
5756
}
@@ -64,7 +63,6 @@ module "readonly_role" {
6463
role_suffix = "readonly"
6564
iam_policy_arns = [
6665
"arn:aws:iam::aws:policy/ReadOnlyAccess",
67-
aws_iam_policy.lock_state_files.id
6866
]
6967
ip_restrictions = local.ip_restrictions
7068
}
@@ -82,27 +80,3 @@ module "pentester_role" {
8280
]
8381
ip_restrictions = var.pentester_cidr_ranges
8482
}
85-
86-
87-
resource "aws_iam_policy" "lock_state_files" {
88-
name = "lock-state-files"
89-
path = "/"
90-
91-
description = "Allow reading and writing from a DynamoDB table used for Terraform state file locking"
92-
93-
policy = jsonencode({
94-
Version = "2012-10-17"
95-
Statement = [
96-
{
97-
Effect = "Allow"
98-
Action = [
99-
"dynamodb:DescribeTable",
100-
"dynamodb:GetItem",
101-
"dynamodb:PutItem",
102-
"dynamodb:DeleteItem"
103-
]
104-
Resource = ["arn:aws:dynamodb:eu-west-2:${var.aws_account_id}:table/${var.dynamodb_table}"]
105-
}
106-
]
107-
})
108-
}

infra/deployments/integration/inputs.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ variable "bucket" {
2424
nullable = false
2525
}
2626

27-
variable "dynamodb_table" {
28-
description = "Name of the DynamoDB table used for state file locking. This is named to match the key in the S3 type backend"
29-
type = string
30-
nullable = false
31-
default = "tmp"
32-
}
33-
3427
variable "require_vpn_to_access" {
3528
type = bool
3629
description = "Whether this AWS account will require users to be on the VPN to access it"

infra/modules/deployer-access/policy.tf

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
##
66
data "aws_iam_policy_document" "forms_infra" {
77
source_policy_documents = [
8-
data.aws_iam_policy_document.lock_state_files.json,
98
data.aws_iam_policy_document.alerts.json,
109
data.aws_iam_policy_document.dns.json,
1110
data.aws_iam_policy_document.monitoring.json,
@@ -81,19 +80,6 @@ resource "aws_iam_role_policy_attachment" "full_read_only" {
8180
role = aws_iam_role.deployer.id
8281
}
8382

84-
data "aws_iam_policy_document" "lock_state_files" {
85-
statement {
86-
sid = "AllowStateFileLocking"
87-
effect = "Allow"
88-
actions = [
89-
"dynamodb:DescribeTable",
90-
"dynamodb:GetItem",
91-
"dynamodb:PutItem",
92-
"dynamodb:DeleteItem"
93-
]
94-
resources = [var.dynamodb_state_file_locks_table_arn]
95-
}
96-
}
9783
data "aws_iam_policy_document" "alerts" {
9884
statement {
9985
sid = "ManageKMSKeyAlerts"

infra/modules/deployer-access/variables.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,3 @@ variable "codestar_connection_arn" {
2828
type = string
2929
description = "ARN of the CodeStar connection in the account"
3030
}
31-
32-
variable "dynamodb_state_file_locks_table_arn" {
33-
type = string
34-
description = "The arn of the DynamoDB table being used for state file locking"
35-
}

0 commit comments

Comments
 (0)