Skip to content

refactor(argocd): remove role 'aa' from project configurations in val… #393

refactor(argocd): remove role 'aa' from project configurations in val…

refactor(argocd): remove role 'aa' from project configurations in val… #393

Workflow file for this run

name: Terraform
on:
push:
paths:
- "*.tf"
- ".github/workflows/terraform.yaml"
branches:
- "*"
pull_request:
env:
TF_VAR_ARGOCD_SERVER: "argocd.naturalselectionlabs.com:443"
TF_VAR_ARGOCD_PASSWORD: ${{ secrets.TF_VAR_ARGOCD_PASSWORD }}
TF_VAR_PAT: ${{ secrets.TF_VAR_PAT }}
TF_VAR_GITHUB_APP_ID: ${{ secrets.TF_VAR_GITHUB_APP_ID }}
TF_VAR_GITHUB_APP_PRIVATE_KEY_BASE64: ${{ secrets.TF_VAR_GITHUB_APP_PRIVATE_KEY_BASE64 }}
TF_VAR_OVH_CA_DATA: ${{ secrets.OVH_CA_DATA }}
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
ALIBABA_CLOUD_REGION: us-east-1
jobs:
terraform:
name: "Terraform"
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: aliyun/configure-aliyun-credentials-action@v1
with:
role-to-assume: "acs:ram::5621254376179407:role/terraform"
oidc-provider-arn: "acs:ram::5621254376179407:oidc-provider/github"
role-session-name: "github-action-session"
role-session-expiration: 1800
audience: "sts.aliyuncs.com"
- name: Set OVH Kubeconfig
run: |
mkdir -p ~/.kube
echo "$OVH_KUBECONFIG" | base64 -d > ~/.kube/config.ovh
env:
OVH_KUBECONFIG: ${{ secrets.OVH_KUBECONFIG }}
- uses: hashicorp/setup-terraform@v2
- name: Format
id: fmt
run: terraform fmt -check -recursive
continue-on-error: true
- name: Init
id: init
run: terraform init -backend-config "prefix=terraform/${{ github.repository }}"
- name: Validate
id: validate
run: terraform validate -no-color
- name: Plan
id: plan
run: terraform plan -no-color
- name: PR comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ github.token }}
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style')
})
// 2. Prepare format of the comment
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${{ steps.validate.outputs.stdout }}
\`\`\`
</details>
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
// 3. If we have a comment, update it, otherwise create a new one
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: output
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}
- name: Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -auto-approve -input=false