Skip to content

Commit

Permalink
feat: save plan file and use it when running apply command
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran committed Aug 25, 2023
1 parent 63a6eb1 commit 840cea5
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions experiment/experiment-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ stages:
- bash: |
WORKSPACE=$(python experiment/experiment-workspace.py)
echo "##vso[task.setvariable variable=workspace]$WORKSPACE"
TAG_TYPE=$(python experiment/tag.py)
echo "##vso[task.setvariable variable=tag_type]$TAG_TYPE"
displayName: Determine deployment environment
env:
REASON: $(Build.Reason)
Expand Down Expand Up @@ -76,12 +79,36 @@ stages:
command: plan
# wait for lock to be released, in case being used by another pipeline run
# https://discuss.hashicorp.com/t/terraform-plan-wait-for-lock-to-be-released/6870/2
commandOptions: -input=false -lock-timeout=5m
commandOptions: -input=false -lock-timeout=5m -out=tfplan
workingDirectory: "$(System.DefaultWorkingDirectory)/experiment"
# service connection
environmentServiceNameAzureRM: compiler-deployer
# the plan is done as part of the apply (below), so don't bother doing it twice
condition: notIn(variables['Build.SourceBranchName'], 'dev')
# need to copy and publish the tfplan to used by next stage if it's going to run
- task: CopyFiles@2
displayName: 'Copy tfplan for use in TerraformApply'
inputs:
targetFolder: '$(Build.ArtifactStagingDirectory)'
condition: |
or(
in(variables['Build.SourceBranchName'], 'dev'),
or(
eq(variables['tag_type'], 'test'),
eq(variables['tag_type'], 'prod')
)
)
- publish: '$(Build.ArtifactStagingDirectory)'
displayName: 'Publish tfplan for use in TerraformApply'
artifact: tfplan
condition: |
or(
in(variables['Build.SourceBranchName'], 'dev'),
or(
eq(variables['tag_type'], 'test'),
eq(variables['tag_type'], 'prod')
)
)
- stage: TerraformApply
dependsOn: TerraformPlan
jobs:
Expand All @@ -102,6 +129,8 @@ stages:
deploy:
steps:
- checkout: self
- download: current
artifact: tfplan
- bash: |
WORKSPACE=$(python experiment/experiment-workspace.py)
echo "##vso[task.setvariable variable=workspace]$WORKSPACE"
Expand Down Expand Up @@ -143,7 +172,7 @@ stages:
provider: azurerm
command: apply
# (ditto the lock comment above)
commandOptions: -input=false -lock-timeout=5m
commandOptions: -input=false -lock-timeout=5m $(Pipeline.Workspace)/tfplan
workingDirectory: "$(System.DefaultWorkingDirectory)/experiment"
# service connection
environmentServiceNameAzureRM: compiler-deployer
Expand Down

0 comments on commit 840cea5

Please sign in to comment.