Skip to content

Infra_features #9

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

Merged
merged 2 commits into from
Dec 11, 2024
Merged
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
62 changes: 62 additions & 0 deletions .github/workflows/terraform-apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Terraform Apply
run-name: ${{ github.actor }} triggered the pipeline

on:
workflow_dispatch:
inputs:
operation:
description: 'Choose the Terraform operation (apply or destroy)'
required: true
default: 'apply'
push:
branches:
- 'infra_main'
# path:
# - '../terraform/**'

env:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TF_VAR_aws_region: ${{ vars.TF_AWS_REGION }}
TF_VAR_ami_id: ${{ vars.TF_AMI_ID }}
TF_VAR_instance_type: ${{ vars.TF_INSTANCE_TYPE }}
TF_VAR_key_pair_name: ${{ vars.TF_KEY_PAIR_NAME }}
TF_VAR_private_key: ${{ secrets.PRIVATE_KEY }}
TF_VAR_domain_name: ${{ vars.TF_DOMAIN_NAME }}
TF_VAR_frontend_domain: ${{ vars.TF_FRONTEND_DOMAIN }}
TF_VAR_db_domain: ${{ vars.TF_DB_DOMAIN }}
TF_VAR_traefik_domain: ${{ vars.TF_TRAEFIK_DOMAIN }}
TF_VAR_cert_email: ${{ secrets.TF_CERT_EMAIL }}
TF_VAR_private_key_path: ./${{ vars.TF_KEY_PAIR_NAME }}.pem

jobs:
build-infra:
name: terraform-ci-cd
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Write Private Key to File
run: |
echo "${{ secrets.PRIVATE_KEY }}" > ${{ vars.TF_KEY_PAIR_NAME }}.pem
chmod 600 ${{ vars.TF_KEY_PAIR_NAME }}.pem

- name: Set up Terraform
uses: hashicorp/setup-terraform@v2

- name: Terraform Init
id: init
run: terraform init
working-directory: ./terraform

- name: Terraform Operation
id: terraform-operation
run: |
if [ "${{ github.event.inputs.operation }}" = "destroy" ]; then
terraform destroy --auto-approve
else
terraform apply --auto-approve
fi
working-directory: ./terraform

3 changes: 1 addition & 2 deletions .github/workflows/terraform-plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ jobs:
const plan = fs.readFileSync('/tmp/tfplan.txt', 'utf8');
const infracost = fs.readFileSync('/tmp/infracost-new.txt', 'utf8');

const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
const output = `#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`

<details><summary>Show Plan</summary>

Expand Down
14 changes: 0 additions & 14 deletions terraform/ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,3 @@ resource "aws_instance" "ec2" {
}
}

resource "aws_instance" "ec2-1" {
ami = var.ami_id
instance_type = var.instance_type
key_name = var.key_pair_name
subnet_id = aws_subnet.public_subnet.id
vpc_security_group_ids = [aws_security_group.sg.id]
tags = {
Name = var.ec2_name
}

provisioner "local-exec" {
command = "echo 'Instance provisioned: ${self.public_ip}'"
}
}
Loading