Last active
May 24, 2016 09:54
-
-
Save yamamoto-febc/4762c5120b6f6935fe359639e174aee7 to your computer and use it in GitHub Desktop.
Terraform for さくらのクラウド(ブリッジ接続メモ) ref: http://qiita.com/yamamoto-febc/items/d3d43251548f3c979aff
This file contains 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
# 確認 | |
terraform plan | |
# 実行 | |
terraform apply | |
# 作ったマシンのグローバルIP確認(2台分表示される) | |
terraform show | grep "shared_nw_address" | |
# 作ったマシンへのSSH | |
ssh root@[先ほど確認したIP] -i id_rsa | |
# ping(異なるゾーンへつながってることを確認) | |
ping 192.168.1.1 | |
# または | |
ping 192.168.1.2 | |
This file contains 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
#!/bin/sh | |
# eth1のIP設定 | |
cat << EOS >> /etc/sysconfig/network-scripts/ifcfg-eth1 | |
BOOTPROTO=static | |
PREFIX0=24 | |
DEVICE=eth1 | |
IPADDR0=192.168.1.1 | |
ONBOOT=yes | |
EOS | |
#反映 | |
ifdown eth1; ifup eth1 |
This file contains 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
#!/bin/sh | |
# eth1のIP設定 | |
cat << EOS >> /etc/sysconfig/network-scripts/ifcfg-eth1 | |
BOOTPROTO=static | |
PREFIX0=24 | |
DEVICE=eth1 | |
IPADDR0=192.168.1.2 | |
ONBOOT=yes | |
EOS | |
#反映 | |
ifdown eth1; ifup eth1 |
This file contains 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
provider "sakuracloud" {} | |
################################################## | |
# サーバー1(石狩第1) | |
################################################## | |
resource "sakuracloud_server" "is1a_sv01" { | |
name = "sv01" | |
disks = ["${sakuracloud_disk.disk01.id}"] | |
tags = ["@virtio-net-pci"] | |
switched_interfaces = [ "${sakuracloud_switch.sw01.id}" ] | |
connection { | |
user = "root" | |
host = "${sakuracloud_server.is1a_sv01.shared_nw_ipaddress}" | |
private_key = "${file("./id_rsa")}" | |
} | |
provisioner "file" { | |
source = "provision_sv01.sh" | |
destination = "/tmp/script.sh" | |
} | |
provisioner "remote-exec" { | |
inline = [ | |
"chmod +x /tmp/script.sh", | |
"/tmp/script.sh" | |
] | |
} | |
zone = "is1a" | |
} | |
################################################## | |
# サーバー2(石狩第2) | |
################################################## | |
resource "sakuracloud_server" "is1b_sv02" { | |
name = "sv02" | |
disks = ["${sakuracloud_disk.disk02.id}"] | |
tags = ["@virtio-net-pci"] | |
switched_interfaces = [ "${sakuracloud_switch.sw02.id}" ] | |
connection { | |
user = "root" | |
host = "${sakuracloud_server.is1b_sv02.shared_nw_ipaddress}" | |
private_key = "${file("./id_rsa")}" | |
} | |
provisioner "file" { | |
source = "provision_sv02.sh" | |
destination = "/tmp/script.sh" | |
} | |
provisioner "remote-exec" { | |
inline = [ | |
"chmod +x /tmp/script.sh", | |
"/tmp/script.sh" | |
] | |
} | |
zone = "is1b" | |
} | |
################################################## | |
# サーバー1用ディスク(石狩第1) | |
################################################## | |
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 = "is1a" | |
} | |
################################################## | |
# サーバー2用ディスク(石狩第1) | |
################################################## | |
resource "sakuracloud_disk" "disk02" { | |
name = "disk02" | |
source_archive_name = "CentOS 7.2 64bit" | |
ssh_key_ids = ["${sakuracloud_ssh_key.mykey.id}"] | |
disable_pw_auth = true | |
zone = "is1b" | |
} | |
################################################## | |
# スイッチ(石狩第1):ブリッジに接続 | |
################################################## | |
resource "sakuracloud_switch" "sw01"{ | |
name = "sw01" | |
zone = "is1a" | |
bridge_id = "${sakuracloud_bridge.br.id}" | |
} | |
################################################## | |
# スイッチ(石狩第2):ブリッジに接続 | |
################################################## | |
resource "sakuracloud_switch" "sw02"{ | |
name = "sw02" | |
zone = "is1b" | |
bridge_id = "${sakuracloud_bridge.br.id}" | |
} | |
################################################## | |
# ブリッジ(ゾーン間の接続) | |
################################################## | |
resource "sakuracloud_bridge" "br"{ | |
name = "br01" | |
zone = "is1a" | |
} | |
/************************ | |
SSHKey | |
************************/ | |
resource "sakuracloud_ssh_key" "mykey" { | |
name = "key" | |
public_key = "${file("./id_rsa.pub")}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment