paint-brush
IaC 파트 3 잠금 해제: 첫 번째 Terraform 배포!~에 의해@chrisray
490 판독값
490 판독값

IaC 파트 3 잠금 해제: 첫 번째 Terraform 배포!

~에 의해 Chris Ray55m2023/09/30
Read on Terminal Reader
Read this story w/o Javascript

너무 오래; 읽다

Terraform으로 구축하기 위한 설정은 어렵습니다! 3부에서는 사업을 시작하고 Terraform을 사용하여 AWS에서 Splunk 서버를 구축합니다.
featured image - IaC 파트 3 잠금 해제: 첫 번째 Terraform 배포!
Chris Ray HackerNoon profile picture
0-item


좀 즐겨보자!

현실을 직시하자면, IaC와 같은 기술적인 내용에 대한 3부작 시리즈는 어려울 수 있습니다. 나는 지금까지 당신이 이 문제로부터 몇 번이나 멀어졌을 것이라고 확신합니다. 파트 3으로 가는 것은 신나는 일입니다. 이때부터 재미있는 부분이 시작됩니다. 고무가 도로에 닿는 순간입니다. 간신히 버틸 수 있을 것 같고 이 부분을 끝낼 수 있을지 의심스럽다면 대부분의 사람들도 그렇게 느낀다는 사실을 아는 것이 좋을 것입니다. 이처럼 추상적인 작업에 들어가서 첫 번째(또는 세 번째) 시도에 성공하는 경우는 거의 없습니다. 사업을 시작합시다!

첫 번째 배포에서는 우리 모두가 알고 있는 Splunk라는 이름을 사용하겠습니다. 이 스크립트에서는 Splunk가 이미 설치 및 구성된 단일 서버를 배포합니다. 이는 Amazon 머신 이미지 (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)에 AMI(Amazing Machine Image)를 사용하겠다고 말씀드린 적이 있습니다. 여기서는 Terraform "data" 키워드를 사용하여 "aws_ami" 리소스를 검색합니다. 또한 이 검색의 일부로 반환되는 모든 데이터에 "Splunk"라는 이름을 지정합니다. 이는 코드의 다른 곳에서 이 데이터를 참조할 수 있도록 하기 위한 것입니다(나중에 이를 염두에 두십시오)...


무엇이든 검색하려면 검색 결과를 찾고자 하는 항목으로만 제한하는 방법이 필요하므로 필터 키워드를 사용한 다음 "name"과 "value"라는 두 인수를 전달합니다. 여기서는 "name" 필드에서 "Splunk"로 시작하는 항목을 검색하도록 "aws_ami" 검색에 지시합니다. 더 구체적으로 조정해야 할 수도 있지만 이 경우에는 이 필터가 좋습니다.


 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"로 지정한 다음 인수를 사용하여 그 아래에 다른 매개변수를 정의합니다.


위에서 최신 "Splunk*" AMI에 대해 "aws_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에서는 리소스 이름, 우리가 정의한 개체 이름, 그리고 " SplunkSecGroup "으로도 정의한 변수 ".name"으로 시작합니다. 또한 이를 위해 t2.micro의 인스턴스_유형을 사용할 수 있으며, 작동합니다. 속도가 너무 느리기 때문에 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)과 동일한 위치로 변경하고 다음을 실행합니다. 명령:

테라폼 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을 시작하는 것입니다.


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 실행하는 것이 좋습니다. 이 출력을 주의 깊게 검토하고 표시되는 내용이 예상한 내용과 일치하는지 확인하세요.

테라폼 적용


 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에서 UI를 사용할 수 있으려면 1~2분 정도 소요됩니다). Splunk에 로그인하려면 다음 세 가지 정보가 필요합니다.

  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 인스턴스 목록이 표시되며, 다른 재미있는 일이 없는 한 이 인스턴스만 있어야 합니다.

올바른 인스턴스(또는 하나만)를 클릭하면 이 보기에서 왼쪽 상단에 “인스턴스 ID”가 표시됩니다. 이 인스턴스 ID는 왼쪽의 복사 버튼을 클릭하여 복사할 수 있으며 오른쪽에는 인스턴스 ID가 표시됩니다. IP 주소.


해당 IP 주소를 선택하고 선택한 브라우저를 사용하여 http://[instanceIP]:8000 입력한 다음 Enter 키를 누르세요. Splunk 로그인이 표시되어야 합니다. 그렇지 않은 경우 1~2분 정도 기다리십시오. Splunk를 처음 실행하는 데 문자 그대로 2~3분이 걸립니다. username = admin , password = SPLUNK-[instanceID] 기억하세요.


테라폼 파괴

구축하는 것은 훌륭하고 새로운 것을 배우는 것은 재미있습니다. 즐거운 시간을 보낸 후 클라우드 리소스를 끄는 것을 잊어버리는 것은 짜증납니다. Terraform 파괴는 Terraform 적용과 반대로 수행됩니다. 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를 추가하세요. SSH 키 쌍을 VM에 자동으로 추가하여 SSH를 통해 UI를 사용할 수 있는 방법을 알아보세요. 가장 중요한 것은 매일 조금씩이라도 이것을 가지고 계속해서 놀아보는 것입니다.


멈추는 순간부터 이 스킬이 천천히 잃기 시작하는 순간입니다.