jdotjdot
jdotjdot

Reputation: 17092

Terraform with Azure Marketplace

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?

Upvotes: 3

Views: 5330

Answers (2)

FloridaDBA
FloridaDBA

Reputation: 87

resource "azurerm_marketplace_agreement"

Upvotes: -1

gingerbreadboy
gingerbreadboy

Reputation: 7757

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}"
}
}

Upvotes: 4

Related Questions