V4 Terraform Attributes & Resource Dependency

V4 Terraform Attributes & Resource Dependency

Terraform Attributes & Resource Dependency




VPC_1 Code

Creating an vpc & subnet using terraform code 

  provider.tf file contents
  provider "aws" {
  region     = "us-west-2"
  access_key = "xyz"
  secret_key = "xyz"
}

main.tf file contains
resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"
   tags = {
    Name = "MyVPC"
  }
}

resource "aws_subnet" "subnet1" {
  vpc_id     = aws_vpc.main.id
  cidr_block = "10.0.1.0/24"

  tags = {
    Name = "MyVPC-Subnet1"
  }
}

resource "aws_subnet" "subnet2" {
  vpc_id     = aws_vpc.main.id
  cidr_block = "10.0.2.0/24"

  tags = {
    Name = "MyVPC-Subnet2"
  }
}

resource "aws_subnet" "subnet3" {
  vpc_id     = aws_vpc.main.id
  cidr_block = "10.0.3.0/24"

  tags = {
    Name = "MyVPC-Subnet3"
  }
}

Instance Code

provider.tf file contents
  provider "aws" {
  region     = "us-west-2"
  access_key = "xyz"
  secret_key = "xyz"
}

main.tf file contains
  
 
resource "aws_instance" "web" {
  ami           = "ami-083ac7c7ecf9bb9b0"
  instance_type = "t2.micro"
  tags = {
    Name = "Web1"
  }
}

output "Public-IP" {
    value=aws_instance.web.public_ip
}

output "Instance-State" {
    value = aws_instance.web.instance_state
}



Presentation Link : Terraform Providers_Resources


Post a Comment

0 Comments