forked from opariffazman/aws-modules
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.tf
More file actions
69 lines (56 loc) · 1.58 KB
/
Copy pathmain.tf
File metadata and controls
69 lines (56 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "6.26.0"
}
}
}
provider "aws" {
region = "ap-southeast-1"
profile = "default"
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "my-vpc"
cidr = "10.0.0.0/16"
azs = ["ap-southeast-1a", "ap-southeast-1b"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
tags = {
Terraform = "true"
Environment = "dev"
}
}
module "security_group" {
source = "terraform-aws-modules/security-group/aws"
name = "web-server"
description = "Security group for web-server with HTTP ports open"
vpc_id = module.vpc.vpc_id
ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["http-80-tcp", "ssh-tcp"]
egress_rules = ["all-all"]
}
module "ec2_instance" {
source = "terraform-aws-modules/ec2-instance/aws"
name = "infratify"
instance_type = "t3.micro"
subnet_id = module.vpc.public_subnets[0]
vpc_security_group_ids = [module.security_group.security_group_id]
associate_public_ip_address = true
user_data = <<-EOF
#!/bin/bash
apt update -y
DEBIAN_FRONTEND=noninteractive apt install -y nginx
systemctl start nginx
systemctl enable nginx
echo "<h1>Hello from Terraform Module!</h1>" > /var/www/html/index.html
EOF
}
output "instance_public_ip" {
description = "Public IP of EC2 instance"
value = module.ec2_instance.public_ip
}
output "instance_id" {
description = "EC2 instance ID"
value = module.ec2_instance.id
}