Coder Social home page Coder Social logo

nadamarei / terraform-infrastructure-project Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 316 KB

ITI-Terraform-Labs

HCL 88.58% Python 11.42%
aws-ec2 aws-s3 aws-vpc-gateway aws-vpc-subnet networking ssh terraform aws-nat-gateway aws-vpc-elastic-ip terraform-provider

terraform-infrastructure-project's Introduction

Terraform Infrastructure Project

This Terraform project creates a VPC with public and private subnets, an internet gateway, route tables, and EC2 instances for a bastion host and an application server. The state file is stored in an S3 bucket and DynamoDB table, and the infrastructure can be deployed to multiple regions using separate workspaces.

Requirements

  • Terraform version 1.4.5 or later.
  • Access keys for an AWS account with sufficient permissions to create the required resources.
  • An S3 bucket and DynamoDB table for storing the Terraform state file.

Usage

1- Clone the repository and navigate to the project directory.

2- Initialize the Terraform project by running the terraform init command.

3- Create two workspace directories named dev and prod by running the mkdir command.

4- Create two variable definition files named dev.tfvars and prod.tfvars with environment-specific variable values.

5- Apply the code and create the infrastructure in the us-east-1 and eu-central-1 regions by running the following commands:

terraform workspace new dev
terraform workspace new prod
terraform apply -var-file=dev.tfvars -var region=us-east-1
terraform apply -var-file=prod.tfvars -var region=eu-central-1

6- To destroy the infrastructure, run the terraform destroy command in each workspace directory.

Variables

The following variables can be set in the dev.tfvars and prod.tfvars files:

Variable Description

vpc_cidr_block The CIDR block for the VPC.
vpc_name The name of the VPC.
igw_name The name of the internet gateway.
public_rt_name The name of the public route table.
private_rt_name The name of the private route table.
ssh_sg_name The name of the security group that allows SSH traffic.
app_sg_name The name of the security group that allows SSH and port 3000 traffic.
bastion_name The name of the Bastion EC2 instance.
bastion_ami The ID of the Amazon Machine Image (AMI) for the Bastion EC2 instance.
bastion_instance_type The instance type for the Bastion EC2 instance.
app_name The name of the application EC2 instance.
app_ami The ID of the Amazon Machine Image (AMI) for the application EC2 instance.
app_instance_type The instance type for the application EC2 instance.
key_name The name of the key pair to use for SSH access.
public_subnet_id The ID of the public subnet.
private_subnet_id The ID of the private subnet.
backend_bucket_name The name of the S3 bucket for storing the Terraform state file.
backend_region The region of the S3 bucket and DynamoDB table.
backend_dynamodb_table_name The name of the DynamoDB table for storing the Terraform state file.

Modules

The project includes a network module that creates the VPC, internet gateway, route tables, and subnets. To use this module, add the following code to your main Terraform file:

module "network" {
  source = "./network"
  vpc_cidr_block = var.vpc_cidr_block
  vpc_name = var.vpc_name
  igw_name = var.igw_name
  public_rt_name = var.public_rt_name
  private_rt_name = var.private_rt_name
  ssh_sg_name = var.ssh_sg_name
  app_sg_name = var.app_sg_name
  public_subnet_cidr_block = var.public_subnet_cidr_block
  private_subnet_cidr_block = var.private_subnet_cidr_block
}

terraform-infrastructure-project's People

Contributors

nadamarei avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.