Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#30 Adding App Terraform Deployment #39

Merged
merged 23 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
60171cc
Initialize branch and Add Keyvault to Gobal Resources
manojvazirani Mar 18, 2019
93454af
adding azure-pipelines yaml
code4clouds Mar 18, 2019
2b2a11b
Add Container Registry to Gobal Resources using Terraform
manojvazirani Mar 18, 2019
0e1558d
Add provider for Azure in Terraform
manojvazirani Mar 18, 2019
0114198
Added .terraform and .vscode file to the .ignore
code4clouds Mar 18, 2019
24908af
Adding additional Terraforms file to the .gitignore
code4clouds Mar 18, 2019
bf7f0c6
Update description for ACR variabes
manojvazirani Mar 18, 2019
b0af8fd
Merge branch 'tfglobal' of github.com:Microsoft/entref-appservice-con…
manojvazirani Mar 18, 2019
d7c44c3
Add keyvault policy and user permissions to access keyvault
manojvazirani Mar 19, 2019
f311175
Update folder name and test usage with environment variables
manojvazirani Mar 19, 2019
f8073ab
WIP: Terraform and shell draft code.
code4clouds Mar 20, 2019
43055b1
Update deploy script with presumption of existing service principal
manojvazirani Mar 21, 2019
8f33d5a
Adding cluster md
code4clouds Mar 22, 2019
47fbc1a
#30 Adding TF for local app developer
code4clouds Mar 22, 2019
41333f6
#30 Adding AutoApprove
code4clouds Mar 22, 2019
a79abab
added link to the readme inside /app
code4clouds Mar 22, 2019
56f8fe5
PR updates
code4clouds Mar 25, 2019
f933fb7
added new naming conventions
code4clouds Mar 25, 2019
830561c
Adding permissions to deploy.sh
code4clouds Mar 25, 2019
ee151da
Removed the ./README.md
code4clouds Mar 25, 2019
9c9c7d8
Update to Readme.md
code4clouds Mar 25, 2019
39918c4
removed deploy.sh on ./shared
code4clouds Mar 25, 2019
22adc02
Added .env loading command and tf vars sample
code4clouds Mar 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update deploy script with presumption of existing service principal
  • Loading branch information
manojvazirani committed Mar 21, 2019
commit 43055b126bcf7590b9bd146d104acfcaa28a2b2d
1 change: 0 additions & 1 deletion cluster/azure/keyvault/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ variable "resource_group_name" {
variable "location" {
description = "The location/region where the core network will be created. The full list of Azure regions can be found at https://azure.microsoft.com/regions"
type = "string"
default = "eastus"
}
83 changes: 23 additions & 60 deletions cluster/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,102 +6,65 @@ IFS=$'\n\t'
# -o: prevents errors in a pipeline from being masked
# IFS new value is less likely to cause confusing bugs when looping arrays or arguments (e.g. $@)

usage() { echo "Usage: $0 -i <subscriptionId> -n <deploymentName> -l <resourceGroupLocation>" 1>&2; exit 1; }
usage() { echo "Usage: $0 -i <APP_ID> -n <APP_SECRET> -l <TENANT_ID>" 1>&2; exit 1; }

declare SUBSCRIPTION_ID=${SUBSCRIPTION_ID:=""}
declare DEPLOYMENT_NAME=${DEPLOYMENT_NAME:=""}
declare RESOURCE_GROUP_LOCATON=${RESOURCE_GROUP_LOCATON:=""}
declare DEPLOYMENT_NAME=${DEPLOYMENT_NAME:=""}
declare DEBUG=false
declare APP_ID=${APP_ID:=""}
declare APP_SECRET=${APP_SECRET:=""}
declare TENANT_ID=${TENANT_ID:=""}

# Initialize parameters specified from command line
while getopts ":i:n:l:" arg; do
case "${arg}" in
i)
SUBSCRIPTION_ID=${OPTARG}
APP_ID=${OPTARG}
;;
n)
DEPLOYMENT_NAME=${OPTARG}
APP_SECRET=${OPTARG}
;;
l)
RESOURCE_GROUP_LOCATON=${OPTARG}
TENANT_ID=${OPTARG}
;;
esac
done
shift $((OPTIND-1))

#Prompt for parameters is some required parameters are missing
if [[ -z "$SUBSCRIPTION_ID" ]]; then
echo "Your subscription ID can be looked up with the CLI using: az account show --out json "
echo "Enter your subscription ID:"
read SUBSCRIPTION_ID
[[ "${SUBSCRIPTION_ID:?}" ]]
if [[ -z "$APP_ID" ]]; then
echo "Enter your Application ID:"
read APP_ID
[[ "${APP_ID:?}" ]]
fi

if [[ -z "$RESOURCE_GROUP_LOCATON" ]]; then
echo "If creating a *new* resource group, you need to set a location "
echo "You can lookup locations with the CLI using: az account list-locations "

echo "Enter resource group location:"
read RESOURCE_GROUP_LOCATON
if [[ -z "$APP_SECRET" ]]; then
echo "Enter Application secret:"
read APP_SECRET
fi

if [[ -z "$DEPLOYMENT_NAME" ]]; then
echo "Please enter a Deployment Name for your Application"
read DEPLOYMENT_NAME
[[ "${DEPLOYMENT_NAME:?}" ]]
if [[ -z "$TENANT_ID" ]]; then
echo "Please enter your Tenant ID"
read TENANT_ID
[[ "${TENANT_ID:?}" ]]
fi

if [[ -z "$SUBSCRIPTION_ID" ]]; then
echo "Either one of subscriptionId or deploymentName is empty"
if [[ (-z "$APP_ID") && (-z "$APP_SECRET") && (-z "$TENANT_ID") ]]; then
echo "Either one of Application ID or Application secret or Tenant ID is empty"
usage
fi

#login to azure using your credentials
#Login to azure using your credentials
echo "Login to Azure..."
(
set +x
az login
accountsetout=`az account set --subscription $SUBSCRIPTION_ID`
echo $accountsetout
output=`az login --service-principal -u $APP_ID -p $APP_SECRET --tenant $TENANT_ID`
# SP_JSON=`az ad sp create-for-rbac --role="Contributor"`
# echo $SP_JSON
# export SP_NAME=`echo $SP_JSON | jq -r '.name'`
# export SP_PASS=`echo $SP_JSON | jq -r '.password'`
# export SP_TENANT=`echo $SP_JSON | jq -r '.tenant'`
# output=`az login --service-principal -u $SP_NAME -p $SP_PASS --tenant $SP_TENANT`
# echo $output
)

#set the default subscription id

az login --service-principal -u $APP_ID -p $APP_SECRET --tenant $TENANT_ID
set +e

#Check for existing RG
# TODO:DELETE az group show --name $resourceGroupName 1> /dev/null

# if [ $? != 0 ]; then
# echo "Resource group with name" $resourceGroupName "could not be found. Creating new resource group.."
# set -e
# (
# set -x
# az group create --name $resourceGroupName --location $resourceGroupLocation 1> /dev/null
# )
# else
# echo "Using existing resource group..."
# fi

#Start deployment
echo "Starting deployment..."
(
[ "$DEBUG" == 'true' ] && set -x
terraform init
terraform apply
# TODO : az group deployment create --name "$DEPLOYMENT_NAME" --resource-group "$resourceGroupName" --template-file "$templateFilePath" #--parameters "@${parametersFilePath}"
)

if [ $? == 0 ];
then
echo "Template has been successfully deployed"
echo "Terraform Template has been successfully deployed"
fi