From a0c65acf16fdec4246e98c6038815af3c9b84ba9 Mon Sep 17 00:00:00 2001 From: michaelfmnk Date: Tue, 30 Jul 2024 13:45:07 +0200 Subject: [PATCH] FIX: [TF] Data source "host" crashing Terraform provider --- cloudconnexa/data_source_host.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cloudconnexa/data_source_host.go b/cloudconnexa/data_source_host.go index c8180b5..ccc8762 100644 --- a/cloudconnexa/data_source_host.go +++ b/cloudconnexa/data_source_host.go @@ -101,10 +101,15 @@ func dataSourceHost() *schema.Resource { func dataSourceHostRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*cloudconnexa.Client) var diags diag.Diagnostics - host, err := c.Hosts.GetByName(d.Get("name").(string)) + name := d.Get("name").(string) + host, err := c.Hosts.GetByName(name) if err != nil { return append(diags, diag.FromErr(err)...) } + if host == nil { + return append(diags, diag.Errorf("Host with name %s was not found", name)...) + } + d.SetId(host.Id) d.Set("name", host.Name) d.Set("description", host.Description)