Skip to content

Commit

Permalink
Merge pull request #666 from perfectsense/bugfix/convert-db-subnet-gr…
Browse files Browse the repository at this point in the history
…oup-subnets-into-list

Convert db subnet group subnets into list
  • Loading branch information
harjain99 authored Oct 1, 2024
2 parents 192d8be + 84f116f commit edacdc6
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/main/java/gyro/aws/rds/DbSubnetGroupResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
* Create a db subnet group.
Expand Down Expand Up @@ -63,7 +66,7 @@ public class DbSubnetGroupResource extends RdsTaggableResource implements Copyab

private String description;
private String name;
private Set<SubnetResource> subnets;
private List<SubnetResource> subnets;

/**
* The description for the DB subnet group.
Expand Down Expand Up @@ -96,23 +99,26 @@ public void setName(String name) {
*/
@Required
@Updatable
public Set<SubnetResource> getSubnets() {
public List<SubnetResource> getSubnets() {
if (subnets == null) {
return new HashSet<>();
return new ArrayList<>();
}

return subnets;
return subnets.stream()
.sorted(Comparator.comparing(SubnetResource::getName))
.collect(Collectors.toList());
}

public void setSubnets(Set<SubnetResource> subnets) {
this.subnets = subnets;
public void setSubnets(List<SubnetResource> subnets) {
this.subnets = new ArrayList<>(subnets);
}

@Override
public void copyFrom(DBSubnetGroup group) {
setDescription(group.dbSubnetGroupDescription());
setName(group.dbSubnetGroupName());
setSubnets(group.subnets().stream().map(s -> findById(SubnetResource.class, s.subnetIdentifier())).collect(Collectors.toSet()));
setSubnets(group.subnets().stream().map(s -> findById(SubnetResource.class, s.subnetIdentifier()))
.collect(Collectors.toList()));
setArn(group.dbSubnetGroupArn());
}

Expand Down Expand Up @@ -143,8 +149,8 @@ public void doCreate(GyroUI ui, State state) {
RdsClient client = createClient(RdsClient.class);
CreateDbSubnetGroupResponse response = client.createDBSubnetGroup(
r -> r.dbSubnetGroupDescription(getDescription())
.dbSubnetGroupName(getName())
.subnetIds(getSubnets().stream().map(SubnetResource::getId).collect(Collectors.toSet()))
.dbSubnetGroupName(getName())
.subnetIds(getSubnets().stream().map(SubnetResource::getId).collect(Collectors.toList()))
);

setArn(response.dbSubnetGroup().dbSubnetGroupArn());
Expand All @@ -155,8 +161,8 @@ public void doUpdate(Resource current, Set<String> changedProperties) {
RdsClient client = createClient(RdsClient.class);
client.modifyDBSubnetGroup(
r -> r.dbSubnetGroupName(getName())
.dbSubnetGroupDescription(getDescription())
.subnetIds(getSubnets().stream().map(SubnetResource::getId).collect(Collectors.toSet()))
.dbSubnetGroupDescription(getDescription())
.subnetIds(getSubnets().stream().map(SubnetResource::getId).collect(Collectors.toList()))
);
}

Expand Down

0 comments on commit edacdc6

Please sign in to comment.