paint-brush
IaC のロックを解除するパート 3: 初めての Terraform デプロイメント!@chrisray
490 測定値
490 測定値

IaC のロックを解除するパート 3: 初めての Terraform デプロイメント!

Chris Ray55m2023/09/30
Read on Terminal Reader

長すぎる; 読むには

Terraform でビルドするためのセットアップは難しいです。パート 3 では、本題に取り掛かり、Terraform を使用して AWS に Splunk サーバーを構築します。
featured image - IaC のロックを解除するパート 3: 初めての Terraform デプロイメント!
Chris Ray HackerNoon profile picture
0-item


楽しもう!

正直に言って、IaC のような技術的なものを 3 部構成のシリーズで扱うのは難しい場合があります。あなたもこれまで何度かこの状況から引き離されたことがあるはずです。パート 3 に進むのはエキサイティングです。楽しいパートが始まるのはそこからです。ゴムが路面に着地する瞬間です。ギリギリで耐えられると感じていて、この部分を最後までやり遂げることができるか疑問がある場合は、ほとんどの人も同じように感じていることを知っておくとよいでしょう。これほど抽象的な内容を最初の試行 (または 3 回目の試行) で成功させる人はほとんどいません。本題に入りましょう!

この最初の展開では、誰もが名前で知っている Splunk を使用してみましょう。このスクリプトでは、Splunk がすでにインストールされ構成されている単一サーバーをデプロイします。これには、 Amazon Machine Image (AMI) が使用されます。選択できる AMI は多数あります。 Windows や Linux など、異なる OS のものもあります。 Ubuntu、CentOS などの Linux のさまざまなディストリビューションもあれば、このような事前に構築されたアプリケーションもあります。


Splunk EC2サーバー (「Splunk インスタンス」) を起動し、パブリック IP アドレスのみが TCP ポート 8000 (デフォルトの Splunk UI ポート) に到達できるようにネットワーク アクセスを作成し、シンプルな Terraform でこれらすべてを破棄します。完了したらコマンドを実行します。


各部分を簡単に確認できるように、単一のterraformファイル (main.tf) をいくつかの小さなチャンクに分割します。そして最後に、実行できるようにすべてをまとめます。

Terraform ランドで自分で物事を解決する方法

始める前に、ここで検討しなかった質問に対する答えを見つけるためにどこに行けばよいかを知っておくことが重要です。例として、Terraform で構築を開始したとき、「引数をどうやって知ることができるのでしょう (これは、EC2 インスタンス内の仮想マシンのタイプやセキュリティ グループで許可されるイングレス プロトコルなど、リソースを定義する方法です)」と疑問に思いました。この例、およびここで答えられていない他の多くの質問については、 Terraform レジストリにアクセスして、利用可能なプロバイダー、リソース、引数、および構文について詳しく知ることができます。


たとえば、レジストリで「セキュリティ グループ」リソース (このチュートリアルで使用します) を見つけてから、 [入力] タブに移動して、使用可能なすべての引数 (参考までに、変数と呼ばれています) を表示します。リソースを構成するときに許可されます。さて...回り道は完了し、最初の TF デプロイメントの構成に移ります。

Terraform を使用した構築

最初のステップでは、使用するプロバイダーを定義する必要があります。 AWS で作業しているため、プロバイダーは「AWS」になります。ここでも、処理する領域を定義します。


 provider "aws" { region = "us-west-1" }


覚えていると思いますが、仮想マシン (EC2) には Amazing Machine Image (AMI) を使用するつもりだと言いました。ここでは、Terraform の「data」キーワードを使用して、リソース「aws_ami」を検索します。さらに、この検索の一部として返されるデータには「Splunk」という名前を付けます。これは、コード内の他の場所でこのデータを参照できるようにするためです (後で覚えておいてください)...


何かを検索するには、検索結果を検索したいもののみに制限する何らかの方法が必要であるため、フィルター キーワードを使用し、それに 2 つの引数「名前」と「値」を渡します。ここでは、「aws_ami」の検索に、フィールド「name」で「Splunk」で始まるものを検索するよう指示しています。これはより具体的に調整する必要があるかもしれませんが、この場合、このフィルターは適切です。


 data "aws_ami" "splunk" { most_recent = true filter { name = "name" values = ["splunk*"] } }


