Answers: <p>Your question is really vague and depends a lot of information that you didn't supply.</p>
  <p>Some of things you didn't mention were what git branching strategy you are using.</p>
  <p>Typically you are not going to run <code>terraform apply</code> on every single commit. Instead you are going to have people open a PR and on that PR you will run linting and other static code checks like <code>tfsec</code>, <code>terraform validate</code> etc.</p>
  <p>Then once that PR is merged to the <code>master/main</code> branch of your repo, you will run <code>terraform apply</code>.</p>
  <p>This is still a beginners pipeline though because it has lots of problems still, like what happens when you merge to master but your deployment fails.</p>
  <p>You need to talk to your team about how they want to build and test there software so that you can pick a branching strat and then design the pipeline around that.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-04-04T20:14:34.323Z
Answers: Hi Levi, thank you for the response. Since posting this I’ve gotten a lot more clarification, from both my team and Microsoft engineers. But thank you for pointing out that git branching strategy is/was key to understanding their expectations.  Ended up making a Build/release pipeline with a script to iterate through and collect changes from the terraform plan json file and output into a PR that triggers a release pipeline. Still working out some kinks and adding features like basing it off a template and checks to ensure backend is configured correctly. Thanks again
Answers: SaintLaurent
Answers: CC BY-SA 4.0
Answers: 2022-03-30T14:54:09.180Z
Answers: 2022-03-30T14:54:09.180Z
Answers: Levi
Body: <p>Looking to get pointed in the right direction:</p>
  <p>I am trying to build a pipeline that will recognize changes in a remote terraform template that will recognize changes compared to the previous git command before mine and have it only apply those changes by using specified commands:</p>
  <pre><code>terraform get -update
  terraform plan
  </code></pre>
  <p>I also want it to display to the user and have user confirmation to proceed and have 2 min for total user response</p>
  <p>Still green with Jenkins but so far:</p>
  <p>I have the git fetch stage to grab the branch on the remote repository</p>
  <p>A terraform init stage to initialize terraform</p>
  <p><strong>Can anyone point me to the right direction to detect the changes and apply them with the commands?</strong></p>
  
Tags: <jenkins><jenkins-plugins><bitbucket><bitbucket-pipelines><jenkins-blueocean>
Title: Building a pipeline to recognize changes in a terraform template compared to the git commit before and having it apply changes using specified command
UserDisplayName: SaintLaurent
ThreadText: # Building a pipeline to recognize changes in a terraform template compared to the git commit before and having it apply changes using specified command
  
  (Asked by: username_0 on 2021-11-02)
  
  Looking to get pointed in the right direction:
  
  I am trying to build a pipeline that will recognize changes in a remote terraform template that will recognize changes compared to the previous git command before mine and have it only apply those changes by using specified commands:
  
  ```
  terraform get -update
  terraform plan
  
  ```
  
  I also want it to display to the user and have user confirmation to proceed and have 2 min for total user response
  
  Still green with Jenkins but so far:
  
  I have the git fetch stage to grab the branch on the remote repository
  
  A terraform init stage to initialize terraform
  
  **Can anyone point me to the right direction to detect the changes and apply them with the commands?**
  
  **Tags:** jenkins, jenkins-plugins, bitbucket, bitbucket-pipelines, jenkins-blueocean
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-03-30. Score: 0
  
  Your question is really vague and depends a lot of information that you didn't supply.
  
  Some of things you didn't mention were what git branching strategy you are using.
  
  Typically you are not going to run `terraform apply` on every single commit. Instead you are going to have people open a PR and on that PR you will run linting and other static code checks like `tfsec`, `terraform validate` etc.
  
  Then once that PR is merged to the `master/main` branch of your repo, you will run `terraform apply`.
  
  This is still a beginners pipeline though because it has lots of problems still, like what happens when you merge to master but your deployment fails.
  
  You need to talk to your team about how they want to build and test there software so that you can pick a branching strat and then design the pipeline around that.
  
  > **Comments:**
  > **username_0**: Hi username_1, thank you for the response. Since posting this I’ve gotten a lot more clarification, from both my team and Microsoft engineers. But thank you for pointing out that git branching strategy is/was key to understanding their expectations.  Ended up making a Build/release pipeline with a script to iterate through and collect changes from the terraform plan json file and output into a PR that triggers a release pipeline. Still working out some kinks and adding features like basing it off a template and checks to ensure backend is configured correctly. Thanks again  
  
  ---
  
  