# Using default AWS values for Network
data "aws_vpc" "default" {
- default = true
+ default = true
***REMOVED***
-data "aws_subnets" "default" {
- filter {
- name = "vpc-id"
- values = [data.aws_vpc.default.id]
- ***REMOVED***
+resource "aws_default_subnet" "a" {
+ availability_zone = "us-east-1a"
+***REMOVED***
+
+# Attach IGW as the default route to the subnet
+resource "aws_internet_gateway" "igw" {
+ vpc_id = data.aws_vpc.default.id
***REMOVED***
# Ubuntu linux AMI version
data "aws_ami" "ubuntu" {
- most_recent = true
- owners = ["099720109477"] # Offical Canonical ID
+ most_recent = true
+ owners = ["099720109477"] # Offical Canonical ID
filter {
- name = "name"
- values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
+ name = "name"
+ values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
***REMOVED***
***REMOVED***
# Security group
resource "aws_security_group" "gitweb" {
- name = "${var.project_name***REMOVED***-sg"
- description = "SSH from my IP; HTTP only from CloudFront origin-facing"
- vpc_id = "data.aws_vpc.default.id"
+ name = "${var.project_name***REMOVED***-sg"
+ description = "SSH from my IP; HTTP only from CloudFront origin-facing"
+ vpc_id = data.aws_vpc.default.id
ingress {
- description = "SSH only from my IP"
- from_port = 22
- to_port = 22
- protocol = "tcp"
- cidr_blocks = [var.my_ip_cidr]
+ description = "SSH only from my IP"
+ from_port = 22
+ to_port = 22
+ protocol = "tcp"
+ cidr_blocks = [var.my_ip_cidr]
***REMOVED***
ingress {
***REMOVED***
egress {
- description = "Allow outbound for updates"
- from_port = 0
- to_port = 0
- protocol = "-1"
- cidr_blocks = ["0.0.0.0/0"]
-
- tags {
- Name = "${var.project_name***REMOVED***-sg"
- ***REMOVED***
+ description = "Allow outbound for updates"
+ from_port = 0
+ to_port = 0
+ protocol = "-1"
+ cidr_blocks = ["0.0.0.0/0"]
+ ***REMOVED***
+
+ tags = {
+ Name = "${var.project_name***REMOVED***-sg"
***REMOVED***
***REMOVED***
# EC2 instance
resource "aws_instance" "gitweb" {
- ami = data.aws_ami.ubuntu.id
- instance_type = var.instance_type
- subnet_id = data.aws_subnets.default.ids[0]
- vpc_security_group_ids = [aws_security_group.gitweb.id]
- key_name = var.key_name
+ ami = data.aws_ami.ubuntu.id
+ instance_type = var.instance_type
+ subnet_id = aws_default_subnet.a.id
+ vpc_security_group_ids = [aws_security_group.gitweb.id]
+ key_name = var.key_name
- user_data = file("${path.module/user_data_config.sh***REMOVED***")
+ user_data = file("${path.module***REMOVED***/user_data_config.sh")
- tags {
+ tags = {
Name = "${var.project_name***REMOVED***-ec2"
***REMOVED***
***REMOVED***
# Elastic IP for stability (because of CloudFront)
resource "aws_eip" "gitweb" {
- domanin = "vpc"
- instance = aws_instance.gitweb.id
+ domain = "vpc"
+ instance = aws_instance.gitweb.id
- tags {
+ tags = {
Name = "${var.project_name***REMOVED***-eip"
***REMOVED***
***REMOVED***
# CloudFront distribuition
resource "aws_cloudfront_distribution" "gitweb" {
enabled = true
- is_ipv6_enabeld = true
+ is_ipv6_enabled = true
comment = "GitWeb behind CloudFront (origin restricted)"
origin {
- # CloudFront custom origin can use IP addr directly
- domain_name = aws_eip.gitweb.public_ip
- origin_id = "${var.project_name***REMOVED***-origin"
+ # Using the public DNS of the instance just to be simple,
+ # because it has also a EIP
+ domain_name = aws_eip.gitweb.public_dns
+ origin_id = "${var.project_name***REMOVED***-origin"
custom_origin_config {
- http_port = 80
- https_port = 443
- origin_protocol_policy = "http-only"
- origin_ssl_protocols = ["TLSv1.3"]
+ http_port = 80
+ https_port = 443
+ origin_protocol_policy = "http-only"
+ origin_ssl_protocols = ["TLSv1.2"]
***REMOVED***
***REMOVED***
- default_cache_bahavior {
- target_origin_id = "${var.project_name***REMOVED***-origin"
- viewer_protocol_policy = "redirect-to-https"
+ default_cache_behavior {
+ target_origin_id = "${var.project_name***REMOVED***-origin"
+ viewer_protocol_policy = "redirect-to-https"
+
+ allowed_methods = ["GET", "HEAD"]
+ cached_methods = ["GET", "HEAD"]
- allowed-methods = ["GET", "HEAD"]
- cached_methods = ["GET", "HEAD"]
-
# GitWeb relies on query strings
- forward_values {
- query_string = true
- headers = []
+ forwarded_values {
+ query_string = true
+ headers = []
cookies {
forward = "none"
***REMOVED***