Skip to content

Commit

Permalink
feat: run terraform apply for tag named for test or prod
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran committed Aug 25, 2023
1 parent 7e11c3b commit 01a3ea2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
42 changes: 32 additions & 10 deletions experiment/experiment-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,41 @@ stages:
- deployment: Apply
condition: succeeded()
environment: Approval
variables:
- name: INDIVIDUAL_SOURCE
value: $[variables['Build.SourceBranchName']]
- name: IS_TAG
value: $[startsWith(variables['Build.SourceBranch'], 'refs/tags/')]
strategy:
runOnce:
deploy:
steps:
- task: TerraformTaskV3@3
- checkout: self
- bash: |
TAG_TYPE=$(python experiment/tag.py)
echo "##vso[task.setvariable variable=tag_type]$TAG_TYPE"
displayName: Determine tag type (either test or prod)
env:
REASON: $(Build.Reason)
# - task: TerraformTaskV3@3
- task: Bash@3
displayName: Terraform apply
inputs:
provider: azurerm
command: apply
# (ditto the lock comment above)
commandOptions: -input=false -lock-timeout=5m
workingDirectory: "$(System.DefaultWorkingDirectory)/experiment"
# service connection
environmentServiceNameAzureRM: compiler-deployer
# only run on certain branches
condition: in(variables['Build.SourceBranchName'], 'dev')
# provider: azurerm
# command: apply
# # (ditto the lock comment above)
# commandOptions: -input=false -lock-timeout=5m
# workingDirectory: "$(System.DefaultWorkingDirectory)/experiment"
# # service connection
# environmentServiceNameAzureRM: compiler-deployer
targetType: inline
script: echo "terraform apply"
# only run on dev branch OR if it's a tag for test or prod
condition: |
or(
in(variables['Build.SourceBranchName'], 'dev'),
or(
eq(variables['tag_type'], 'test'),
eq(variables['tag_type'], 'prod')
)
)
19 changes: 19 additions & 0 deletions experiment/tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import re

REASON = os.environ["REASON"]
# use variable corresponding to tag triggers
SOURCE = os.environ["INDIVIDUAL_SOURCE"]
IS_TAG = os.environ["IS_TAG"].lower() == "true"

if REASON == "IndividualCI" and IS_TAG:
if re.fullmatch(r"20\d\d.\d\d.\d+-rc\d+", SOURCE):
tag_type = "test"
elif re.fullmatch(r"20\d\d.\d\d.\d+", SOURCE):
tag_type = "prod"
else:
tag_type = None
else:
tag_type = None

print(tag_type)

0 comments on commit 01a3ea2

Please sign in to comment.