|
| 1 | +AWSTemplateFormatVersion: '2010-09-09' |
| 2 | +Transform: AWS::Serverless-2016-10-31 |
| 3 | +Description: > |
| 4 | + Versant tfe Cluster |
| 5 | +
|
| 6 | + Terraform Enterprise |
| 7 | +
|
| 8 | +Parameters: |
| 9 | + Domain: |
| 10 | + Type: String |
| 11 | + Description: 'Application Platform' |
| 12 | + |
| 13 | + System: |
| 14 | + Type: String |
| 15 | + Description: 'Application System' |
| 16 | + |
| 17 | + Component: |
| 18 | + Type: String |
| 19 | + Description: 'Application Component' |
| 20 | + |
| 21 | + CodeBranch: |
| 22 | + Type: String |
| 23 | + Description: "Name of deployment branch" |
| 24 | + |
| 25 | + VpcId: |
| 26 | + Type: AWS::SSM::Parameter::Value<String> |
| 27 | + Description: Account VPC ID |
| 28 | + |
| 29 | + |
| 30 | + VpcSubnets: |
| 31 | + Type: AWS::SSM::Parameter::Value<CommaDelimitedList> |
| 32 | + Description: Account subnets |
| 33 | + |
| 34 | + Hostname: |
| 35 | + Type: String |
| 36 | + Description: Site FQDN |
| 37 | + |
| 38 | + DnsZoneId: |
| 39 | + Type: AWS::SSM::Parameter::Value<String> |
| 40 | + Description: Route53 Hosted Zone ID |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +Resources: |
| 45 | + |
| 46 | + # ALB Resources |
| 47 | + ## ALB networking |
| 48 | + EcsAlbSecurityGroup: |
| 49 | + Type: AWS::EC2::SecurityGroup |
| 50 | + Properties: |
| 51 | + GroupDescription: Access to ALB for Fargate |
| 52 | + VpcId: !Ref VpcId |
| 53 | + SecurityGroupIngress: |
| 54 | + - IpProtocol: tcp |
| 55 | + CidrIp: 0.0.0.0/0 |
| 56 | + FromPort: 443 |
| 57 | + ToPort: 443 |
| 58 | + |
| 59 | + # ALB DNS Record |
| 60 | + SiteDnsRecord: |
| 61 | + Type: AWS::Route53::RecordSet |
| 62 | + Properties: |
| 63 | + HostedZoneId: !Ref DnsZoneId |
| 64 | + Name: !Ref Hostname |
| 65 | + Type: A |
| 66 | + AliasTarget: |
| 67 | + DNSName: !GetAtt EcsAlb.DNSName |
| 68 | + HostedZoneId: !GetAtt EcsAlb.CanonicalHostedZoneID |
| 69 | + |
| 70 | + SiteCertificate: |
| 71 | + Type: AWS::CertificateManager::Certificate |
| 72 | + Properties: |
| 73 | + DomainName: !Ref Hostname |
| 74 | + ValidationMethod: DNS |
| 75 | + DomainValidationOptions: |
| 76 | + - DomainName: !Ref Hostname |
| 77 | + HostedZoneId: !Ref DnsZoneId |
| 78 | + |
| 79 | + ## ALB setup |
| 80 | + EcsAlb: |
| 81 | + Type: AWS::ElasticLoadBalancingV2::LoadBalancer |
| 82 | + Properties: |
| 83 | + Type: application |
| 84 | + Scheme: internet-facing |
| 85 | + Subnets: !Ref VpcSubnets |
| 86 | + SecurityGroups: |
| 87 | + - !Ref EcsAlbSecurityGroup |
| 88 | + |
| 89 | + EcsAlbListener: |
| 90 | + Type: AWS::ElasticLoadBalancingV2::Listener |
| 91 | + Properties: |
| 92 | + DefaultActions: |
| 93 | + - Type: fixed-response |
| 94 | + Order: 50000 |
| 95 | + FixedResponseConfig: |
| 96 | + ContentType: application/json |
| 97 | + StatusCode: 200 |
| 98 | + MessageBody: '{ "healthy": true }' |
| 99 | + LoadBalancerArn: !Ref 'EcsAlb' |
| 100 | + Port: 443 |
| 101 | + Protocol: HTTPS |
| 102 | + Certificates: |
| 103 | + - CertificateArn: !Ref SiteCertificate |
| 104 | + |
| 105 | + |
| 106 | + # ECS Resources |
| 107 | + ## Cluster |
| 108 | + EcsCluster: |
| 109 | + Type: AWS::ECS::Cluster |
| 110 | + |
| 111 | + ## ECS Network Access |
| 112 | + ContainerSecurityGroup: |
| 113 | + Type: AWS::EC2::SecurityGroup |
| 114 | + Properties: |
| 115 | + GroupDescription: Fargate container access |
| 116 | + VpcId: !Ref 'VpcId' |
| 117 | + |
| 118 | + |
| 119 | + ContainerAlbSecurityGroupIngress: |
| 120 | + Type: AWS::EC2::SecurityGroupIngress |
| 121 | + Properties: |
| 122 | + Description: Ingress from ALBs |
| 123 | + GroupId: !Ref ContainerSecurityGroup |
| 124 | + # All TCP ports |
| 125 | + IpProtocol: tcp |
| 126 | + FromPort: 80 |
| 127 | + ToPort: 65535 |
| 128 | + SourceSecurityGroupId: !Ref EcsAlbSecurityGroup |
| 129 | + |
| 130 | + |
| 131 | + # SSM Values |
| 132 | + EcsClusterNameSsmParam: |
| 133 | + Type: AWS::SSM::Parameter |
| 134 | + Properties: |
| 135 | + Type: String |
| 136 | + Description: Name of ECS Cluster |
| 137 | + Name: !Sub /${Domain}/${System}/${Component}/${CodeBranch}/EcsClusterName |
| 138 | + Value: !Ref EcsCluster |
| 139 | + |
| 140 | + ContainerSecurityGroupIdSsmParam: |
| 141 | + Type: AWS::SSM::Parameter |
| 142 | + Properties: |
| 143 | + Type: String |
| 144 | + Description: Name of ECS Cluster |
| 145 | + Name: !Sub /${Domain}/${System}/${Component}/${CodeBranch}/ContainerSecurityGroupId |
| 146 | + Value: !Ref ContainerSecurityGroup |
| 147 | + |
| 148 | + |
| 149 | + EcsAlbListenerArnSsmParam: |
| 150 | + Type: AWS::SSM::Parameter |
| 151 | + Properties: |
| 152 | + Type: String |
| 153 | + Description: ARN of cluster ALB |
| 154 | + Name: !Sub /${Domain}/${System}/${Component}/${CodeBranch}/EcsAlbListenerArn |
| 155 | + Value: !Ref EcsAlbListener |
| 156 | + |
0 commit comments