# Path: stacker_blueprints/empire/base.py
# class EmpireBase(Blueprint):
#     def create_conditions(self):
#         logger.debug("No conditions to setup for %s", self.name)
# 
#     def create_security_groups(self):
#         logger.debug("No security_groups to setup for %s", self.name)
# 
#     def create_ecs_cluster(self):
#         logger.debug("No ecs cluster to setup for %s", self.name)
# 
#     def create_load_balancer(self):
#         logger.debug("No load_balancer to setup for %s", self.name)
# 
#     def create_iam_profile(self):
#         logger.debug("No iam_profile to setup for %s", self.name)
# 
#     def create_autoscaling_group(self):
#         logger.debug("No autoscaling_group to setup for %s", self.name)
# 
#     def generate_seed_contents(self):
#         raise Exception('Empire subclass must define seed contents')
# 
#     def generate_user_data(self):
#         contents = Join("", self.generate_seed_contents())
#         stanza = Base64(Join(
#             "",
#             [
#                 "#cloud-config\n",
#                 "write_files:\n",
#                 "  - encoding: b64\n",
#                 "    content: ", Base64(contents), "\n",
#                 "    owner: root:root\n",
#                 "    path: /etc/empire/seed\n",
#                 "    permissions: 0640\n"
#             ]
#         ))
#         return stanza
# 
#     def create_template(self):
#         self.create_conditions()
#         self.create_security_groups()
#         self.create_ecs_cluster()
#         self.create_load_balancer()
#         self.create_iam_profile()
#         self.create_autoscaling_group()
# 
# Path: stacker_blueprints/empire/policies.py
# def ecs_agent_policy():
#     p = Policy(
#         Statement=[
#             Statement(
#                 Effect=Allow,
#                 Resource=["*"],
#                 Action=[
#                     ecs.CreateCluster,
#                     ecs.RegisterContainerInstance,
#                     ecs.DeregisterContainerInstance,
#                     ecs.DiscoverPollEndpoint,
#                     ecs.Action("Submit*"),
#                     ecs.Poll,
#                     ecs.Action("StartTelemetrySession")]),
#             Statement(
#                 Effect=Allow,
#                 Action=[
#                     ecr.GetAuthorizationToken,
#                     ecr.BatchCheckLayerAvailability,
#                     ecr.GetDownloadUrlForLayer,
#                     ecr.BatchGetImage,
#                 ],
#                 Resource=["*"],
#             ),
#         ]
#     )
# 
#     return p


