@@ -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