diff --git a/cookbooks/aws-parallelcluster-environment/libraries/fsx.rb b/cookbooks/aws-parallelcluster-environment/libraries/fsx.rb index 397335aa8..dc5909f41 100644 --- a/cookbooks/aws-parallelcluster-environment/libraries/fsx.rb +++ b/cookbooks/aws-parallelcluster-environment/libraries/fsx.rb @@ -1,4 +1,10 @@ def aws_domain_for_fsx(region) # DNS names have the default AWS domain (amazonaws.com) also in China and GovCloud. - region.start_with?("us-iso") ? aws_domain : CLASSIC_AWS_DOMAIN + if region.start_with?("us-iso-") + US_ISO_AWS_DOMAIN + elsif region.start_with?("us-isob-") + US_ISOB_AWS_DOMAIN + else + CLASSIC_AWS_DOMAIN + end end diff --git a/cookbooks/aws-parallelcluster-environment/spec/unit/libraries/fsx_spec.rb b/cookbooks/aws-parallelcluster-environment/spec/unit/libraries/fsx_spec.rb new file mode 100644 index 000000000..9b4c853f2 --- /dev/null +++ b/cookbooks/aws-parallelcluster-environment/spec/unit/libraries/fsx_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe 'aws-parallelcluster-environment:libraries:aws_domain_for_fsx' do + shared_examples 'a valid aws_domain_for_fsx function' do |region, expected_aws_domain| + it 'returns the correct AWS domain' do + result = aws_domain_for_fsx(region) + expect(result).to eq(expected_aws_domain) + end + end + + context 'when in US-ISO region' do + include_examples 'a valid aws_domain_for_fsx function', 'us-iso-WHATEVER', 'c2s.ic.gov' + end + + context 'when in US-ISOB region' do + include_examples 'a valid aws_domain_for_fsx function', 'us-isob-', 'sc2s.sgov.gov' + end + + context 'when in CN region' do + include_examples 'a valid aws_domain_for_fsx function', 'cn-WHATEVER', 'amazonaws.com' + end + + context 'when in GovCloud region' do + include_examples 'a valid aws_domain_for_fsx function', 'us-gov-WHATEVER', 'amazonaws.com' + end + + context 'when in whatever else region' do + include_examples 'a valid aws_domain_for_fsx function', 'WHATEVER-ELSE', 'amazonaws.com' + end +end