Skip to content

Commit

Permalink
fix readme and tf fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
oussamaca committed Nov 7, 2022
1 parent 6b3adcb commit d5ba18b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ To connect to the VM:
- Create a SSH key on your Github account: [Add a ssh key documentation](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)
- Share your handle Github with Padok's team member

- Launch a "Remote SSH Session" with VSCode extension via the command `ssh cs@<handleGithub>.aws.cs.padok.cloud`
- Launch a "Remote SSH Session" with VSCode extension via the command `ssh cs@<handleGithub>.cs.padok.school`

## Explore the Terraform code

Expand Down Expand Up @@ -106,16 +106,14 @@ Create a second Terraform workspace to be able to have two identical environment
```
tf workspace new dev
cp prd.tfvars dev.tfvars
```
The `tfvars` files will be used to defined environment specific variable values.
We want only one webserver in each environment:
1. Modify the dev.tfvars to change the `environment` variable from `prd` to `dev`. It will create resource with `dev` in their name for development environment.
1. The dev.tfvars has already been created with development values (vpc,subnet) . It will create resource with `dev` in their name for development environment.
2. Modify `main.tf` to have only one resource to describe both environments (instead of the two existing resources `staging_webserver` and `production_webserver`).
<details>
Expand Down
8 changes: 4 additions & 4 deletions iac/dev.tfvars
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
environment = "dev"
vpc_id = "vpc-0fbfe8a414325b6e6"
private_subnets = ["subnet-0e185b7265256ab22", "subnet-0b4e47a0eb4f52406"]
public_subnets = ["subnet-000da12999c598b26","subnet-054b28934c16043b5"]
environment = "dev"
vpc_id = "vpc-0fbfe8a414325b6e6"
private_subnets = ["subnet-0e185b7265256ab22", "subnet-0b4e47a0eb4f52406"]
public_subnets = ["subnet-000da12999c598b26", "subnet-054b28934c16043b5"]
14 changes: 7 additions & 7 deletions iac/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data "aws_ami" "webserver_ami" {

filter {
name = "name"
values =["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}

filter {
Expand All @@ -44,13 +44,13 @@ PRODUCTION ENVIRONMENT
resource "aws_instance" "production_webserver" {

// Define the image
ami = data.aws_ami.webserver_ami.id
ami = data.aws_ami.webserver_ami.id

// Define the type of instance. t2.micro is a small machine
instance_type = "t2.micro"

// Define the SSH key pair
key_name = aws_key_pair.key_pair.key_name
key_name = aws_key_pair.key_pair.key_name

// Create a public IP adress for the instance
associate_public_ip_address = true
Expand All @@ -64,7 +64,7 @@ resource "aws_instance" "production_webserver" {
)

// Define in which subnet the instance is
subnet_id = var.public_subnets[0]
subnet_id = var.public_subnets[0]

// Define which security group is associated to the instance
vpc_security_group_ids = [
Expand All @@ -81,13 +81,13 @@ STAGING ENVIRONMENT
resource "aws_instance" "staging_webserver" {

// Define the image
ami = data.aws_ami.webserver_ami.id
ami = data.aws_ami.webserver_ami.id

// Define the type of instance. t2.micro is a small machine
instance_type = "t2.micro"

// Define the SSH key pair
key_name = aws_key_pair.key_pair.key_name
key_name = aws_key_pair.key_pair.key_name

// Create a public IP adress for the instance
associate_public_ip_address = true
Expand All @@ -101,7 +101,7 @@ resource "aws_instance" "staging_webserver" {
)

// Define in which subnet the instance is
subnet_id = var.public_subnets[0]
subnet_id = var.public_subnets[0]

// Define which security group is associated to the instance
vpc_security_group_ids = [
Expand Down
4 changes: 2 additions & 2 deletions iac/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resource "aws_security_group" "allow_pub" {
description = "Allow SSH inbound traffic"

// VPC in which the subnet will be
vpc_id = var.vpc_id
vpc_id = var.vpc_id

// Ingress rules. This allow everything. Very secure
ingress {
Expand Down Expand Up @@ -46,7 +46,7 @@ resource "aws_security_group" "allow_priv" {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["10.0.0.0/24","10.0.1.0/24","10.0.2.0/24","10.0.3.0/24"]
cidr_blocks = ["10.0.0.0/24", "10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
}

// Ingress rules. This allow everything. Very secure
Expand Down
8 changes: 4 additions & 4 deletions iac/prd.tfvars
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

environment = "prd"
vpc_id = "vpc-06987f5dade98b59a"
private_subnets = ["subnet-0aaae4f50bfd26d64","subnet-04659d20c010aac58"]
public_subnets = ["subnet-0b93808f63a1676d4","subnet-023ee16302deb756c"]
environment = "prd"
vpc_id = "vpc-06987f5dade98b59a"
private_subnets = ["subnet-0aaae4f50bfd26d64", "subnet-04659d20c010aac58"]
public_subnets = ["subnet-0b93808f63a1676d4", "subnet-023ee16302deb756c"]
16 changes: 8 additions & 8 deletions iac/variables.tf
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
variable "aws_region" {
type = string
default = "eu-west-3"
type = string
default = "eu-west-3"
description = "the region were the assets will be deployed"
}

variable "aws_profile" {
type = string
type = string
description = "Name of the AWS profile in ~/.aws/credentials"
default = "padok-supelec"
default = "padok-supelec"
}

variable "environment" {
type = string
type = string
description = "Name of the environment"
}

variable "vpc_id" {
type = string
type = string
description = "ID of the VPC"
}

variable "public_subnets" {
type = list
type = list(any)
description = "ID of the public subnet"
}

variable "private_subnets" {
type = list
type = list(any)
description = "ID of the private subnet"
}

0 comments on commit d5ba18b

Please sign in to comment.