Skip to content

Commit d3e3b67

Browse files
authored
Update AWS DataSync Deployment Script for Azure with SubsciptionID (#1)
* Update README.md * Update datasync.sh * Add files via upload
1 parent 42be9ca commit d3e3b67

File tree

3 files changed

+60
-20
lines changed

3 files changed

+60
-20
lines changed

README.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@ For information on moving data from Azure Files SMB shares to AWS using AWS Data
1515

1616
To start the deployment, make sure you have met all the necessary prerequisites and are familiar with the configuration parameters needed for successful execution.
1717

18-
It's recommended to log in to your Azure account before running the script. During the script execution, you'll be prompted to enter the authorization code provided in the Azure console to grant the script access to your Azure resources.
18+
**It is recommended to log in to your Azure account before running the script.** During the script execution, you'll be prompted to enter the authorization code provided in the Azure console to grant the script access to your Azure resources.
1919

2020
## Deployment Steps
2121

22-
The deployment script automates several steps to ensure a smooth integration between AWS DataSync and Azure services. Here's a breakdown of the deployment process:
22+
The deployment script automates the following steps to integrate AWS DataSync with Azure:
2323

24-
1. Provide Configuration Parameters: Before executing the script, open it in your preferred editor and provide the necessary configuration parameters. These parameters will be used to customize the deployment according to your requirements.
25-
2. Install Azure CLI and AzCopy: As a part of the setup process, the script will **automatically** download and install the Azure Command-Line Interface (CLI) and AzCopy tools. These tools are essential for managing and transferring data within the Azure environment.
26-
3. Download AWS DataSync Agent for Hyper-V: The script will download the AWS DataSync Agent specifically designed for Hyper-V environment.
27-
4. Convert VHDX to VHD: Once the AWS DataSync Agent is downloaded, the script will take care of converting the Virtual Hard Disk (VHDX) file to the compatible Hyper-V Disk (HVD) format for Azure
28-
5. Azure Authentication: To access and manage your Azure resources, the script will guide you through the authentication process, ensuring secure access to your Azure account.
29-
6. Create Resource Group: The deployment script will automatically create or use an existing Azure Resource Group. This Resource Group will serve as the container for your deployed resources.
30-
7. Upload VHD as Managed Disk: The script will upload the converted VHD file as a managed disk within the specified Resource Group. This disk will contain the AWS DataSync Agent.
31-
8. Create Virtual Machine: Leveraging the uploaded managed disk, the script will create an Azure Virtual Machine in either a new VNET or an existing VNET and subnet.
24+
1. **Provide Configuration Parameters**: Customize the deployment by specifying required parameters such as deployment type, location, resource group, and VM details.
25+
2. **Install Dependencies**: Automatically installs Azure CLI, AzCopy, and other required tools.
26+
3. **Download and Convert DataSync Agent**: Downloads the AWS DataSync agent and converts it to a VHD format compatible with Azure.
27+
4. **Authenticate with Azure**: Guides you through logging into Azure to manage resources securely and validates the provided Subscription ID (if specified).
28+
5. **Create or Use Resource Group**: Ensures the specified Azure resource group exists or creates it if necessary.
29+
6. **Upload VHD to Azure**: Renames the VHD file to match the Azure VM name and uploads it as a managed disk in Azure.
30+
7. **Create Azure VM**: Deploys an Azure Virtual Machine using the uploaded VHD, supporting both new and existing VNET configurations.
3231

3332
### Prerequisites
3433

@@ -51,6 +50,9 @@ Before running the deployment script, please ensure that you have the following
5150
- **Virtual Machine Name (-v)**: The name for the Azure Virtual Machine that will host the AWS DataSync Agent (e.g. aws-datasync-vm)
5251
- **Virtual Machine Size (-z)**: Azure VM size (e.g., 'Standard_E4s_v3', 'Standard_E16_v5')
5352

53+
**Optional Parameter:**
54+
- **Subscription ID (-u)**: Azure subscription ID (optional)
55+
5456
**Additional Parameters (when -d is existing_vnet):**
5557
- **VNET Resource Group (-g)**: Virtual network resource group (required for 'existing_vnet')
5658
- **VNET Name (-n)**: Virtual network name (required for 'existing_vnet')
@@ -70,9 +72,6 @@ When selecting the Azure Virtual Machine for the Datasync Agent, we recommend th
7072
- For detailed AWS DataSync agent requirements, see the [AWS DataSync Agent Requirements](https://docs.aws.amazon.com/datasync/latest/userguide/agent-requirements.html) documentation.
7173

7274
---
73-
74-
### Download the Deployment Script
75-
7675
Run the following command to download the deployment script from the code repository:
7776

7877
```
@@ -86,15 +85,26 @@ chmod +x datasync.sh
8685

8786
Once you have your parameters ready, you can initiate the deployment script using the following commands:
8887

89-
For new_vnet deployment:
9088
```
91-
sudo bash datasync.sh -d new_vnet -l eastus -r myResourceGroup -v myVM -z Standard_E4s_v3
89+
sudo bash datasync.sh -d new_vnet -l eastus -r testResourceGroup -v testVM -z Standard_E4s_v3 -u xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
9290
```
9391

92+
Replace `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` with your actual Azure subscription ID.
93+
9494
For existing_vnet deployment:
9595
```
96-
sudo bash datasync.sh -d existing_vnet -l eastus -r aws-datasync-rg -v datasync-vm -g existing-vnet-rg -n existing-vnet -s existing-subnet -z Standard_E16_v5
96+
sudo bash datasync.sh -d existing_vnet -l eastus -r aws-datasync-rg -v datasync-vm -g existing-vnet-rg -n existing-vnet -s existing-subnet -z Standard_E16_v5 -u mySubscriptionId
9797
```
98+
Replace `subscription-id` with your actual Azure subscription ID.
99+
100+
### Subscription ID Validation
101+
102+
The script validates the provided Azure subscription ID to ensure it is correct. If the subscription ID is invalid, the script will log an error and exit. Retrieve the correct subscription ID using the following command in Azure CloudShell:
103+
104+
```
105+
az account list --output table
106+
```
107+
### Download the Deployment Script
98108

99109
## Azure CLI Login
100110
You will be prompted to login to Azure and allow the script to create the Virtual Machine for the DataSync Appliance

docs/deployment-menu-options.png

3.47 KB
Loading

src/bash/datasync.sh

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ function show_help() {
4747
echo " -g <vnet_rg> Virtual network resource group (required for 'existing_vnet')"
4848
echo " -n <vnet_name> Virtual network name (required for 'existing_vnet')"
4949
echo " -s <subnet_name> Subnet name (required for 'existing_vnet')"
50+
echo " -u <subscription_id> Azure subscription ID (optional)"
5051
echo " -h Show this help message"
5152
echo
5253
echo -e "${CYAN}Examples:${RESET}"
53-
echo " $0 -d new_vnet -l eastus -r myResourceGroup -v myVM -z Standard_E4s_v3"
54-
echo " $0 -d existing_vnet -l eastus -r myResourceGroup -v myVM -g myVnetRG -n myVnet -s mySubnet -z Standard_E16_v5"
54+
echo " $0 -d new_vnet -l eastus -r myResourceGroup -v myVM -z Standard_E4s_v3 -u mySubscriptionId"
55+
echo " $0 -d existing_vnet -l eastus -r myResourceGroup -v myVM -g myVnetRG -n myVnet -s mySubnet -z Standard_E16_v5 -u mySubscriptionId"
5556
exit 0
5657
}
5758

@@ -154,6 +155,14 @@ function convert_datasync() {
154155
qemu-img convert -f raw -o subformat=fixed,force_size -O vpc "$rawdisk" "$vhddisk"
155156

156157
rm "$rawdisk"
158+
159+
# Rename the VHD file to match the Azure VM name before upload
160+
vhddisk="/tmp/${vm_name}.vhd"
161+
mv /tmp/*.vhd "$vhddisk" || {
162+
log_error "Failed to rename VHD file to match the VM name."
163+
exit 1
164+
}
165+
157166
disk_name=$(basename "$vhddisk" .vhd)
158167
upload_size=$(qemu-img info --output json "$vhddisk" | jq -r '."virtual-size"')
159168
log_success "DataSync agent converted to VHD successfully."
@@ -179,13 +188,33 @@ function upload_to_azure() {
179188
exit 1
180189
}
181190

191+
if [ -n "${subscription_id:-}" ]; then
192+
log_info "Validating Azure subscription: $subscription_id"
193+
az account show --subscription "$subscription_id" > /dev/null 2>&1 || {
194+
log_error "Please ensure you entered the correct Azure subscription ID. You can run the command \"az account list --output table\" from Azure CloudShell to provide the subscription ID."
195+
exit 1
196+
}
197+
log_success "Azure subscription ID is valid: $subscription_id"
198+
az account set --subscription "$subscription_id" || {
199+
log_error "Please ensure you entered the correct Azure subscription ID. You can run the command \"az account list --output table\" from Azure CloudShell to provide the subscription ID."
200+
exit 1
201+
}
202+
fi
203+
182204
check_resource_group
183205

184206
az disk create -n "$disk_name" -g "$resource_group" -l "$location" --os-type Linux --upload-type Upload --upload-size-bytes "$upload_size" --sku Standard_LRS --only-show-errors || {
185-
log_error "Failed to create Azure disk."
207+
log_error "Failed to create Azure disk. Ensure the disk is created with the correct upload type."
186208
exit 1
187209
}
188210

211+
# Verify the disk state before granting SAS access
212+
disk_state=$(az disk show -n "$disk_name" -g "$resource_group" --query 'diskState' -o tsv)
213+
if [[ "$disk_state" != "ReadyToUpload" && "$disk_state" != "ActiveUpload" ]]; then
214+
log_error "Disk is not in a valid state for upload. Current state: $disk_state"
215+
exit 1
216+
fi
217+
189218
sas_uri=$(az disk grant-access -n "$disk_name" -g "$resource_group" --access-level Write --duration-in-seconds 86400 | jq -r '.accessSas') || {
190219
log_error "Failed to grant SAS access."
191220
exit 1
@@ -224,7 +253,7 @@ if [ "$#" -eq 0 ]; then
224253
fi
225254

226255
# Parse command-line arguments
227-
while getopts ":d:l:r:v:g:n:s:z:h" opt; do
256+
while getopts ":d:l:r:v:g:n:s:z:u:h" opt; do
228257
case $opt in
229258
d) deployment_type="$OPTARG" ;;
230259
l) location="$OPTARG" ;;
@@ -234,6 +263,7 @@ while getopts ":d:l:r:v:g:n:s:z:h" opt; do
234263
n) vnet_name="$OPTARG" ;;
235264
s) subnet_name="$OPTARG" ;;
236265
z) vm_size="$OPTARG" ;;
266+
u) subscription_id="$OPTARG" ;;
237267
h) show_help ;;
238268
*)
239269
log_error "Invalid option: -$OPTARG"

0 commit comments

Comments
 (0)