diff --git a/src/main/java/gyro/azure/containerservice/ClusterLoadBalancerProfile.java b/src/main/java/gyro/azure/containerservice/ClusterLoadBalancerProfile.java index f3c5fa8b..431cffbc 100644 --- a/src/main/java/gyro/azure/containerservice/ClusterLoadBalancerProfile.java +++ b/src/main/java/gyro/azure/containerservice/ClusterLoadBalancerProfile.java @@ -66,10 +66,6 @@ public void setEffectiveOutboundIps(List effectiveOutboundIps) { * If set to ``true`` enables multiple standard load balancer. Defaults to ``false``. */ public Boolean getEnableMultipleStandardLoadBalancers() { - if (enableMultipleStandardLoadBalancers == null) { - enableMultipleStandardLoadBalancers = false; - } - return enableMultipleStandardLoadBalancers; } @@ -171,7 +167,9 @@ protected ManagedClusterLoadBalancerProfile toClusterLoadBalancerProfile() { profile.withAllocatedOutboundPorts(getAllocatedOutboundPorts()); } - profile.withEnableMultipleStandardLoadBalancers(getEnableMultipleStandardLoadBalancers()); + if (getEnableMultipleStandardLoadBalancers() != null) { + profile.withEnableMultipleStandardLoadBalancers(getEnableMultipleStandardLoadBalancers()); + } if (getIdleTimeoutInMinutes() != null) { profile.withIdleTimeoutInMinutes(getIdleTimeoutInMinutes()); diff --git a/src/main/java/gyro/azure/network/NetworkResource.java b/src/main/java/gyro/azure/network/NetworkResource.java index a634f64d..c2b71eab 100644 --- a/src/main/java/gyro/azure/network/NetworkResource.java +++ b/src/main/java/gyro/azure/network/NetworkResource.java @@ -132,6 +132,7 @@ public void setAddressSpaces(Set addressSpaces) { * * @subresource gyro.azure.network.SubnetResource */ + @Required public Set getSubnet() { if (subnet == null) { subnet = new HashSet<>(); @@ -273,12 +274,13 @@ public void create(GyroUI ui, State state) { withAddressSpace = networkDefWithoutAddress.withAddressSpace(addressSpace); } + withAddressSpace = withAddressSpace.withSubnets(getSubnet().stream() + .collect(Collectors.toMap(SubnetResource::getName, SubnetResource::getAddressPrefix))); + Network network = withAddressSpace .withTags(getTags()) .create(); - network = network.update().withoutSubnet("subnet1").apply(); - copyFrom(network); } diff --git a/src/main/java/gyro/azure/network/SubnetResource.java b/src/main/java/gyro/azure/network/SubnetResource.java index c109df5b..2151c060 100644 --- a/src/main/java/gyro/azure/network/SubnetResource.java +++ b/src/main/java/gyro/azure/network/SubnetResource.java @@ -151,6 +151,7 @@ public void copyFrom(Subnet subnet) { RouteTableResource.class, subnet.routeTableId()) : null); setServiceEndpoints(toServiceEndpoints(subnet.servicesWithAccess())); + setId(subnet.innerModel().id()); } @Override @@ -186,6 +187,8 @@ public void create(GyroUI ui, State state) { Network response = updateWithAttach.attach().apply(); setId(response.subnets().get(getName()).id()); + + parent.refresh(); } @Override diff --git a/src/main/java/gyro/azure/storage/CloudBlobContainerResource.java b/src/main/java/gyro/azure/storage/CloudBlobContainerResource.java index 9b5d098d..523a10a0 100644 --- a/src/main/java/gyro/azure/storage/CloudBlobContainerResource.java +++ b/src/main/java/gyro/azure/storage/CloudBlobContainerResource.java @@ -18,15 +18,21 @@ import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.concurrent.TimeUnit; +import com.azure.resourcemanager.storage.models.StorageAccount; import com.azure.storage.blob.BlobContainerClient; import com.azure.storage.blob.BlobServiceClient; import com.azure.storage.blob.BlobServiceClientBuilder; +import com.azure.storage.blob.models.BlobContainerAccessPolicies; +import com.azure.storage.blob.models.BlobErrorCode; +import com.azure.storage.blob.models.BlobStorageException; import com.azure.storage.blob.models.PublicAccessType; import gyro.azure.AzureResource; import gyro.azure.Copyable; +import gyro.core.GyroException; import gyro.core.GyroUI; import gyro.core.Type; import gyro.core.Wait; @@ -77,7 +83,6 @@ public void setName(String name) { /** * The public access of the container. */ - @Required @ValidStrings({ "blob", "container" }) @Updatable public String getPublicAccess() { @@ -127,7 +132,8 @@ public void setId(String id) { @Override public void copyFrom(BlobContainerClient container) { - setPublicAccess(container.getAccessPolicy().getBlobAccessType().toString()); + setPublicAccess(Optional.ofNullable(container).map(BlobContainerClient::getAccessPolicy).map( + BlobContainerAccessPolicies::getBlobAccessType).map(PublicAccessType::toString).orElse(null)); setName(container.getBlobContainerName()); setMetadata(container.getProperties().getMetadata()); setStorageAccount(findById(StorageAccountResource.class, container.getAccountName())); @@ -150,16 +156,45 @@ public boolean refresh() { public void create(GyroUI ui, State state) { BlobContainerClient blobContainer = blobContainer(); - blobContainer.create(); + try { + blobContainer.create(); - blobContainer = blobContainer(); + } catch (BlobStorageException ex) { + throw new GyroException( + String.format("Could not create container [%s] as it already exists", getName()), ex); + } - blobContainer.setAccessPolicy(PublicAccessType.fromString(getPublicAccess()), null); + state.save(); if (!getMetadata().isEmpty()) { blobContainer.setMetadata(getMetadata()); } + state.save(); + + if (getPublicAccess() != null) { + StorageAccount refreshedStorageAccount = getStorageAccount().getStorageAccount(); + + if (refreshedStorageAccount != null && refreshedStorageAccount.isBlobPublicAccessAllowed()) { + Wait.atMost(2, TimeUnit.MINUTES) + .prompt(false) + .checkEvery(10, TimeUnit.SECONDS) + .until(() -> { + try { + blobContainer.setAccessPolicy(PublicAccessType.fromString(getPublicAccess()), null); + return true; + + } catch (BlobStorageException ex) { + if (BlobErrorCode.fromString("PublicAccessNotPermitted").equals(ex.getErrorCode())) { + // Retrying as the storage account has not transitioned to public yet + return false; + } + throw ex; + } + }); + } + } + copyFrom(blobContainer); }