Sunday, 3 November 2024

ClodFormation, terraform and CDK example

AWSTemplateFormatVersion: "2010-09-09"

Description: "CloudFormation Template for VPC Endpoints and Route 53 with VPC and Subnets as parameters."

 

Parameters:

  SelectedRegion:

    Description: "Select the region for deployment (us-east-1 or ap-east-1)."

    Type: String

    AllowedValues:

      - us-east-1

      - ap-east-1

    Default: us-east-1

 

  VPCID:

    Description: "The VPC ID where the resources will be deployed."

    Type: String

 

  Subnet1ID:

    Description: "The ID of the first subnet."

    Type: String

 

  Subnet2ID:

    Description: "The ID of the second subnet."

    Type: String

 

  Subnet3ID:

    Description: "The ID of the third subnet."

    Type: String

 

Resources:

  # VPC Endpoints

  VPCEndpointS3:

    Type: AWS::EC2::VPCEndpoint

    Properties:

      VpcId: !Ref VPCID

      ServiceName: !Sub "com.amazonaws.${SelectedRegion}.s3"

      VpcEndpointType: Gateway

 

  VPCEndpointEC2:

    Type: AWS::EC2::VPCEndpoint

    Properties:

      VpcId: !Ref VPCID

      ServiceName: !Sub "com.amazonaws.${SelectedRegion}.ec2"

      VpcEndpointType: Interface

      SubnetIds:

        - !Ref Subnet1ID

        - !Ref Subnet2ID

        - !Ref Subnet3ID

 

  VPCEndpointSSM:

    Type: AWS::EC2::VPCEndpoint

    Properties:

      VpcId: !Ref VPCID

      ServiceName: !Sub "com.amazonaws.${SelectedRegion}.ssm"

      VpcEndpointType: Interface

      SubnetIds:

        - !Ref Subnet1ID

        - !Ref Subnet2ID

        - !Ref Subnet3ID

 

  VPCEndpointSecretsManager:

    Type: AWS::EC2::VPCEndpoint

    Properties:

      VpcId: !Ref VPCID

      ServiceName: !Sub "com.amazonaws.${SelectedRegion}.secretsmanager"

      VpcEndpointType: Interface

      SubnetIds:

        - !Ref Subnet1ID

        - !Ref Subnet2ID

        - !Ref Subnet3ID

 

  VPCEndpointCloudWatchLogs:

    Type: AWS::EC2::VPCEndpoint

    Properties:

      VpcId: !Ref VPCID

      ServiceName: !Sub "com.amazonaws.${SelectedRegion}.logs"

      VpcEndpointType: Interface

      SubnetIds:

        - !Ref Subnet1ID

        - !Ref Subnet2ID

        - !Ref Subnet3ID

 

  # Route 53 Hosted Zone

  Route53HostedZone:

    Type: AWS::Route53::HostedZone

    Properties:

      Name: !Sub "example-${SelectedRegion}.com"

 

  # Route 53 Record Set

  Route53RecordSet:

    Type: AWS::Route53::RecordSet

    Properties:

      HostedZoneId: !Ref Route53HostedZone

      Name: "app.example.com."

      Type: A

      AliasTarget:

        DNSName: !Sub "vpce.${SelectedRegion}.amazonaws.com"

        HostedZoneId: !GetAtt Route53HostedZone.Id

 

Outputs:

  SelectedRegionOutput:

    Description: "The selected region."

    Value: !Ref SelectedRegion

 

  VPCIDOutput:

    Description: "The VPC ID used for this deployment."

    Value: !Ref VPCID

 

  Subnet1IDOutput:

    Description: "The Subnet ID for Subnet 1."

    Value: !Ref Subnet1ID

 

  Subnet2IDOutput:

    Description: "The Subnet ID for Subnet 2."

    Value: !Ref Subnet2ID

 

  Subnet3IDOutput:

    Description: "The Subnet ID for Subnet 3."

    Value: !Ref Subnet3ID

 

  HostedZoneIDOutput:

    Description: "The Route 53 Hosted Zone ID."

    Value: !Ref Route53HostedZone

No comments:

Post a Comment