Skip to content

Commit 9f38b2b

Browse files
authored
refactor(iac)!: Restructure into environments and modules (#101)
1 parent 83dbdb7 commit 9f38b2b

33 files changed

+172
-648
lines changed

.github/workflows/delete-workflow-run.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Delete old workflow runs
22
on:
33
schedule:
44
- cron: 0 0 1 * *
5-
workflow_call: {}
5+
workflow_dispatch: {}
66

77
# Disable permissions for all available scopes
88
permissions: {}

.github/workflows/infracost.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,31 @@ name: Infracost
33
on:
44
pull_request:
55
branches: [main]
6-
types: [opened, synchronize]
6+
types: [opened, reopened, synchronize]
77
paths:
8-
- "**/*.tf"
9-
- "**/*.tfvars"
8+
- iac/**/*.tf
9+
- iac/**/*.tfvars
10+
- iac/**/*.tftpl
11+
- iac/**/*.hcl
1012

1113
permissions: {}
1214

1315
concurrency:
1416
group: ${{ github.workflow }}-${{ github.repository }}
1517
cancel-in-progress: true
1618

19+
defaults:
20+
run:
21+
shell: bash
22+
working-directory: iac
23+
1724
jobs:
1825
infracost:
1926
name: Infracost Pull Request Checks
20-
runs-on: ubuntu-latest
21-
defaults:
22-
run:
23-
shell: bash
24-
working-directory: ./terraform
2527
permissions:
2628
contents: read
2729
pull-requests: write
30+
runs-on: ubuntu-latest
2831
timeout-minutes: 10
2932
steps:
3033
- name: Setup Infracost
@@ -37,6 +40,7 @@ jobs:
3740
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3841
with:
3942
ref: ${{ github.event.pull_request.base.ref }}
43+
persist-credentials: false
4044

4145
# Generate Infracost JSON file as the baseline.
4246
- name: Generate Infracost cost estimate baseline

.github/workflows/terraform-docs.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ on:
55
types: [closed]
66
branches: [main]
77
paths:
8-
- terraform/**/*.tf
9-
- terraform/**/*.tfvars
10-
- terraform/**/*.tftpl
8+
- iac/**/*.tf
9+
- iac/**/*.tfvars
10+
- iac/**/*.tftpl
11+
- iac/**/*.hcl
1112

1213
# Disable permissions for all available scopes
1314
permissions: {}

.trunk/configs/.tflint_ci.hcl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ plugin "terraform" {
44
preset = "all"
55
}
66

7-
Enable the AWS plugin if required
87
plugin "aws" {
98
enabled = true
109
version = "0.33.0"
1110
source = "github.com/terraform-linters/tflint-ruleset-aws"
1211

1312
# Deep check can be enabled in CI/CD pipelines, where AWS credentials are set
14-
# This configuration file should be references using the `--config` flag
15-
# Example: https://github.com/3ware/aws-network-speciality/blob/79a2be0813e053f17ed4f802705f7b6f2c350f0d/.github/workflows/terraform-ci.yaml#L114
1613
deep_check = true
17-
}
14+
}

iac/environments/dev/.terraform.lock.hcl

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iac/environments/dev/main.tf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
terraform {
2+
required_version = ">= 1.9, < 2.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = "~> 5.90"
8+
}
9+
}
10+
11+
cloud {
12+
organization = "3ware"
13+
hostname = "app.terraform.io"
14+
15+
workspaces {
16+
project = var.aws_project
17+
name = "${var.aws_service}-${var.aws_region}-${var.aws_environment}"
18+
19+
}
20+
}
21+
}
22+
23+
provider "aws" {
24+
region = var.aws_region
25+
26+
default_tags {
27+
tags = {
28+
"3ware:project-id" = var.aws_project
29+
"3ware:environment" = var.aws_environment
30+
"3ware:service" = var.aws_service
31+
"3ware:managed-by-terraform" = true
32+
"3ware:workspace" = terraform.workspace
33+
}
34+
}
35+
}
36+
37+
module "gitops_2024" {
38+
source = "../../modules/gitops-2024"
39+
40+
aws_environment = var.aws_environment
41+
instance_type = "t2.micro"
42+
vpc_cidr_block = "10.0.0.0/16"
43+
}

iac/environments/dev/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "grafana_ip" {
2+
description = "The public IP address of the Grafana instance"
3+
value = module.gitops_2024.grafana_ip
4+
}

iac/environments/dev/terraform.tfvars

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
aws_environment = "development"
2+
aws_project = "gitops-2024"
3+
aws_region = "eu-west-2"
4+
aws_service = "gitops-infra"

iac/environments/dev/variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
variable "aws_environment" {
2+
description = "(Required) The AWS environment to deploy resources to"
3+
type = string
4+
}
5+
6+
variable "aws_project" {
7+
description = "(Required) The AWS project to deploy resources to"
8+
type = string
9+
}
10+
11+
variable "aws_region" {
12+
description = "(Required) The AWS region to deploy resources to"
13+
type = string
14+
}
15+
16+
variable "aws_service" {
17+
description = "(Required) The AWS service being deployed"
18+
type = string
19+
}
File renamed without changes.

0 commit comments

Comments
 (0)