Skip to content

AWS Infrastructure Creation with OpenTofu This repository contains an Infrastructure as Code (IaC) project that uses OpenTofu to deploy a basic infrastructure on Amazon Web Services (AWS). The main goal is to create a Virtual Private Cloud (VPC)

Notifications You must be signed in to change notification settings

rodriveracr/opentofu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS Infrastructure Creation with OpenTofu This repository contains an Infrastructure as Code (IaC) project that uses OpenTofu to deploy a basic infrastructure on Amazon Web Services (AWS). The main goal is to create a Virtual Private Cloud (VPC) and a public subnet using a modular and automated approach.

What I did Deployed a VPC: Configured a VPC with a CIDR block of 10.0.0.0/16 and the tag opentofu-demo-vpc.

Added a public subnet: Created a subnet within the VPC with a CIDR block of 10.0.1.0/24 and the tag opentofu-demo-public-subnet.

Automated with OpenTofu: Used OpenTofu to define, plan, and apply the infrastructure in the AWS us-east-2 region.

Structured the project: Organized files with modules, variables, and outputs to facilitate reuse and management.

Project Structure main.tf: Defines the AWS provider and calls the VPC module with customizable variables.

variables.tf: Contains variables (region, vpc_cidr, subnet_cidr, project_name) with default values.

outputs.tf: Exposes the IDs of the VPC and subnet (vpc_id, subnet_id) generated.

modules/vpc/main.tf: Implements the aws_vpc and aws_subnet resources with their configurations.

.gitignore: Ignores sensitive files such as .tfstate and .terraform/ to protect state and providers.

Requirements OpenTofu: Installed locally (version 1.10.6 or higher).

AWS CLI or credentials: Set environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION with an IAM user that has permissions (e.g., AdministratorAccess).

Git: To version and push the project to GitHub.

How to Use Clone the repository:

bash git clone https://github.com/rodriveracr/opentofu.git cd opentofu Configure AWS credentials: Obtain an Access Key ID and Secret Access Key from the AWS console (IAM > Users). In the terminal, set:

bash $env:AWS_ACCESS_KEY_ID = "your-access-key" $env:AWS_SECRET_ACCESS_KEY = "your-secret-key" $env:AWS_REGION = "us-east-2" Initialize OpenTofu:

bash tofu init This installs the required providers and modules.

Review the plan:

bash tofu plan Shows the resources to be created (VPC and subnet).

Apply the infrastructure:

bash tofu apply Confirm with yes to create the resources. The IDs will be shown as outputs.

Verify in AWS: Go to the AWS console and check the VPC and subnet in the us-east-2 region.

Destroy resources (optional):

bash tofu destroy Confirm with yes to delete everything.

Results VPC ID: vpc-0f3d72c8b3d353eae

Subnet ID: subnet-0c4bfed0c0a5ae9c5 These resources are active in AWS and were created with the corresponding tags.

Contributions This project is a starting point. You can:

Add more resources (e.g., internet gateway, route table) by editing modules/vpc/main.tf.

Adjust variables in variables.tf to customize the infrastructure.

Share improvements in this repository.

Security Notes Do not upload access keys to GitHub.

Use environment variables or a remote backend for state.

Monitor costs in the AWS console, although this project uses the Free Tier.

Thanks for exploring this OpenTofu project!

About

AWS Infrastructure Creation with OpenTofu This repository contains an Infrastructure as Code (IaC) project that uses OpenTofu to deploy a basic infrastructure on Amazon Web Services (AWS). The main goal is to create a Virtual Private Cloud (VPC)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages