以前作成した環境をteraformで構築する。
下記が作成した際の記事である。
https://qiita.com/Cache-Hit/items/994a0095e8965912e677
- 下記の構成を複製する。
カスタムイメージを指定、teraformで複製する。
注意点としてはカスタムイメージを作成すると一時的にサーバと接続ができなくなる。
Teraformで作成する目的
上記構成図から下記を作成する。
- コンパートメント
- VCN
- Fauld Domain
- サブネット
- ルート・ルール
- セキュリティルール
- Webサーバ(表記Server)とBase Database(表記Database)を構築する。
その後、カスタムイメージからVPNサーバを作成し、インターネットゲートウェイなどは手作業で作成、
接続しコンテンツを確認して終了とする。
WebサーバとDBサーバはプライベートサブネットにあり、
ローカルIP指定でWordpressのページが見られればWebサーバとDBの接続ができていることを確認する。
Teraformのダウンロード
下記サイトからインストールする
Windows10を利用するため、該当のファイルをダウンロードする。
ダウンロードしたのち、指定の保管先に移す。
今回は C:\Windows\配下にteraformというディレクトリを作り、その中に格納した。
C:\Users\81803>dir C:\Windows\teraform\
ドライブ C のボリューム ラベルがありません。
ボリューム シリアル番号は 7695-EEAF です
C:\Windows\teraform のディレクトリ
2024/04/19 11:27 <DIR> .
2024/04/19 11:27 <DIR> ..
2024/04/19 11:11 85,470,896 terraform.exe
1 個のファイル 85,470,896 バイト
2 個のディレクトリ 38,652,416,000 バイトの空き領域
バージョン確認
ディレクトリ移動
C:\Users\81803>cd C:\Windows\teraform\
C:\Windows\teraform>
バージョン確認
C:\Windows\teraform>terraform -v
Terraform v1.8.1
on windows_386
terraformコマンドを実行
C:\Windows\teraform>terraform
Usage: terraform [global options] <subcommand> [args]
The available commands for execution are listed below.
The primary workflow commands are given first, followed by
less common or more advanced commands.
Main commands:
init Prepare your working directory for other commands
validate Check whether the configuration is valid
plan Show changes required by the current configuration
apply Create or update infrastructure
destroy Destroy previously-created infrastructure
All other commands:
console Try Terraform expressions at an interactive command prompt
fmt Reformat your configuration in the standard style
force-unlock Release a stuck lock on the current workspace
get Install or upgrade remote Terraform modules
graph Generate a Graphviz graph of the steps in an operation
import Associate existing infrastructure with a Terraform resource
login Obtain and save credentials for a remote host
logout Remove locally-stored credentials for a remote host
metadata Metadata related commands
output Show output values from your root module
providers Show the providers required for this configuration
refresh Update the state to match remote systems
show Show the current state or a saved plan
state Advanced state management
taint Mark a resource instance as not fully functional
test Execute integration tests for Terraform modules
untaint Remove the 'tainted' state from a resource instance
version Show the current Terraform version
workspace Workspace management
Global options (use these before the subcommand, if any):
-chdir=DIR Switch to a different working directory before executing the
given subcommand.
-help Show this help output, or the help for a specified subcommand.
-version An alias for the "version" subcommand.