Created
September 28, 2021 04:13
-
-
Save yamamoto-febc/4c7881c691be70dc8a48e1a51cdc32f6 to your computer and use it in GitHub Desktop.
Terraformからさくらのクラウドの「IPアドレス設定スクリプト」を利用する例
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 { | |
required_providers { | |
sakuracloud = { | |
source = "sacloud/sakuracloud" | |
version = "2.12.0" | |
} | |
} | |
} | |
# IPアドレス設定用 パブリックスタートアップスクリプト | |
data "sakuracloud_note" "ipaddress" { | |
filter { | |
names = ["IPアドレス設定スクリプト for Ubuntu"] | |
} | |
} | |
# Ubuntu パブリックアーカイブ | |
data "sakuracloud_archive" "ubuntu" { | |
os_type = "ubuntu2004" | |
} | |
# ディスク | |
resource "sakuracloud_disk" "example" { | |
name = "example" | |
source_archive_id = data.sakuracloud_archive.ubuntu.id | |
} | |
# サーバ | |
resource "sakuracloud_server" "example" { | |
name = "example" | |
disks = [sakuracloud_disk.example.id] | |
core = 1 | |
memory = 2 | |
# eth0 | |
network_interface { | |
upstream = "shared" | |
} | |
# eth1 | |
network_interface { | |
upstream = sakuracloud_switch.sw1.id | |
user_ip_address = "192.168.1.1" | |
} | |
# eth2 | |
network_interface { | |
upstream = sakuracloud_switch.sw2.id | |
user_ip_address = "192.168.2.1" | |
} | |
disk_edit_parameter { | |
hostname = "example" | |
disable_pw_auth = true | |
ssh_keys = [file("~/.ssh/id_rsa.pub")] | |
# IPアドレス設定スタートアップスクリプト | |
# variablesでIPアドレスを渡す(詳細は該当スタートアップスクリプトのドキュメントを参照) | |
note { | |
id = data.sakuracloud_note.ipaddress.id | |
variables = { | |
addresses = <<EOT | |
192.168.1.1/24 | |
192.168.2.1/24 | |
EOT | |
} | |
} | |
} | |
} | |
# eth1が接続するスイッチ | |
resource "sakuracloud_switch" "sw1" { | |
name = "for-eth1" | |
} | |
# eth2が接続するスイッチ | |
resource "sakuracloud_switch" "sw2" { | |
name = "for-eth2" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment