3

我已经开始接触Terraform并且很喜欢它,因为出于成本原因,我的服务跨多个基础设施提供商,因此可以轻松复制完整的服务而不会在 IaaS 提供商之间出现问题。

我通过 Azure 市场使用一些第三方服务,类似于 Heroku 的附加组件。我在 Terraform 中看到了一个用于 Heroku 附加组件声明的工具,但不是用于 Azure 市场订阅的工具。我怎样才能做到这一点?

更新: 如何通过 Terraform 创建 Azure 市场订单/订阅?

4

1 回答 1

3

如果我正确理解了您的问题,我认为关键是创建声明 VM,并使用以下部分替换占位符;

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
}

所以一个完整的 VM 资源定义应该是这样的。

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}"
}
}
于 2018-01-17T13:56:04.540 回答