-
Notifications
You must be signed in to change notification settings - Fork 0
Add Terraform infrastructure setup with S3 state backend #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,111 @@ | ||||||
| name: Terraform CI/CD | ||||||
|
|
||||||
| on: | ||||||
| push: | ||||||
| branches: [ main, develop ] | ||||||
| paths: | ||||||
| - 'environments/**' | ||||||
| - 'modules/**' | ||||||
| - '.github/workflows/terraform.yml' | ||||||
| pull_request: | ||||||
| branches: [ main ] | ||||||
| paths: | ||||||
| - 'environments/**' | ||||||
| - 'modules/**' | ||||||
| - '.github/workflows/terraform.yml' | ||||||
| workflow_dispatch: | ||||||
|
|
||||||
| jobs: | ||||||
| terraform-validate: | ||||||
| name: Validate Terraform | ||||||
| runs-on: ubuntu-latest | ||||||
|
|
||||||
| permissions: | ||||||
| contents: read | ||||||
|
|
||||||
| strategy: | ||||||
| matrix: | ||||||
| environment: [dev, prod] | ||||||
|
||||||
| environment: [dev, prod] | |
| environment: [dev] |
Copilot
AI
Feb 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
terraform fmt -check is configured with continue-on-error: true, which allows unformatted Terraform code to pass CI even though the job is labeled as a format check. If formatting is meant to be enforced, remove continue-on-error so the workflow fails on fmt differences.
| continue-on-error: true |
Copilot
AI
Feb 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plan step runs terraform plan without any AWS credentials setup in the workflow. With the AWS provider configured, plan will typically fail on CI (provider credential validation / refresh). Add an explicit AWS auth step (e.g., OIDC via aws-actions/configure-aws-credentials + permissions: id-token: write, or repository secrets) before running init/plan.
Copilot
AI
Feb 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
terraform init -backend=false is used in the apply job. That explicitly disables the S3 backend in backend.tf, so terraform apply will use local state on the runner (no remote state, no locking) and will drift/break future runs. The apply job should run a normal terraform init configured for the remote backend.
| run: terraform init -backend=false | |
| run: terraform init |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| terraform { | ||
| backend "s3" { | ||
| bucket = "my-terraform-state" | ||
| key = "dev/terraform.tfstate" | ||
| region = "eu-central-1" | ||
| dynamodb_table = "terraform-locks" | ||
| encrypt = true | ||
| } | ||
|
Comment on lines
+2
to
+8
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| terraform { | ||
| required_version = ">= 1.6.0" | ||
|
|
||
| required_providers { | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = "~> 5.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "aws" { | ||
| region = var.aws_region | ||
|
|
||
| default_tags { | ||
| tags = { | ||
| Environment = "dev" | ||
| Project = "SolVoid" | ||
| ManagedBy = "Terraform" | ||
| } | ||
| } | ||
|
Comment on lines
+15
to
+21
|
||
| } | ||
|
|
||
| # Example resource - VPC | ||
| resource "aws_vpc" "main" { | ||
| cidr_block = var.vpc_cidr | ||
| enable_dns_hostnames = true | ||
| enable_dns_support = true | ||
|
|
||
| tags = { | ||
| Name = "${var.project_name}-vpc-dev" | ||
| } | ||
| } | ||
|
Comment on lines
+30
to
+33
|
||
|
|
||
| # Example resource - Subnet | ||
| resource "aws_subnet" "public" { | ||
| vpc_id = aws_vpc.main.id | ||
| cidr_block = var.public_subnet_cidr | ||
| map_public_ip_on_launch = true | ||
|
|
||
| tags = { | ||
| Name = "${var.project_name}-public-subnet-dev" | ||
| } | ||
| } | ||
|
|
||
| # Example resource - Internet Gateway | ||
| resource "aws_internet_gateway" "main" { | ||
| vpc_id = aws_vpc.main.id | ||
|
|
||
| tags = { | ||
| Name = "${var.project_name}-igw-dev" | ||
| } | ||
| } | ||
|
|
||
| # Example resource - Route Table | ||
| resource "aws_route_table" "public" { | ||
| vpc_id = aws_vpc.main.id | ||
|
|
||
| route { | ||
| cidr_block = "0.0.0.0/0" | ||
| gateway_id = aws_internet_gateway.main.id | ||
| } | ||
|
|
||
| tags = { | ||
| Name = "${var.project_name}-public-rt-dev" | ||
| } | ||
| } | ||
|
|
||
| # Example resource - Route Table Association | ||
| resource "aws_route_table_association" "public" { | ||
| subnet_id = aws_subnet.public.id | ||
| route_table_id = aws_route_table.public.id | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||
| variable "aws_region" { | ||||||
| description = "AWS region for infrastructure deployment" | ||||||
| type = string | ||||||
| default = "us-east-1" | ||||||
|
||||||
| default = "us-east-1" | |
| default = "eu-central-1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description mentions
environments/prod/andmodules/, but neither directory is present in the repo (empty directories aren’t tracked by git). If you want these to exist as scaffolding, add a placeholder file like.gitkeep/README, or adjust the workflow/description accordingly.