adding code base for lab 3

This commit is contained in:
Ric Harvey 2024-04-16 18:23:24 +01:00
parent c8531bff33
commit ecac8cccba
Signed by: ric
GPG key ID: 7FDEB4C0C7D5CB61
12 changed files with 53 additions and 3987 deletions

View file

@ -4,3 +4,4 @@ data "aws_security_group" "default" {
name = "default"
vpc_id = module.vpc.vpc_id
}

2
3-remote-states/code/env/dev.tfvars vendored Normal file
View file

@ -0,0 +1,2 @@
ami_id = "ami-029b91ed285a24a90"
instance_size = t4g.nano

View file

@ -2,9 +2,8 @@ locals {
default_tags = merge(
var.additional_tags,
{
Maintainer = "Ric"
Owner = var.name
Environment = var.environment
ManagedBy = "terraform"
ManagedBy = "tofu/terraform"
})
}

View file

@ -1,13 +1,20 @@
provider "aws" {
region = var.region
region = "eu-west-1"
}
resource "aws_security_group" "web_server_sg_tf" {
name = "web-server-sg-tf"
description = "Allow HTTP to web server"
vpc_id = module.vpc.vpc_id
ingress {
description = "SSH ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "HTTP ingress"
from_port = 80
@ -34,8 +41,15 @@ egress {
resource "aws_instance" "test_ami" {
ami = var.ami_id
instance_type = "t3.micro"
instance_type = var.instance_size
associate_public_ip_address = true
subnet_id = module.vpc.public_subnets[0]
subnet_id = module.vpc.public_subnets[0]
vpc_security_group_ids = [aws_security_group.web_server_sg_tf.id]
user_data = <<-EOF
#!/bin/bash
sudo dnf install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx
EOF
}

View file

@ -25,3 +25,9 @@ output "nat_public_ips" {
description = "List of public Elastic IPs created for AWS NAT Gateway"
value = module.vpc.nat_public_ips
}
# Public IP of instance
output "instance_public_ip" {
description = "Show the public IP of the instance deployed"
value = aws_instance.test_ami.public_ip
}

View file

@ -1,19 +1,13 @@
variable "name" {
description = "Solution name"
description = "Name of our Application"
type = string
default = "my-vpc"
default = "lab-1-app"
}
variable "environment" {
description = "Execution environment"
description = "The deployment environment"
type = string
default = "development"
}
variable "region" {
description = "AWS region"
type = string
default = "eu-west-1"
default = "dev"
}
variable "private_subnet_suffix" {
@ -40,7 +34,15 @@ variable "additional_tags" {
default = {}
}
variable "ami_id" {
description = "ami to use for example"
type = string
variable "instance_size" {
description = "Size of the instance to run"
type = string
default = "t4g.nano"
}
variable "ami_id" {
description = "Instance Amazon Machine Image to run"
type = string
default = "ami-029b91ed285a24a90"
}

View file

@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.66.1"
}
}
}

View file

@ -1,19 +0,0 @@
# This file is maintained automatically by "tofu init".
# Manual edits may be lost in future updates.
provider "registry.opentofu.org/hashicorp/aws" {
version = "5.45.0"
hashes = [
"h1:A8MJa+VwONA4BNO5xzeleguJbrblNLnXBImHTK/qgFg=",
"zh:1d71c406aeaf4ba762eb62e4595ab9c9f8da1a2c9b74bb4277c0acfd9678ae65",
"zh:3b00b13154eadedb37bca99bf7cbd556fa9472e6900c970effa17a270ee9f721",
"zh:6f264e8b70153925ac8abfa83ebffe2c2d5a27ab5557a6b16124269b08ac2441",
"zh:80f7d552faf5c43d7dc22c6c1f7e70557b9f01c67db07abbb0330d5d3fc0e464",
"zh:863a2a2e6ae5b42fc46b209d8f2761c882d46aca481a8c49ef221d290b4fd88e",
"zh:8e3bddeb2da7e6bcfd0b0221a083778d2f7fc5cd64f55de7d8d79bd1f7378bae",
"zh:c726104e46cd743bbf240101d7975f44091d893b6e97b46070df0041779b04d2",
"zh:db73a89b462fdd6eb6f32e6ed464430a895fc2e54fb629e8b99773fc32a6a7a8",
"zh:e35179b89eba358f521ffd4546345b4d0683ca3364a9deb8f3b7b4bf60be6f02",
"zh:e7b54a0faecd34a9c73729d1d1f0cfc1b8f56bae789f95987002616f1265ce72",
]
}

View file

@ -1,3 +0,0 @@
name = "Ric Harvey"
environment = "dev"
ami_id = "ami-0f5eb0451af853a24"

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff