Skip to content

Commit

Permalink
fix: disable region check for Azure CloudEnvironment (#69)
Browse files Browse the repository at this point in the history
fix #66

Azure needs to use ResourceGroup name in the region parameter, so cannot
validate it

---------

Co-authored-by: Max Xu <[email protected]>
  • Loading branch information
jiangpengcheng and maxsxu authored Dec 7, 2024
1 parent d6e32bc commit 5d5dfcb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func init() {
"cloud_connection_name": "Name of the cloud connection",
"environment_type": "Type of the cloud environment, either: dev, test, staging, production, acc, qa or poc",
"cloud_environment_name": "Name of the cloud environment",
"region": "The region of the cloud environment",
"region": "The region of the cloud environment, for Azure, it should be the resource group name",
"zone": "The zone of the cloud environment, the underlying infrastructure will only be created in this zone if configured",
"default_gateway": "The default gateway of the cloud environment",
"apikey_name": "The name of the api key",
Expand Down
18 changes: 13 additions & 5 deletions cloud/resource_cloud_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func resourceCloudEnvironment() *schema.Resource {
Type: schema.TypeString,
Required: true,
Description: descriptions["region"],
ValidateFunc: validateRegion,
ValidateFunc: validateNotBlank,
},
"zone": {
Type: schema.TypeString,
Expand Down Expand Up @@ -212,12 +212,24 @@ func resourceCloudEnvironmentCreate(ctx context.Context, d *schema.ResourceData,
if err != nil {
return diag.FromErr(fmt.Errorf("ERROR_INIT_CLIENT_ON_CLOUD_ENVIRONMENT: %w", err))
}

cc, err := clientSet.CloudV1alpha1().CloudConnections(namespace).Get(ctx, cloudConnectionName, metav1.GetOptions{})
if err != nil {
return diag.FromErr(err)
}

annotations := make(map[string]string)
if len(rawAnnotations) > 0 {
annotations = convertToStringMap(rawAnnotations)
}
annotations["cloud.streamnative.io/environment-type"] = cloudEnvironmentType

if cc.Spec.ConnectionType != cloudv1alpha1.ConnectionTypeAzure {
if !contains(validRegions, region) {
return diag.FromErr(fmt.Errorf("invalid region: %s", region))
}
}

cloudEnvironment := &cloudv1alpha1.CloudEnvironment{
TypeMeta: metav1.TypeMeta{
Kind: "CloudEnvironment",
Expand Down Expand Up @@ -256,10 +268,6 @@ func resourceCloudEnvironmentCreate(ctx context.Context, d *schema.ResourceData,
}

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

0 comments on commit 5d5dfcb

Please sign in to comment.