CMDB-Server/ec2-user/deploy/userXX/step1/main.tf

29 lines
1.2 KiB
Terraform
Raw Normal View History

2025-07-03 17:24:43 +09:00
## プロバイダの指定
provider "aws" {
region = "ap-northeast-1" # 東京リージョン
}
# EC2インスタンスの作成(Web1)
resource "aws_instance" "handson_web1" {
ami = "ami-0f75d1a8c9141bd00" # AMIの指定 (AmazonLinux2023)
instance_type = "t2.micro" # インスタンスタイプの指定
availability_zone = "ap-northeast-1a" # アベイラビリティーゾーンの指定
subnet_id = "subnet-05b27965d35bb735f" # 既存サブネットの指定
vpc_security_group_ids = [
"sg-0d92c039f14e9f825", # 既存セキュリティグループの指定
]
key_name = "jenkins-keypair" # 指定キーペアの指定
tags = {
Name = "userXX_handson_web1" # タグ名の指定
}
# 初期セットアップ
user_data = <<-EOF
#! /bin/bash
sudo yum update
sudo yum install -y httpd git
sudo chkconfig httpd on
sudo service httpd start
echo "<h1>hello world</h1>" | sudo tee /var/www/html/index.html
echo "10.1.5.19 aws-handson-gitea.com" | sudo tee -a /etc/hosts
EOF
}