def build_endpoints()

in source/idea/idea-administrator/src/ideaadministrator/app/cdk/stacks/cluster_manager_stack.py [0:0]


    def build_endpoints(self):

        cluster_endpoints_lambda_arn = self.context.config().get_string('cluster.cluster_endpoints_lambda_arn', required=True)

        external_https_listener_arn = self.context.config().get_string('cluster.load_balancers.external_alb.https_listener_arn', required=True)
        # web portal endpoint
        default_target_group = elbv2.CfnTargetGroup(
            self.stack,
            'web-portal-target-group',
            port=8443,
            protocol='HTTPS',
            target_type='instance',
            vpc_id=self.cluster.vpc.vpc_id,
            name=self.get_target_group_name('web-portal'),
            health_check_path='/healthcheck'
        )

        self.web_portal_endpoint = cdk.CustomResource(
            self.stack,
            'web-portal-endpoint',
            service_token=cluster_endpoints_lambda_arn,
            properties={
                'endpoint_name': f'{self.module_id}-web-portal-endpoint',
                'listener_arn': external_https_listener_arn,
                'priority': 0,
                'default_action': True,
                'actions': [
                    {
                        'Type': 'forward',
                        'TargetGroupArn': default_target_group.ref
                    }
                ]
            },
            resource_type='Custom::WebPortalEndpoint'
        )

        # cluster manager api external endpoint
        external_endpoint_priority = self.context.config().get_int('cluster-manager.endpoints.external.priority', required=True)
        external_endpoint_path_patterns = self.context.config().get_list('cluster-manager.endpoints.external.path_patterns', required=True)
        external_target_group = elbv2.CfnTargetGroup(
            self.stack,
            f'{self.module_id}-external-target-group',
            port=8443,
            protocol='HTTPS',
            target_type='instance',
            vpc_id=self.cluster.vpc.vpc_id,
            name=self.get_target_group_name('cm-ext'),
            health_check_path='/healthcheck'
        )
        self.external_endpoint = cdk.CustomResource(
            self.stack,
            'external-endpoint',
            service_token=cluster_endpoints_lambda_arn,
            properties={
                'endpoint_name': f'{self.module_id}-external-endpoint',
                'listener_arn': external_https_listener_arn,
                'priority': external_endpoint_priority,
                'conditions': [
                    {
                        'Field': 'path-pattern',
                        'Values': external_endpoint_path_patterns
                    }
                ],
                'actions': [
                    {
                        'Type': 'forward',
                        'TargetGroupArn': external_target_group.ref
                    }
                ]
            },
            resource_type='Custom::ClusterManagerEndpointExternal'
        )

        # cluster manager api internal endpoint
        internal_https_listener_arn = self.context.config().get_string('cluster.load_balancers.internal_alb.https_listener_arn', required=True)
        internal_endpoint_priority = self.context.config().get_int('cluster-manager.endpoints.internal.priority', required=True)
        internal_endpoint_path_patterns = self.context.config().get_list('cluster-manager.endpoints.internal.path_patterns', required=True)
        internal_target_group = elbv2.CfnTargetGroup(
            self.stack,
            f'{self.module_id}-internal-target-group',
            port=8443,
            protocol='HTTPS',
            target_type='instance',
            vpc_id=self.cluster.vpc.vpc_id,
            name=self.get_target_group_name('cm-int'),
            health_check_path='/healthcheck'
        )
        self.internal_endpoint = cdk.CustomResource(
            self.stack,
            'internal-endpoint',
            service_token=cluster_endpoints_lambda_arn,
            properties={
                'endpoint_name': f'{self.module_id}-internal-endpoint',
                'listener_arn': internal_https_listener_arn,
                'priority': internal_endpoint_priority,
                'conditions': [
                    {
                        'Field': 'path-pattern',
                        'Values': internal_endpoint_path_patterns
                    }
                ],
                'actions': [
                    {
                        'Type': 'forward',
                        'TargetGroupArn': internal_target_group.ref
                    }
                ]
            },
            resource_type='Custom::ClusterManagerEndpointInternal'
        )

        # register target groups with ASG
        self.auto_scaling_group.node.default_child.target_group_arns = [
            default_target_group.ref,
            internal_target_group.ref,
            external_target_group.ref
        ]