Skip to content

Commit

Permalink
feat: Implements placement options and license specifications (#615)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Dan Webb <[email protected]>
  • Loading branch information
mfortin and damacus authored Nov 28, 2023
1 parent a8e84e5 commit 10f0232
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
37 changes: 37 additions & 0 deletions lib/kitchen/driver/aws/instance_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,43 @@ def ec2_instance_data
i[:placement] = { tenancy: }
end
end
placement = config[:placement]
if placement
unless i.key?(:placement)
i[:placement] = {}
end
if placement[:affinity]
i[:placement][:affinity] = placement[:affinity]
end
if placement[:availability_zone]
i[:placement][:availability_zone] = placement[:availability_zone]
end
if placement[:group_id] && !placement[:group_name]
i[:placement][:group_id] = placement[:group_id]
end
if placement[:group_name] && !placement[:group_id]
i[:placement][:group_name] = placement[:group_name]
end
if placement[:host_id]
i[:placement][:host_id] = placement[:host_id]
end
if placement[:host_resource_group_arn]
i[:placement][:host_resource_group_arn] = placement[:host_resource_group_arn]
end
if placement[:partition_number]
i[:placement][:partition_number] = placement[:partition_number]
end
if placement[:tenancy]
i[:placement][:tenancy] = placement[:tenancy]
end
end
license_specifications = config[:licenses]
if license_specifications
i[:licenses] = []
license_specifications.each do |license_configuration_arn|
i[:licenses].append({ license_configuration_arn: license_configuration_arn[:license_configuration_arn] })
end
end
unless config[:instance_initiated_shutdown_behavior].nil? ||
config[:instance_initiated_shutdown_behavior].empty?
i[:instance_initiated_shutdown_behavior] = config[:instance_initiated_shutdown_behavior]
Expand Down
47 changes: 45 additions & 2 deletions spec/kitchen/driver/aws/instance_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,37 @@
end
end

context "when placement host resource group arn and licenses are provided" do
let(:config) do
{
region: "eu-east-1",
placement: {
host_resource_group_arn: "arn:aws:ec2:us-east-1:123456789012:resource-group/my-group",
},
licenses: [
{
license_configuration_arn: "arn:aws:ec2:us-east-1:123456789012:license-configuration/my-license",
}
],
}
end

it "adds the region to it in the instance data" do
expect(generator.ec2_instance_data).to eq(
instance_type: nil,
ebs_optimized: nil,
image_id: nil,
key_name: nil,
subnet_id: nil,
private_ip_address: nil,
max_count: 1,
min_count: 1,
placement: { host_resource_group_arn: "arn:aws:ec2:us-east-1:123456789012:resource-group/my-group"},
licenses: [{license_configuration_arn: "arn:aws:ec2:us-east-1:123456789012:license-configuration/my-license"}]
)
end
end

context "when provided the maximum config" do
let(:config) do
{
Expand Down Expand Up @@ -672,9 +703,15 @@
string_tag: "string",
integer_tag: 1,
},
licenses: [{
license_configuration_arn: "arn:aws:ec2:us-east-1:123456789012:license-configuration/my-license",
}],
placement: {
availability_zone: "eu-west-1a",
tenancy: "dedicated"
},
}
end

it "returns the maximum data" do
expect(generator.ec2_instance_data).to eq(
instance_type: "micro",
Expand All @@ -694,6 +731,9 @@
},
],
iam_instance_profile: { name: "iam-123" },
licenses: [{
license_configuration_arn: "arn:aws:ec2:us-east-1:123456789012:license-configuration/my-license",
}],
network_interfaces: [{
device_index: 0,
associate_public_ip_address: true,
Expand All @@ -702,7 +742,10 @@
groups: ["sg-789"],
private_ip_address: "0.0.0.0",
}],
placement: { availability_zone: "eu-west-1a" },
placement: {
availability_zone: "eu-west-1a",
tenancy: "dedicated"
},
user_data: Base64.encode64("foo"),
max_count: 1,
min_count: 1,
Expand Down

0 comments on commit 10f0232

Please sign in to comment.