Skip to content

Commit 61df5e9

Browse files
authored
Merge pull request #1506 from alphagov/appease_tflint
Appease TFLint
2 parents c6aafbf + 8b701e7 commit 61df5e9

12 files changed

Lines changed: 57 additions & 33 deletions

File tree

.github/workflows/terraform-ci.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,7 @@ jobs:
152152

153153
- name: Run tflint
154154
run: |
155-
tflint_deadline=$(date -d 2025-06-01 +%s)
156-
now=$(date +%s)
157-
info_only=true
158-
159-
if [ "${now}" -ge "${tflint_deadline}" ]; then
160-
echo "The deadline for addressing tflint errors has passed. They have begun failing the tests"
161-
info_only=false
162-
fi
163-
164-
make tflint TFLINT_INFO_ONLY=$info_only
155+
make tflint
165156
166157
- name: Run Checkov against Terraform
167158
uses: "docker://ghcr.io/bridgecrewio/checkov:3.2.386"

.tflint.hcl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ plugin "aws" {
88
version = "0.37.0"
99
source = "github.com/terraform-linters/tflint-ruleset-aws"
1010
}
11+
12+
rule "terraform_unused_declarations" {
13+
# disabled because we use a shared "inputs.tf" file and a set of ".tfvars" filesin a lot of places
14+
# and tflint is unable to tell the difference between a variable being unused in a particular root
15+
# and a variable being completely unused.
16+
#
17+
# If asked to fix the problem, tflint will simply delete all the variables it thinks aren't used,
18+
# which results in half the variables being deleted erronously.
19+
enabled = false
20+
}

Makefile

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
22
CODEBUILD_CI ?= false
33
SHELL=/usr/bin/env bash
44

5-
TFLINT_INFO_ONLY ?= false
6-
ifeq ($(TFLINT_INFO_ONLY), true)
7-
TFLINT_ARGS = --force
8-
endif
9-
105
##
116
# Environment targets
127
##
@@ -173,23 +168,34 @@ tflint_init:
173168

174169
.PHONY: tflint_modules
175170
tflint_modules:
176-
tflint --chdir=infra/modules/ --recursive --config "$$(pwd)/.tflint.hcl" ${TFLINT_ARGS}
171+
@# some rules are disabled because modules don't
172+
@# need to define the things those rules check for
173+
tflint --chdir=infra/modules/ --recursive --config "$$(pwd)/.tflint.hcl" \
174+
--disable-rule "terraform_required_version" \
175+
--disable-rule "terraform_required_providers" \
176+
${TFLINT_ARGS}
177177

178178
.PHONY: tflint_deploy
179179
tflint_deploy:
180-
tflint --chdir=infra/deployments/deploy/ --recursive --config "$$(pwd)/.tflint.hcl" ${TFLINT_ARGS}
180+
for root in $(DEPLOY_TF_ROOTS); do \
181+
tflint --chdir="infra/deployments/$${root}" --config "$$(pwd)/.tflint.hcl" ${TFLINT_ARGS}; \
182+
done;
181183

182184
.PHONY: tflint_forms
183185
tflint_forms:
184-
tflint --chdir=infra/deployments/forms/ --recursive --config "$$(pwd)/.tflint.hcl" ${TFLINT_ARGS} \
185-
--var-file="$$(pwd)/infra/deployments/forms/tfvars/production.tfvars" \
186-
--var-file="$$(pwd)/infra/deployments/forms/account/tfvars/backends/production.tfvars"
186+
for root in $(FORMS_TF_ROOTS); do \
187+
tflint --chdir="infra/deployments/$${root}" --config "$$(pwd)/.tflint.hcl" ${TFLINT_ARGS} \
188+
--var-file="$$(pwd)/infra/deployments/forms/tfvars/production.tfvars" \
189+
--var-file="$$(pwd)/infra/deployments/forms/account/tfvars/backends/production.tfvars"; \
190+
done;
187191

