Skip to content

Commit

Permalink
Merge pull request #569 from microsoft/dayland/add-tf-state-support-f…
Browse files Browse the repository at this point in the history
…or-us-gov-pipelines

Add Azure Government Cloud support and update login credentials
  • Loading branch information
dayland committed Mar 18, 2024
2 parents f02c82f + 6a68a55 commit b405d09
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ take-dir-ownership:
@sudo chown -R vscode .

terraform-remote-backend:
@mv ./infra/backend.tf.ci ./infra/backend.tf
@./scripts/terraform-remote-backend.sh

infrastructure-remote-backend: terraform-remote-backend infrastructure

Expand Down
3 changes: 2 additions & 1 deletion infra/backend.tf.ci
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
terraform {
required_version = ">= 0.13"
required_version = ">= 0.15.3"
backend "azurerm" {
environment = "public"
}
}
6 changes: 6 additions & 0 deletions infra/backend.tf.us.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
terraform {
required_version = ">= 0.15.3"
backend "azurerm" {
environment = "usgovernment"
}
}
2 changes: 1 addition & 1 deletion scripts/check-subscription.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ figlet Check Subscription
if [ -n "${IN_AUTOMATION}" ]
then

if [ -n "${AZURE_ENVIRONMENT}" ] && [ $AZURE_ENVIRONMENT == "AzureUSGovernment" ]; then
if [ -n "${AZURE_ENVIRONMENT}" ] && [[ $AZURE_ENVIRONMENT == "AzureUSGovernment" ]]; then
az cloud set --name AzureUSGovernment
fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy-enrichment-webapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fi
if [ -n "${IN_AUTOMATION}" ]
then

if [ -n "${AZURE_ENVIRONMENT}" ] && $AZURE_ENVIRONMENT == "AzureUSGovernment"; then
if [ -n "${AZURE_ENVIRONMENT}" ] && [[ $AZURE_ENVIRONMENT == "AzureUSGovernment" ]]; then
az cloud set --name AzureUSGovernment
fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cd $BINARIES_OUTPUT_PATH
if [ -n "${IN_AUTOMATION}" ]
then

if [ -n "${AZURE_ENVIRONMENT}" ] && $AZURE_ENVIRONMENT == "AzureUSGovernment"; then
if [ -n "${AZURE_ENVIRONMENT}" ] && [[ $AZURE_ENVIRONMENT == "AzureUSGovernment" ]]; then
az cloud set --name AzureUSGovernment
fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy-search-indexes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ source "${DIR}/environments/infrastructure.env"
if [ -n "${IN_AUTOMATION}" ]
then

if [ -n "${AZURE_ENVIRONMENT}" ] && $AZURE_ENVIRONMENT == "AzureUSGovernment"; then
if [ -n "${AZURE_ENVIRONMENT}" ] && [[ $AZURE_ENVIRONMENT == "AzureUSGovernment" ]]; then
az cloud set --name AzureUSGovernment
fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy-webapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fi
if [ -n "${IN_AUTOMATION}" ]
then

if [ -n "${AZURE_ENVIRONMENT}" ] && $AZURE_ENVIRONMENT == "AzureUSGovernment"; then
if [ -n "${AZURE_ENVIRONMENT}" ] && [[ $AZURE_ENVIRONMENT == "AzureUSGovernment" ]]; then
az cloud set --name AzureUSGovernment
fi

Expand Down
11 changes: 11 additions & 0 deletions scripts/inf-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ if [ -n "${IN_AUTOMATION}" ]; then
export TF_VAR_aadMgmtClientSecret=$aadMgmtAppSecret
fi

if [ -n "${IN_AUTOMATION}" ]
then

if [ -n "${AZURE_ENVIRONMENT}" ] && [[ $AZURE_ENVIRONMENT == "AzureUSGovernment" ]]; then
az cloud set --name AzureUSGovernment
fi

az login --service-principal -u "$ARM_CLIENT_ID" -p "$ARM_CLIENT_SECRET" --tenant "$ARM_TENANT_ID"
az account set -s "$ARM_SUBSCRIPTION_ID"
fi

# Create our application configuration file before starting infrastructure
${DIR}/configuration-create.sh

Expand Down
2 changes: 1 addition & 1 deletion scripts/inf-destroy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if [ -n "${IN_AUTOMATION}" ]
then
echo "Delete the resource group $RG_NAME, but don't wait (fire and forget)"

if [ -n "${AZURE_ENVIRONMENT}" ] && $AZURE_ENVIRONMENT == "AzureUSGovernment"; then
if [ -n "${AZURE_ENVIRONMENT}" ] && [[ $AZURE_ENVIRONMENT == "AzureUSGovernment" ]]; then
az cloud set --name AzureUSGovernment
fi

Expand Down
11 changes: 10 additions & 1 deletion scripts/terraform-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,20 @@ trap finish EXIT

if [ -n "${IN_AUTOMATION}" ]
then
terraform init -backend-config="resource_group_name=$TF_BACKEND_RESOURCE_GROUP" \
if [ -n "${AZURE_ENVIRONMENT}" ] && [[ "$AZURE_ENVIRONMENT" == "AzureUSGovernment" ]]; then
terraform init -backend-config="resource_group_name=$TF_BACKEND_RESOURCE_GROUP" \
-backend-config="storage_account_name=$TF_BACKEND_STORAGE_ACCOUNT" \
-backend-config="container_name=$TF_BACKEND_CONTAINER" \
-backend-config="access_key=$TF_BACKEND_ACCESS_KEY" \
-backend-config="key=$TF_BACKEND_STATE_KEY" \
-backend-config="environment=usgovernment"
else
terraform init -backend-config="resource_group_name=$TF_BACKEND_RESOURCE_GROUP" \
-backend-config="storage_account_name=$TF_BACKEND_STORAGE_ACCOUNT" \
-backend-config="container_name=$TF_BACKEND_CONTAINER" \
-backend-config="access_key=$TF_BACKEND_ACCESS_KEY" \
-backend-config="key=$TF_BACKEND_STATE_KEY"
fi
else
terraform init -upgrade
fi
Expand Down
11 changes: 11 additions & 0 deletions scripts/terraform-remote-backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

#!/bin/bash
set -e

if [ -n "${AZURE_ENVIRONMENT}" ] && [[ "$AZURE_ENVIRONMENT" == "AzureUSGovernment" ]]; then
mv ./infra/backend.tf.us.ci ./infra/backend.tf
else
mv ./infra/backend.tf.ci ./infra/backend.tf
fi

0 comments on commit b405d09

Please sign in to comment.