Skip to content

Instantly share code, notes, and snippets.

@maxstreifeneder
Last active January 19, 2020 16:09
Show Gist options
  • Save maxstreifeneder/7fac1f685805c07fd3fe7d669d7e83d1 to your computer and use it in GitHub Desktop.
Save maxstreifeneder/7fac1f685805c07fd3fe7d669d7e83d1 to your computer and use it in GitHub Desktop.
My quick&dirty setup script for Azure service broker in SAP Cloud Platform Cloud Foundry
#==============================================================================
#==============================================================================
# SETUP AZURE SERVICE BROKER IN SAP CLOUD PLATFORM
#==============================================================================
#==============================================================================
#==============================================================================
# SAP Cloud Platform User Details
#==============================================================================
SCPUser={insert SCP username}
SCPPassword={insert SCP Password}
SCPorg={insert SCP CF organization}
SCPspace={insert SCP CF space}
#==============================================================================
# Azure Service Principal Details
#==============================================================================
spAppID={insert appId of service principal}
spPassword={insert password of service principal}
spTenantID={insert tenantId of service principal}
#==============================================================================
# Azure Resource Group for Redis Cache of service broker
#==============================================================================
AzureResourceGroup={insert target ressource group for redis cache}
#==============================================================================
# Get name for redis cache and servicebrokername in SCP CF
#==============================================================================
read -p "How should your Azure Redis Cache be named? " redisCacheName
read -p "How should your service broker in SAP Cloud Platform Cloud Foundry be named? " serviceBrokerName
az account set --subscription {insert subscription id of Azure}
# Prepare Microsoft.Cache
az provider show -n Microsoft.Cache -o table
az provider register --namespace Microsoft.Cache
az provider show -n Microsoft.Cache -o table
# Create Redis Cache in Azure
az redis create -n $redisCacheName -g $AzureResourceGroup -l WestEurope --sku Standard --vm-size C1
redisStatus="provisioning"
until [ $redisStatus == "Succeeded" ]
do
redisStatus=$(az redis show --name $redisCacheName --resource-group $AzureResourceGroup --query provisioningState --output tsv)
echo "Checking status of Redis Cache $redisCacheName: $redisStatus .."
sleep 20
done
# Prepare directory for Open Service Broker sourcecode
cd ~
rm -r -f osba
mkdir osba
git clone https://github.com/Azure/open-service-broker-azure.git ~/osba
# Get Subscription ID
accountID=$(az account show --query id)
# Get Azure Redis Cache Host & Key
redCacheHost=$(az redis show --name $redisCacheName --resource-group $AzureResourceGroup --query hostName --output tsv)
redCacheKey=$(az redis list-keys -n $redisCacheName -g $AzureResourceGroup --query primaryKey --output tsv)
# Replace placeholders in generic manifest file with actual subscription values
sed -i.bak1 's/<YOUR SUBSCRIPTION ID>/'$accountID'/' ~/osba/contrib/cf/manifest.yml
sed -i.bak2 's/<HOSTNAME FROM AZURE REDIS CACHE>/'$redCacheHost'/' ~/osba/contrib/cf/manifest.yml
sed -i.bak3 's/<PRIMARYKEY FROM AZURE REDIS CACHE>/'$redCacheKey'/' ~/osba/contrib/cf/manifest.yml
sed -i.bak4 's/<YOUR TENANT ID>/'$spTenantID'/' ~/osba/contrib/cf/manifest.yml
sed -i.bak5 's/<APPID FROM SERVICE PRINCIPAL>/'$spAppID'/' ~/osba/contrib/cf/manifest.yml
sed -i.bak6 's/<PASSWORD FROM SERVICE PRINCIPAL>/'$spPassword'/' ~/osba/contrib/cf/manifest.yml
sed -i.bak7 's/v1.8.13\/go-buildpack-v1.8.13.zip/v1.8.35\/go-buildpack-cflinuxfs3-v1.8.35.zip/' ~/osba/contrib/cf/manifest.yml
sed -i.bak8 's/osba/'$serviceBrokerName'/' ~/osba/contrib/cf/manifest.yml
# Login to SAP Cloud Platform Cloud Foundry
cf api https://api.cf.eu10.hana.ondemand.com
cf login -u $SCPUser -p $SCPPassword -o "$SCPorg" -s "$SCPspace"
cf install-plugin multiapps -f
# Deploy service broker application to SAP Cloud Platform Cloud Foundry
cd ~/osba && cf push -f contrib/cf/manifest.yml
# Register the service broker application as a service broker in SAP Cloud Platform Cloud Foundry
appRoute=https://$serviceBrokerName.cfapps.eu10.hana.ondemand.com
cf create-service-broker $serviceBrokerName username password $appRoute --space-scoped
cf service-brokers
# Download CAP Application from public GitHub repository
cd ~/osba
curl https://github.com/SAP-samples/cloud-foundry-cap-azure-cities/releases/download/v1.3.0/city-explorer-demo-app_1.3.0.mtar -L --output ~/osba/teched_cap_application.mtar
# Deploy the CAP Application to SAP Cloud Platform Cloud Foundry
cf deploy ~/osba/teched_cap_application.mtar -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment