markdown 用于将VSI部署到专用主机的Terraform示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 用于将VSI部署到专用主机的Terraform示例相关的知识,希望对你有一定的参考价值。

## Get current dedicated host details and guests
In this case the Dedicated Host I was testing against had not had any VSIs deployed on to it:

```
tycho ~ ◎ curl -s "https://$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY@api.softlayer.com/rest/v3/SoftLayer_Virtual_DedicatedHost/10401/getObject"
{
    "accountId": 78003,
    "cpuCount": 56,
    "createDate": "2017-08-04T05:15:56-07:00",
    "diskCapacity": 1200,
    "id": 10401,
    "memoryCapacity": 242,
    "modifyDate": null,
    "name": "kbryandedihost"
}

tycho ~ ◎ curl -s "https://$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY@api.softlayer.com/rest/v3/SoftLayer_Virtual_DedicatedHost/10401/getGuests" | pmj
[]
```

I then used the following `main.tf` file to deploy a VSI on to the host. 

```hcl
# Softlayer username
variable slusername {}

# SoftLayer API key
variable slapikey {}

# The datacenter to deploy to
variable datacenter {
  default = "dal10"
}

# The target operating system for the VSI
variable os {
  default = "UBUNTU_LATEST_64"
}

# The number of cores for the VSI
variable vm_cores {
  default = 4
}

# The amount of memory for the VSI
variable vm_memory {
  default = 4096
}

# The private vlan to deploy the virtual guests on to 
variable priv_vlan { 
  default = 2101937
}

# The public vlan to deploy the virtual guests on to 
variable pub_vlan { 
  default = 2101935
}

# The domain name for the virtual guests
variable domainname { 
  default = "cde.services"
}

provider "ibm" {
  softlayer_username = "${var.slusername}"
  softlayer_api_key  = "${var.slapikey}"
}

data "ibm_compute_ssh_key" "sshkey" {
    label = "tycho"
}

resource "ibm_compute_vm_instance" "node" {
    hostname = "dedivstest"
    domain = "${var.domainname}"
    os_reference_code = "${var.os}"
    datacenter = "${var.datacenter}"
    network_speed = 1000
    hourly_billing = true
    private_network_only = false 
    cores = "${var.vm_cores}"
    memory = "${var.vm_memory}"
    disks = [100, 100]
    local_disk = true
    private_vlan_id = "${var.priv_vlan}"
    public_vlan_id = "${var.pub_vlan}"
    ssh_key_ids = ["${data.ibm_compute_ssh_key.sshkey.id}"]
    dedicated_host_id = 10401
}
```

## Running `terraform apply`

```
tycho ~ ◎ terraform apply
data.ibm_compute_ssh_key.sshkey: Refreshing state...
ibm_compute_vm_instance.node: Creating...
  block_storage_ids.#:          "" => "<computed>"
  cores:                        "" => "4"
  datacenter:                   "" => "dal10"
  dedicated_host_id:            "" => "10401"
  disks.#:                      "" => "2"
  disks.0:                      "" => "100"
  disks.1:                      "" => "100"
  domain:                       "" => "cde.services"
  file_storage_ids.#:           "" => "<computed>"
  hostname:                     "" => "dedivstest"
  hourly_billing:               "" => "true"
  ip_address_id:                "" => "<computed>"
  ip_address_id_private:        "" => "<computed>"
  ipv4_address:                 "" => "<computed>"
  ipv4_address_private:         "" => "<computed>"
  ipv6_address:                 "" => "<computed>"
  ipv6_address_id:              "" => "<computed>"
  ipv6_enabled:                 "" => "false"
  local_disk:                   "" => "true"
  memory:                       "" => "4096"
  network_speed:                "" => "1000"
  os_reference_code:            "" => "UBUNTU_LATEST_64"
  private_interface_id:         "" => "<computed>"
  private_network_only:         "" => "false"
  private_security_group_ids.#: "" => "<computed>"
  private_subnet:               "" => "<computed>"
  private_subnet_id:            "" => "<computed>"
  private_vlan_id:              "" => "2101937"
  public_bandwidth_limited:     "" => "<computed>"
  public_bandwidth_unlimited:   "" => "false"
  public_interface_id:          "" => "<computed>"
  public_ipv6_subnet:           "" => "<computed>"
  public_ipv6_subnet_id:        "" => "<computed>"
  public_security_group_ids.#:  "" => "<computed>"
  public_subnet:                "" => "<computed>"
  public_subnet_id:             "" => "<computed>"
  public_vlan_id:               "" => "2101935"
  secondary_ip_addresses.#:     "" => "<computed>"
  ssh_key_ids.#:                "" => "1"
  ssh_key_ids.972047:           "" => "972047"
  wait_time_minutes:            "" => "90"
  
 ibm_compute_vm_instance.node: Still creating... (10s elapsed)
ibm_compute_vm_instance.node: Still creating... (20s elapsed)
ibm_compute_vm_instance.node: Still creating... (30s elapsed)
ibm_compute_vm_instance.node: Still creating... (40s elapsed)
ibm_compute_vm_instance.node: Still creating... (50s elapsed)
ibm_compute_vm_instance.node: Still creating... (1m0s elapsed)
ibm_compute_vm_instance.node: Still creating... (1m10s elapsed)
 ... (yadda yadda yadda) 
ibm_compute_vm_instance.node: Creation complete (ID: 45097597)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
```

## Verifying it ended up on the dedicated host

```
tycho ~ ◎ curl -s "https://$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY@api.softlayer.com/rest/v3/SoftLayer_Virtual_DedicatedHost/10401/getGuests" | pmj
[
    {
        "accountId": 78003,
        "createDate": "2017-11-27T12:37:45-06:00",
        "dedicatedAccountHostOnlyFlag": false,
        "domain": "cde.services",
        "fullyQualifiedDomainName": "dedivstest.cde.services",
        "globalIdentifier": "a1687010-9d38-453d-8965-3fc2b2a1f6f2",
        "hostname": "dedivstest",
        "id": 45097597,
        "lastPowerStateId": null,
        "lastVerifiedDate": null,
        "maxCpu": 4,
        "maxCpuUnits": "CORE",
        "maxMemory": 4096,
        "metricPollDate": null,
        "modifyDate": "2017-11-27T12:40:41-06:00",
        "primaryBackendIpAddress": "10.93.26.20",
        "primaryIpAddress": "169.60.9.88",
        "provisionDate": "2017-11-27T12:40:41-06:00",
        "startCpus": 4,
        "status": {
            "keyName": "ACTIVE",
            "name": "Active"
        },
        "statusId": 1001,
        "typeId": 2,
        "uuid": "88ecddf2-a35d-8c9e-b850-9a6e780b4489"
    }
]

```

以上是关于markdown 用于将VSI部署到专用主机的Terraform示例的主要内容,如果未能解决你的问题,请参考以下文章

如何在专用网络中部署 Java Web 服务

python 用于订购VSI并指定安装后脚本URL的Python示例

markdown 将来自repo的分支合并到另一个repo中作为专用分支下的子目录

微软增加了Azure专用主机选项 用于在单租户服务器上运行vm

如何将内部 MobileFirst 混合应用程序部署到专用的 Bluemix 环境?

使用多个项目时,Firebase 部署到错误的主机