diff --git a/civo/instances/resource_instance.go b/civo/instances/resource_instance.go index 8b8519f6..f51fd547 100644 --- a/civo/instances/resource_instance.go +++ b/civo/instances/resource_instance.go @@ -60,21 +60,12 @@ func ResourceInstance() *schema.Resource { ForceNew: true, Description: "This must be the ID of the network from the network listing (optional; default network used when not specified)", }, - "template": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ExactlyOneOf: []string{"template", "disk_image"}, - Deprecated: "\"template\" attribute is deprecated. Moving forward, please use \"disk_image\" attribute.", - Description: "The ID for the template to use to build the instance", - }, "disk_image": { Type: schema.TypeString, - Optional: true, - Computed: true, - ExactlyOneOf: []string{"template", "disk_image"}, + Required: true, Description: "The ID for the disk image to use to build the instance", ForceNew: true, + ValidateFunc: utils.ValidateUUID, }, "initial_user": { Type: schema.TypeString, @@ -244,14 +235,6 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter config.NetworkID = defaultNetwork.ID } - if attr, ok := d.GetOk("template"); ok { - findTemplate, err := apiClient.FindDiskImage(attr.(string)) - if err != nil { - return diag.Errorf("[ERR] failed to get the template: %s", err) - } - config.TemplateID = findTemplate.ID - } - if attr, ok := d.GetOk("disk_image"); ok { findDiskImage, err := apiClient.FindDiskImage(attr.(string)) if err != nil { @@ -374,7 +357,6 @@ func resourceInstanceRead(_ context.Context, d *schema.ResourceData, m interface d.Set("firewall_id", resp.FirewallID) d.Set("status", resp.Status) d.Set("script", resp.Script) - // d.Set("reserved_ipv4", resp.ReservedIPID) d.Set("created_at", resp.CreatedAt.UTC().String()) d.Set("notes", resp.Notes) d.Set("disk_image", resp.SourceID) @@ -385,10 +367,6 @@ func resourceInstanceRead(_ context.Context, d *schema.ResourceData, m interface d.Set("public_ip_required", "none") } - if _, ok := d.GetOk("template"); ok { - d.Set("template", d.Get("template").(string)) - } - if d.HasChange("reserved_ipv4") { _, new := d.GetChange("reserved_ipv4") newValue := new.(string) diff --git a/docs/resources/instance.md b/docs/resources/instance.md index 119f21f9..26b23ad3 100644 --- a/docs/resources/instance.md +++ b/docs/resources/instance.md @@ -126,10 +126,10 @@ resource "civo_instance" "example" { ### Required - `firewall_id` (String) The ID of the firewall to use, from the current list. If left blank or not sent, the default firewall will be used (open to all) - +- `disk_image` (String) The ID for the disk image to use to build the instance +- ### Optional -- `disk_image` (String) The ID for the disk image to use to build the instance - `hostname` (String) A fully qualified domain name that should be set as the instance's hostname - `initial_user` (String) The name of the initial user created on the server (optional; this will default to the template's default_username and fallback to civo) - `network_id` (String) This must be the ID of the network from the network listing (optional; default network used when not specified) @@ -145,7 +145,6 @@ resource "civo_instance" "example" { - `tags` (Set of String) An optional list of tags, represented as a key, value pair - `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts)) defines timeouts for cluster creation, read and update, default is 30 minutes for all - ### Nested Schema for `timeouts` diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 270de824..5fa2ce74 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -6,6 +6,7 @@ package utils import ( "encoding/json" "fmt" + "github.com/google/uuid" "regexp" "sort" "strconv" @@ -240,3 +241,13 @@ func ParseErrorResponse(errorMsg string) (*CustomError, error) { } return &customErr, nil } + +// ValidateUUID checks if a given string is a UUID or not +func ValidateUUID(v interface{}, k string) (ws []string, errors []error) { + value := v.(string) + _, err := uuid.Parse(value) + if err != nil { + errors = append(errors, fmt.Errorf("%q must be a valid UUID", k)) + } + return +}