from troposphere import (
    Ref,
    Output,
    GetAtt,
    FindInMap,
)
from troposphere import (
    ec2,
    autoscaling,
    ecs,
)
from troposphere.autoscaling import Tag as ASTag
from troposphere.iam import (
    InstanceProfile,
    Policy,
    Role,
)
from awacs.helpers.trust import (
    get_default_assumerole_policy,
)
from stacker.blueprints.variables.types import (
    CFNCommaDelimitedList,
    CFNNumber,
    CFNString,
    EC2KeyPairKeyName,
    EC2SecurityGroupId,
    EC2SubnetIdList,
    EC2VPCId,
)
from .base import EmpireBase
from .policies import ecs_agent_policy
                CLUSTER_SG_NAME,
                GroupDescription=CLUSTER_SG_NAME,
                VpcId=Ref("VpcId")))

        t.add_output(
            Output("SecurityGroup", Value=Ref(CLUSTER_SG_NAME)))

        # Allow access to the DB
        t.add_resource(
            ec2.SecurityGroupIngress(
                "EmpireControllerDBAccess",
                IpProtocol="tcp", FromPort=5432, ToPort=5432,
                SourceSecurityGroupId=Ref(CLUSTER_SG_NAME),
                GroupId=Ref("DatabaseSecurityGroup")))

    def create_ecs_cluster(self):
        t = self.template
        t.add_resource(ecs.Cluster("EmpireControllerCluster"))
        t.add_output(
            Output("ECSCluster", Value=Ref("EmpireControllerCluster")))

    def build_block_device(self):
        volume = autoscaling.EBSBlockDevice(VolumeSize="50")
        return [autoscaling.BlockDeviceMapping(
            DeviceName="/dev/sdh", Ebs=volume)]

    def generate_iam_policies(self):
        return [
            Policy(
                PolicyName="ecs-agent",

# Path: stacker_blueprints/empire/base.py
# class EmpireBase(Blueprint):
#     def create_conditions(self):
#         logger.debug("No conditions to setup for %s", self.name)
# 
#     def create_security_groups(self):
#         logger.debug("No security_groups to setup for %s", self.name)
# 
#     def create_ecs_cluster(self):
#         logger.debug("No ecs cluster to setup for %s", self.name)
# 
#     def create_load_balancer(self):
#         logger.debug("No load_balancer to setup for %s", self.name)
# 
#     def create_iam_profile(self):
#         logger.debug("No iam_profile to setup for %s", self.name)
# 
#     def create_autoscaling_group(self):
#         logger.debug("No autoscaling_group to setup for %s", self.name)
# 
#     def generate_seed_contents(self):
#         raise Exception('Empire subclass must define seed contents')
# 
#     def generate_user_data(self):
#         contents = Join("", self.generate_seed_contents())
#         stanza = Base64(Join(
#             "",
#             [
#                 "#cloud-config\n",
#                 "write_files:\n",
#                 "  - encoding: b64\n",
#                 "    content: ", Base64(contents), "\n",
#                 "    owner: root:root\n",
#                 "    path: /etc/empire/seed\n",
#                 "    permissions: 0640\n"
#             ]
#         ))
#         return stanza
# 
#     def create_template(self):
#         self.create_conditions()
#         self.create_security_groups()
#         self.create_ecs_cluster()
#         self.create_load_balancer()
#         self.create_iam_profile()
#         self.create_autoscaling_group()
# 
# Path: stacker_blueprints/empire/policies.py
# def ecs_agent_policy():
#     p = Policy(
#         Statement=[
#             Statement(
#                 Effect=Allow,
#                 Resource=["*"],
#                 Action=[
#                     ecs.CreateCluster,
#                     ecs.RegisterContainerInstance,
#                     ecs.DeregisterContainerInstance,
#                     ecs.DiscoverPollEndpoint,
#                     ecs.Action("Submit*"),
#                     ecs.Poll,
#                     ecs.Action("StartTelemetrySession")]),
#             Statement(
#                 Effect=Allow,
#                 Action=[
#                     ecr.GetAuthorizationToken,
#                     ecr.BatchCheckLayerAvailability,
#                     ecr.GetDownloadUrlForLayer,
#                     ecr.BatchGetImage,
#                 ],
#                 Resource=["*"],
#             ),
#         ]
#     )
# 
#     return p


# Path: stacker_blueprints/empire/controller.py
from troposphere import (
    Ref,
    Output,
    GetAtt,
    FindInMap,
)
from troposphere import (
    ec2,
    autoscaling,
    ecs,
)
from troposphere.autoscaling import Tag as ASTag
from troposphere.iam import (
    InstanceProfile,
    Policy,
    Role,
)
from awacs.helpers.trust import (
    get_default_assumerole_policy,
)
from stacker.blueprints.variables.types import (
    CFNCommaDelimitedList,
    CFNNumber,
    CFNString,
    EC2KeyPairKeyName,
    EC2SecurityGroupId,
    EC2SubnetIdList,
    EC2VPCId,
)
from .base import EmpireBase
from .policies import ecs_agent_policy

                CLUSTER_SG_NAME,
                GroupDescription=CLUSTER_SG_NAME,
                VpcId=Ref("VpcId")))

        t.add_output(
            Output("SecurityGroup", Value=Ref(CLUSTER_SG_NAME)))

        # Allow access to the DB
        t.add_resource(
            ec2.SecurityGroupIngress(
                "EmpireControllerDBAccess",
                IpProtocol="tcp", FromPort=5432, ToPort=5432,
                SourceSecurityGroupId=Ref(CLUSTER_SG_NAME),
                GroupId=Ref("DatabaseSecurityGroup")))

    def create_ecs_cluster(self):
        t = self.template
        t.add_resource(ecs.Cluster("EmpireControllerCluster"))
        t.add_output(
            Output("ECSCluster", Value=Ref("EmpireControllerCluster")))

    def build_block_device(self):
        volume = autoscaling.EBSBlockDevice(VolumeSize="50")
        return [autoscaling.BlockDeviceMapping(
            DeviceName="/dev/sdh", Ebs=volume)]

    def generate_iam_policies(self):
        return [
            Policy(
                PolicyName="ecs-agent",

                PolicyDocument=ecs_agent_policy(),