0% found this document useful (0 votes)
16 views4 pages

VPC and s3

This document provides Terraform configurations for setting up an AWS Virtual Private Cloud (VPC) and an Amazon S3 bucket. The VPC setup includes components such as public and private subnets, an Internet Gateway, and a NAT Gateway, while the S3 bucket is configured with versioning, server-side encryption, and public access restrictions. The Terraform code snippets illustrate the implementation of these resources with specific attributes and settings.

Uploaded by

Shailendra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

VPC and s3

This document provides Terraform configurations for setting up an AWS Virtual Private Cloud (VPC) and an Amazon S3 bucket. The VPC setup includes components such as public and private subnets, an Internet Gateway, and a NAT Gateway, while the S3 bucket is configured with versioning, server-side encryption, and public access restrictions. The Terraform code snippets illustrate the implementation of these resources with specific attributes and settings.

Uploaded by

Shailendra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

AWS VPC and S3 with Terraform

VPC Setup Using Terraform

This Terraform configuration creates a basic Virtual Private Cloud (VPC) setup on AWS.

Key Components:

- VPC with DNS hostnames enabled

- Public and private subnets

- Internet Gateway and NAT Gateway

- Route tables for public and private traffic

Terraform Code:

resource "aws_vpc" "my-vpc" {

cidr_block = "11.0.0.0/16"

enable_dns_hostnames = true

instance_tenancy = "default"

tags = {

Name = "terraform-vpc"

resource "aws_subnet" "public" {

vpc_id = aws_vpc.my-vpc.id

cidr_block = "11.0.1.0/24"

availability_zone = "us-east-1a"

map_public_ip_on_launch = true

tags = {

Name = "public-subnet"

}
AWS VPC and S3 with Terraform

resource "aws_subnet" "private" {

vpc_id = aws_vpc.my-vpc.id

cidr_block = "11.0.2.0/24"

availability_zone = "us-east-1a"

tags = {

Name = "private-subnet"

resource "aws_internet_gateway" "igw" {

vpc_id = aws_vpc.my-vpc.id

tags = {

Name = "internet-gateway"

resource "aws_eip" "nat_eip" {

domain = "vpc"

resource "aws_nat_gateway" "nat" {

allocation_id = aws_eip.nat_eip.id

subnet_id = aws_subnet.public.id

tags = {

Name = "nat-gateway"

resource "aws_route_table" "public_rt" {

vpc_id = aws_vpc.my-vpc.id

route {
AWS VPC and S3 with Terraform

cidr_block = "0.0.0.0/0"

gateway_id = aws_internet_gateway.igw.id

tags = {

Name = "public-rt"

resource "aws_route_table" "private_rt" {

vpc_id = aws_vpc.my-vpc.id

route {

cidr_block = "0.0.0.0/0"

nat_gateway_id = aws_nat_gateway.nat.id

tags = {

Name = "private-rt"

S3 Bucket Setup Using Terraform

This Terraform configuration sets up a secure and versioned Amazon S3 bucket.

Key Features:

- S3 bucket with versioning enabled

- Server-side encryption with AES256

- Public access blocked for security

Terraform Code:

resource "aws_s3_bucket" "my_bucket" {


AWS VPC and S3 with Terraform

bucket = "my-unique-bucket-name-12345"

tags = {

Name = "MyBucket"

Environment = "Dev"

resource "aws_s3_bucket_versioning" "versioning" {

bucket = aws_s3_bucket.my_bucket.id

versioning_configuration {

status = "Enabled"

resource "aws_s3_bucket_server_side_encryption_configuration" "encryption" {

bucket = aws_s3_bucket.my_bucket.bucket

rule {

apply_server_side_encryption_by_default {

sse_algorithm = "AES256"

resource "aws_s3_bucket_public_access_block" "public_access" {

bucket = aws_s3_bucket.my_bucket.id

block_public_acls = true

block_public_policy = true

ignore_public_acls = true

restrict_public_buckets = true

You might also like