【问题标题】:Terraform with Azure Marketplace使用 Azure 市场的 Terraform
【发布时间】:2016-05-10 03:26:26
【问题描述】:

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

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

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

【问题讨论】:

  • 我不确定我是否理解这个问题,但是...如果市场上没有可用的服务/图像,您可以自行启动它(以任何方式最适合相关工具)。
  • 问题是“如何通过 Terraform 创建 Azure 市场订单/订阅”
  • 正如@DavidMakogon 提到的,如果它不在 Azure 市场中,您必须自己创建。或者让 Terraform 向 Azure 市场发布你可以使用的东西。我还在 Azure Marketplace 上进行了搜索,似乎他们没有提供任何报价。 (azure.microsoft.com/en-us/marketplace/?term=terraform)
  • @PeterKirchner Terraform 不需要向市场发布任何内容或进入市场即可执行此操作——它是一种利用现有 IaaS API 创建、销毁等实例的 DevOps 工具。例如,我已经使用它来创建 Heroku 插件,而 Terraform 不需要已发布的插件。

标签: azure azure-marketplace terraform


【解决方案1】:

如果我正确理解您的问题,我认为关键是创建声明 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
}

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

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

【讨论】:

    猜你喜欢
    • 2022-07-04
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 2021-06-15
    • 2016-11-01
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多