-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move development work into separate pipeline file
revert original pipeline back
- Loading branch information
1 parent
e919339
commit 9dbdd8c
Showing
2 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
trigger: | ||
# automatically runs on pull requests | ||
# https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/github?view=azure-devops&tabs=yaml#pr-triggers | ||
branches: | ||
include: | ||
- dev | ||
- test | ||
- prod | ||
tags: | ||
include: | ||
- 20??.??.? | ||
# only run for changes to Terraform files | ||
paths: | ||
include: | ||
- experiment-pipeline.yml | ||
stages: | ||
- stage: terraform | ||
pool: | ||
vmImage: ubuntu-latest | ||
jobs: | ||
- job: terraform | ||
variables: | ||
- name: OTHER_SOURCE | ||
value: $[variables['System.PullRequest.SourceBranch']] | ||
- name: INDIVIDUAL_SOURCE | ||
value: $[variables['Build.SourceBranchName']] | ||
- name: IS_TAG | ||
value: $[startsWith(variables['Build.SourceBranch'], 'refs/tags/')] | ||
- name: TARGET | ||
value: $[variables['System.PullRequest.TargetBranch']] | ||
steps: | ||
- bash: | | ||
echo $(IS_TAG) | ||
# set the workspace variable at runtime (rather than build time) so that all the necessary variables are available, and we can use Python | ||
# https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&tabs=bash#about-tasksetvariable | ||
- bash: | | ||
WORKSPACE=$(python terraform/pipeline/workspace.py) | ||
echo "##vso[task.setvariable variable=workspace]$WORKSPACE" | ||
displayName: Determine deployment environment | ||
env: | ||
REASON: $(Build.Reason) | ||
# https://github.com/microsoft/azure-pipelines-terraform/tree/main/Tasks/TerraformInstaller#readme | ||
- task: TerraformInstaller@0 | ||
displayName: Install Terraform | ||
inputs: | ||
terraformVersion: 1.3.1 | ||
# https://github.com/microsoft/azure-pipelines-terraform/tree/main/Tasks/TerraformTask/TerraformTaskV3#readme | ||
- task: TerraformTaskV3@3 | ||
displayName: Terraform init | ||
inputs: | ||
provider: azurerm | ||
command: init | ||
workingDirectory: "$(System.DefaultWorkingDirectory)/terraform" | ||
# https://developer.hashicorp.com/terraform/tutorials/automation/automate-terraform#automated-terraform-cli-workflow | ||
commandOptions: -input=false | ||
# service connection | ||
backendServiceArm: deployer | ||
# needs to match main.tf | ||
backendAzureRmResourceGroupName: courtesy-cards-eligibility-terraform | ||
backendAzureRmStorageAccountName: courtesycardsterraform | ||
backendAzureRmContainerName: tfstate | ||
backendAzureRmKey: terraform.tfstate | ||
- task: TerraformTaskV3@3 | ||
displayName: Select environment | ||
inputs: | ||
provider: azurerm | ||
command: custom | ||
customCommand: workspace | ||
commandOptions: select $(workspace) | ||
workingDirectory: "$(System.DefaultWorkingDirectory)/terraform" | ||
# service connection | ||
environmentServiceNameAzureRM: deployer | ||
- task: TerraformTaskV3@3 | ||
displayName: Terraform plan | ||
inputs: | ||
provider: azurerm | ||
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 | ||
workingDirectory: "$(System.DefaultWorkingDirectory)/terraform" | ||
# service connection | ||
environmentServiceNameAzureRM: deployer | ||
# the plan is done as part of the apply (below), so don't bother doing it twice | ||
condition: notIn(variables['Build.SourceBranchName'], 'dev', 'test', 'prod') | ||
- task: TerraformTaskV3@3 | ||
displayName: Terraform apply | ||
inputs: | ||
provider: azurerm | ||
command: apply | ||
# (ditto the lock comment above) | ||
commandOptions: -input=false -lock-timeout=5m | ||
workingDirectory: "$(System.DefaultWorkingDirectory)/terraform" | ||
# service connection | ||
environmentServiceNameAzureRM: deployer | ||
# only run on certain branches | ||
condition: in(variables['Build.SourceBranchName'], 'dev', 'test', 'prod') |
This file contains 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