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 525722c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
33 changes: 23 additions & 10 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 @@ -92,15 +95,25 @@ stages:
runOnce:
deploy:
steps:
- task: TerraformTaskV3@3
# - 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($(tag_type), 'test'),
eq($(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 525722c

Please sign in to comment.