728x90
1. EC2 웹 서버 배포
- init.sh
#!/bin/bash
apt-get update
apt-get install -y apache2
echo "hoon-test-web" > /var/www/html/index.html
systemctl start apache2
systemctl enable apache2
- main.tf
provider "aws" {
region = "ap-northeast-2"
}
data "template_file" "init-sh" {
template = file("init.sh")
}
resource "aws_instance" "test-web-srv" {
ami = "ami-0e73d7a01dba794a4"
instance_type = "t2.micro"
associate_public_ip_address = true
vpc_security_group_ids = [aws_security_group.web-sg.id]
tags = {
Name = "test-web-srv"
}
user_data = data.template_file.init-sh.rendered
}
resource "aws_security_group" "web-sg" {
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = -1
cidr_blocks = ["0.0.0.0/0"]
}
}
output "public_ip" {
value = aws_instance.test-web-srv.public_ip
}
728x90
'Cloud > Terraform' 카테고리의 다른 글
[T101] Terraform 101 Study 실습(3) - AWS 자원 생성 (0) | 2024.07.01 |
---|---|
[T101] Terraform 101 Study 실습(2) - precondition (0) | 2024.07.01 |
[T101] Terraform 101 Study 3주차 (2) (0) | 2024.06.30 |
[T101] Terraform 101 Study 3주차 (1) (0) | 2024.06.26 |
[T101] Terraform 101 Study 2주차 (3) (0) | 2024.06.22 |