Skip to content

Commit

Permalink
JENKINS-72643: Fixed listing regions when using ec2 instance profile …
Browse files Browse the repository at this point in the history
…credentials

In the case where a user specified an ARN Role in the advanced section of cloud config we need to use that information when pulling the list of regions.

In my case without this ARN Role being used with credentials I would get an empty drop-down list with no errors.

I added a log message with the exception to expose a bit of information in case of failures.
  • Loading branch information
craigcomstock committed Mar 26, 2024
1 parent bb1db79 commit 16a8ba9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/hudson/plugins/ec2/AmazonEC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,20 @@ public FormValidation doCheckAltEC2Endpoint(@QueryParameter String value) {
public ListBoxModel doFillRegionItems(
@QueryParameter String altEC2Endpoint,
@QueryParameter boolean useInstanceProfileForCredentials,
@QueryParameter String roleArn,
@QueryParameter String roleSessionName,
@QueryParameter String region,
@QueryParameter String credentialsId)

throws IOException, ServletException {
ListBoxModel model = new ListBoxModel();
if (Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
try {
AWSCredentialsProvider credentialsProvider = createCredentialsProvider(useInstanceProfileForCredentials,
credentialsId);
credentialsId,
roleArn,
roleSessionName,
region);
AmazonEC2 client = AmazonEC2Factory.getInstance().connect(credentialsProvider, determineEC2EndpointURL(altEC2Endpoint));
DescribeRegionsResult regions = client.describeRegions();
List<Region> regionList = regions.getRegions();
Expand All @@ -201,6 +207,7 @@ public ListBoxModel doFillRegionItems(
model.add(name, name);
}
} catch (SdkClientException ex) {
LOGGER.log(Level.INFO, "AmazonEC2Cloud.doFillRegionItems() got exception: " + ex);

Check warning on line 210 in src/main/java/hudson/plugins/ec2/AmazonEC2Cloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 210 is not covered by tests
// Ignore, as this may happen before the credentials are specified
}
}
Expand Down

0 comments on commit 16a8ba9

Please sign in to comment.