func BuildApiGatewayTemplateFromIngressRule()

in pkg/cloudformation/cloudformation.go [237:286]


func BuildApiGatewayTemplateFromIngressRule(cfg *TemplateConfig) *cfn.Template {
	template := cfn.NewTemplate()
	paths := cfg.Rule.IngressRuleValue.HTTP.Paths

	methodLogicalNames := []string{}
	resourceMap := mapApiGatewayMethodsAndResourcesFromPaths(paths)
	for k, resource := range resourceMap {
		if _, ok := resource.(*resources.AWSApiGatewayMethod); ok {
			methodLogicalNames = append(methodLogicalNames, k)
		}

		template.Resources[k] = resource
	}

	targetGroup := buildAWSElasticLoadBalancingV2TargetGroup(*cfg.Network.Vpc.VpcId, cfg.Network.InstanceIDs, cfg.NodePort, []string{"LoadBalancer"})
	template.Resources["TargetGroup"] = targetGroup

	listener := buildAWSElasticLoadBalancingV2Listener()
	template.Resources["Listener"] = listener

	securityGroupIngresses := buildAWSEC2SecurityGroupIngresses(cfg.Network.SecurityGroupIDs, *cfg.Network.Vpc.CidrBlock, cfg.NodePort)
	for i, sgI := range securityGroupIngresses {
		template.Resources[fmt.Sprintf("SecurityGroupIngress%d", i)] = sgI
	}

	restAPI := buildAWSApiGatewayRestAPI(cfg.Arns)
	template.Resources["RestAPI"] = restAPI

	deployment := buildAWSApiGatewayDeployment(cfg.StageName, methodLogicalNames)
	template.Resources["Deployment"] = deployment

	loadBalancer := buildAWSElasticLoadBalancingV2LoadBalancer(cfg.Network.SubnetIDs)
	template.Resources["LoadBalancer"] = loadBalancer

	vPCLink := buildAWSApiGatewayVpcLink([]string{"LoadBalancer"})
	template.Resources["VPCLink"] = vPCLink

	if cfg.CustomDomainName != "" && cfg.CertificateArn != "" {
		customDomain := buildCustomDomain(cfg.CustomDomainName, cfg.CertificateArn)
		template.Resources["CustomDomain"] = customDomain
	}

	template.Outputs = map[string]interface{}{
		OutputKeyRestApiID:          Output{Value: cfn.Ref("RestAPI")},
		OutputKeyAPIGatewayEndpoint: Output{Value: cfn.Join("", []string{"https://", cfn.Ref("RestAPI"), ".execute-api.", cfn.Ref("AWS::Region"), ".amazonaws.com/", cfg.StageName})},
		OutputKeyClientARNS:         Output{Value: strings.Join(cfg.Arns, ",")},
	}

	return template
}