From 32925f0280ddfce2d797d03fa756901656bb2587 Mon Sep 17 00:00:00 2001 From: Mihail Radkov Date: Thu, 15 Feb 2024 18:12:45 +0200 Subject: [PATCH] TES-277: Fixes in the SIG image definition creation script - The `gallery_subscription_id` is now a required variable - Fixed `create_image_definition.sh` to use `gallery_subscription_id` --- CHANGELOG.md | 10 ++++++++++ README.md | 32 ++++++++++++++++---------------- azure.pkr.hcl | 3 +-- create_image_definition.sh | 35 +++++++++++++++++++++++------------ variables.pkr.hcl | 3 +-- 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a423446..12de681 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to the Packer template for creating GraphDB Azure VM images will be documented in this file. +## 1.2.0 + +### Changes + +- The `gallery_subscription_id` is now a required variable instead of defaulting to `subscription_id`. + +### Fixes + +- Fixed [create_image_definition.sh](create_image_definition.sh) to use `gallery_subscription_id` + ## 1.1.0 - Installed Azure CLI diff --git a/README.md b/README.md index e30b9d6..5fbdc54 100644 --- a/README.md +++ b/README.md @@ -33,19 +33,20 @@ Follow these steps to build an AMI for GraphDB using Packer: The Packer configuration allows you to customize various parameters, such as the GraphDB version, Azure build and replication regions, subscription, client and tenant IDs. To do so, create a variables file `variables.pkrvars.hcl`, example file: - ```bash - subscription_id = "" - tenant_id = "" - client_id = "" - client_secret = "" - build_location = "East US" - graphdb_version = "10.4.0" - gallery_image_definition = "10.4.0-x86_64" - gallery_resource_group = "Packer-RG" - gallery_name = "GraphDB" - gallery_image_replication_regions = ["North Europe", "UK South"] - build_allowed_inbound_ip_addresses = "" - ``` + ```bash + subscription_id = "" + tenant_id = "" + client_id = "" + client_secret = "" + build_location = "East US" + graphdb_version = "10.4.0" + gallery_subscription_id = "" + gallery_image_definition = "10.4.0-x86_64" + gallery_resource_group = "Packer-RG" + gallery_name = "GraphDB" + gallery_image_replication_regions = ["North Europe", "UK South"] + build_allowed_inbound_ip_addresses = "" + ``` 4. **Build the AMI**: @@ -85,7 +86,7 @@ The following points can be customized in a packer variables file `variables.pkr **Subscription Configuration** -* `subscription_id` (string): Your Azure subscription ID. +* `subscription_id` (string): Your Azure subscription ID. VM images will be built in this subscription. * `tenant_id` (string): Your Azure Active Directory tenant ID. * `client_id` (string): The client ID (Service Principal ID) used for authentication. * `client_secret` (string): The client secret (Service Principal Secret) used for authentication. @@ -116,8 +117,7 @@ The following points can be customized in a packer variables file `variables.pkr **Gallery Configuration** -* `gallery_subscription_id` (string): ID of the subscription where the Shared Image Gallery is located. Will use subscription_id as default if - unspecified +* `gallery_subscription_id` (string): ID of the subscription where the Shared Image Gallery is located. Can be the same as `subscription_id`. * `gallery_resource_group` (string): The resource group where the image gallery is located. * `gallery_name` (string): The name of the image gallery. * `gallery_image_definition` (string): The name of the x86_64 image to use. diff --git a/azure.pkr.hcl b/azure.pkr.hcl index 8403afb..02a7911 100644 --- a/azure.pkr.hcl +++ b/azure.pkr.hcl @@ -2,7 +2,6 @@ locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") # See https://github.com/hashicorp/packer-plugin-azure/issues/65 version_timestamp = formatdate("YYYY.MM.DD", timestamp()) - gallery_subscription_id = var.gallery_subscription_id != null ? var.gallery_subscription_id : var.subscription_id } source azure-arm ubuntu-x86-64 { @@ -21,7 +20,7 @@ source azure-arm ubuntu-x86-64 { image_sku = var.base_image_sku shared_image_gallery_destination { - subscription = local.gallery_subscription_id + subscription = var.gallery_subscription_id resource_group = var.gallery_resource_group gallery_name = var.gallery_name image_name = var.gallery_image_definition diff --git a/create_image_definition.sh b/create_image_definition.sh index e9cce37..93a48aa 100755 --- a/create_image_definition.sh +++ b/create_image_definition.sh @@ -20,14 +20,18 @@ if ! [ -f "$variables_file" ]; then fi # Extracts required variables from the variables_file -subscription_id=$(grep 'subscription_id' "$variables_file" | cut -d '"' -f 2) -echo "Subscription ID: $subscription_id" +gallery_subscription_id=$(grep 'gallery_subscription_id' "$variables_file" | cut -d '"' -f 2) +echo "Subscription ID: $gallery_subscription_id" + gallery_image_definition=$(grep 'gallery_image_definition' "$variables_file" | cut -d '"' -f 2) echo "Image definition name: $gallery_image_definition" + graphdb_version=$(grep 'graphdb_version' "$variables_file" | cut -d '"' -f 2) echo "GraphDB version: $graphdb_version" + gallery_resource_group=$(grep 'gallery_resource_group' "$variables_file" | cut -d '"' -f 2) echo "Resource group: $gallery_resource_group" + gallery_name=$(grep 'gallery_name' "$variables_file" | cut -d '"' -f 2) echo "Gallery: $gallery_name" @@ -39,13 +43,13 @@ fi # Constructs the az sig image-definition create command az_command="az sig image-definition create \ - --subscription $subscription_id \ - -g $gallery_resource_group \ - --gallery-name $gallery_name \ - --gallery-image-definition "$gallery_image_definition" \ + --subscription \"$gallery_subscription_id\" \ + --resource-group \"$gallery_resource_group\" \ + --gallery-name \"$gallery_name\" \ + --gallery-image-definition \"$gallery_image_definition\" \ --publisher Ontotext \ --offer GraphDB \ - --sku "$graphdb_version" \ + --sku \"$graphdb_version\" \ --os-type Linux \ --hyper-v-generation v2 \ --minimum-cpu-core 4 \ @@ -53,10 +57,17 @@ az_command="az sig image-definition create \ --minimum-memory 4 \ --maximum-memory 128 " -# TODO: defuk is this : echo "Extracted variables and constructed Azure CLI command:" -echo "Creating SIG" +echo "$az_command" + +echo "Creating SIG image definition" eval "$az_command" -# Waits for the Shared Image Gallery to be created -az sig image-definition wait -i "$gallery_image_definition" -r "$gallery_name" -g "$gallery_resource_group" --created --subscription $subscription_id -echo "Begin building of the Azure VM image" + +echo "Waiting for the SIG image definition creation to complete" +az sig image-definition wait \ + --subscription "$gallery_subscription_id" \ + --resource-group"$gallery_resource_group" \ + --gallery-name "$gallery_name" \ + --gallery-image-definition "$gallery_image_definition" \ + --created +echo "SUCCESS: SIG image definition created" diff --git a/variables.pkr.hcl b/variables.pkr.hcl index f13f648..5a08504 100644 --- a/variables.pkr.hcl +++ b/variables.pkr.hcl @@ -130,9 +130,8 @@ variable base_image_sku { ######################################## variable gallery_subscription_id { - description = "ID of the subscription where the Shared Image Gallery is located. Will use subscription_id as default if unspecified." + description = "ID of the subscription where the Shared Image Gallery is located. Can be the same as subscription_id." type = string - default = null } variable gallery_resource_group {