From 52220a303f96b4d7d38f0280bf2270fa6b4eec01 Mon Sep 17 00:00:00 2001 From: Timothy Olaleke Date: Sun, 26 Feb 2023 14:48:03 +0000 Subject: [PATCH 1/2] feat: automate testing of module using GitHub Actions --- .github/workflows/tf_plan.yaml | 39 ++++++++++++++++++++++++++++++++++ .gitignore | 24 +++++++++++++++++++++ dev-resources/backend.tf | 6 ++++++ dev-resources/main.tf | 3 +++ dev-resources/provider.tf | 3 +++ 5 files changed, 75 insertions(+) create mode 100644 .github/workflows/tf_plan.yaml create mode 100644 .gitignore create mode 100644 dev-resources/backend.tf create mode 100644 dev-resources/main.tf create mode 100644 dev-resources/provider.tf diff --git a/.github/workflows/tf_plan.yaml b/.github/workflows/tf_plan.yaml new file mode 100644 index 0000000..c461e96 --- /dev/null +++ b/.github/workflows/tf_plan.yaml @@ -0,0 +1,39 @@ + +name: 'Terraform Plan & Apply' + +on: + push: + branches: [ "test" ] + pull_request: + +jobs: + terraform: + name: 'Terraform' + runs-on: ubuntu-latest + + steps: + # Checkout the repository to the GitHub Actions runner + - name: Checkout + uses: actions/checkout@v3 + + - name: Configure AWS Credentials Action For GitHub Actions + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + - name: Setup Terraform CLI + uses: hashicorp/setup-terraform@v2.0.2 + + + - name: Terraform Init & Apply + run: | + cd dev-resources + echo "** Running Terraform Init**" + terraform init + + echo "** Running Terraform Validate**" + terraform validate + + echo "** Running Terraform Plan**" + terraform plan diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e1caf97 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +.DS_Store + +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log + +# Kitchen files +**/inspec.lock +**/.kitchen +**/.kitchen.local.yml +**/Gemfile.lock + +# Ignore any .tfvars files that are generated automatically for each Terraform +# run. Most .tfvars files are managed as part of configuration and so should be +# included in version control. +# +# example.tfvars +**/terraform.tfvars diff --git a/dev-resources/backend.tf b/dev-resources/backend.tf new file mode 100644 index 0000000..9371943 --- /dev/null +++ b/dev-resources/backend.tf @@ -0,0 +1,6 @@ +terraform { + backend "s3" { + bucket = "iac-devops-playground" + region = "us-east-1" + } +} diff --git a/dev-resources/main.tf b/dev-resources/main.tf new file mode 100644 index 0000000..a8bbffb --- /dev/null +++ b/dev-resources/main.tf @@ -0,0 +1,3 @@ +module "dev_load_balancer" { + source = "./AWS Module/Load Balancer" +} \ No newline at end of file diff --git a/dev-resources/provider.tf b/dev-resources/provider.tf new file mode 100644 index 0000000..e123d7a --- /dev/null +++ b/dev-resources/provider.tf @@ -0,0 +1,3 @@ +provider "aws" { + region = "us-east-1" +} From 68cb8048e704dc9151d2413e86912c966b719edb Mon Sep 17 00:00:00 2001 From: Timothy Olaleke Date: Sun, 26 Feb 2023 16:00:01 +0000 Subject: [PATCH 2/2] chore: terraform dry run --- .github/workflows/tf_plan.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tf_plan.yaml b/.github/workflows/tf_plan.yaml index c461e96..455bed6 100644 --- a/.github/workflows/tf_plan.yaml +++ b/.github/workflows/tf_plan.yaml @@ -26,7 +26,7 @@ jobs: uses: hashicorp/setup-terraform@v2.0.2 - - name: Terraform Init & Apply + - name: Terraform Init & Dry Apply run: | cd dev-resources echo "** Running Terraform Init**" @@ -37,3 +37,6 @@ jobs: echo "** Running Terraform Plan**" terraform plan + + echo "** Running Terraform Dry Apply**" + terraform apply -auto-approve --dry-run