Skip to content

Commit

Permalink
refactor: move development work into separate pipeline file
Browse files Browse the repository at this point in the history
revert original pipeline back
  • Loading branch information
angela-tran committed Aug 21, 2023
1 parent e919339 commit 9dbdd8c
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 7 deletions.
97 changes: 97 additions & 0 deletions experiment-pipeline.yml
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')
7 changes: 0 additions & 7 deletions terraform/pipeline/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ trigger:
- dev
- test
- prod
tags:
include:
- 20??.??.?
# only run for changes to Terraform files
paths:
include:
Expand All @@ -24,13 +21,9 @@ stages:
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: |
Expand Down

0 comments on commit 9dbdd8c

Please sign in to comment.