From 1aa13b911d79295db6571c8033850e8386fb8524 Mon Sep 17 00:00:00 2001 From: jiangpengcheng Date: Tue, 5 Nov 2024 10:10:13 +0800 Subject: [PATCH 1/2] Disable region check --- cloud/provider.go | 2 +- cloud/resource_cloud_environment.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cloud/provider.go b/cloud/provider.go index 8aaf66f..f984585 100644 --- a/cloud/provider.go +++ b/cloud/provider.go @@ -123,7 +123,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", diff --git a/cloud/resource_cloud_environment.go b/cloud/resource_cloud_environment.go index 21ac6e9..c3e34fd 100644 --- a/cloud/resource_cloud_environment.go +++ b/cloud/resource_cloud_environment.go @@ -79,7 +79,7 @@ func resourceCloudEnvironment() *schema.Resource { Type: schema.TypeString, Required: true, Description: descriptions["region"], - ValidateFunc: validateRegion, + ValidateFunc: validateNotBlank, }, "zone": { Type: schema.TypeString, From 1fa1e2eca64dcc2bab28dc7386233ada56f7e1d6 Mon Sep 17 00:00:00 2001 From: Max Xu Date: Sat, 7 Dec 2024 13:21:57 +0800 Subject: [PATCH 2/2] Only check aws and gcp region --- cloud/resource_cloud_environment.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cloud/resource_cloud_environment.go b/cloud/resource_cloud_environment.go index ce60ab6..ff6cf88 100644 --- a/cloud/resource_cloud_environment.go +++ b/cloud/resource_cloud_environment.go @@ -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", @@ -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")) }