Skip to content

Commit

Permalink
Expose ipv6cidr when auto assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanjan90 committed Feb 20, 2024
1 parent d1938c8 commit aaf9827
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/main/java/gyro/aws/ec2/VpcResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import com.psddev.dari.util.ObjectUtils;
import gyro.aws.AwsCredentials;
Expand All @@ -27,12 +28,14 @@
import gyro.core.GyroException;
import gyro.core.GyroUI;
import gyro.core.Type;
import gyro.core.Wait;
import gyro.core.resource.Id;
import gyro.core.resource.Output;
import gyro.core.resource.TestValue;
import gyro.core.resource.Updatable;
import gyro.core.scope.State;
import gyro.core.validation.Required;
import org.apache.commons.lang3.StringUtils;
import software.amazon.awssdk.services.ec2.Ec2Client;
import software.amazon.awssdk.services.ec2.model.AttributeBooleanValue;
import software.amazon.awssdk.services.ec2.model.ClassicLinkDnsSupport;
Expand Down Expand Up @@ -84,6 +87,7 @@ public class VpcResource extends Ec2TaggableResource<Vpc> implements Copyable<Vp
private Boolean defaultVpc;
private String region;
private String account;
private String ipv6CidrBlock;

/**
* The IPv4 network range for the VPC, in CIDR notation.
Expand Down Expand Up @@ -262,6 +266,18 @@ public void setAccount(String account) {
this.account = account;
}

/**
* The IPv6 CIDR block associated with the VPC.
*/
@Output
public String getIpv6CidrBlock() {
return ipv6CidrBlock;
}

public void setIpv6CidrBlock(String ipv6CidrBlock) {
this.ipv6CidrBlock = ipv6CidrBlock;
}

@Override
public String getResourceId() {
return getId();
Expand All @@ -276,6 +292,7 @@ public void copyFrom(Vpc vpc) {
setOwnerId(vpc.ownerId());
setDefaultVpc(vpc.isDefault());
setProvideIpv6CidrBlock(!vpc.ipv6CidrBlockAssociationSet().isEmpty());
setIpv6CidrBlock(vpc.ipv6CidrBlockAssociationSet().isEmpty() ? null : vpc.ipv6CidrBlockAssociationSet().get(0).ipv6CidrBlock());

Ec2Client client = createClient(Ec2Client.class);

Expand Down Expand Up @@ -350,6 +367,20 @@ protected void doCreate(GyroUI ui, State state) {
setInstanceTenancy(vpc.instanceTenancyAsString());
setRegion(credentials(AwsCredentials.class).getRegion());

if (getProvideIpv6CidrBlock() != null && getProvideIpv6CidrBlock()) {
Wait.atMost(1, TimeUnit.MINUTES)
.checkEvery(10, TimeUnit.SECONDS)
.prompt(false)
.until(() -> {
Vpc vpcResponse = getVpc(client);

setIpv6CidrBlock(vpcResponse.ipv6CidrBlockAssociationSet().isEmpty()
? null : vpcResponse.ipv6CidrBlockAssociationSet().get(0).ipv6CidrBlock());
return !StringUtils.isBlank(getIpv6CidrBlock());
});
}


modifySettings(client, new HashSet<>());
}

Expand Down

0 comments on commit aaf9827

Please sign in to comment.