Skip to content

Provision with Terraform #1

Provision with Terraform

Provision with Terraform #1

name: Provision with Terraform
run-name: Provision with Terraform
on:
workflow_dispatch:
inputs:
hubEnv:
description: Select target hub and stage
required: true
type: choice
options:
- 'BACKEND_EMEA_TEST'
deploymentType:
description: Select deployment type
required: true
type: choice
options:
- 'ecs'
- 'eks'
jobs:
properties:
uses: ./.github/workflows/datacenterMap.yml
with:
hubEnv: ${{ inputs.hubEnv }}
secrets: inherit
terraform:
runs-on: ubuntu-latest
needs: properties
env:
AWS_ACCOUNT: ${{ needs.properties.outputs.AWS_ACCOUNT }}
AWS_PROFILE: ${{ needs.properties.outputs.PROFILE }}
AWS_KEY: ${{ secrets[format('{0}_AWS_KEY', inputs.hubEnv)] }}
AWS_SECRET: ${{ secrets[format('{0}_AWS_SECRET', inputs.hubEnv)] }}
AWS_REGION: ${{ needs.properties.outputs.REGION }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- name: Install Terraform ${{ env.terraform_version }}
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.7.0
terraform_wrapper: false
- name: Configure AWS profile
run: |
mkdir -p ~/.aws
echo "[${{ env.AWS_PROFILE }}]" > ~/.aws/credentials
echo "aws_access_key_id = ${{ env.AWS_KEY }}" >> ~/.aws/credentials
echo "aws_secret_access_key = ${{ env.AWS_SECRET }}" >> ~/.aws/credentials
- name: Run Terraform apply
run: |
cd aws-infrastructure/terraform
chmod +x setup_new_region.sh
chmod +x w2.sh
./setup_new_region.sh w2.sh ${{ inputs.deploymentType }} ${{ env.AWS_PROFILE }} ${{ env.AWS_REGION }} apply -auto-approve
- name: Login to monitoring ECR
if: ${{ inputs.deploymentType == 'ecs' }}
run: |
aws ecr get-login-password --region ${{ env.AWS_REGION }} --profile ${{ env.AWS_PROFILE }} | docker login --username AWS --password-stdin ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com
- name: Deploy monitoring base images
if: ${{ inputs.deploymentType == 'ecs' }}
run: |
cd aws-infrastructure
echo "Deploying Elasticsearch"
cd docker-elasticsearch
docker build -t elasticsearch-custom .
docker tag elasticsearch-custom ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com/monitoring:elasticsearch
docker push ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com/monitoring:elasticsearch
cd ..
echo "Deploying Filebeat"
cd docker-filebeat
docker build -t filebeat-custom .
docker tag filebeat-custom ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com/monitoring:filebeat
docker push ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com/monitoring:filebeat
cd ..
echo "Deploying Grafana"
cd docker-grafana
docker build -t grafana-custom .
docker tag grafana-custom ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com/monitoring:grafana
docker push ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com/monitoring:grafana
cd ..
echo "Deploying Kibana"
cd docker-kibana
docker build -t kibana-custom .
docker tag kibana-custom ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com/monitoring:kibana
docker push ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com/monitoring:kibana
cd ..
echo "Deploying Prometheus"
cd docker-prometheus
docker build -t prometheus-custom .
docker tag prometheus-custom ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com/monitoring:prometheus
docker push ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com/monitoring:prometheus
cd ..