diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml new file mode 100644 index 000000000..7ef8e43f4 --- /dev/null +++ b/.github/workflows/terraform.yml @@ -0,0 +1,90 @@ +name: "vprofile IAC" +on: + push: + branches: + - main + - stage + paths: + - terraform/** + pull_request: + branches: + - main + paths: + - terraform/** + +jobs: + terraform: + name: "Apply terraform packages" + runs-on: ubuntu-latest + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + BUCKET_TF_STATE: ${{ secrets.BUCKET_TF_STATE }} + AWS_REGION: "us-east-2" + defaults: + run: + shell: bash + working-directory: ./terraform + steps: + - name: "checkout repository" + uses: actions/checkout@v3 + + - name: "Setup Terraform" + uses: hashicorp/setup-terraform@v2 + with: + terraform_version: 1.6.3 + + + - name: "Terraform Init" + id: init + run: | + terraform init \ + -backend-config="bucket=${BUCKET_TF_STATE}" \ + + - name: "Terraform format check" + id: fmt + run: | + terraform fmt -check + + - name: "Terraform Validate" + id: "Validate" + run: | + terraform validate + + - name: "Terraform Plan" + id: "Plan" + run: | + terraform plan -no-color -input=false -out=tfplan + continue-on-error: true + + - name: Terraform plan status + if: steps.Plan.outcome == 'failure' + run: exit 1 + + - name: "Terraform Apply" + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + id: "Apply" + run: | + terraform apply -input=false -auto-approve tfplan + + - name: "Configure AWS Credentials" + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + + - name: "Get kube config file" + id: getconfig + if: steps.Apply.outcome == 'success' || steps.Plan.outcome == 'success' + run: | + aws eks update-kubeconfig --region ${{ env.AWS_REGION }} --name kitops-eks + + - name: "Install ingress-nginx controller" + if: steps.getconfig.outcome == 'success' + run: | + kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/aws/deploy.yaml + + + diff --git a/terraform/main.tf b/terraform/main.tf index 94b6fc75a..884ef5ac8 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -13,4 +13,3 @@ locals { cluster_name = var.clusterName } -## \ No newline at end of file diff --git a/terraform/vpc.tf b/terraform/vpc.tf index 5775ce1c3..1f3333dc7 100644 --- a/terraform/vpc.tf +++ b/terraform/vpc.tf @@ -23,4 +23,4 @@ module "vpc" { "kubernetes.io/cluster/${local.cluster_name}" = "shared" "kubernetes.io/role/internal-elb" = 1 } -} +}