Class: Ufo::Cfn::Stack::Builder::Resources::EcsService

Inherits:
Base show all
Defined in:
lib/ufo/cfn/stack/builder/resources/ecs_service.rb

Instance Attribute Summary

Attributes inherited from Base

#vars

Attributes inherited from Ufo::CLI::Base

#task_definition

Instance Method Summary collapse

Methods inherited from Base

build, #initialize, #managed_security_group, #managed_security_groups?, #security_groups

Methods included from Ufo::Concerns

#deploy, #info, #ps

Methods included from Ufo::Concerns::Names

#names

Methods included from AwsServices

#acm, #applicationautoscaling, #aws_options, #cfn, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #s3, #ssm_client, #waf_client

Methods included from AwsServices::Concerns

#find_stack, #find_stack_resources, #stack_resources, #status, #task_definition_arns

Methods inherited from Ufo::CLI::Base

#initialize

Methods included from Utils::Sure

#sure?

Methods included from Utils::Pretty

#pretty_home, #pretty_path, #pretty_time

Methods included from Utils::Logging

#logger

Constructor Details

This class inherits a constructor from Ufo::Cfn::Stack::Builder::Base

Instance Method Details

#buildObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/ufo/cfn/stack/builder/resources/ecs_service.rb', line 3

def build
  attrs = {
    Type: "AWS::ECS::Service",
    Properties: properties
  }

  attrs[:DependsOn] = "Listener" if vars[:create_elb]

  attrs
end

#propertiesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ufo/cfn/stack/builder/resources/ecs_service.rb', line 14

def properties
  props = {
    Cluster: @cluster,
    DeploymentConfiguration: deployment_configuration,
    DesiredCount: {
      "Fn::If": [
        "EcsDesiredCountIsBlank",
        {Ref: "AWS::NoValue"},
        {Ref: "EcsDesiredCount"}
      ]
    },
    EnableExecuteCommand: Ufo.config.exec.enabled,
    LoadBalancers: {
      "Fn::If": [
        "CreateTargetGroupIsTrue",
        [
          {
            ContainerName: vars[:container][:name],
            ContainerPort: vars[:container][:port],
            TargetGroupArn: {Ref: "TargetGroup"}
          }
        ],
        {
          "Fn::If": [
            "ElbTargetGroupIsBlank",
            [],
            [
              {
                ContainerName: vars[:container][:name],
                ContainerPort: vars[:container][:port],
                TargetGroupArn: {Ref: "ElbTargetGroup"}
              }
            ]
          ]
        }
      ]
    },
    SchedulingStrategy: {Ref: "EcsSchedulingStrategy"}
  }

  props[:TaskDefinition] = vars[:rollback_task_definition] ? vars[:rollback_task_definition] : {Ref: "TaskDefinition"}

  if vars[:container][:network_mode].to_s == 'awsvpc'
    props[:NetworkConfiguration] = {
      AwsvpcConfiguration: {
        Subnets: {Ref: "EcsSubnets"},
        SecurityGroups: security_groups(:ecs)
      }
    }

    if vars[:container][:fargate]
      props[:LaunchType] = "FARGATE"
      props[:NetworkConfiguration][:AwsvpcConfiguration][:AssignPublicIp] = "ENABLED" # Works with fargate but doesnt seem to work with non-fargate
    end
  end

  props
end