Skip to content

Instantly share code, notes, and snippets.

@yamamoto-febc
Created July 2, 2016 02:58
Show Gist options
  • Select an option

  • Save yamamoto-febc/170522b53a996e7b745b638638c68371 to your computer and use it in GitHub Desktop.

Select an option

Save yamamoto-febc/170522b53a996e7b745b638638c68371 to your computer and use it in GitHub Desktop.
/************************
Server
************************/
resource "sakuracloud_server" "server01" {
name = "server01"
disks = ["${sakuracloud_disk.disk01.id}"]
tags = ["@virtio-net-pci"]
connection {
user = "root"
host = "${self.base_nw_ipaddress}"
private_key = "${file("./id_rsa")}"
}
provisioner "file" {
source = "cofu_linux_amd64"
destination = "/usr/bin/cofu"
}
provisioner "file" {
source = "recipes"
destination = "/tmp/cofu"
}
provisioner "remote-exec" {
inline = [
"chmod +x /usr/bin/cofu",
"cd /tmp/cofu",
"cofu sample.lua",
]
}
zone = "is1b"
}
/************************
Disk
************************/
resource "sakuracloud_disk" "disk01" {
name = "disk01"
source_archive_name = "CentOS 7.2 64bit"
ssh_key_ids = ["${sakuracloud_ssh_key.mykey.id}"]
disable_pw_auth = true
zone = "is1b"
}
/************************
SSHKey
************************/
resource "sakuracloud_ssh_key" "mykey" {
name = "key"
public_key = "${file("./id_rsa.pub")}"
}
# ssh helper , usage : $(terrafor output ssh)
output "ssh" {
value = "ssh -i ${path.root}/id_rsa root@${sakuracloud_server.server01.base_nw_ipaddress}"
}
software_package "httpd" {
action = "install",
}
service "httpd" {
action = {"enable", "start"},
}
@yamamoto-febc
Copy link
Author

Go言語製プロビジョニングツールcofuを試してみました。
参考:オープンソースこねこね:Goでプロビジョニングツールを作った

背景

Terraformで作ったインフラのプロビジョニングをどう行うか悩みどころでした。
chefの場合はchef serverが必要だし、ansible + local-execだったら手元にansibleが必要だし、、
remote-execでシェルスクリプトをガンガン実行でもいいですが、cofuならその辺の問題クリアできていいですね!

手順

Terraform for さくらのクラウドを使います。

手元のマシンで以下のような定義ファイルを作成しておきます。

[root]
├── cofu_linux_amd64 # cofuリリースページからLinux64bit用バイナリをダウンロード
├── main.tf                    # Terrafrom 定義ファイル(gist参照)
└── recipes
    └── sample.lua        # cofu定義ファイル(gist参照)

以下実行手順です

# SSH用キーペア生成
$ ssh-keygen -C "" -f id_rsa
# terraform でインフラ作成 & cofuでプロビジョニング
$ terraform apply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment