|
| 1 | +name: $(MODULE_NAME)-$(date:yyyyMMdd)-$(rev:.r) |
| 2 | +trigger: none |
| 3 | +pr: |
| 4 | + branches: |
| 5 | + include: |
| 6 | + - refs/heads/master |
| 7 | + - refs/heads/main |
| 8 | +resources: |
| 9 | + repositories: |
| 10 | + - repository: self |
| 11 | +variables: |
| 12 | + - name: TERRAFORM_SEC_VERSION |
| 13 | + value: "v1.26.0" |
| 14 | + - name: GITHUB_REPO |
| 15 | + value: "Think-Cube/terraform-azure-cosmosdb-database-container" |
| 16 | + - group: GITHUB-PAT-TOKEN |
| 17 | + - name: VM_IMAGE |
| 18 | + value: ubuntu-latest |
| 19 | + - name: MODULE_NAME |
| 20 | + value: "terraform-azure-cosmosdb-database-container" |
| 21 | +pool: |
| 22 | + vmImage: $(VM_IMAGE) |
| 23 | +stages: |
| 24 | + - stage: Validate_Terraform_Module |
| 25 | + displayName: 'Validate Terraform Module' |
| 26 | + jobs: |
| 27 | + - job: Validate_Terraform_Module |
| 28 | + displayName: 'Validate Terraform Module' |
| 29 | + steps: |
| 30 | + - checkout: self |
| 31 | + displayName: 'Checkout Module' |
| 32 | + fetchDepth: 1 |
| 33 | + - task: TerraformCLI@0 |
| 34 | + displayName: 'Terraform Init' |
| 35 | + inputs: |
| 36 | + command: 'init' |
| 37 | + allowTelemetryCollection: false |
| 38 | + - task: TerraformCLI@0 |
| 39 | + displayName: 'Terraform Validate' |
| 40 | + inputs: |
| 41 | + command: 'validate' |
| 42 | + allowTelemetryCollection: false |
| 43 | + - task: tfsec@1 |
| 44 | + displayName: 'Terraform SEC check' |
| 45 | + inputs: |
| 46 | + version: '$(TERRAFORM_SEC_VERSION)' |
| 47 | + dir: '$(System.DefaultWorkingDirectory)' |
| 48 | + - script: | |
| 49 | + cd /tmp |
| 50 | + curl -sSLo /tmp/terraform-docs.tar.gz https://terraform-docs.io/dl/v0.19.0/terraform-docs-v0.19.0-$(uname)-amd64.tar.gz |
| 51 | + tar -xzf /tmp/terraform-docs.tar.gz |
| 52 | + chmod +x /tmp/terraform-docs |
| 53 | + displayName: 'Download terraform-docs' |
| 54 | + - script: | |
| 55 | + # Variables |
| 56 | + github_token="$(GITHUB_TOKEN)" |
| 57 | + # Generate or update README.md |
| 58 | + /tmp/terraform-docs markdown table . > README.md |
| 59 | +
|
| 60 | + # Check if README.md has been updated or created and add to PR |
| 61 | + if [ -f README.md ]; then |
| 62 | + echo "README.md file generated/updated." |
| 63 | + git config --global user.email "devops-bot@example.com" |
| 64 | + git config --global user.name "DevOps Bot" |
| 65 | + git add README.md |
| 66 | + git commit -m "Update README.md with module documentation" |
| 67 | + |
| 68 | + # Set remote URL with authentication token |
| 69 | + git remote set-url origin https://$(GITHUB_TOKEN)@github.com/Think-Cube/terraform-azure-cosmosdb-database-container.git |
| 70 | +
|
| 71 | + # Pull the latest changes to avoid conflicts (source branch of the PR) |
| 72 | + git pull origin $(System.PullRequest.SourceBranch) --rebase |
| 73 | +
|
| 74 | + # Push changes |
| 75 | + git push origin HEAD:$(System.PullRequest.SourceBranch) |
| 76 | + else |
| 77 | + echo "Failed to generate README.md" |
| 78 | + exit 1 |
| 79 | + fi |
| 80 | + displayName: 'Generate and Update README.md Documentation' |
0 commit comments