Skip to content

Commit 6323b20

Browse files
committed
feat(terragrunt): changes on terragrunt and precommit
1 parent 30f8080 commit 6323b20

8 files changed

Lines changed: 131 additions & 113 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ jobs:
1818
name: Pre-Commit Check
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@v6
21+
- uses: actions/checkout@v4
2222

23-
# Terragrunt & OpenTofu versions are read from mase.toml
2423
- name: Install Terragrunt and OpenTofu
2524
uses: gruntwork-io/terragrunt-action@v3
2625

@@ -29,14 +28,20 @@ jobs:
2928
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
3029
echo "$HOME/.tflint.d/bin" >> $GITHUB_PATH
3130
31+
- name: Show tool versions
32+
run: |
33+
terragrunt --version
34+
tofu --version || true
35+
tflint --version
36+
3237
- uses: pre-commit/action@v3.0.1
3338

3439
lint_and_format:
3540
name: Terragrunt Lint & Format
3641
runs-on: ubuntu-latest
3742
needs: pre_commit_check
3843
steps:
39-
- uses: actions/checkout@v6
44+
- uses: actions/checkout@v4
4045

4146
- name: Install Terragrunt and OpenTofu
4247
uses: gruntwork-io/terragrunt-action@v3
@@ -48,33 +53,49 @@ jobs:
4853
4954
- name: Terragrunt Format Check
5055
run: terragrunt hcl format --check
56+
working-directory: environments/local
57+
58+
- name: Cache TFLint plugins
59+
uses: actions/cache@v4
60+
with:
61+
path: ~/.tflint.d
62+
key: tflint-${{ runner.os }}-${{ hashFiles('.tflint.hcl') }}
5163

52-
- name: Run TFLint
53-
run: tflint --config .tflint.hcl
64+
- name: Run TFLint (init + lint)
65+
run: |
66+
tflint --init --config ../../.tflint.hcl
67+
tflint --config ../../.tflint.hcl
68+
working-directory: environments/local
5469

5570
validate:
5671
name: Terragrunt Validate
5772
runs-on: ubuntu-latest
5873
needs: [pre_commit_check, lint_and_format]
5974
steps:
60-
- uses: actions/checkout@v6
75+
- uses: actions/checkout@v4
6176

6277
- name: Install Terragrunt and OpenTofu
6378
uses: gruntwork-io/terragrunt-action@v3
6479

80+
- name: Terragrunt init
81+
run: terragrunt init --backend=false
82+
6583
- name: Terragrunt Validate
66-
run: terragrunt run-all validate
84+
run: terragrunt validate
6785

6886
plan:
6987
name: Terragrunt Plan
7088
runs-on: ubuntu-latest
7189
needs: validate
7290
if: github.event_name == 'pull_request'
7391
steps:
74-
- uses: actions/checkout@v6
92+
- uses: actions/checkout@v4
7593

7694
- name: Install Terragrunt and OpenTofu
7795
uses: gruntwork-io/terragrunt-action@v3
7896

97+
- name: Terragrunt Init
98+
run: terragrunt init --backend=false
99+
79100
- name: Terragrunt Plan
80-
run: terragrunt plan --all --non-interactive
101+
run: terragrunt run plan --non-interactive

.pre-commit-config.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ repos:
77
- id: end-of-file-fixer
88
- id: trailing-whitespace
99
- id: detect-private-key
10+
1011
- repo: https://github.com/gitleaks/gitleaks
1112
rev: v8.30.0
1213
hooks:
1314
- id: gitleaks
15+
1416
- repo: https://github.com/antonbabenko/pre-commit-terraform
15-
rev: v1.99.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
17+
rev: v1.99.0
1618
hooks:
1719
- id: terraform_validate
1820
args:
19-
- --hook-config=--tf-path=tofu
21+
- --hook-config=--tf-path=tofu
22+
2023
- id: terraform_fmt
24+
2125
- id: terraform_tflint
2226
args:
23-
- --hook-config=--tf-path=tofu
24-
- --args=-no-color
25-
- --args=-diff
27+
- --hook-config=--tf-path=tofu

.tflint.hcl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ config {
44
}
55

66
plugin "terraform" {
7-
enabled = true
8-
version = "0.12.0"
9-
source = "github.com/terraform-linters/tflint-ruleset-terraform"
7+
enabled = true
8+
version = "0.12.0"
9+
source = "github.com/terraform-linters/tflint-ruleset-terraform"
1010
}
1111

1212
plugin "azurerm" {
13-
enabled = true
14-
version = "0.23.0"
15-
source = "github.com/terraform-linters/tflint-ruleset-azurerm"
13+
enabled = true
14+
version = "0.23.0"
15+
source = "github.com/terraform-linters/tflint-ruleset-azurerm"
1616
}
1717

1818
# FIXME: USE rules to override the warnings

environments/local/network/terragrunt.hcl

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,69 +14,69 @@ terraform {
1414
}
1515

