테라폼 파일 내용
resource "aws_instance" "api-a" {
ami = "ami-0233c2d874b811deb" # 이부분은 AWS OS
instance_type = "t2.micro" #인스턴스 스팩
key_name = aws_key_pair.web_admin.key_name #페어키 설정
# vpc_security_group_ids = "sg-09dea36c" #걍 디폴트로 쓸거라서 설정 안해줘도 됨
subnet_id = "subnet-XXXXXX" #사용할 서브넷을 선택해준다
user_data = <<-EOF #여기서부터 유저 데이터 시작 <<-EOF 로 넣어줘서 수정할때 echo로 박는다.
##########################################
#!/bin/bash
echo '[nginx]' >> /etc/yum.repos.d/nginx.repo
echo 'name=nginx repo' >> /etc/yum.repos.d/nginx.repo
echo 'baseurl=http://nginx.org/packages/centos/7/$basearch/' >> /etc/yum.repos.d/nginx.repo
echo 'gpgcheck=0' >> /etc/yum.repos.d/nginx.repo
echo 'enabled=1' >> /etc/yum.repos.d/nginx.repo
#####이후 nginx 설치와 테스트 해볼 것들을 대충 넣어준다.
sudo yum update -y
sudo yum install nginx -y
echo '111111111 to nginx!' > /usr/share/nginx/html/index.html
systemctl enable nginx --now
##########################################
EOF
#태그를 달아준다.
tags = {
Name = "api-a"
}
# 이부분도 쪼금 찾아본 곳인데 퍼블릭 IPv4 주소가 활성화가 안되서찾아 보니 이렇게 설정하면 되더라고함
#아마 VPC 에서 디폴트값으로 활성화나 비 활성화나 그런걸 설정할 수 있는 곳이 있는듯 무튼 보안상은
#associate_public_ip_address = "true" 를 기입해주면서 쓰는게 더 나을듯 함
associate_public_ip_address = "true"
}
terraform plan 결과
+ resource "aws_instance" "api-a" {
+ ami = "ami-0233c2d874b811deb"
+ 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)
+ get_password_data = false
+ host_id = (known after apply)
+ id = (known after apply)
+ instance_initiated_shutdown_behavior = (known after apply)
+ instance_state = (known after apply)
+ instance_type = "t2.micro"
+ ipv6_address_count = (known after apply)
+ ipv6_addresses = (known after apply)
+ key_name = "web_admin"
+ outpost_arn = (known after apply)
+ password_data = (known after apply)
+ placement_group = (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 = "subnet-XXXXXXX"
+ tags = {
+ "Name" = "api-a"
}
+ tags_all = {
+ "Name" = "api-a"
}
+ tenancy = (known after apply)
+ user_data = "d162351a56bffe3933613a0929917be3dcc7b92b"
+ 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)
}
}
+ 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)
}
+ metadata_options {
+ http_endpoint = (known after apply)
+ http_put_response_hop_limit = (known after apply)
+ http_tokens = (known after apply)
}
+ network_interface {
+ delete_on_termination = (known after apply)
+ device_index = (known after apply)
+ network_interface_id = (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' 카테고리의 다른 글
[테라폼] AWS ALB 어플리케이션 로드밸런싱과 HTTPS 리다이렉션 (0) | 2021.07.23 |
---|---|
[테라폼] terraform 기본 개념 (0) | 2021.07.20 |
[테라폼] terraform 우분투 간단 설치 (0) | 2021.07.20 |
AWS에서 정적 웹 사이트 호스팅 만들기 (0) | 2020.09.20 |
AWS에서 웹 애플리케이션 배포하기 (0) | 2020.09.20 |