diff --git a/.github/workflows/teraform.yml b/.github/workflows/teraform.yml new file mode 100644 index 000000000..449f780f5 --- /dev/null +++ b/.github/workflows/teraform.yml @@ -0,0 +1,61 @@ +name: "Vprofile IAC" +on: + push: + branches: + - main + - stage + paths: + - terraform/** + pull_request: + branches: + -main + paths: + -terraform/** + +env: + #credentials for deployment to AWS + AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}} + # S3 bucket for the TERRAFORM STATE use + BUCKET_TF_STATE: ${{ secrets.BUCKET_TF_STATE}} + AWS_REGION: us-east-1 + EKS_CLUSTER: vprofile-eks + +jobs: + terraform: + name: "Apply terraform code changes" + run-on: "ubuntu-latest" + defaults: + run: + shell: bash + working-directory: ./terraform + + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Setup Terraform with specified version on the runner + 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 + 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 planfile + continue-on-error: true + + - name: Terraform plan status + if: steps.plan.outcome =='failure' + run: exit 1 \ No newline at end of file diff --git a/terraform/eks-cluster.tf b/terraform/eks-cluster.tf index 2c4610920..bc2339b2f 100644 --- a/terraform/eks-cluster.tf +++ b/terraform/eks-cluster.tf @@ -36,3 +36,4 @@ module "eks" { } } } +## \ No newline at end of file diff --git a/terraform/main.tf b/terraform/main.tf index 94b6fc75a..081f66db1 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -13,4 +13,4 @@ locals { cluster_name = var.clusterName } -## \ No newline at end of file +# \ No newline at end of file diff --git a/terraform/terraform.tf b/terraform/terraform.tf index 67b75c673..779c05f65 100644 --- a/terraform/terraform.tf +++ b/terraform/terraform.tf @@ -27,9 +27,9 @@ terraform { } backend "s3" { - bucket = "gitopsterrastate" - key = "terraform.tfstate" - region = "us-east-2" + bucket = "vprofileaction220" + key = "teraform.tfstate" + region = "us-east-1" } required_version = "~> 1.6.3" diff --git a/terraform/variables.tf b/terraform/variables.tf index a41d982a0..7026470ac 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -7,5 +7,6 @@ variable "region" { variable "clusterName" { description = "Name of the EKS cluster" type = string - default = "kitops-eks" + default = "vprofile-eks" } +#