I have a Terraform script that creates a Virtual Machine on Azure based on this image from the Azure Marketplace: https://azuremarketplace.microsoft.com/en-us/marketplace/apps/gitlab.gitlab-ce
But I don't know how to identify the values to put in these fields:
This is a snippet from the Terraform script
resource "azurerm_virtual_machine" "gitlab_vm" {
# ... other configuration
storage_image_reference {
publisher = "GitLab"
offer = "GitLab Community Edition"
# sku = "???"
version = "latest"
}
# ... other configuration
}
If I run the previous details with terraform plan
and e.g. publisher = "GitLabXXX"
(something that does not exist), then Terraform does not raise any error. When I run terraform apply
after a while an error is raised and the VM resource is not created (although all the other resources e.g. the networking stuff are created).
This applies in a similar way to Azure ARM templates:
"imageReference": {
"publisher": "[variables('pubName')]",
"offer": "[variables('offerName')]",
"sku" : "[parameters('skuName')]",
"version":"latest"
},
I have some virtual machine that are up and running with a similar Terraform configuration that I found on the internet (see the Ubuntu example below), but what are the rules to translate the information from the Azure Marketplace webpage to the script?
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
There may be a more efficient way to do this, but I typically use the Azure CLI to get the publisher, offer, SKU, and version. First, if you do something like:
az vm image list --offer GitLab -o table --all
You'll get back a list with the offer, publisher, SKU, URN, and Version. In your case, it should be something like this for gitlab-ce:
I'm pretty sure the azurerm provider just calls ARM with these values so it should match what you get from the CLI, though I can certainly be corrected on this if I'm mistaken.
You'll also need to include a plan block. The details for that can be retrieved via the CLI with something like this:
az vm image show --location westus --urn gitlab:gitlab-ce:gitlab-ce:1.0.4 -o json
So your plan block would look something like:
plan {
name = "gitlab-ce"
publisher = "gitlab"
product = "gitlab-ce"
}