Skip to content

Commit

Permalink
Make saving initial_password in instance to state as optional (#318)
Browse files Browse the repository at this point in the history
* feat: Add write_password to instance schema
  • Loading branch information
uzaxirr authored Aug 13, 2024
1 parent fbfebd5 commit c379776
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion civo/instances/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -348,14 +355,19 @@ 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)
d.Set("cpu_cores", resp.CPUCores)
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)
Expand Down
1 change: 1 addition & 0 deletions docs/resources/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ resource "civo_instance" "example" {
- `sshkey_id` (String) The ID of an already uploaded SSH public key to use for login to the default user (optional; if one isn't provided a random password will be set and returned in the initial_password field)
- `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
- `write_password` (Boolean) If set to true then initial_password for the instance will be saved to terraform state file. (default: false)

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`
Expand Down

0 comments on commit c379776

Please sign in to comment.