terraform-aws-ecs-cluster icon indicating copy to clipboard operation
terraform-aws-ecs-cluster copied to clipboard

Use launch_template instead of deprecated launch_configuration

Open jonassvalin opened this issue 2 years ago • 0 comments

Authors: @jonassvalin @gryff

We have migrated the module to use launch_template instead of the deprecated launch_configuration.

Most of the values were a 1-to-1 match from attributes in the configuration.

Two things are worthy of note in the changes:

  1. In the README there was a documented variable of launch_configuration_create_before_destroy, which never seemed to be used, instead the lifecycle parameter was always hardcoded to true. We kept this behaviour and deleted the variable from the README.
  2. There were some integration tests that asserted things on the launch configuration that are not possible to directly assert on the returned launch_template object. The object we get back is of type LaunchTemplateSpecification https://docs.aws.amazon.com/sdk-for-ruby/v2/api/Aws/EC2/Types/LaunchTemplateSpecification.html which only includes name, id and version. We added a test for the ID, but had to omit the following tests that were previously in the full.spec:
describe 'Launch Configuration' do

  it 'does not add a docker block device' do # TODO: does this do anything?
    expect(launch_config.block_device_mappings.size).to(eq(1))
  end

  context 'when custom security groups are provided' do
    it {
      expect(launch_config).to have_security_group(
                                 "#{component}-#{deployment_identifier}-0"
                               )
    }

    it {
      expect(launch_config).to have_security_group(
                                 "#{component}-#{deployment_identifier}-1"
                               )
    }

    it 'has correct number of security groups' do
      expect(launch_config.security_groups.size).to(eq(3))
    end
  end

  its(:user_data) do
    is_expected.to eq(Base64.strict_encode64(<<~DOC))
        #!/bin/bash
        echo "ECS_CLUSTER=#{cluster_name}" > /etc/ecs/ecs.config
    DOC
  end

  it {
    expect(launch_config).to have_security_group(cluster_name)
  }
end

I believe all the cases are covered by the unit tests, however.

jonassvalin avatar Dec 07 '22 15:12 jonassvalin