Skip to content

Commit 5d5dfcb

Browse files
fix: disable region check for Azure CloudEnvironment (#69)
fix #66 Azure needs to use ResourceGroup name in the region parameter, so cannot validate it --------- Co-authored-by: Max Xu <[email protected]>
1 parent d6e32bc commit 5d5dfcb

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

cloud/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func init() {
124124
"cloud_connection_name": "Name of the cloud connection",
125125
"environment_type": "Type of the cloud environment, either: dev, test, staging, production, acc, qa or poc",
126126
"cloud_environment_name": "Name of the cloud environment",
127-
"region": "The region of the cloud environment",
127+
"region": "The region of the cloud environment, for Azure, it should be the resource group name",
128128
"zone": "The zone of the cloud environment, the underlying infrastructure will only be created in this zone if configured",
129129
"default_gateway": "The default gateway of the cloud environment",
130130
"apikey_name": "The name of the api key",

cloud/resource_cloud_environment.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func resourceCloudEnvironment() *schema.Resource {
9090
Type: schema.TypeString,
9191
Required: true,
9292
Description: descriptions["region"],
93-
ValidateFunc: validateRegion,
93+
ValidateFunc: validateNotBlank,
9494
},
9595
"zone": {
9696
Type: schema.TypeString,
@@ -212,12 +212,24 @@ func resourceCloudEnvironmentCreate(ctx context.Context, d *schema.ResourceData,
212212
if err != nil {
213213
return diag.FromErr(fmt.Errorf("ERROR_INIT_CLIENT_ON_CLOUD_ENVIRONMENT: %w", err))
214214
}
215+
216+
cc, err := clientSet.CloudV1alpha1().CloudConnections(namespace).Get(ctx, cloudConnectionName, metav1.GetOptions{})
217+
if err != nil {
218+
return diag.FromErr(err)
219+
}
220+
215221
annotations := make(map[string]string)
216222
if len(rawAnnotations) > 0 {
217223
annotations = convertToStringMap(rawAnnotations)
218224
}
219225
annotations["cloud.streamnative.io/environment-type"] = cloudEnvironmentType
220226

227+
if cc.Spec.ConnectionType != cloudv1alpha1.ConnectionTypeAzure {
228+
if !contains(validRegions, region) {
229+
return diag.FromErr(fmt.Errorf("invalid region: %s", region))
230+
}
231+
}
232+
221233
cloudEnvironment := &cloudv1alpha1.CloudEnvironment{
222234
TypeMeta: metav1.TypeMeta{
223235
Kind: "CloudEnvironment",
@@ -256,10 +268,6 @@ func resourceCloudEnvironmentCreate(ctx context.Context, d *schema.ResourceData,
256268
}
257269

258270
if cloudEnvironment.Spec.Network.ID != "" {
259-
cc, err := clientSet.CloudV1alpha1().CloudConnections(namespace).Get(ctx, cloudConnectionName, metav1.GetOptions{})
260-
if err != nil {
261-
return diag.FromErr(err)
262-
}
263271
if cc.Spec.ConnectionType == cloudv1alpha1.ConnectionTypeAzure {
264272
return diag.FromErr(fmt.Errorf("ERROR_CREATE_CLOUD_ENVIRONMENT: Azure doesn't support specify network id yet. Please use network cidr"))
265273
}

0 commit comments

Comments
 (0)