Skip to content

Commit 46af808

Browse files
authored
Throw exception when deploy with used deployment name (#3183)
1 parent 5faafc0 commit 46af808

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/forms/arm/CreateDeploymentForm.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@
3838
import com.intellij.openapi.wm.WindowManager;
3939
import com.intellij.ui.HyperlinkLabel;
4040
import com.microsoft.azure.management.Azure;
41+
import com.microsoft.azure.management.resources.Deployment;
4142
import com.microsoft.azure.management.resources.Deployment.DefinitionStages.WithTemplate;
4243
import com.microsoft.azure.management.resources.DeploymentMode;
4344
import com.microsoft.azure.management.resources.Location;
4445
import com.microsoft.azure.management.resources.ResourceGroup;
4546
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
4647
import com.microsoft.azuretools.authmanage.AuthMethodManager;
4748
import com.microsoft.azuretools.authmanage.models.SubscriptionDetail;
49+
import com.microsoft.azuretools.core.mvp.model.AzureMvpModel;
50+
import com.microsoft.azuretools.core.mvp.model.ResourceEx;
4851
import com.microsoft.azuretools.telemetry.TelemetryConstants;
4952
import com.microsoft.azuretools.telemetrywrapper.EventType;
5053
import com.microsoft.azuretools.telemetrywrapper.EventUtil;
@@ -72,6 +75,8 @@
7275

7376
public class CreateDeploymentForm extends DeploymentBaseForm {
7477

78+
private static final String DUPLICATED_DEPLOYMENT_NAME = "A deployment with the same name already exists";
79+
7580
private JPanel contentPane;
7681
private JTextField rgNameTextFiled;
7782
private JComboBox rgNameCb;
@@ -153,6 +158,13 @@ public void run(@NotNull ProgressIndicator indicator) {
153158
((ElementWrapper<Region>) regionCb.getSelectedItem()).getValue());
154159
} else {
155160
ResourceGroup rg = ((ElementWrapper<ResourceGroup>) rgNameCb.getSelectedItem()).getValue();
161+
List<ResourceEx<Deployment>> deployments = AzureMvpModel.getInstance()
162+
.getDeploymentByRgName(subs.getSubscriptionId(), rg.name());
163+
boolean isExist = deployments.parallelStream()
164+
.anyMatch(deployment -> deployment.getResource().name().equals(deploymentName));
165+
if (isExist) {
166+
throw new RuntimeException(DUPLICATED_DEPLOYMENT_NAME);
167+
}
156168
rgName = rg.name();
157169
template = azure.deployments().define(deploymentName).withExistingResourceGroup(rg);
158170
}

0 commit comments

Comments
 (0)