diff --git a/.github/workflows/terraform-examples.yml b/.github/workflows/terraform-examples.yml index 2a655de..25f812e 100644 --- a/.github/workflows/terraform-examples.yml +++ b/.github/workflows/terraform-examples.yml @@ -9,32 +9,44 @@ on: jobs: - check-terraform-fmt: + terraform-tflint: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Setup TFLint + uses: terraform-linters/setup-tflint@v6 + with: + cache: true + - name: Show version + run: tflint --version + # - name: help + # run: tflint -help + - name: Run + run: tflint --chdir=terraform --recursive + + terraform-check-fmt: runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@v4 - - name: Install Terraform uses: hashicorp/setup-terraform@v2 - - name: Check Terraform formatting run: | bash terraform/repo-scripts/check-terraform-fmt.sh terraform - check-terraform-variables-tailscale-install-scripts: + terraform-check-variables-tailscale-install-scripts: runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@v4 - # - name: tree # working-directory: terraform # run: | # apt-get -y update # apt-get -y install tree # tree -a - - name: Check variables-tailscale-install-scripts.tf files run: | bash terraform/repo-scripts/check-variables-tailscale-install-scripts.sh terraform diff --git a/Makefile b/Makefile index 6bde89d..5273da4 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,13 @@ default: help +.PHONY: terraform-tflint +terraform-tflint: ## Run 'terraform-tflint' github actions with https://github.com/nektos/act + act -j terraform-tflint + .PHONY: check-terraform-examples -check-terraform-examples: ## Run specific 'check' github actions with https://github.com/nektos/act - act -j check-terraform-fmt - act -j check-variables-tailscale-install-scripts +terraform-check-examples: ## Run specific 'check' github actions with https://github.com/nektos/act + act -j terraform-check-fmt + act -j terraform-check-variables-tailscale-install-scripts .PHONY: help help: ## Display this information. Default target. diff --git a/terraform/.tflint.hcl b/terraform/.tflint.hcl new file mode 100644 index 0000000..b8edc99 --- /dev/null +++ b/terraform/.tflint.hcl @@ -0,0 +1,4 @@ +plugin "terraform" { + enabled = true + preset = "all" +} diff --git a/terraform/aws/aws-ec2-autoscaling-relay-to-private-subnet/versions.tf b/terraform/aws/aws-ec2-autoscaling-relay-to-private-subnet/versions.tf index 8906343..70d492f 100644 --- a/terraform/aws/aws-ec2-autoscaling-relay-to-private-subnet/versions.tf +++ b/terraform/aws/aws-ec2-autoscaling-relay-to-private-subnet/versions.tf @@ -1,8 +1,14 @@ terraform { required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 6.0, < 7.0" + } tailscale = { source = "tailscale/tailscale" version = ">= 0.24" } } + + required_version = ">= 1.0, < 2.0" } diff --git a/terraform/aws/aws-ec2-autoscaling-session-recorder/versions.tf b/terraform/aws/aws-ec2-autoscaling-session-recorder/versions.tf index 8906343..70d492f 100644 --- a/terraform/aws/aws-ec2-autoscaling-session-recorder/versions.tf +++ b/terraform/aws/aws-ec2-autoscaling-session-recorder/versions.tf @@ -1,8 +1,14 @@ terraform { required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 6.0, < 7.0" + } tailscale = { source = "tailscale/tailscale" version = ">= 0.24" } } + + required_version = ">= 1.0, < 2.0" } diff --git a/terraform/aws/aws-ec2-autoscaling/versions.tf b/terraform/aws/aws-ec2-autoscaling/versions.tf index 8906343..70d492f 100644 --- a/terraform/aws/aws-ec2-autoscaling/versions.tf +++ b/terraform/aws/aws-ec2-autoscaling/versions.tf @@ -1,8 +1,14 @@ terraform { required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 6.0, < 7.0" + } tailscale = { source = "tailscale/tailscale" version = ">= 0.24" } } + + required_version = ">= 1.0, < 2.0" } diff --git a/terraform/aws/aws-ec2-instance-dual-stack-ipv4-ipv6/outputs.tf b/terraform/aws/aws-ec2-instance-dual-stack-ipv4-ipv6/outputs.tf index 8ed38ee..739e305 100644 --- a/terraform/aws/aws-ec2-instance-dual-stack-ipv4-ipv6/outputs.tf +++ b/terraform/aws/aws-ec2-instance-dual-stack-ipv4-ipv6/outputs.tf @@ -15,7 +15,7 @@ output "nat_public_ips" { } output "instance_ids" { - value = module.tailscale_aws_ec2.*.instance_id + value = module.tailscale_aws_ec2[*].instance_id } output "user_data_md5" { diff --git a/terraform/aws/aws-ec2-instance-dual-stack-ipv4-ipv6/versions.tf b/terraform/aws/aws-ec2-instance-dual-stack-ipv4-ipv6/versions.tf index 8906343..70d492f 100644 --- a/terraform/aws/aws-ec2-instance-dual-stack-ipv4-ipv6/versions.tf +++ b/terraform/aws/aws-ec2-instance-dual-stack-ipv4-ipv6/versions.tf @@ -1,8 +1,14 @@ terraform { required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 6.0, < 7.0" + } tailscale = { source = "tailscale/tailscale" version = ">= 0.24" } } + + required_version = ">= 1.0, < 2.0" } diff --git a/terraform/aws/aws-ec2-instance/outputs.tf b/terraform/aws/aws-ec2-instance/outputs.tf index 8ed38ee..739e305 100644 --- a/terraform/aws/aws-ec2-instance/outputs.tf +++ b/terraform/aws/aws-ec2-instance/outputs.tf @@ -15,7 +15,7 @@ output "nat_public_ips" { } output "instance_ids" { - value = module.tailscale_aws_ec2.*.instance_id + value = module.tailscale_aws_ec2[*].instance_id } output "user_data_md5" { diff --git a/terraform/aws/aws-ec2-instance/versions.tf b/terraform/aws/aws-ec2-instance/versions.tf index 8906343..70d492f 100644 --- a/terraform/aws/aws-ec2-instance/versions.tf +++ b/terraform/aws/aws-ec2-instance/versions.tf @@ -1,8 +1,14 @@ terraform { required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 6.0, < 7.0" + } tailscale = { source = "tailscale/tailscale" version = ">= 0.24" } } + + required_version = ">= 1.0, < 2.0" } diff --git a/terraform/aws/internal-modules/aws-ec2-autoscaling/versions.tf b/terraform/aws/internal-modules/aws-ec2-autoscaling/versions.tf index 951051f..310c3f7 100644 --- a/terraform/aws/internal-modules/aws-ec2-autoscaling/versions.tf +++ b/terraform/aws/internal-modules/aws-ec2-autoscaling/versions.tf @@ -5,4 +5,6 @@ terraform { version = ">= 6.0, < 7.0" } } + + required_version = ">= 1.0, < 2.0" } diff --git a/terraform/aws/internal-modules/aws-ec2-instance/versions.tf b/terraform/aws/internal-modules/aws-ec2-instance/versions.tf index 951051f..310c3f7 100644 --- a/terraform/aws/internal-modules/aws-ec2-instance/versions.tf +++ b/terraform/aws/internal-modules/aws-ec2-instance/versions.tf @@ -5,4 +5,6 @@ terraform { version = ">= 6.0, < 7.0" } } + + required_version = ">= 1.0, < 2.0" } diff --git a/terraform/aws/internal-modules/aws-vpc/versions.tf b/terraform/aws/internal-modules/aws-vpc/versions.tf index 951051f..32ccbe9 100644 --- a/terraform/aws/internal-modules/aws-vpc/versions.tf +++ b/terraform/aws/internal-modules/aws-vpc/versions.tf @@ -4,5 +4,11 @@ terraform { source = "hashicorp/aws" version = ">= 6.0, < 7.0" } + random = { + source = "hashicorp/random" + version = ">= 3.0, < 4.0" + } } + + required_version = ">= 1.0, < 2.0" } diff --git a/terraform/azure/azure-linux-vm/main.tf b/terraform/azure/azure-linux-vm/main.tf index 45138cf..2c39950 100644 --- a/terraform/azure/azure-linux-vm/main.tf +++ b/terraform/azure/azure-linux-vm/main.tf @@ -27,7 +27,6 @@ locals { location = azurerm_resource_group.main.location vpc_cidr_block = module.vpc.vnet_address_space - vpc_id = module.vpc.vnet_id subnet_id = module.vpc.public_subnet_id network_security_group_id = azurerm_network_security_group.tailscale_ingress.id instance_type = "Standard_D2as_v6" diff --git a/terraform/azure/azure-linux-vm/versions.tf b/terraform/azure/azure-linux-vm/versions.tf index 8906343..d5e75c5 100644 --- a/terraform/azure/azure-linux-vm/versions.tf +++ b/terraform/azure/azure-linux-vm/versions.tf @@ -1,8 +1,14 @@ terraform { required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 4.0, < 5.0" + } tailscale = { source = "tailscale/tailscale" version = ">= 0.24" } } + + required_version = ">= 1.0, < 2.0" } diff --git a/terraform/azure/internal-modules/azure-linux-vm/versions.tf b/terraform/azure/internal-modules/azure-linux-vm/versions.tf index 7746b9c..6bfcb98 100644 --- a/terraform/azure/internal-modules/azure-linux-vm/versions.tf +++ b/terraform/azure/internal-modules/azure-linux-vm/versions.tf @@ -5,4 +5,6 @@ terraform { version = ">= 4.0, < 5.0" } } + + required_version = ">= 1.0, < 2.0" } diff --git a/terraform/azure/internal-modules/azure-network/outputs.tf b/terraform/azure/internal-modules/azure-network/outputs.tf index aad274a..36f9ef3 100644 --- a/terraform/azure/internal-modules/azure-network/outputs.tf +++ b/terraform/azure/internal-modules/azure-network/outputs.tf @@ -37,10 +37,10 @@ output "private_dns_resolver_inbound_endpoint_ip" { } output "nat_public_ips" { - value = azurerm_public_ip.nat.*.ip_address + value = azurerm_public_ip.nat[*].ip_address } output "nat_ids" { description = "Useful for using within `depends_on` for other resources" - value = azurerm_nat_gateway.nat.*.id + value = azurerm_nat_gateway.nat[*].id } diff --git a/terraform/azure/internal-modules/azure-network/versions.tf b/terraform/azure/internal-modules/azure-network/versions.tf index 7746b9c..963d0dd 100644 --- a/terraform/azure/internal-modules/azure-network/versions.tf +++ b/terraform/azure/internal-modules/azure-network/versions.tf @@ -4,5 +4,11 @@ terraform { source = "hashicorp/azurerm" version = ">= 4.0, < 5.0" } + random = { + source = "hashicorp/random" + version = ">= 3.0, < 4.0" + } } + + required_version = ">= 1.0, < 2.0" } diff --git a/terraform/google/google-compute-instance/versions.tf b/terraform/google/google-compute-instance/versions.tf index 8906343..97df296 100644 --- a/terraform/google/google-compute-instance/versions.tf +++ b/terraform/google/google-compute-instance/versions.tf @@ -1,8 +1,14 @@ terraform { required_providers { + google = { + source = "hashicorp/google" + version = ">= 7.0, < 8.0" + } tailscale = { source = "tailscale/tailscale" version = ">= 0.24" } } + + required_version = ">= 1.0, < 2.0" } diff --git a/terraform/google/internal-modules/google-compute-instance/main.tf b/terraform/google/internal-modules/google-compute-instance/main.tf index 38baf4d..fb26d9f 100644 --- a/terraform/google/internal-modules/google-compute-instance/main.tf +++ b/terraform/google/internal-modules/google-compute-instance/main.tf @@ -9,10 +9,6 @@ module "tailscale_install_scripts" { additional_after_scripts = var.additional_after_scripts } -data "google_compute_subnetwork" "selected" { - self_link = "https://www.googleapis.com/compute/v1/${var.subnet}" # requires full URL - https://github.com/hashicorp/terraform-provider-google/issues/9919 -} - data "google_compute_image" "ubuntu" { project = "ubuntu-os-cloud" family = "ubuntu-2404-lts-amd64" diff --git a/terraform/google/internal-modules/google-compute-instance/versions.tf b/terraform/google/internal-modules/google-compute-instance/versions.tf index b3679ed..98cc894 100644 --- a/terraform/google/internal-modules/google-compute-instance/versions.tf +++ b/terraform/google/internal-modules/google-compute-instance/versions.tf @@ -5,5 +5,6 @@ terraform { version = ">= 7.0, < 8.0" } } -} + required_version = ">= 1.0, < 2.0" +} diff --git a/terraform/google/internal-modules/google-vpc/versions.tf b/terraform/google/internal-modules/google-vpc/versions.tf index b3679ed..3d6cd98 100644 --- a/terraform/google/internal-modules/google-vpc/versions.tf +++ b/terraform/google/internal-modules/google-vpc/versions.tf @@ -4,6 +4,11 @@ terraform { source = "hashicorp/google" version = ">= 7.0, < 8.0" } + random = { + source = "hashicorp/random" + version = ">= 3.0, < 4.0" + } } -} + required_version = ">= 1.0, < 2.0" +} diff --git a/terraform/internal-modules/tailscale-advertise-routes/versions.tf b/terraform/internal-modules/tailscale-advertise-routes/versions.tf new file mode 100644 index 0000000..f8f3ed3 --- /dev/null +++ b/terraform/internal-modules/tailscale-advertise-routes/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 1.0, < 2.0" +} diff --git a/terraform/internal-modules/tailscale-install-scripts/versions.tf b/terraform/internal-modules/tailscale-install-scripts/versions.tf new file mode 100644 index 0000000..f8f3ed3 --- /dev/null +++ b/terraform/internal-modules/tailscale-install-scripts/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 1.0, < 2.0" +}