AWS では、リソースへのネットワーク アクセスは、多くの場合、「セキュリティ グループ」と呼ばれるリソースを通じて制御されます。この例では、私の IP アドレス (または、このスクリプトを作成するときはあなたの IP アドレス) からの TCP ポート 8000 の受信 (「イングレス」) を許可するセキュリティ グループを使用します。機密情報のないプライベート アカウントで Splunk を使用しているため、アウトバウンド (「出口」) の通信を許可します。ただし、これが運用環境の場合は、ベスト プラクティスに従うために、必要な IP とポートの範囲を特定し、それらのみにアクセスを制限する必要があります。


プロトコルと「cidr_blocks」を含むイングレスパラメータを定義していることに注意してください。ここで設定を誤ると、誤って環境をより広範なインターネットに開放してしまう可能性があるため、これは重要です。AWS 環境に追加のネットワーク セキュリティを提供する方法について知りたい場合は、お知らせください。Application Load Balancerの追加に関するチュートリアルを作成できます ( ALB) をこの構成に追加して、追加のセキュリティ機能を提供します。


 resource "aws_security_group" "splunksg" { name = "SplunkSecGroup" description = "Allow-on-port-8000" ingress { from_port = 8000 to_port = 8000 protocol = "tcp" cidr_blocks = ["YOUR_IP_HERE"] # Replace 'YOUR_PUBLIC_HERE' with your public IP address } egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } }


最後に、私たちがここにいる理由は、Splunk を実行する仮想マシンです。 Terraform コードの他のすべての部分の場合と同様に、まずリソース (この場合は「aws_instance」) を定義し、それに「splunk_ec2」という名前を付けます。次に、引数を使用してその下の他のパラメーターを定義します。


上で「aws_ami」で最新の「Splunk*」AMI を検索するために使用した「data」キーワードを覚えていますか? 「Splunk」という名前があります。ここで、EC2 インスタンス設定で、そのクエリに含まれるデータを参照できます。 「ami」引数を使用し、「data.aws_ami.splunk.id」にあるものと等しいことを示すことで参照します。これは理解するのに非常に重要な概念なので、2 分間かけて詳しく説明しましょう。


  1. data.aws_ami. 」は、上で作成したコード ブロック内の data キーワードを参照しています。
  2. splunk.id 」は、このデータに付けた名前「Splunk」を参照し、最後の部分「id」は、「data」クエリによって返される AMI ID を参照します。 AMI ID は人間には覚えにくい文字列ですが、一意であり、マシンにとっては使いやすいものです。


下に進むと、この EC2 の security_group が、上で定義した「splunksg」セキュリティ グループであると言います。これは、AMI の「データ」命名と同じロジックを使用します。 IE では、リソース名、定義したオブジェクト名、そして変数「.name」で始まり、これも「 SplunkSecGroup 」として定義しました。また、これには t2.micro の instance_type を使用できることにも注意してください。動作しますが、非常に遅いので、t2.medium を選択します。


最後に、このインスタンスにタグを適用します。これは、AWS アカウントが大きくなり、アセットの追跡が難しくなった場合に役立ちます。


 resource "aws_instance" "splunk_ec2" { ami = data.aws_ami.splunk.id instance_type = "t2.medium" security_groups = [aws_security_group.splunksg.name] tags = { Name = "SplunkInstance" } }


さて、この部分に進んでこれをファイル システムに放り込んで実行し、チュートリアルを「完了」したので世界に安心することもできたかもしれませんが、それはやめてください。そんなに怠惰にならないでください。私と一緒に読んで構築するために時間を割くことの価値は、間違いを犯す痛みと、それらの間違いを修正する喜びにあります。


すべてをまとめると、次のような Terraform スクリプトが完成します。


 provider "aws" { region = "us-west-1" } data "aws_ami" "splunk" { most_recent = true filter { name = "name" values = ["splunk*"] } } resource "aws_security_group" "splunksg" { name = "SplunkSecGroup" description = "Allow-on-port-8000" ingress { from_port = 8000 to_port = 8000 protocol = "tcp" cidr_blocks = ["YOUR_PUBLIC_HERE/32"] # Replace 'YOUR_PUBLIC_HERE' with your public IP address } egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } } resource "aws_instance" "splunk_ec2" { ami = data.aws_ami.splunk.id instance_type = "t2.medium" security_groups = [aws_security_group.splunksg.name] tags = { Name = "SplunkInstance" } }


わお、見てください、コードは 43 行です。大変そうに思えますが、これで完了です。更新したり、作成したり、破棄したり、共有したりできます。


この時点で、 IaCのロック解除のパート 2でこれを機能させるために必要なすべての要素をすでにセットアップしているため、必要なのは、ファイルを正しい拡張子 ( main.tf を使用しましょう) で保存することだけです。


CMD または PowerShell を管理者として開き (CTRL+SHIFT+CLICK または右クリックして「実行…」)、「CD」を選択するか、作成したばかりのファイル (main.tf) と同じ場所にディレクトリを変更して、次のコマンドを実行します。コマンド:

Terraform INIT


 c:\Users\Chris\Documents\Projects\terraform\YT single server arch AWS>terraform init Initializing the backend... Initializing provider plugins... - Reusing previous version of hashicorp/aws from the dependency lock file - Using previously-installed hashicorp/aws v5.1.0 Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.


Terraform initそのディレクトリ内の Terraform を初期化します。これは基本的に Terraform を起動することになります。


テラフォーム計画


c:\Users\Chris\Documents\Projects\terraform\YT single server arch AWS>terraform plan Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_instance.splunk_server will be created + resource "aws_instance" "splunk_server" { + ami = "ami-0b5cb59327b8d7e1f" + arn = (known after apply) + associate_public_ip_address = true + availability_zone = (known after apply) + cpu_core_count = (known after apply) + cpu_threads_per_core = (known after apply) + disable_api_stop = (known after apply) + disable_api_termination = (known after apply) + ebs_optimized = (known after apply) + get_password_data = false + host_id = (known after apply) + host_resource_group_arn = (known after apply) + iam_instance_profile = (known after apply) + id = (known after apply) + instance_initiated_shutdown_behavior = (known after apply) + instance_state = (known after apply) + instance_type = "t3.large" + ipv6_address_count = (known after apply) + ipv6_addresses = (known after apply) + key_name = (known after apply) + monitoring = (known after apply) + outpost_arn = (known after apply) + password_data = (known after apply) + placement_group = (known after apply) + placement_partition_number = (known after apply) + primary_network_interface_id = (known after apply) + private_dns = (known after apply) + private_ip = (known after apply) + public_dns = (known after apply) + public_ip = (known after apply) + secondary_private_ips = (known after apply) + security_groups = (known after apply) + source_dest_check = true + subnet_id = (known after apply) + tags_all = (known after apply) + tenancy = (known after apply) + user_data = (known after apply) + user_data_base64 = (known after apply) + user_data_replace_on_change = false + vpc_security_group_ids = (known after apply) + capacity_reservation_specification { + capacity_reservation_preference = (known after apply) + capacity_reservation_target { + capacity_reservation_id = (known after apply) + capacity_reservation_resource_group_arn = (known after apply) } } + cpu_options { + amd_sev_snp = (known after apply) + core_count = (known after apply) + threads_per_core = (known after apply) } + ebs_block_device { + delete_on_termination = (known after apply) + device_name = (known after apply) + encrypted = (known after apply) + iops = (known after apply) + kms_key_id = (known after apply) + snapshot_id = (known after apply) + tags = (known after apply) + throughput = (known after apply) + volume_id = (known after apply) + volume_size = (known after apply) + volume_type = (known after apply) } + enclave_options { + enabled = (known after apply) } + ephemeral_block_device { + device_name = (known after apply) + no_device = (known after apply) + virtual_name = (known after apply) } + maintenance_options { + auto_recovery = (known after apply) } + metadata_options { + http_endpoint = (known after apply) + http_put_response_hop_limit = (known after apply) + http_tokens = (known after apply) + instance_metadata_tags = (known after apply) } + network_interface { + delete_on_termination = (known after apply) + device_index = (known after apply) + network_card_index = (known after apply) + network_interface_id = (known after apply) } + private_dns_name_options { + enable_resource_name_dns_a_record = (known after apply) + enable_resource_name_dns_aaaa_record = (known after apply) + hostname_type = (known after apply) } + root_block_device { + delete_on_termination = (known after apply) + device_name = (known after apply) + encrypted = (known after apply) + iops = (known after apply) + kms_key_id = (known after apply) + tags = (known after apply) + throughput = (known after apply) + volume_id = (known after apply) + volume_size = (known after apply) + volume_type = (known after apply) } } # aws_security_group.splunk_server will be created + resource "aws_security_group" "splunk_server" { + arn = (known after apply) + description = "Managed by Terraform" + egress = (known after apply) + id = (known after apply) + ingress = [ + { + cidr_blocks = [ + "[redacted]/32", ] + description = "" + from_port = 22 + ipv6_cidr_blocks = [] + prefix_list_ids = [] + protocol = "tcp" + security_groups = [] + self = false + to_port = 22 }, + { + cidr_blocks = [ + "[redacted]/32", ] + description = "" + from_port = 8000 + ipv6_cidr_blocks = [] + prefix_list_ids = [] + protocol = "tcp" + security_groups = [] + self = false + to_port = 8000 }, ] + name = (known after apply) + name_prefix = "splunk-group" + owner_id = (known after apply) + revoke_rules_on_delete = false + tags_all = (known after apply) + vpc_id = (known after apply) } # aws_subnet.splunk_server will be created + resource "aws_subnet" "splunk_server" { + arn = (known after apply) + assign_ipv6_address_on_creation = false + availability_zone = (known after apply) + availability_zone_id = (known after apply) + cidr_block = "172.31.1.0/28" + enable_dns64 = false + enable_resource_name_dns_a_record_on_launch = false + enable_resource_name_dns_aaaa_record_on_launch = false + id = (known after apply) + ipv6_cidr_block_association_id = (known after apply) + ipv6_native = false + map_public_ip_on_launch = false + owner_id = (known after apply) + private_dns_hostname_type_on_launch = (known after apply) + tags_all = (known after apply) + vpc_id = "vpc-[redacted]" } Plan: 3 to add, 0 to change, 0 to destroy. ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now. c:\Users\Chris\Documents\Projects\terraform\YT single server arch AWS>


それが完了したら、実際にクラウド環境に変更を加えずに、 Terraform ビルドが何を行うかを確認する方法であるterraform planを実行することをお勧めします。この出力を注意深く確認し、表示される内容が期待したものと一致していることを確認してください。

Terraform の適用


c:\Users\Chris\Documents\Projects\terraform\YT single server arch AWS>terraform apply Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_instance.splunk_server will be created + resource "aws_instance" "splunk_server" { + ami = "ami-0b5cb59327b8d7e1f" + arn = (known after apply) + associate_public_ip_address = true + availability_zone = (known after apply) + cpu_core_count = (known after apply) + cpu_threads_per_core = (known after apply) + disable_api_stop = (known after apply) + disable_api_termination = (known after apply) + ebs_optimized = (known after apply) + get_password_data = false + host_id = (known after apply) + host_resource_group_arn = (known after apply) + iam_instance_profile = (known after apply) + id = (known after apply) + instance_initiated_shutdown_behavior = (known after apply) + instance_state = (known after apply) + instance_type = "t3.large" + ipv6_address_count = (known after apply) + ipv6_addresses = (known after apply) + key_name = (known after apply) + monitoring = (known after apply) + outpost_arn = (known after apply) + password_data = (known after apply) + placement_group = (known after apply) + placement_partition_number = (known after apply) + primary_network_interface_id = (known after apply) + private_dns = (known after apply) + private_ip = (known after apply) + public_dns = (known after apply) + public_ip = (known after apply) + secondary_private_ips = (known after apply) + security_groups = (known after apply) + source_dest_check = true + subnet_id = (known after apply) + tags_all = (known after apply) + tenancy = (known after apply) + user_data = (known after apply) + user_data_base64 = (known after apply) + user_data_replace_on_change = false + vpc_security_group_ids = (known after apply) + capacity_reservation_specification { + capacity_reservation_preference = (known after apply) + capacity_reservation_target { + capacity_reservation_id = (known after apply) + capacity_reservation_resource_group_arn = (known after apply) } } + cpu_options { + amd_sev_snp = (known after apply) + core_count = (known after apply) + threads_per_core = (known after apply) } + ebs_block_device { + delete_on_termination = (known after apply) + device_name = (known after apply) + encrypted = (known after apply) + iops = (known after apply) + kms_key_id = (known after apply) + snapshot_id = (known after apply) + tags = (known after apply) + throughput = (known after apply) + volume_id = (known after apply) + volume_size = (known after apply) + volume_type = (known after apply) } + enclave_options { + enabled = (known after apply) } + ephemeral_block_device { + device_name = (known after apply) + no_device = (known after apply) + virtual_name = (known after apply) } + maintenance_options { + auto_recovery = (known after apply) } + metadata_options { + http_endpoint = (known after apply) + http_put_response_hop_limit = (known after apply) + http_tokens = (known after apply) + instance_metadata_tags = (known after apply) } + network_interface { + delete_on_termination = (known after apply) + device_index = (known after apply) + network_card_index = (known after apply) + network_interface_id = (known after apply) } + private_dns_name_options { + enable_resource_name_dns_a_record = (known after apply) + enable_resource_name_dns_aaaa_record = (known after apply) + hostname_type = (known after apply) } + root_block_device { + delete_on_termination = (known after apply) + device_name = (known after apply) + encrypted = (known after apply) + iops = (known after apply) + kms_key_id = (known after apply) + tags = (known after apply) + throughput = (known after apply) + volume_id = (known after apply) + volume_size = (known after apply) + volume_type = (known after apply) } } # aws_security_group.splunk_server will be created + resource "aws_security_group" "splunk_server" { + arn = (known after apply) + description = "Managed by Terraform" + egress = (known after apply) + id = (known after apply) + ingress = [ + { + cidr_blocks = [ + "[redacted]/32", ] + description = "" + from_port = 22 + ipv6_cidr_blocks = [] + prefix_list_ids = [] + protocol = "tcp" + security_groups = [] + self = false + to_port = 22 }, + { + cidr_blocks = [ + "[redacted]/32", ] + description = "" + from_port = 8000 + ipv6_cidr_blocks = [] + prefix_list_ids = [] + protocol = "tcp" + security_groups = [] + self = false + to_port = 8000 }, ] + name = (known after apply) + name_prefix = "splunk-group" + owner_id = (known after apply) + revoke_rules_on_delete = false + tags_all = (known after apply) + vpc_id = (known after apply) } # aws_subnet.splunk_server will be created + resource "aws_subnet" "splunk_server" { + arn = (known after apply) + assign_ipv6_address_on_creation = false + availability_zone = (known after apply) + availability_zone_id = (known after apply) + cidr_block = "172.31.1.0/28" + enable_dns64 = false + enable_resource_name_dns_a_record_on_launch = false + enable_resource_name_dns_aaaa_record_on_launch = false + id = (known after apply) + ipv6_cidr_block_association_id = (known after apply) + ipv6_native = false + map_public_ip_on_launch = false + owner_id = (known after apply) + private_dns_hostname_type_on_launch = (known after apply) + tags_all = (known after apply) + vpc_id = "vpc-[redacted]" } Plan: 3 to add, 0 to change, 0 to destroy. Changes to Outputs: + splunk_server_public_ip = (known after apply) Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes aws_subnet.splunk_server: Creating... aws_security_group.splunk_server: Creating... aws_subnet.splunk_server: Creation complete after 1s [id=subnet-053c39ae3dcc97112] aws_security_group.splunk_server: Creation complete after 2s [id=sg-03bf97ed2524e4aee] aws_instance.splunk_server: Creating... aws_instance.splunk_server: Still creating... [10s elapsed] aws_instance.splunk_server: Creation complete after 13s [id=i-050c4bad2d2a6ba93] Apply complete! Resources: 3 added, 0 changed, 0 destroyed. c:\Users\Chris\Documents\Projects\terraform\YT single server arch AWS>


最後に、 terraform applyを実行するとコードが取得され、AWS アカウントに適用されます。これには数秒から 1 分ほどかかる場合がありますが、完了すると成功メッセージが表示されます。エラーが発生した場合は、エラーを注意深く確認してください。 Terraform エラーは通常、高品質であり、理解するために (もしあれば) 多くの調査を必要としないヒントを提供します。

Splunk ログイン

この時点で、Splunk サーバーにログインできる状態になっていると考えられます (Splunk で UI が使用可能になるまでに 1 ~ 2 分かかります)。 Splunk にログインするには、次の 3 つの情報が必要です。

  1. ユーザー名 ( admin
  2. パスワード ( SPLUNK-<instanceid>
  3. AWS のこの EC2 インスタンスの IP アドレスとポート (例: http://10.10.10.10:8000 )


Terraform から IP アドレスを抽出してスクリプトの出力として配信したり、 AWS CLIを使用してこの情報を収集したりすることは可能ですが、ここではわかりやすくするためにそれを行いませんでした。 IP アドレスとインスタンス ID を取得するには、AWS コンソールにログインする必要があります。


サービス メニューで EC2 を検索し、[EC2]、[インスタンス (実行中)] の順にクリックします。このビューには、実行中の EC2 インスタンスのリストが表示されます。他に面白いことが起こっていない限り、これが 1 つだけであるはずです。

正しいインスタンス (または唯一のインスタンス) をクリックすると、このビューの左上に「インスタンス ID」が表示されます。これは左側のコピー ボタンをクリックしてコピーでき、右側にはインスタンス ID が表示されます。 IPアドレス。


その IP アドレスを取得し、選択したブラウザを使用してhttp://[instanceIP]:8000と入力し、Enter キーを押します。 Splunk のログインが表示されるはずです。表示されない場合は、さらに 1 ~ 2 分待ちます。Splunk の初回起動には (文字通り) 2 ~ 3 分かかります。 username = adminpassword = SPLUNK-[instanceID]を覚えておいてください。


テラフォームデストロイ

構築するのは素晴らしく、新しいことを学ぶのは楽しいものです。楽しみが終わったらクラウド リソースをオフにするのを忘れるのは最悪です。 Terraform destroy は、terraform apply の逆を実行します。 terraform ファイルで指定されたインフラストラクチャを破棄します。 terraform destroy を使用するには (今すぐ実行する必要があります)、コマンド ラインに戻ってterraform destroyと入力します。 terraform destroy の実行が成功すると、Splunk UI が表示されない (おそらく切断されたことが通知されます) ことと、destroy コマンドの出力によってわかります。


 c:\Users\Chris\Documents\Projects\terraform\YT single server arch AWS>terraform destroy aws_subnet.splunk_server: Refreshing state... [id=subnet-053c39ae3dcc97112] aws_security_group.splunk_server: Refreshing state... [id=sg-03bf97ed2524e4aee] aws_instance.splunk_server: Refreshing state... [id=i-050c4bad2d2a6ba93] Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: - destroy Terraform will perform the following actions: # aws_instance.splunk_server will be destroyed - resource "aws_instance" "splunk_server" { - ami = "ami-0b5cb59327b8d7e1f" -> null - arn = "arn:aws:ec2:us-west-2:625982356191:instance/i-050c4bad2d2a6ba93" -> null - associate_public_ip_address = true -> null - availability_zone = "us-west-2b" -> null - cpu_core_count = 1 -> null - cpu_threads_per_core = 2 -> null - disable_api_stop = false -> null - disable_api_termination = false -> null - ebs_optimized = false -> null - get_password_data = false -> null - hibernation = false -> null - id = "i-050c4bad2d2a6ba93" -> null - instance_initiated_shutdown_behavior = "stop" -> null - instance_state = "running" -> null - instance_type = "t3.large" -> null - ipv6_address_count = 0 -> null - ipv6_addresses = [] -> null - monitoring = false -> null - placement_partition_number = 0 -> null - primary_network_interface_id = "eni-059f68aecb53fc4bb" -> null - private_dns = "ip-172-31-1-11.us-west-2.compute.internal" -> null - private_ip = "172.31.1.11" -> null - public_dns = "[redacted].us-west-2.compute.amazonaws.com" -> null - public_ip = "[redacted]" -> null - secondary_private_ips = [] -> null - security_groups = [ - "splunk-group20230929124520702900000001", ] -> null - source_dest_check = true -> null - subnet_id = "subnet-053c39ae3dcc97112" -> null - tags = {} -> null - tags_all = {} -> null - tenancy = "default" -> null - user_data_replace_on_change = false -> null - vpc_security_group_ids = [ - "sg-03bf97ed2524e4aee", ] -> null - capacity_reservation_specification { - capacity_reservation_preference = "open" -> null } - cpu_options { - core_count = 1 -> null - threads_per_core = 2 -> null } - credit_specification { - cpu_credits = "unlimited" -> null } - enclave_options { - enabled = false -> null } - maintenance_options { - auto_recovery = "default" -> null } - metadata_options { - http_endpoint = "enabled" -> null - http_put_response_hop_limit = 1 -> null - http_tokens = "optional" -> null - instance_metadata_tags = "disabled" -> null } - private_dns_name_options { - enable_resource_name_dns_a_record = false -> null - enable_resource_name_dns_aaaa_record = false -> null - hostname_type = "ip-name" -> null } - root_block_device { - delete_on_termination = true -> null - device_name = "/dev/xvda" -> null - encrypted = false -> null - iops = 100 -> null - tags = {} -> null - throughput = 0 -> null - volume_id = "vol-0e283fb892f5fe38a" -> null - volume_size = 20 -> null - volume_type = "gp2" -> null } } # aws_security_group.splunk_server will be destroyed - resource "aws_security_group" "splunk_server" { - arn = "arn:aws:ec2:us-west-2:625982356191:security-group/sg-03bf97ed2524e4aee" -> null - description = "Managed by Terraform" -> null - egress = [] -> null - id = "sg-03bf97ed2524e4aee" -> null - ingress = [ - { - cidr_blocks = [ - "[redacted]/32", ] - description = "" - from_port = 22 - ipv6_cidr_blocks = [] - prefix_list_ids = [] - protocol = "tcp" - security_groups = [] - self = false - to_port = 22 }, - { - cidr_blocks = [ - "[redacted]/32", ] - description = "" - from_port = 8000 - ipv6_cidr_blocks = [] - prefix_list_ids = [] - protocol = "tcp" - security_groups = [] - self = false - to_port = 8000 }, ] -> null - name = "splunk-group20230929124520702900000001" -> null - name_prefix = "splunk-group" -> null - owner_id = "625982356191" -> null - revoke_rules_on_delete = false -> null - tags = {} -> null - tags_all = {} -> null - vpc_id = "vpc-002c2876364b2b282" -> null } # aws_subnet.splunk_server will be destroyed - resource "aws_subnet" "splunk_server" { - arn = "arn:aws:ec2:us-west-2:625982356191:subnet/subnet-053c39ae3dcc97112" -> null - assign_ipv6_address_on_creation = false -> null - availability_zone = "us-west-2b" -> null - availability_zone_id = "usw2-az1" -> null - cidr_block = "172.31.1.0/28" -> null - enable_dns64 = false -> null - enable_lni_at_device_index = 0 -> null - enable_resource_name_dns_a_record_on_launch = false -> null - enable_resource_name_dns_aaaa_record_on_launch = false -> null - id = "subnet-053c39ae3dcc97112" -> null - ipv6_native = false -> null - map_customer_owned_ip_on_launch = false -> null - map_public_ip_on_launch = false -> null - owner_id = "625982356191" -> null - private_dns_hostname_type_on_launch = "ip-name" -> null - tags = {} -> null - tags_all = {} -> null - vpc_id = "vpc-002c2876364b2b282" -> null } Plan: 0 to add, 0 to change, 3 to destroy. Do you really want to destroy all resources? Terraform will destroy all your managed infrastructure, as shown above. There is no undo. Only 'yes' will be accepted to confirm. Enter a value: yes aws_instance.splunk_server: Destroying... [id=i-050c4bad2d2a6ba93] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 10s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 20s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 30s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 40s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 51s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 1m1s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 1m11s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 1m21s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 1m31s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 1m41s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 1m51s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 2m1s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 2m11s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 2m21s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 2m31s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 2m41s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 2m51s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 3m1s elapsed] aws_instance.splunk_server: Still destroying... [id=i-050c4bad2d2a6ba93, 3m11s elapsed] aws_instance.splunk_server: Destruction complete after 3m14s aws_subnet.splunk_server: Destroying... [id=subnet-053c39ae3dcc97112] aws_security_group.splunk_server: Destroying... [id=sg-03bf97ed2524e4aee] aws_subnet.splunk_server: Destruction complete after 0s aws_security_group.splunk_server: Destruction complete after 0s Destroy complete! Resources: 3 destroyed. c:\Users\Chris\Documents\Projects\terraform\YT single server arch AWS>


このようなモンスターのチュートリアルを最後まで進めるのは簡単ではありません。ここまで到達できたらおめでとうございます!何かを見逃していたら、おそらくそれは申し訳ありません。現時点では、この新しく発見したスキルを試し続ける価値があります。Terraform スクリプトを変更し、ストレージを追加するために EC2 インスタンスに EBS ボリュームを追加します。長期保存用に S3 を追加します。 VM に SSH キー ペアを自動的に追加して、SSH で接続して UI を使用できるようにする方法を見つけます。大切なのは、毎日少しずつでも遊び続けることです。


立ち止まった瞬間が、このスキルをゆっくりと失い始める瞬間です。