[root@myeks2-bastion-EC2 seo]# [root@myeks2-bastion-EC2 seo]# ls 1backup create_key.tf main.tf terraform_key.pem terraform.tfstate terraform.tfstate.backup [root@myeks2-bastion-EC2 seo]# [root@myeks2-bastion-EC2 seo]# more *.tf :::::::::::::: create_key.tf :::::::::::::: # RSA key of size 4096 bits resource "tls_private_key" "terraform_make_key" { algorithm = "RSA" rsa_bits = 4096 } resource "aws_key_pair" "terraform_make_keypair" { key_name = "terraform_key" public_key=tls_private_key.terraform_make_key.public_key_openssh } resource "local_file" "terraform_downloads_key" { filename = "terraform_key.pem" content = tls_private_key.terraform_make_key.private_key_pem } :::::::::::::: main.tf :::::::::::::: provider "aws" { region = "ap-northeast-2" } resource "aws_instance" "example" { ami = "ami-0c031a79ffb01a803" instance_type = "t3.medium" key_name = aws_key_pair.terraform_make_keypair.key_name vpc_security_group_ids = [aws_security_group.instance.id] user_data = <<-EOF #!/bin/bash echo "Hello, T101 Study" > index.html nohup busybox httpd -f -p 80 & EOF tags = { Name = "aws-tts-seou-web02" } } resource "aws_security_group" "instance" { name = var.security_group_name ingress { from_port = 22 to_port = 22 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] } } variable "security_group_name" { description = "The name of the security group" type = string default = "terraform-aws-tts-seoul-web02-sg" } output "public_ip" { value = aws_instance.example.public_ip description = "The public IP of the Instance" } [root@myeks2-bastion-EC2 seo]