Skip to content

Commit de39523

Browse files
init repo
added bicep cli into setup machine script added support for subscription Id, fixed bugs fixed test vm added support for signing marketplace agreement, refactoring refactoring improved UX, README, added E2E script improved README and UX added RDP for MacOS improved docs added bicepparam example for VM, changed path for extension scripts
1 parent 20fbd5f commit de39523

20 files changed

+1204
-160
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
03-test-vm.bicepparam
2-
01-prereq.bicepparam
3-
02-cbs.bicepparam
1+
tmp*.json
2+
*.bicepparam
3+
e2e-demo-params.sh

00-setup-machine.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,29 @@ echo "Installing tools"
88
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
99

1010

11-
#4.5. Install the Azure CLI packages, jq, .NET, zip
11+
#4.5. Install the Azure CLI packages, bicep, jq, .NET, zip
1212
if [[ "$OSTYPE" =~ ^linux ]]; then
1313
sudo apt -qy install jq
14+
15+
curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64
16+
# Mark it as executable
17+
chmod +x ./bicep
18+
# Add bicep to your PATH (requires admin)
19+
sudo mv ./bicep /usr/local/bin/bicep
1420
fi
1521

1622
if [[ "$OSTYPE" =~ ^darwin ]]; then
23+
# Add the tap for bicep
24+
brew tap azure/bicep
25+
1726
brew help
1827
if [[ $? != 0 ]] ; then
1928
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2029
else
2130
brew update
2231
fi
2332
brew install jq
33+
brew install bicep
2434
fi
2535

2636
# check installed tooling
@@ -40,7 +50,6 @@ if [ $? == 0 ]; then
4050
else
4151
echo "Installing bicep"
4252
az bicep install
43-
exit 1;
4453
fi
4554

4655
jq --version
@@ -51,12 +60,20 @@ else
5160
exit 1;
5261
fi
5362

63+
bicep --version
64+
if [ $? == 0 ]; then
65+
echosuccess "[.] bicep-cli tool...OK";
66+
else
67+
echoerr "Error with 'bicep-cli' tool!";
68+
exit 1;
69+
fi
70+
5471
echo "Asking user to log in...";
5572
# ask user for login
5673
az login
5774
if [ $? == 0 ]; then
5875
echosuccess "
59-
Your machine should be ready! Now proceed with ./deploy.sh script
76+
Your machine should be ready! Now proceed with './01-deploy-prerequisities.sh' script
6077
6178
";
6279
else

01-deploy-prerequisities.sh

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
11
#!/bin/bash
22

3-
SHOW_DEBUG_OUTPUT=false
4-
5-
escape_quotes(){
6-
echo $@ | sed s/'"'/'\\"'/g
7-
}
8-
9-
10-
echoerr() { printf "\033[0;31m%s\n\033[0m" "$*" >&2; }
11-
echosuccess() { printf "\033[0;32m%s\n\033[0m" "$*" >&2; }
12-
3+
source $(dirname $0)/script-modules/common.sh
134

145
# Read the bicep parameters
156
parametersfilename='01-prereq.bicepparam'
167

17-
echo " "
18-
echo " "
19-
echo " CBS DEPLOYMENT - PREREQUISITES "
20-
echo " "
21-
echo " "
22-
echo " "
23-
8+
source $(dirname $0)/script-modules/ascii-logo.sh
249

25-
echo "Deploying required infrastructure"
10+
echo -e "
11+
------------------------------------------------------------
12+
Pure Cloud Block Store - Prerequisites Deployment
13+
(c) 2023 Pure Storage
14+
v$CLI_VERSION
15+
------------------------------------------------------------
16+
"
2617

2718
paramsJson=`bicep build-params $parametersfilename --stdout | jq -r ".parametersJson"`
2819

2920

