diff --git a/cloud/provider.go b/cloud/provider.go index 53f7e8b..7f2dc8b 100644 --- a/cloud/provider.go +++ b/cloud/provider.go @@ -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", diff --git a/cloud/resource_cloud_environment.go b/cloud/resource_cloud_environment.go index 1c6acf0..ff6cf88 100644 --- a/cloud/resource_cloud_environment.go +++ b/cloud/resource_cloud_environment.go @@ -90,7 +90,7 @@ func resourceCloudEnvironment() *schema.Resource { Type: schema.TypeString, Required: true, Description: descriptions["region"], - ValidateFunc: validateRegion, + ValidateFunc: validateNotBlank, }, "zone": { Type: schema.TypeString, @@ -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")) }