i want to add vpc using terraform
- User
i want to add vpc using terraform
- Assistant
Sure! Here's an example of how you can use Terraform to create a VPC on AWS:
First, create a new Terraform file with a
.tfextension (e.g.,main.tf) and add the following code:provider "aws" { region = "us-west-2" # Replace with your desired AWS region } resource "aws_vpc" "my_vpc" { cidr_block = "10.0.0.0/16" # Replace with your desired VPC CIDR block tags = { Name = "my-vpc" # Replace with your desired VPC name } }Save the file and open a terminal in the directory containing the Terraform file. Initialize the Terraform project using the command:
terraform init.Then, run
terraform planto see an execution plan for creating the VPC.Finally, run
terraform applyto create the VPC on AWS. Confirm the creation by typingyeswhen prompted.Terraform will provision the VPC according to the provided configuration and output the VPC ID upon successful completion.
Note: Make sure you have set up your AWS credentials and configured the AWS CLI before running Terraform.