3021
location=`echo $paramsJson | jq -r ".parameters.location.value"`
22+
subscriptionId=`echo $paramsJson | jq -r ".parameters.subscriptionId.value"`
23+
resourceGroupName=`echo $paramsJson | jq -r ".parameters.resourceGroupName.value"`
24+
25+
echo -e "${C_BLUE3}${C_GREY85}
26+
[Step #1] Deploying required infrastructure in subscription $subscriptionId:${NO_FORMAT}
27+
28+
"
29+
echo "
30+
Subscription Id: $subscriptionId
31+
RG name: $resourceGroupName
32+
Location: $location
33+
34+
"
35+
3136

3237
# Deploy our infrastructure
3338
output=$(az deployment sub create \
3439
--name "CBS-deploy-prereq-bicep-sh" \
3540
--location $location \
41+
--subscription $subscriptionId \
3642
--template-file "templates/prerequisites.bicep" \
3743
--parameters $parametersfilename
3844
)
@@ -64,5 +70,5 @@ echo " ----------------------------------------------"
6470
echo ""
6571
echo ""
6672
echo ""
67-
echosuccess "The deployment of prerequisities has been completed. Now you can proceed to deployment of CBS itself with *02-deploy-cbs.sh*."
73+
echosuccess "[COMPLETED] The deployment of prerequisities has been completed. Now you can proceed to deployment of CBS with **02-deploy-cbs.sh** script file."
6874
echo ""

01-prereq.bicepparam.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using 'templates/prerequisites.bicep'
22

33
param location = 'westeurope'
4+
param subscriptionId = 'xxxxxxxx-xxxx-xxxx-xxx-xxxxxxxxxxxx'
45
param resourceGroupName = 'your-resource-group-name'
6+

02-cbs.bicepparam.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using 'templates/cbs-managed-app.bicep'
22

33
param location = 'westeurope'
4-
param resourceName = 'my-resource-name'
4+
param subscriptionId = 'xxxxxxxx-xxxx-xxxx-xxx-xxxxxxxxxxxx'
55
param resourceGroupName = 'your-resource-group-name'
6+
7+
param resourceName = 'my-resource-name'
68
param alertRecipients = 'my-email-address@contoso.dev'
79
param arrayName = 'my-array-name'
810
param licenseKey = 'CBS-TRIAL-LICENSE'

02-deploy-cbs.sh

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,86 @@
11
#!/bin/bash
2+
set -e
23
SHOW_DEBUG_OUTPUT=false
34

4-
escape_quotes(){
5-
echo $@ | sed s/'"'/'\\"'/g
6-
}
7-
8-
9-
curlwithcode() {
10-
code=0
11-
# Run curl in a separate command, capturing output of -w "%{http_code}" into statuscode
12-
# and sending the content to a file with -o >(cat >/tmp/curl_body)
13-
statuscode=$(curl -w "%{http_code}" \
14-
-o >(cat >/tmp/curl_body) \
15-
"$@"
16-
) || code="$?"
17-
18-
body="$(cat /tmp/curl_body)"
19-
echo "{\"statusCode\": $statuscode,"
20-
echo "\"exitCode\": $code,"
21-
echo "\"body\": \"$(escape_quotes $body)\"}"
22-
}
23-
24-
echoerr() { printf "\033[0;31m%s\n\033[0m" "$*" >&2; }
25-
echosuccess() { printf "\033[0;32m%s\n\033[0m" "$*" >&2; }
5+
source $(dirname $0)/script-modules/common.sh
266

277

288
# Read the bicep parameters
299
parametersfilename='./02-cbs.bicepparam'
3010

31-
echo " "
32-
echo " "
33-
echo " CBS DEPLOYMENT "
34-
echo " "
35-
echo " "
36-
echo " "
37-
38-
3911

40-
echo "Deploying CBS managed app"
12+
source $(dirname $0)/script-modules/ascii-logo.sh
4113

42-
paramsJson=`bicep build-params $parametersfilename --stdout | jq -r ".parametersJson"`
14+
echo -e "
15+
------------------------------------------------------------
16+
Pure Cloud Block Store - CBS Deployment
17+
(c) 2023 Pure Storage
18+
v$CLI_VERSION
19+
------------------------------------------------------------
20+
"
4321

22+
bicep_raw=`bicep build-params $parametersfilename --stdout`
23+
paramsJson=`echo $bicep_raw | jq -r ".parametersJson"`
4424

4525
location=`echo $paramsJson | jq -r ".parameters.location.value"`
26+
subscriptionId=`echo $paramsJson | jq -r ".parameters.subscriptionId.value"`
4627
resourceGroupName=`echo $paramsJson | jq -r ".parameters.resourceGroupName.value"`
4728

29+
echo -e "${C_BLUE3}${C_GREY85}
30+
[Step #1] Enabling CBS deployment for selected subscription $subscriptionId:${NO_FORMAT}
31+
32+
"
33+
34+
35+
36+
AZURE_MARKETPLACE_PLAN_NAME=`echo $paramsJson | jq -r .parameters.azureMarketPlacePlanName.value`
37+
if [ "$AZURE_MARKETPLACE_PLAN_NAME" = "null" ];
38+
then
39+
AZURE_MARKETPLACE_PLAN_NAME=`echo $bicep_raw | jq -r .templateJson | jq -r .parameters.azureMarketPlacePlanName.defaultValue`
40+
fi
41+
42+
AZURE_MARKETPLACE_PUBLISHER=`echo $paramsJson | jq -r .parameters.azureMarketPlacePlanPublisher.value`
43+
if [ "$AZURE_MARKETPLACE_PUBLISHER" = "null" ];
44+
then
45+
AZURE_MARKETPLACE_PUBLISHER=`echo $bicep_raw | jq -r .templateJson | jq -r .parameters.azureMarketPlacePlanPublisher.defaultValue`
46+
fi
47+
48+
AZURE_MARKETPLACE_PLAN_OFFER=`echo $paramsJson | jq -r .parameters.azureMarketPlacePlanOffer.value`
49+
if [ "$AZURE_MARKETPLACE_PLAN_OFFER" = "null" ];
50+
then
51+
AZURE_MARKETPLACE_PLAN_OFFER=`echo $bicep_raw | jq -r .templateJson | jq -r .parameters.azureMarketPlacePlanOffer.defaultValue`
52+
fi
53+
54+
enablementOutput=$(az vm image terms accept \
55+
--subscription $subscriptionId \
56+
--publisher $AZURE_MARKETPLACE_PUBLISHER \
57+
--offer $AZURE_MARKETPLACE_PLAN_OFFER \
58+
--plan $AZURE_MARKETPLACE_PLAN_NAME)
59+
60+
accepted=`echo $enablementOutput | jq -r '.properties.outputs.accepted.value'`
61+
if [ $accepted ]
62+
then
63+
echosuccess "[COMPLETED] Plan '$AZURE_MARKETPLACE_PLAN_NAME' enabled."
64+
else
65+
echoerr "[Step #1][FAILURE] Enablement failed - offer: $AZURE_MARKETPLACE_PLAN_OFFER, plan: $AZURE_MARKETPLACE_PLAN_NAME, publisher: $AZURE_MARKETPLACE_PUBLISHER"
66+
echo $enablementOutput
67+
exit 1;
68+
fi
69+
70+
echo -e "${C_BLUE3}${C_GREY85}
71+
[Step #2] Deploying CBS managed app:${NO_FORMAT}
72+
"
73+
echo "
74+
Subscription Id: $subscriptionId
75+
RG name: $resourceGroupName
76+
Location: $location
77+
78+
"
4879
# Deploy our infrastructure
4980
output=$(az deployment group create \
5081
--name "CBS-deploy-sh" \
5182
--resource-group $resourceGroupName \
83+
--subscription $subscriptionId \
5284
--template-file "templates/cbs-managed-app.bicep" \
5385
--parameters $parametersfilename
5486
)
@@ -67,7 +99,7 @@ cbsiSCSIEndpointCT1=`echo $output | jq -r '.properties.outputs.cbsiSCSIEndpointC
6799
echo ""
68100
echo ""
69101
echo ""
70-
echosuccess "The deployment of CBS managed application has been completed."
102+
echosuccess "[COMPLETED] The deployment of CBS managed application has been completed."
71103
echo ""
72104

73105
echo " ******** Array parameters ********"

0 commit comments

Comments
 (0)