aroN
aroN

Reputation: 175

Unable to create VPC and routing table using cloud formation

Iam new to cloud formation. I tried creating vpc,subnet and its routing table using cloud formation.But unable to create it.Anyone please help me to solve the issue.My yaml file is as follows:

myvpc:
    Type: AWS::EC2::VPC
    Properties:
        CidrBlock: 10.0.0.0/16
        EnableDnsSupport: true
        EnableDnsHostnames: true
        InstanceTenancy: default
        Tags:
            - Name: gccvpc

myinternetgateway:
    Type: AWS::EC2::InternetGateway
    Properties:
        Tags: 
            - Name: gccgt

mygatewayattach:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
        InternetGatewayId: !Ref myinternetgateway
        VpcId: !Ref myvpc

mysubnet1:
    Type: AWS::EC2::Subnet
    Properties:
        AvailabilityZone: us-east-1a
        VpcId: !Ref myvpc
        CidrBlock: 10.0.1.0/24
        MapPublicIpOnLaunch: true


Routetable:
    Type: AWS::EC2::RouteTable
    Properties:
        VpcId: !Ref myvpc

Route:
    Type: AWS::EC2::Route
    DependsOn: myinternetgateway
    Properties:
        DestinationCidrBlock: 0.0.0.0/0
        GatewayId: !Ref myinternetgateway
        RouteTableId: !Ref Routetable
SubnetARouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
        RouteTableId: !Ref Routetable
        SubnetId: !Ref mysubnet1

Upvotes: 0

Views: 265

Answers (1)

George Rushby
George Rushby

Reputation: 1345

You were missing the resources condition and your tag properties were incorrect. Please post the error next time which you can find on the events tab in the CloudFormation Console.

Resources:
  myvpc:
    Type: "AWS::EC2::VPC"
    Properties:
      CidrBlock: "10.0.0.0/16"
      EnableDnsSupport: "true"
      EnableDnsHostnames: "true"
      InstanceTenancy: "default"
      Tags:
      - Key: "Name" 
        Value: "gccvpc"

  myinternetgateway:
    Type: "AWS::EC2::InternetGateway"
    Properties:
      Tags:
      - Key: "Name" 
        Value: "gccvpc"

  mygatewayattach:
    Type: "AWS::EC2::VPCGatewayAttachment"
    Properties:
      InternetGatewayId: !Ref "myinternetgateway"
      VpcId: !Ref "myvpc"

  mysubnet1:
    Type: "AWS::EC2::Subnet"
    Properties:
      AvailabilityZone: "us-east-1a"
      VpcId: !Ref "myvpc"
      CidrBlock: "10.0.1.0/24"
      MapPublicIpOnLaunch: "true"

  Routetable:
    Type: "AWS::EC2::RouteTable"
    Properties:
      VpcId: !Ref "myvpc"

  Route:
    Type: "AWS::EC2::Route"
    DependsOn: "myinternetgateway"
    Properties:
      DestinationCidrBlock: "0.0.0.0/0"
      GatewayId: !Ref "myinternetgateway"
      RouteTableId: !Ref "Routetable"

  SubnetARouteTableAssociation:
    Type: "AWS::EC2::SubnetRouteTableAssociation"
    Properties:
      RouteTableId: !Ref "Routetable"
      SubnetId: !Ref "mysubnet1"

Upvotes: 2

Related Questions