1616
inputs = merge(
17-
local.common_vars.locals.common_vars,
18-
{
19-
# Virtual Network Configuration
20-
vnet_config = {
21-
name = "vnet-example"
22-
address_space = ["10.0.0.0/16"]
17+
local.common_vars.locals.common_vars,
18+
{
19+
# Virtual Network Configuration
20+
vnet_config = {
21+
name = "vnet-example"
22+
address_space = ["10.0.0.0/16"]
23+
}
24+
# Subnet Configuration
25+
subnet_configs = {
26+
public = {
27+
address_prefixes = ["10.0.1.0/24"]
28+
}
29+
private = {
30+
address_prefixes = ["10.0.2.0/24"]
2331
}
24-
# Subnet Configuration
25-
subnet_configs = {
26-
public = {
27-
address_prefixes = ["10.0.1.0/24"]
28-
}
29-
private = {
30-
address_prefixes = ["10.0.2.0/24"]
31-
}
32+
}
33+
# Network Security Group Configuration
34+
nsg_configs = {
35+
public = {
36+
security_rules = [
37+
{
38+
name = "SSH"
39+
priority = 100
40+
direction = "Inbound"
41+
access = "Allow"
42+
protocol = "Tcp"
43+
source_port_range = "*"
44+
destination_port_range = "22"
45+
source_address_prefix = "*"
46+
destination_address_prefix = "*"
47+
}
48+
]
3249
}
33-
# Network Security Group Configuration
34-
nsg_configs = {
35-
public = {
36-
security_rules = [
37-
{
38-
name = "SSH"
39-
priority = 100
40-
direction = "Inbound"
41-
access = "Allow"
42-
protocol = "Tcp"
43-
source_port_range = "*"
44-
destination_port_range = "22"
45-
source_address_prefix = "*"
46-
destination_address_prefix = "*"
47-
}
48-
]
49-
}
50-
private = {
51-
security_rules = [
52-
{
53-
name = "SSH-from-public"
54-
priority = 100
55-
direction = "Inbound"
56-
access = "Allow"
57-
protocol = "Tcp"
58-
source_port_range = "*"
59-
destination_port_range = "22"
60-
source_address_prefix = "10.0.1.0/24"
61-
destination_address_prefix = "*"
62-
}
63-
]
64-
}
50+
private = {
51+
security_rules = [
52+
{
53+
name = "SSH-from-public"
54+
priority = 100
55+
direction = "Inbound"
56+
access = "Allow"
57+
protocol = "Tcp"
58+
source_port_range = "*"
59+
destination_port_range = "22"
60+
source_address_prefix = "10.0.1.0/24"
61+
destination_address_prefix = "*"
62+
}
63+
]
64+
}
65+
}
66+
# Route Table Configuration
67+
route_table_configs = {
68+
public = {
69+
routes = [
70+
{
71+
name = "default-route"
72+
address_prefix = "0.0.0.0/0"
73+
next_hop_type = "Internet"
74+
}
75+
]
6576
}
66-
# Route Table Configuration
67-
route_table_configs = {
68-
public = {
69-
routes = [
70-
{
71-
name = "default-route"
72-
address_prefix = "0.0.0.0/0"
73-
next_hop_type = "Internet"
74-
}
75-
]
76-
}
77-
private = {
78-
routes = []
79-
}
77+
private = {
78+
routes = []
8079
}
8180
}
81+
}
8282
)

environments/local/virtual_machine/terragrunt.hcl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@ terraform {
1414
}
1515

1616
dependency "network" {
17-
config_path = find_in_parent_folders("network")
17+
config_path = "../network"
1818

1919
mock_outputs = {
2020
subnets = {
21-
public = "subnet-id-public"
21+
public = "subnet-id-public"
2222
}
2323
}
2424
}
2525
inputs = merge(
26-
local.common_vars.locals.common_vars,
27-
{
28-
subnet_id = dependency.network.outputs.subnets["public"]
29-
vm_config = {
30-
name = "public-vm"
31-
subnet_key = "public"
32-
size = "Standard_B1s"
33-
admin_username = "adminuser"
34-
admin_ssh_key_public_key = "~/.ssh/id_rsa.pub"
35-
public_ip = true
36-
os_image = {
37-
publisher = "Canonical"
38-
offer = "UbuntuServer"
39-
sku = "18.04-LTS"
40-
version = "latest"
41-
}
26+
local.common_vars.locals.common_vars,
27+
{
28+
subnet_id = dependency.network.outputs.subnets["public"]
29+
vm_config = {
30+
name = "public-vm"
31+
subnet_key = "public"
32+
size = "Standard_B1s"
33+
admin_username = "adminuser"
34+
admin_ssh_key_public_key = "~/.ssh/id_rsa.pub"
35+
public_ip = true
36+
os_image = {
37+
publisher = "Canonical"
38+
offer = "UbuntuServer"
39+
sku = "18.04-LTS"
40+
version = "latest"
4241
}
4342
}
43+
}
4444
)

environments/root.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
generate "backend" {
33
path = "backend.tf"
44
if_exists = "overwrite_terragrunt"
5-
contents = <<EOF
5+
contents = <<EOF
66
terraform {
77
backend "azurerm" {
88
resource_group_name = "susilnemterraformstate-rg"

providers.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ terraform {
99
}
1010
}
1111
}
12+
13+
provider "azurerm" {
14+
features {}
15+
}

terragrunt.hcl

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ remote_state {
1515
}
1616
}
1717

18-
1918
locals {
2019
azure_provider_config = <<EOF
2120
terraform {
@@ -28,24 +27,16 @@ terraform {
2827
}
2928
}
3029
}
30+
31+
provider "azurerm" {
32+
features {}
33+
}
3134
EOF
3235
}
3336

34-
# Configure the Azure provider
37+
# Generate providers
3538
generate "providers" {
3639
path = "providers.tf"
3740
if_exists = "overwrite_terragrunt"
3841
contents = local.azure_provider_config
3942
}
40-
41-
generate "provider-az-network" {
42-
path = "modules/az_network/providers.tf"
43-
if_exists = "overwrite_terragrunt"
44-
contents = local.azure_provider_config
45-
}
46-
47-
generate "provider-az-virtual-machine" {
48-
path = "modules/az_virtual_machine/providers.tf"
49-
if_exists = "overwrite_terragrunt"
50-
contents = local.azure_provider_config
51-
}

0 commit comments

Comments
 (0)