adding code base for lab 3
This commit is contained in:
parent
c8531bff33
commit
ecac8cccba
12 changed files with 53 additions and 3987 deletions
|
@ -4,3 +4,4 @@ data "aws_security_group" "default" {
|
||||||
name = "default"
|
name = "default"
|
||||||
vpc_id = module.vpc.vpc_id
|
vpc_id = module.vpc.vpc_id
|
||||||
}
|
}
|
||||||
|
|
2
3-remote-states/code/env/dev.tfvars
vendored
Normal file
2
3-remote-states/code/env/dev.tfvars
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ami_id = "ami-029b91ed285a24a90"
|
||||||
|
instance_size = t4g.nano
|
|
@ -2,9 +2,8 @@ locals {
|
||||||
default_tags = merge(
|
default_tags = merge(
|
||||||
var.additional_tags,
|
var.additional_tags,
|
||||||
{
|
{
|
||||||
Maintainer = "Ric"
|
|
||||||
Owner = var.name
|
Owner = var.name
|
||||||
Environment = var.environment
|
Environment = var.environment
|
||||||
ManagedBy = "terraform"
|
ManagedBy = "tofu/terraform"
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -1,13 +1,20 @@
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = var.region
|
region = "eu-west-1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
resource "aws_security_group" "web_server_sg_tf" {
|
resource "aws_security_group" "web_server_sg_tf" {
|
||||||
name = "web-server-sg-tf"
|
name = "web-server-sg-tf"
|
||||||
description = "Allow HTTP to web server"
|
description = "Allow HTTP to web server"
|
||||||
vpc_id = module.vpc.vpc_id
|
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 {
|
ingress {
|
||||||
description = "HTTP ingress"
|
description = "HTTP ingress"
|
||||||
from_port = 80
|
from_port = 80
|
||||||
|
@ -34,8 +41,15 @@ egress {
|
||||||
|
|
||||||
resource "aws_instance" "test_ami" {
|
resource "aws_instance" "test_ami" {
|
||||||
ami = var.ami_id
|
ami = var.ami_id
|
||||||
instance_type = "t3.micro"
|
instance_type = var.instance_size
|
||||||
associate_public_ip_address = true
|
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]
|
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
|
||||||
}
|
}
|
|
@ -25,3 +25,9 @@ output "nat_public_ips" {
|
||||||
description = "List of public Elastic IPs created for AWS NAT Gateway"
|
description = "List of public Elastic IPs created for AWS NAT Gateway"
|
||||||
value = module.vpc.nat_public_ips
|
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
|
||||||
|
}
|
|
@ -1,19 +1,13 @@
|
||||||
variable "name" {
|
variable "name" {
|
||||||
description = "Solution name"
|
description = "Name of our Application"
|
||||||
type = string
|
type = string
|
||||||
default = "my-vpc"
|
default = "lab-1-app"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "environment" {
|
variable "environment" {
|
||||||
description = "Execution environment"
|
description = "The deployment environment"
|
||||||
type = string
|
type = string
|
||||||
default = "development"
|
default = "dev"
|
||||||
}
|
|
||||||
|
|
||||||
variable "region" {
|
|
||||||
description = "AWS region"
|
|
||||||
type = string
|
|
||||||
default = "eu-west-1"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "private_subnet_suffix" {
|
variable "private_subnet_suffix" {
|
||||||
|
@ -40,7 +34,15 @@ variable "additional_tags" {
|
||||||
default = {}
|
default = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "ami_id" {
|
variable "instance_size" {
|
||||||
description = "ami to use for example"
|
description = "Size of the instance to run"
|
||||||
type = string
|
type = string
|
||||||
|
default = "t4g.nano"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "ami_id" {
|
||||||
|
description = "Instance Amazon Machine Image to run"
|
||||||
|
type = string
|
||||||
|
default = "ami-029b91ed285a24a90"
|
||||||
|
}
|
||||||
|
|
10
3-remote-states/code/versions.tf
Normal file
10
3-remote-states/code/versions.tf
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
terraform {
|
||||||
|
required_version = ">= 1.0"
|
||||||
|
|
||||||
|
required_providers {
|
||||||
|
aws = {
|
||||||
|
source = "hashicorp/aws"
|
||||||
|
version = ">= 4.66.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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",
|
|
||||||
]
|
|
||||||
}
|
|
3
3-remote-states/iac/env/dev.tfvars
vendored
3
3-remote-states/iac/env/dev.tfvars
vendored
|
@ -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
Loading…
Reference in a new issue