diff --git a/test/cases/api.sh b/test/cases/api.sh index c24dedb24..4d96b7630 100755 --- a/test/cases/api.sh +++ b/test/cases/api.sh @@ -1547,16 +1547,17 @@ function verifyInAzure() { $AZURE_CMD login --service-principal --username "${V2_AZURE_CLIENT_ID}" --password "${V2_AZURE_CLIENT_SECRET}" --tenant "${AZURE_TENANT_ID}" set -x - # verify that the image exists + # verify that the image exists and tag it $AZURE_CMD image show --resource-group "${AZURE_RESOURCE_GROUP}" --name "${AZURE_IMAGE_NAME}" + $AZURE_CMD image update --resource-group "${AZURE_RESOURCE_GROUP}" --name "${AZURE_IMAGE_NAME}" --tags gitlab-ci-test=true # Verify that the image boots and have customizations applied # Create SSH keys to use AZURE_SSH_KEY="$WORKDIR/id_azure" ssh-keygen -t rsa-sha2-512 -f "$AZURE_SSH_KEY" -C "$SSH_USER" -N "" - # Create network resources with predictable names - $AZURE_CMD network nsg create --resource-group "$AZURE_RESOURCE_GROUP" --name "nsg-$TEST_ID" --location "$AZURE_LOCATION" + # Create network resources with predictable names and tag + $AZURE_CMD network nsg create --resource-group "$AZURE_RESOURCE_GROUP" --name "nsg-$TEST_ID" --location "$AZURE_LOCATION" --tags gitlab-ci-test=true $AZURE_CMD network nsg rule create --resource-group "$AZURE_RESOURCE_GROUP" \ --nsg-name "nsg-$TEST_ID" \ --name SSH \ @@ -1567,15 +1568,20 @@ function verifyInAzure() { --destination-port-ranges 22 \ --source-port-ranges '*' \ --source-address-prefixes '*' - $AZURE_CMD network vnet create --resource-group "$AZURE_RESOURCE_GROUP" --name "vnet-$TEST_ID" --subnet-name "snet-$TEST_ID" --location "$AZURE_LOCATION" - $AZURE_CMD network public-ip create --resource-group "$AZURE_RESOURCE_GROUP" --name "ip-$TEST_ID" --location "$AZURE_LOCATION" + $AZURE_CMD network vnet create --resource-group "$AZURE_RESOURCE_GROUP" \ + --name "vnet-$TEST_ID" \ + --subnet-name "snet-$TEST_ID" \ + --location "$AZURE_LOCATION" \ + --tags gitlab-ci-test=true + $AZURE_CMD network public-ip create --resource-group "$AZURE_RESOURCE_GROUP" --name "ip-$TEST_ID" --location "$AZURE_LOCATION" --tags gitlab-ci-test=true $AZURE_CMD network nic create --resource-group "$AZURE_RESOURCE_GROUP" \ --name "iface-$TEST_ID" \ --subnet "snet-$TEST_ID" \ --vnet-name "vnet-$TEST_ID" \ --network-security-group "nsg-$TEST_ID" \ --public-ip-address "ip-$TEST_ID" \ - --location "$AZURE_LOCATION" + --location "$AZURE_LOCATION" \ + --tags gitlab-ci-test=true # create the instance AZURE_INSTANCE_NAME="vm-$TEST_ID" @@ -1588,7 +1594,8 @@ function verifyInAzure() { --authentication-type "ssh" \ --location "$AZURE_LOCATION" \ --nics "iface-$TEST_ID" \ - --os-disk-name "disk-$TEST_ID" + --os-disk-name "disk-$TEST_ID" \ + --tags gitlab-ci-test=true $AZURE_CMD vm show --name "$AZURE_INSTANCE_NAME" --resource-group "$AZURE_RESOURCE_GROUP" --show-details > "$WORKDIR/vm_details.json" HOST=$(jq -r '.publicIps' "$WORKDIR/vm_details.json") diff --git a/test/data/azure/deployment-template.json b/test/data/azure/deployment-template.json index 7ff81b377..4e2dcdaf0 100644 --- a/test/data/azure/deployment-template.json +++ b/test/data/azure/deployment-template.json @@ -47,6 +47,9 @@ "type": "Microsoft.Network/networkInterfaces", "apiVersion": "2019-07-01", "location": "[parameters('location')]", + "tags": { + "gitlab-ci-test": "true" + }, "dependsOn": [ "[concat('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]", "[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]", @@ -77,6 +80,9 @@ "type": "Microsoft.Network/networkSecurityGroups", "apiVersion": "2019-02-01", "location": "[parameters('location')]", + "tags": { + "gitlab-ci-test": "true" + }, "properties": { "securityRules": [ { @@ -100,6 +106,9 @@ "type": "Microsoft.Network/virtualNetworks", "apiVersion": "2019-09-01", "location": "[parameters('location')]", + "tags": { + "gitlab-ci-test": "true" + }, "properties": { "addressSpace": { "addressPrefixes": [ @@ -121,6 +130,9 @@ "type": "Microsoft.Network/publicIpAddresses", "apiVersion": "2019-02-01", "location": "[parameters('location')]", + "tags": { + "gitlab-ci-test": "true" + }, "properties": { "publicIpAllocationMethod": "Dynamic" }, @@ -133,6 +145,9 @@ "type": "Microsoft.Compute/images", "apiVersion": "2019-07-01", "location": "[parameters('location')]", + "tags": { + "gitlab-ci-test": "true" + }, "properties": { "hyperVGeneration": "V2", "storageProfile": { @@ -149,6 +164,9 @@ "type": "Microsoft.Compute/virtualMachines", "apiVersion": "2019-07-01", "location": "[parameters('location')]", + "tags": { + "gitlab-ci-test": "true" + }, "dependsOn": [ "[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]", "[concat('Microsoft.Compute/images/', parameters('imageName'))]" diff --git a/test/data/azure/main.tf b/test/data/azure/main.tf index b821ef1a8..2de3d70e0 100644 --- a/test/data/azure/main.tf +++ b/test/data/azure/main.tf @@ -58,6 +58,9 @@ resource "azurerm_storage_blob" "testBlob" { # Create vm image resource "azurerm_image" "testimage" { name = join("-", ["image", var.TEST_ID]) + tags = { + gitlab-ci-test = "true" + } location = data.azurerm_resource_group.testResourceGroup.location resource_group_name = data.azurerm_resource_group.testResourceGroup.name hyper_v_generation = var.HYPER_V_GEN @@ -73,6 +76,9 @@ resource "azurerm_image" "testimage" { # Create virtual network resource "azurerm_virtual_network" "testterraformnetwork" { name = join("-", ["vnet", var.TEST_ID]) + tags = { + gitlab-ci-test = "true" + } address_space = ["10.0.0.0/16"] location = data.azurerm_resource_group.testResourceGroup.location resource_group_name = data.azurerm_resource_group.testResourceGroup.name @@ -90,6 +96,9 @@ resource "azurerm_subnet" "testterraformsubnet" { # Create public IPs resource "azurerm_public_ip" "testterraformpublicip" { name = join("-", ["ip", var.TEST_ID]) + tags = { + gitlab-ci-test = "true" + } location = data.azurerm_resource_group.testResourceGroup.location resource_group_name = data.azurerm_resource_group.testResourceGroup.name allocation_method = "Dynamic" @@ -99,6 +108,9 @@ resource "azurerm_public_ip" "testterraformpublicip" { # Create Network Security Group and rule resource "azurerm_network_security_group" "testterraformnsg" { name = join("-", ["nsg", var.TEST_ID]) + tags = { + gitlab-ci-test = "true" + } location = data.azurerm_resource_group.testResourceGroup.location resource_group_name = data.azurerm_resource_group.testResourceGroup.name @@ -119,6 +131,9 @@ resource "azurerm_network_security_group" "testterraformnsg" { # Create network interface resource "azurerm_network_interface" "testterraformnic" { name = join("-", ["iface", var.TEST_ID]) + tags = { + gitlab-ci-test = "true" + } location = data.azurerm_resource_group.testResourceGroup.location resource_group_name = data.azurerm_resource_group.testResourceGroup.name @@ -142,6 +157,7 @@ resource "tls_private_key" "test_ssh" { algorithm = "RSA" rsa_bits = 4096 } + output "tls_private_key" { value = tls_private_key.test_ssh.private_key_pem sensitive = true @@ -150,6 +166,9 @@ output "tls_private_key" { # Create virtual machine resource "azurerm_linux_virtual_machine" "testterraformvm" { name = join("-", ["vm", var.TEST_ID]) + tags = { + gitlab-ci-test = "true" + } location = data.azurerm_resource_group.testResourceGroup.location resource_group_name = data.azurerm_resource_group.testResourceGroup.name network_interface_ids = [azurerm_network_interface.testterraformnic.id]