Last active
January 23, 2024 14:11
-
-
Save GTRekter/51f8be3fbfb13b3696f92e117d956597 to your computer and use it in GitHub Desktop.
This snippet contains the steps to generate a terraform plan and post it as a comment of a pull request in Azure DevOps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- script: | | |
terraform plan -out tf.tfplan | |
displayName: Generate Terraform plan | |
- script: | | |
terraform show -no-color tf.tfplan > $(Agent.TempDirectory)/tf.txt | |
displayName: Convert Terraform plan to text | |
- bash: | | |
cd $(Agent.TempDirectory) | |
ENCODED_URL=$(echo "$(System.CollectionUri)$(System.TeamProject)/_apis/git/repositories/${{ variables.SourceRepositoryName }}/pullRequests/$(System.PullRequest.PullRequestId)/threads?api-version=7.0" | sed 's/ /%20/g') | |
jq --rawfile comment tf.txt '.comments[0].content=$comment' <<< '{"comments": [{"parentCommentId": 0,"content": "","commentType": 1}],"status": 1}' | | |
curl --request POST "$ENCODED_URL" \ | |
--header "Content-Type: application/json" \ | |
--header "Accept: application/json" \ | |
--header "Authorization: Bearer $SYSTEM_ACCESSTOKEN" \ | |
--data @- \ | |
--verbose | |
env: | |
SYSTEM_ACCESSTOKEN: $(System.AccessToken) | |
displayName: 'Post comment with Terraform Plan' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment