Skip to content

Feature/unit test addedd #74

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/terraform-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
name: Terratest
on: # yamllint disable-line rule:truthy
pull_request:
types: [opened]
workflow_dispatch:
inputs:
pr_number:
description: 'Pull Request Number'
required: true

permissions:
id-token: write
contents: read
statuses: write # Required for setting commit status

jobs:
terratest:
runs-on: ubuntu-latest
name: Terratest Checks

env:
PR_NUMBER: >-
${{ github.event_name == 'workflow_dispatch' &&
github.event.inputs.pr_number || github.event.pull_request.number }}


steps:
- name: Checkout PR code
uses: actions/checkout@v4
with:
ref: refs/pull/${{ env.PR_NUMBER }}/head

- name: Configure AWS credentials via OIDC
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.ARC_IAC_TERRATEST_ROLE }}
aws-region: us-east-1

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'

- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.5.7
terraform_wrapper: false

- name: Create test directory and download go from S3
run: |
mkdir -p terra-test
aws s3 cp ${{ secrets.ARC_TERRATEST_GO_FILE }} terra-test/terra_test.go
- name: Initialize Go module and install dependencies
run: |
cd terra-test
ls
go mod init terraform-test || true
go get github.com/gruntwork-io/terratest/modules/terraform
go get github.com/stretchr/testify/assert
go mod tidy
go test -v -timeout 40m
- name: Report check status manually
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr_number = parseInt(process.env.PR_NUMBER);
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr_number,
});
const sha = pr.data.head.sha;
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: sha,
state: 'success',
context: 'terratest',
description: 'Manual terratest completed successfully',
target_url:
`https://github.com/${context.repo.owner}/${context.repo.repo}` +
`/actions/runs/${process.env.GITHUB_RUN_ID}`,
});
1 change: 1 addition & 0 deletions examples/ecs-ec2/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions examples/ecs-ec2/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ locals {

lb_data = {
listener_port = 80
security_group_id = "sg-023e8f71ae18450ff"
#security_group_id = "sg-023e8f71ae18450ff"
security_group_id = "sg-03fce1229012b0955"
}
}

Expand All @@ -154,7 +155,8 @@ locals {
ecs_service = {
cluster_name = "arc-ecs-module-poc-2"
service_name = "arc-ecs-module-service-poc-2"
repository_name = "12345.dkr.ecr.us-east-1.amazonaws.com/arc/arc-poc-ecs"
#repository_name = "12345.dkr.ecr.us-east-1.amazonaws.com/arc/arc-poc-ecs"
repository_name = "884360309640.dkr.ecr.us-east-1.amazonaws.com/arc/arc-poc-ecs-test"
ecs_subnets = data.aws_subnets.private.ids
enable_load_balancer = true
aws_lb_target_group_name = "arc-poc-alb-tg"
Expand All @@ -174,7 +176,8 @@ locals {

lb_data = {
listener_port = 80
security_group_id = "sg-023e8f71ae18450ff"
#security_group_id = "sg-023e8f71ae18450ff"
security_group_id = "sg-03fce1229012b0955"
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions examples/ecs-ec2/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
region = "us-east-1"
environment = "develop"
namespace = "arc"
vpc_name = "arc-poc"
subnet_names = ["arc-poc-db-az1", "arc-poc-db-az2"]
vpc_name = "arc-poc-vpc"
#subnet_names = ["arc-poc-db-az1", "arc-poc-db-az2"]
subnet_names = ["arc-poc-private-subnet-private-us-east-1a","arc-poc-private-subnet-private-us-east-1b"]
1 change: 1 addition & 0 deletions examples/ecs-fargate/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions examples/ecs-fargate/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ locals {

lb_data = {
listener_port = 80
security_group_id = "sg-023e8f71ae18450ff"
#security_group_id = "sg-023e8f71ae18450ff"
security_group_id = "sg-03fce1229012b0955"
}
}

Expand Down Expand Up @@ -92,7 +93,8 @@ locals {

lb_data = {
listener_port = 80
security_group_id = "sg-023e8f71ae18450ff"
#security_group_id = "sg-023e8f71ae18450ff"
security_group_id = "sg-03fce1229012b0955"
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions examples/ecs-fargate/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
region = "us-east-1"
environment = "develop"
namespace = "arc"
vpc_name = "arc-poc"
subnet_names = ["arc-poc-db-az1", "arc-poc-db-az2"]
vpc_name = "arc-poc-vpc"
#subnet_names = ["arc-poc-db-az1", "arc-poc-db-az2"]
subnet_names = ["arc-poc-private-subnet-private-us-east-1a","arc-poc-private-subnet-private-us-east-1b"]
Loading