3
votes

I've started to get into Terraform and am loving it, since for cost reasons I have my services across a number of infrastructure providers, so it makes it easy to replicate full services without issues across IaaS providers.

I use some third-party services through the Azure marketplace, similar to Heroku's Add-Ons. I see a facility in Terraform for Heroku Add-On declarations, but not for Azure marketplace subscriptions. How can I do this?

Update: How do I create an Azure marketplace order/subscription via Terraform?

1
I'm not sure I understand the question, but... if a service/image isn't available in the marketplace, it's up to you to spin it up on your own (in whichever way is most appropriate for the tool in question).David Makogon
The question is "How do I create an Azure marketplace order/subscription via Terraform"jdotjdot
As @DavidMakogon mentioned, if it is not in the Azure Marketplace you have to create in on your own. Or ask Terraform to publish something to the Azure Marketplace what you can use. I also did a search on the Azure Marketplace and it seems there is no offer from them. (azure.microsoft.com/en-us/marketplace/?term=terraform)Peter Kirchner
@PeterKirchner Terraform shouldn't need to publish anything to the marketplace or be in the marketplace to do this--it's a DevOps tool that leverages existing IaaS APIs to create, destroy, etc. instances. I have already used it to create Heroku AddOns, for example, and Terraform has no need of a published AddOn.jdotjdot

1 Answers

2
votes

If I understand your preoblem correctly I think the key is to create declare VM with the following sections with placeholder replaced;

plan {
    publisher = "${publisher}" // e.g. bitnami
    product = "${offer}"  // e.g. elk
    name = "${sku}"  // e.g. 46
}

storage_image_reference {
    publisher = "${publisher}" // e.g. bitnami
    offer = "${offer}" // e.g. elk
    sku = "${sku}" // e.g. 46
    version = "${version}"  // e.g. latest
}

So a complete VM resource definition would lok something like this.

resource "azurerm_virtual_machine" "virtual_machine" {
    count = "${var.vm_count}"
    name = "${element(module.template.vm_names, count.index)}"
    location = "${var.location}"
    resource_group_name = "${var.resource_group_name}"
    network_interface_ids = ["${element(azurerm_network_interface.network_interface.*.id, count.index)}"]
    vm_size = "${var.vm_size}"
    delete_data_disks_on_termination = true
    delete_os_disk_on_termination = true

plan {
    publisher = "${var.publisher}"
    product = "${var.offer}"
    name = "${var.sku}"
}

boot_diagnostics {
    enabled = true
    storage_uri = "${var.boot_diagnostics_storage_url}"
}

storage_image_reference {
    publisher = "${var.publisher}"
    offer = "${var.offer}"
    sku = "${var.sku}"
    version = "${var.version}"
}

storage_os_disk {
    name = "primarydisk"
    vhd_uri = "${join("", list(var.disks_container_url, "/" , element(module.template.vm_names, count.index), ".vhd"))}"
    caching = "ReadWrite"
    create_option = "FromImage"
}

os_profile {
    computer_name = "${element(module.template.vm_names, count.index)}"
    admin_username = "${element(module.template.user_names, count.index)}"
}

os_profile_linux_config {
    disable_password_authentication = true
    ssh_keys = [{
        path     = "/home/${element(module.template.user_names, count.index)}/.ssh/authorized_keys"
        key_data = "${replace(file("../vars/keys/vm.pub"),"\n","")}"
    }]
}

tags {
    environment = "${var.resource_group_name}"
}
}