188192
.PHONY: tflint_integration
189193
tflint_integration:
190-
tflint --chdir=infra/deployments/integration/ --recursive --config "$$(pwd)/.tflint.hcl" ${TFLINT_ARGS} \
191-
--var-file="$$(pwd)/infra/deployments/integration/tfvars/integration.tfvars" \
192-
--var-file="$$(pwd)/infra/deployments/integration/tfvars/backend/integration.tfvars"
194+
for root in $(INTEGRATION_TF_ROOTS); do \
195+
tflint --chdir="infra/deployments/$${root}" --config "$$(pwd)/.tflint.hcl" ${TFLINT_ARGS} \
196+
--var-file="$$(pwd)/infra/deployments/integration/tfvars/integration.tfvars" \
197+
--var-file="$$(pwd)/infra/deployments/integration/tfvars/backend/integration.tfvars"; \
198+
done;
193199

194200
##
195201
# Help text
@@ -274,9 +280,14 @@ TASKS
274280
help This help text
275281
fmt Automatically format all Terraform code
276282
lint Run all linting tasks
277-
checkov Run Checkov (a Terraform linter) against all Terraform code
278283
lint_ruby Run Rubocop against all Ruby code
279284
spec Run Rspec tests against Ruby and Terraform code
285+
286+
checkov Run Checkov (a Terraform linter) against all Terraform code
287+
Checkov is evaluating how we configure things in AWS.
288+
289+
tflint Run TFLint (a Terraform linter) against all Terraform code.
290+
TFLint is evaluating the quality of our Terraform code.
280291
endef
281292
export help_tasks
282293

infra/modules/code-build-docker-build/iam.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ data "aws_iam_policy_document" "codebuild" {
3838
]
3939
resources = [
4040
"${var.artifact_store_arn}/*",
41-
"${var.artifact_store_arn}"
41+
var.artifact_store_arn
4242
]
4343
effect = "Allow"
4444
}

infra/modules/code-build-run-e2e-tests/iam.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ data "aws_iam_policy_document" "codebuild" {
3434
]
3535
resources = [
3636
"${var.artifact_store_arn}/*",
37-
"${var.artifact_store_arn}"
37+
var.artifact_store_arn
3838
]
3939
effect = "Allow"
4040
}

infra/modules/environment/alb.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ module "acm_certicate_with_validation" {
147147
}
148148

149149
domain_name = var.root_domain
150-
subject_alternative_names = lookup(local.subject_alternative_names, var.env_name)
150+
subject_alternative_names = local.subject_alternative_names[var.env_name]
151151
}
152152

153153
resource "aws_lb_listener" "listener" {

infra/modules/environment/cloudfront.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module "cloudfront" {
88
}
99

1010
env_name = var.env_name
11-
domain_name = "${lookup(local.domain_names, var.env_name)}forms.service.gov.uk"
11+
domain_name = "${local.domain_names[var.env_name]}forms.service.gov.uk"
1212
alb_dns_name = aws_lb.alb.dns_name
1313
ip_rate_limit = var.ip_rate_limit
1414
ips_to_block = var.ips_to_block
@@ -19,7 +19,7 @@ module "cloudfront" {
1919
aws_nat_gateway.nat_c.public_ip,
2020
]
2121

22-
subject_alternative_names = lookup(local.subject_alternative_names, var.env_name)
22+
subject_alternative_names = local.subject_alternative_names[var.env_name]
2323
}
2424

2525
resource "aws_ssm_parameter" "email_zendesk" {

infra/modules/forms-product-page/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ variable "memory" {
2424
variable "zendesk_subdomain" {
2525
description = "The Zendesk tenant the support form should create tickets on"
2626
default = "govuk"
27+
type = string
2728
}
2829

2930
variable "admin_base_url" {

infra/modules/gds-user-role/variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
variable "role_suffix" {}
1+
variable "role_suffix" {
2+
type = string
3+
description = "The value to be used as a suffix on each role. This value will be prefixed with a dash, so it does not need to be included"
4+
}
25

3-
variable "email" {}
6+
variable "email" {
7+
type = string
8+
description = "The email address of the human who will use this role"
9+
}
410

511
variable "iam_policy_arns" {
612
type = list(any)

infra/modules/rds/rds.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
locals {
22
rds_port = 5432
33
timestamp = timestamp()
4-
timestamp_sanitized = replace("${local.timestamp}", "/[- TZ:]/", "")
4+
timestamp_sanitized = replace(local.timestamp, "/[- TZ:]/", "")
55
}
66

77
data "aws_ssm_parameter" "database_password" {

0 commit comments

Comments
 (0)