Created
July 2, 2016 02:58
-
-
Save yamamoto-febc/170522b53a996e7b745b638638c68371 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /************************ | |
| 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}" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| software_package "httpd" { | |
| action = "install", | |
| } | |
| service "httpd" { | |
| action = {"enable", "start"}, | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Go言語製プロビジョニングツールcofuを試してみました。
参考:オープンソースこねこね:Goでプロビジョニングツールを作った
背景
Terraformで作ったインフラのプロビジョニングをどう行うか悩みどころでした。
chefの場合はchef serverが必要だし、ansible + local-execだったら手元にansibleが必要だし、、
remote-execでシェルスクリプトをガンガン実行でもいいですが、cofuならその辺の問題クリアできていいですね!
手順
Terraform for さくらのクラウドを使います。
手元のマシンで以下のような定義ファイルを作成しておきます。
以下実行手順です