Skip to content

Commit

Permalink
Merge pull request #15 from Optum/fix-ci-namespace
Browse files Browse the repository at this point in the history
WIP: Fix namespace in tagged release
  • Loading branch information
AmudaPalani authored Aug 26, 2019
2 parents 8fadef3 + e5b2e92 commit 0b91ed3
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pr:
- master

steps:

# Setup Python
- task: UsePythonVersion@0
inputs:
Expand All @@ -28,7 +27,7 @@ steps:
- task: CmdLine@2
inputs:
script: 'pip install awscli'
displayName: 'Install awscli'
displayName: 'Install awscli'

# Install Terraform
- task: TerraformInstaller@0
Expand Down Expand Up @@ -57,6 +56,30 @@ steps:
make build
displayName: 'Build'

# Configure the namespace used by Terraform
# May be referenced as an env var (eg. "${NAMESPACE}")
# Or as a pipeline variable (eg. "$(namespace)")
- script: |
PR_NUMBER="$(System.PullRequest.PullRequestNumber)"
# This is the branch name, or the git tag name
NS_BRANCH_OR_TAG="$(Build.SourceBranchName)"
# TODO tag name can't be namespace, AWS doesn't like
# it as a resource name.
# If it's a tagged version, just call it `release` or something
if [[ -z ${PR_NUMBER} ]]; then
NS="release"
else
NS="pr-${PR_NUMBER}"
fi
echo "Namespace is ${NS}"
# Set the namespace as a Azure Pipeline variable
# See https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#set-in-script
echo "##vso[task.setvariable variable=namespace]${NS}"
displayName: "Configure AWS Namespace"

# terraform init
- task: TerraformTaskV1@0
displayName: 'terraform init'
Expand All @@ -66,7 +89,7 @@ steps:
workingDirectory: './modules'
backendServiceAWS: 'AWS_Terraform_Connection'
backendAWSBucketName: '$(BACKEND_AWS_BUCKET_NAME)'
backendAWSKey: 'pr-$(System.PullRequest.PullRequestNumber)/terraform.tfstate'
backendAWSKey: '$(namespace)/terraform.tfstate'

# terraform apply
- task: TerraformTaskV1@0
Expand All @@ -75,7 +98,7 @@ steps:
provider: 'aws'
command: 'apply'
workingDirectory: './modules'
commandOptions: '-var="namespace=pr-$(System.PullRequest.PullRequestNumber)" -var="budget_notification_from_email=$(NOTIFY_EMAIL)"'
commandOptions: '-var="namespace=$(namespace)" -var="budget_notification_from_email=$(NOTIFY_EMAIL)"'
environmentServiceNameAWS: 'AWS_Terraform_Connection'

# Deploy Application Code to AWS
Expand All @@ -84,7 +107,7 @@ steps:
inputs:
awsCredentials: 'AWS_Login'
regionName: 'us-east-1'
arguments: './bin/build_artifacts.zip pr-$(System.PullRequest.PullRequestNumber) $(ARTIFACTS_BUCKET_NAME)-pr-$(System.PullRequest.PullRequestNumber)'
arguments: './bin/build_artifacts.zip $(namespace) $(ARTIFACTS_BUCKET_NAME)-$(namespace)'
scriptType: 'filePath'
filePath: './scripts/deploy.sh'

Expand Down Expand Up @@ -119,7 +142,7 @@ steps:
provider: 'aws'
command: 'destroy'
workingDirectory: './modules'
commandOptions: '-var="namespace=pr-$(System.PullRequest.PullRequestNumber)" -var="budget_notification_from_email=$(NOTIFY_EMAIL)"'
commandOptions: '-var="namespace=$(namespace)" -var="budget_notification_from_email=$(NOTIFY_EMAIL)"'
environmentServiceNameAWS: 'AWS_Terraform_Connection'

# Publish a Github Release for tagged commits
Expand All @@ -133,4 +156,4 @@ steps:
$(Build.SourcesDirectory)/bin/build_artifacts.zip
$(Build.SourcesDirectory)/bin/terraform_artifacts.zip
$(Build.SourcesDirectory)/scripts/deploy.sh
$(Build.SourcesDirectory)/scripts/restore_db.sh
$(Build.SourcesDirectory)/scripts/restore_db.sh

0 comments on commit 0b91ed3

Please sign in to comment.