Skip to content

Commit

Permalink
Add Github action to lint terraform code
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Sep 15, 2021
1 parent 82ecc89 commit 08ecfab
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 7 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Lint
on:
push:
branches: [ main ]
pull_request:

jobs:
tflint:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
component: [core, data_services, fcrepo, solrcloud]

steps:
- uses: actions/checkout@v2
name: Checkout source code

- uses: actions/cache@v2
name: Cache plugin dir
with:
path: ~/.tflint.d/plugins
key: tflint-${{ hashFiles('.tflint.hcl') }}

- uses: terraform-linters/setup-tflint@v1
name: Setup tflint

- name: Show version
run: tflint --version

- name: Lint ${{ matrix.component }} component
run: |
terraform init -backend=false -input=false
tflint -c ../.tflint.hcl --init
tflint -c ../.tflint.hcl -f compact
working-directory: ./${{ matrix.component }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.terraform
**/.terraform
*.tfstate
*.tfvars
20 changes: 20 additions & 0 deletions .tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
config {
module = true
}

plugin "aws" {
enabled = true
version = "0.7.1"
source = "github.com/terraform-linters/tflint-ruleset-aws"
}

rule "aws_resource_missing_tags" {
enabled = true
tags = ["Component", "Environment", "Git", "Project"]
}

rule "terraform_module_pinned_source" {
enabled = false
style = "flexible"
default_branches = ["master"]
}
6 changes: 4 additions & 2 deletions core/vpc.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
source = "terraform-aws-modules/vpc/aws"
version = "3.7.0"

name = "${local.namespace}-vpc"
cidr = var.cidr_block
Expand Down Expand Up @@ -65,7 +66,8 @@ resource "aws_security_group" "internal_http" {
}

module "endpoints" {
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
version = "3.7.0"

vpc_id = module.vpc.vpc_id
security_group_ids = [module.vpc.default_security_group_id, aws_security_group.endpoint_access.id]
Expand Down
3 changes: 3 additions & 0 deletions data_services/elasticsearch.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
resource "aws_security_group" "elasticsearch" {
name = "${local.namespace}-elasticsearch"
tags = local.tags
}

resource "aws_security_group_rule" "elasticsearch_egress" {
Expand Down Expand Up @@ -127,6 +128,7 @@ data "aws_iam_policy_document" "elasticsearch_read_access" {
resource "aws_iam_policy" "elasticsearch_read_access" {
name = "${local.namespace}-elasticsearch-read"
policy = data.aws_iam_policy_document.elasticsearch_read_access.json
tags = local.tags
}

data "aws_iam_policy_document" "elasticsearch_full_access" {
Expand All @@ -143,4 +145,5 @@ data "aws_iam_policy_document" "elasticsearch_full_access" {
resource "aws_iam_policy" "elasticsearch_full_access" {
name = "${local.namespace}-elasticsearch-full"
policy = data.aws_iam_policy_document.elasticsearch_full_access.json
tags = local.tags
}
9 changes: 6 additions & 3 deletions data_services/postgres.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ resource "aws_security_group" "db" {
name = "${local.namespace}-db"
description = "RDS Security Group"
vpc_id = module.core.outputs.vpc.id
tags = local.tags
}

resource "aws_security_group_rule" "db_egress" {
Expand All @@ -34,6 +35,7 @@ resource "aws_security_group" "db_client" {
name = "${local.namespace}-db-client"
description = "RDS Client Security Group"
vpc_id = module.core.outputs.vpc.id
tags = local.tags
}

resource "aws_db_subnet_group" "db_subnet_group" {
Expand All @@ -43,9 +45,10 @@ resource "aws_db_subnet_group" "db_subnet_group" {
}

resource "aws_db_parameter_group" "db_parameter_group" {
name_prefix = "${local.namespace}-db-"
family = "postgres${element(split(".", var.postgres_version), 0)}"

name_prefix = "${local.namespace}-db-"
family = "postgres${element(split(".", var.postgres_version), 0)}"
tags = local.tags

parameter {
name = "client_encoding"
value = "UTF8"
Expand Down
1 change: 0 additions & 1 deletion data_services/redis.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ resource "aws_elasticache_cluster" "redis" {
node_type = "cache.t2.small"
num_cache_nodes = 1
engine_version = "5.0.3"
parameter_group_name = "default.redis5.0"
security_group_ids = [aws_security_group.redis_service.id]
subnet_group_name = aws_elasticache_subnet_group.redis.name
tags = local.tags
Expand Down
4 changes: 4 additions & 0 deletions fcrepo/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ resource "aws_s3_bucket" "fedora_binary_bucket" {
resource "aws_iam_user" "fedora_binary_bucket_user" {
name = "${local.namespace}-fcrepo"
path = "/system/"
tags = local.tags
}

resource "aws_iam_access_key" "fedora_binary_bucket_access_key" {
Expand Down Expand Up @@ -118,6 +119,7 @@ data "aws_iam_policy_document" "fedora_binary_bucket_access" {
resource "aws_iam_policy" "fedora_binary_bucket_policy" {
name = "${local.namespace}-fcrepo-s3-bucket-access"
policy = data.aws_iam_policy_document.fedora_binary_bucket_access.json
tags = local.tags
}

resource "aws_iam_user_policy_attachment" "fedora_binary_bucket_user_access" {
Expand Down Expand Up @@ -249,6 +251,8 @@ resource "aws_service_discovery_service" "fcrepo" {

routing_policy = "MULTIVALUE"
}

tags = local.tags
}

resource "aws_ecs_service" "fcrepo" {
Expand Down
2 changes: 2 additions & 0 deletions solrcloud/solr.tf
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ resource "aws_service_discovery_service" "solr" {

routing_policy = "MULTIVALUE"
}

tags = local.tags
}

resource "aws_ecs_service" "solr" {
Expand Down
2 changes: 2 additions & 0 deletions solrcloud/zookeeper.tf
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ resource "aws_service_discovery_service" "zookeeper" {

routing_policy = "MULTIVALUE"
}

tags = local.tags
}

resource "aws_ecs_service" "zookeeper" {
Expand Down

0 comments on commit 08ecfab

Please sign in to comment.