jenkins-gitops-deploy-ec2 / terraform-dir / instance.tf
instance.tf
Raw
data "aws_ami" "project_ubuntu_ami" {
    most_recent = true
    filter {
        name = "name"
        values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
    }
    owners = ["099720109477"]
}

resource "aws_instance" "project_server" {
    ami = data.aws_ami.project_ubuntu_ami.id
    instance_type = "t2.micro"
    subnet_id = aws_subnet.project_subnet-1.id
    vpc_security_group_ids = [aws_security_group.project_sg.id]
    availability_zone = var.avail_zone
    associate_public_ip_address = true
    key_name = "ansible-demo"
    tags = {
        Name: "${var.env}-server"
    }
    user_data = file("entry-script.sh")
}

output "instance_public_ip" {
  value = aws_instance.project_server.public_ip
}