diff --git a/civo/resource_instance.go b/civo/resource_instance.go index 205b615b..10814692 100644 --- a/civo/resource_instance.go +++ b/civo/resource_instance.go @@ -59,6 +59,7 @@ func resourceInstance() *schema.Resource { "template": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "The ID for the template to use to build the instance", }, "initial_user": { @@ -80,6 +81,7 @@ func resourceInstance() *schema.Resource { "firewall_id": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "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)", }, "tags": { @@ -326,7 +328,7 @@ func resourceInstanceRead(d *schema.ResourceData, m interface{}) error { d.Set("notes", resp.Notes) if _, ok := d.GetOk("template"); ok { - d.Set("template", resp.TemplateID) + d.Set("template", d.Get("template").(string)) } return nil diff --git a/docs/data-sources/template.md b/docs/data-sources/template.md index 18629844..0588f0af 100644 --- a/docs/data-sources/template.md +++ b/docs/data-sources/template.md @@ -53,11 +53,36 @@ resource "civo_instance" "foo-host" { } ``` +It is similar to the previous one with the difference that in this one we use region to only look for the templates of that region. +The Instance/Kubernetes cluster where you use this data source must be in the same region. + +```hcl +data "civo_template" "debian" { + region = "LON1" + filter { + key = "name" + values = ["debian"] + match_by = "re" + } + sort { + key = "version" + direction = "asc" + } +} + +resource "civo_instance" "foo-host" { + region = "LON1" + hostname = "foo.com" + size = element(data.civo_instances_size.small.sizes, 0).name + template = element(data.civo_template.debian.templates, 0).id +} +``` + ## Argument Reference The following arguments are supported: -* `region` - (Optional) If is used, them all instances will be from that region. +* `region` - (Optional) If is used, them all template will be from that region, has to be declared here if is not declared in the provider * `filter` - (Optional) Filter the results. The `filter` block is documented below. * `sort` - (Optional) Sort the results. The `sort` block is documented below.