Skip to content

Commit

Permalink
refactor(ecs): remove user_id check in ecs instance (#5228)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 authored Jul 18, 2024
1 parent 4eeecfe commit 7632367
Showing 1 changed file with 1 addition and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func ResourceComputeInstance() *schema.Resource {
RequiredWith: []string{"spot_duration"},
},

"user_id": { // required if in prePaid charging mode with key_pair.
"user_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Expand Down Expand Up @@ -586,11 +586,6 @@ func resourceComputeInstanceCreate(ctx context.Context, d *schema.ResourceData,
return diag.Errorf("error creating networking v2 client: %s", err)
}

// user_id is required if in prePaid charging mode with key_pair
if err := validateComputeInstanceConfig(d, cfg); err != nil {
return diag.FromErr(err)
}

// Determines the Image ID using the following rules:
// If an image_id was specified, use it.
// If an image_name was specified, look up the image ID, report if error.
Expand Down Expand Up @@ -1481,18 +1476,6 @@ func getOpSvcUserID(d *schema.ResourceData, conf *config.Config) string {
return conf.UserID
}

func validateComputeInstanceConfig(d *schema.ResourceData, conf *config.Config) error {
_, hasSSH := d.GetOk("key_pair")
if d.Get("charging_mode").(string) == "prePaid" && hasSSH {
if getOpSvcUserID(d, conf) == "" {
return fmt.Errorf("user_id must be specified when charging_mode is set to prePaid and " +
"the ECS is logged in using an SSH key")
}
}

return nil
}

func buildInstanceNicsRequest(d *schema.ResourceData) []cloudservers.Nic {
var nicRequests []cloudservers.Nic

Expand Down

0 comments on commit 7632367

Please sign in to comment.