# yum install -y yum-utils
# yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
# yum -y install terraform
# wget https://releases.hashicorp.com/terraform/1.2.3/terraform_1.2.3_linux_amd64.zip
# wget https://releases.hashicorp.com/terraform/1.4.6/terraform_1.4.6_linux_amd64.zip
# unzip terraform_1.2.3_linux_amd64.zip
# unzip terraform_1.4.6_linux_amd64.zip
# mv terraform /usr/local/bin/
# terraform -version
export AWS_ACCESS_KEY_ID=(your access key id)
export AWS_SECRET_ACCESS_KEY=(your secret access key)
# mkdir tf-test && cd $_
# vi main.tf
provider "aws" {
region = "ap-northeast-2"
}
resource "aws_instance" "example" {
ami = "ami-035da6a0773842f64"
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.instance.id]
user_data = <<-EOF
#!/bin/bash
yum install -y httpd
systemctl enable --now httpd
echo "<h1>example</h1>" > /var/www/html/index.html
EOF
tags = {
Name = "terraform-example"
}
}
resource "aws_security_group" "instance" {
name = var.security_group_name
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
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"]
}
tags = {
Name = "tf-web"
}
}
variable "security_group_name" {
description = "The name of the security group"
type = string
default = "terraform-example-instance"
}
output "public_ip" {
value = aws_instance.example.public_ip
description = "The public IP of the Instance"
}
terraform init # 플랫폼별 plugin 형태의 애플리케이션..?
terraform plan
terraform apply # yes라는 커맨드도 입력해서 실행까지
terraform destroy
main.tf 에서 사용자데이터 수정 (<h1>
부분) 하니까 인스턴스가 ip도 바뀌고 껏다가 다시 켜진다. 근데 까보니까 h1태그 적용안됨
main.tf -> user_data에서 첫줄 EOF 아래에 # cloud-boothook 바꾸고 됨
yum install -y rdate
rdate -s time.bora.net
# mkdir azure_cli && cd $_
# echo -e "[azure-cli]
name=Azure CLI
baseurl=https://packages.microsoft.com/yumrepos/azure-cli
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc" | sudo tee /etc/yum.repos.d/azure-cli.repo
# yum install -y azure-cli