1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

terraform で 各 Iaas の仮想インスタンスを作成 (CloudStack/IDCFクラウド)

1
Posted at

概要

terraform で各 IaaS ベンダーの仮想マシンを作成する

今回は IDCFクラウド のベースとなる tf ファイルを作成

対象ベンダー

※AWSは今更なので割愛

事前準備

  • まずはサインアップ
  • 左メニューの [API] リンクより、以下の情報を取得
    • エンドポイントURL
    • API Key
    • Secret Key

手順

tf ファイルを作成

provider.tf
provider "cloudstack" {
  api_url    = "${var.api_url}"
  api_key    = "${var.api_key}"
  secret_key = "${var.secret_key}"
  http_get_only = true
}

※http_get_only = true 必須
ipaddress.tf
resource "cloudstack_ipaddress" "default" {
  network = "${var.network}"
}
incetance.tf
resource "cloudstack_instance" "default" {
  name = "${var.instance_name}"
  display_name = "${var.instance_name}"
  zone = "${var.zone}"
  service_offering = "${var.default_service_offering}"
  network = "${var.network}"
  template = "${var.template}"
  keypair = "${var.keypair}"
  ipaddress = "${var.default_ipaddress}"

  provisioner "local-exec" {
    command = "./kick_api.sh command=enableStaticNat ipaddressid=${cloudstack_ipaddress.default.id} virtualmachineid=${cloudstack_instance.default.id}"
  }
}

※terraform に Static NAT 機能が実装されていないため、bash script for CloudStack API を使用

disk.tf
resource "cloudstack_disk" "default" {
  name             = "${cloudstack_instance.default.name}-DATA"
  disk_offering    = "Custom Disk"
  size             = "${var.default_disk_size}"
  attach           = true
  virtual_machine  = "${cloudstack_instance.default.name}"
  zone             = "${cloudstack_instance.default.zone}"
}
firewall.tf
resource "cloudstack_firewall" "default" {
  ipaddress = "${cloudstack_ipaddress.default.ipaddress}"

  rule {
    source_cidr = "0.0.0.0/0"
    protocol = "tcp"
    ports = ["22"]
  }
}
variables.tf
variable "api_url" {}
variable "api_key" {}
variable "secret_key" {}
variable "zone" {
  default = "pascal"
}
variable "default_service_offering" {}
variable "template" {}
variable "default_disk_size" {}
variable "keypair" {}
variable "network" {
  default = "paskal-network1"
}
variable "instance_name" {}
variable "default_ipaddress" {}

tfvars は以下の通り

terraform.tfvars
## credential
api_url = "https://compute.jp-east.idcfcloud.com/client/api"
api_key = "*********************"
secret_key = "*********************"

## zone
zone = "joule"

## machine type
default_service_offering = "light.S1"

## image
template = "CentOS 6.6 64-bit"

## volume
default_disk_size = "10"

## ssh key
keypair = "ssh-key"

## network interface
network = "joule-network1"

## incetance
instance_name = "************"

## private ip address
default_ipaddress = "10.15.0.10"

結果

$ terraform apply

作成されたリソース

$ terraform graph | dot -Tpng > graph.png

graph.png

アカウントに登録されたメールアドレスにrootパスワードのメールが送信されるので確認

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?