From cb5c15348314e75bc0f50f83569edfcba7c2944a Mon Sep 17 00:00:00 2001 From: Uzair Ali <72073401+uzaxirr@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:58:45 +0530 Subject: [PATCH] feat: Add write_password to instance schema --- civo/instances/resource_instance.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/civo/instances/resource_instance.go b/civo/instances/resource_instance.go index 75dff9f8..df1973be 100644 --- a/civo/instances/resource_instance.go +++ b/civo/instances/resource_instance.go @@ -137,6 +137,13 @@ func ResourceInstance() *schema.Resource { Sensitive: true, Description: "Initial password for login", }, + "write_password": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "If set to true, initial_password for instance will be saved to terraform state file", + ValidateDiagFunc: utils.ValidateProviderVersion, + }, "private_ip": { Type: schema.TypeString, Computed: true, @@ -348,6 +355,12 @@ func resourceInstanceRead(_ context.Context, d *schema.ResourceData, m interface return diag.Errorf("[ERR] failed to get the disk image: %s", err) } + if d.Get("write_password").(bool) { + d.Set("initial_password", resp.InitialPassword) + } else { + d.Set("initial_password", "") + } + d.Set("hostname", resp.Hostname) d.Set("reverse_dns", resp.ReverseDNS) d.Set("size", resp.Size) @@ -355,7 +368,6 @@ func resourceInstanceRead(_ context.Context, d *schema.ResourceData, m interface d.Set("ram_mb", resp.RAMMegabytes) d.Set("disk_gb", resp.DiskGigabytes) d.Set("initial_user", resp.InitialUser) - d.Set("initial_password", resp.InitialPassword) d.Set("source_type", resp.SourceType) d.Set("source_id", resp.SourceID) d.Set("sshkey_id", resp.SSHKeyID)