Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow define security groups in resource_pool #28

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/bosh_aws_cpi/lib/cloud/aws/instance_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def build_instance_params(stemcell_id, resource_pool, networks_spec, disk_locali

set_user_data_parameter(instance_params, networks_spec)
set_key_name_parameter(instance_params, resource_pool["key_name"], options["aws"]["default_key_name"])
set_security_groups_parameter(instance_params, networks_spec, options["aws"]["default_security_groups"])
set_security_groups_parameter(instance_params, resource_pool, networks_spec, options["aws"]["default_security_groups"])
set_vpc_parameters(instance_params, networks_spec)
set_iam_instance_profile_parameter(instance_params, resource_pool["iam_instance_profile"], options["aws"]["default_iam_instance_profile"])
set_availability_zone_parameter(
Expand Down Expand Up @@ -275,8 +275,8 @@ def set_key_name_parameter(instance_params, resource_pool_key_name, default_aws_
instance_params[:key_name] = key_name unless key_name.nil?
end

def set_security_groups_parameter(instance_params, networks_spec, default_security_groups)
security_groups = extract_security_groups(networks_spec)
def set_security_groups_parameter(instance_params, resource_pool, networks_spec, default_security_groups)
security_groups = resource_pool["security_groups"] || extract_security_groups(networks_spec)
if security_groups.empty?
validate_and_prepare_security_groups_parameter(instance_params, default_security_groups)
else
Expand Down
41 changes: 41 additions & 0 deletions src/bosh_aws_cpi/spec/unit/instance_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,11 @@ def set_ephemeral_disk_size(size)
let(:sg_name_1) { 'yay' }
let(:sg_name_2) { 'aya' }
let(:sg_name_3) { 'default' }
let(:sg_name_4) { 'instance' }
let(:sg_id_1) { 'sg-12345678' }
let(:sg_id_2) { 'sg-23456789' }
let(:sg_id_3) { 'sg-01234567' }
let(:sg_id_4) { 'sg-34567890' }

let(:networks_spec) do
{
Expand Down Expand Up @@ -1091,6 +1093,45 @@ def verify_error
verify_error
end
end

context 'when resource_pool have security_groups configured' do
it "overrides network spec security groups names with instance security group names" do
networks_spec['network']['cloud_properties']['security_groups'] = sg_name_1
networks_spec['artwork']['cloud_properties']['security_groups'] = [sg_name_1, sg_name_2]
instance_options['aws']['default_security_groups'] = [sg_name_3]
resource_pool['security_groups'] = [sg_name_4]

verify_security_group_parameter(:security_groups, [sg_name_4])
end
it "overrides network spec security groups ids with instance security group names" do
networks_spec['network']['cloud_properties']['security_groups'] = sg_id_1
networks_spec['artwork']['cloud_properties']['security_groups'] = [sg_id_1, sg_id_2]
instance_options['aws']['default_security_groups'] = [sg_id_3]
resource_pool['security_groups'] = [sg_name_4]

verify_security_group_parameter(:security_groups, [sg_name_4])
end
it "overrides network spec security groups names with instance security group ids" do
networks_spec['network']['cloud_properties']['security_groups'] = sg_name_1
networks_spec['artwork']['cloud_properties']['security_groups'] = [sg_name_1, sg_name_2]
instance_options['aws']['default_security_groups'] = [sg_name_3]
resource_pool['security_groups'] = [sg_id_4]

verify_security_group_parameter(:security_group_ids, [sg_id_4])
end
it "overrides network spec security groups ids with instance security group ids" do
networks_spec['network']['cloud_properties']['security_groups'] = sg_id_1
networks_spec['artwork']['cloud_properties']['security_groups'] = [sg_id_1, sg_id_2]
instance_options['aws']['default_security_groups'] = [sg_id_3]
resource_pool['security_groups'] = [sg_id_4]

verify_security_group_parameter(:security_group_ids, [sg_id_4])
end
it 'raises an error when both ids and names are specified in security_groups' do
resource_pool['security_groups'] = [sg_id_4, sg_name_4]
verify_error
end
end
end

describe 'vpc_parameters' do
Expand Down