Skip to content

Commit

Permalink
Merge pull request #124 from rundeck-plugins/region_update
Browse files Browse the repository at this point in the history
Add region property as alternative to endpoint
  • Loading branch information
chrismcg14 authored Feb 1, 2023
2 parents 73a7fe2 + a4f94ae commit ac7a3f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class EC2ResourceModelSource implements ResourceModelSource {
int httpProxyPort = 80;
String httpProxyUser;
String httpProxyPass;
String region;
String mappingParams;
File mappingFile;
Services services;
Expand Down Expand Up @@ -150,6 +151,7 @@ public class EC2ResourceModelSource implements ResourceModelSource {
public EC2ResourceModelSource(final Properties configuration, final Services services) {
this.accessKey = configuration.getProperty(EC2ResourceModelSourceFactory.ACCESS_KEY);
this.secretKey = configuration.getProperty(EC2ResourceModelSourceFactory.SECRET_KEY);
this.region = configuration.getProperty(EC2ResourceModelSourceFactory.REGION);
this.secretKeyStoragePath = configuration.getProperty(EC2ResourceModelSourceFactory.SECRET_KEY_STORAGE_PATH);
this.endpoint = configuration.getProperty(EC2ResourceModelSourceFactory.ENDPOINT);
this.pageResults = Integer.parseInt(configuration.getProperty(EC2ResourceModelSourceFactory.MAX_RESULTS));
Expand Down Expand Up @@ -241,6 +243,7 @@ private void initialize() {
mapper = new InstanceToNodeMapper(this.credentials, mapping, clientConfiguration, pageResults);
mapper.setFilterParams(params);
mapper.setEndpoint(endpoint);
mapper.setRegion(region);
mapper.setRunningStateOnly(runningOnly);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class EC2ResourceModelSourceFactory implements ResourceModelSourceFactory
public static final String SECRET_KEY = "secretKey";
public static final String SECRET_KEY_STORAGE_PATH = "secretKeyStoragePath";
public static final String ROLE_ARN = "assumeRoleArn";
public static final String REGION = "region";
public static final String MAPPING_FILE = "mappingFile";
public static final String REFRESH_INTERVAL = "refreshInterval";
public static final String SYNCHRONOUS_LOAD = "synchronousLoad";
Expand Down Expand Up @@ -159,6 +160,9 @@ public ResourceModelSource createResourceModelSource(Properties configuration) t
"Optionally use `ALL_REGIONS` to automatically pull in instances from all regions that the AWS credentials (or IAM Role) have access to.",
false,
null))
.property(PropertyUtil.string(REGION, "Region", "AWS EC2 region.",
false,
null))
.property(PropertyUtil.string(HTTP_PROXY_HOST, "HTTP Proxy Host", "HTTP Proxy Host Name, or blank for default", false, null))
.property(PropertyUtil.integer(HTTP_PROXY_PORT, "HTTP Proxy Port", "HTTP Proxy Port, or blank for 80", false, "80"))
.property(PropertyUtil.string(HTTP_PROXY_USER, "HTTP Proxy User", "HTTP Proxy User Name, or blank for default", false, null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.regions.RegionImpl;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.ec2.AmazonEC2Client;
import com.amazonaws.services.ec2.model.*;
import com.dtolabs.rundeck.core.common.INodeEntry;
Expand Down Expand Up @@ -54,6 +56,7 @@ class InstanceToNodeMapper {
private ExecutorService executorService = Executors.newSingleThreadExecutor();
private ArrayList<String> filterParams;
private String endpoint;
private String region;
private boolean runningStateOnly = true;
private Properties mapping;
private int maxResults;
Expand Down Expand Up @@ -141,6 +144,9 @@ public NodeSetImpl performQuery() {
}
}
}
else if(region != null){
ec2.setEndpoint("https://ec2." + region + ".amazonaws.com");
}
else{
zones = ec2.describeAvailabilityZones();

Expand Down Expand Up @@ -496,6 +502,10 @@ public void setEndpoint(final String endpoint) {
this.endpoint = endpoint;
}

public void setRegion(final String region) {
this.region = region;
}

public Properties getMapping() {
return mapping;
}
Expand Down

0 comments on commit ac7a3f2

Please sign in to comment.