Skip to content

Commit

Permalink
Fix bad property mapping for ssh_key_account (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
zentron authored Jun 5, 2024
1 parent 7771378 commit 6f15b02
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
44 changes: 40 additions & 4 deletions octopusdeploy/schema_ssh_key_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ package octopusdeploy
import (
"context"
"fmt"
"strings"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/accounts"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func expandSSHKeyAccount(d *schema.ResourceData) *accounts.SSHKeyAccount {
name := d.Get("name").(string)
username := d.Get("username").(string)
privateKeyFile := core.NewSensitiveValue(d.Get("private_key_passphrase").(string))
privateKeyFile := core.NewSensitiveValue(d.Get("private_key_file").(string))

account, _ := accounts.NewSSHKeyAccount(name, username, privateKeyFile)
account.ID = d.Id()
account.Description = d.Get("description").(string)

if v, ok := d.GetOk("private_key_passphrase"); ok {
account.SetPrivateKeyPassphrase(core.NewSensitiveValue(v.(string)))
}

if v, ok := d.GetOk("tenanted_deployment_participation"); ok {
account.TenantedDeploymentMode = core.TenantedDeploymentMode(v.(string))
Expand Down Expand Up @@ -46,9 +54,10 @@ func getSSHKeyAccountSchema() map[string]*schema.Schema {
ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotEmpty),
},
"private_key_passphrase": {
Optional: true,
Sensitive: true,
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Type: schema.TypeString,
ValidateDiagFunc: warnIfSshPassphraseLooksLikeFile(),
},
"space_id": getSpaceIDSchema(),
"tenanted_deployment_participation": getTenantedDeploymentSchema(),
Expand All @@ -58,6 +67,33 @@ func getSSHKeyAccountSchema() map[string]*schema.Schema {
}
}

func warnIfSshPassphraseLooksLikeFile() schema.SchemaValidateDiagFunc {
return func(v interface{}, path cty.Path) diag.Diagnostics {
var diags diag.Diagnostics

value := v.(string)

// Certificates often start with "---BEGIN".
// If we can detect that, the chances are the user was setting this value to work around the bug

if strings.HasPrefix(value, "LS0tLS1CRUdJTi") {

diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "Certificate value used in \"private_key_passphrase\"",
Detail: `The "private_key_passphrase" appears to be a certificate file.
This may be due to a previous bug with the provider which has been fixed (https://github.com/OctopusDeployLabs/terraform-provider-octopusdeploy/issues/343).
It is advised that you instead set this value on "private_key_file" and leave the passphrase "private_key_passphrase" field blank if none apply.
This warning can be ignored if the passphrase value is expected`,
AttributePath: path,
})
}

return diags
}
}

func setSSHKeyAccount(ctx context.Context, d *schema.ResourceData, account *accounts.SSHKeyAccount) error {
d.Set("description", account.GetDescription())

Expand Down
5 changes: 2 additions & 3 deletions terraform/7-sshaccount/ssh_account.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ resource "octopusdeploy_ssh_key_account" "account_ssh" {
tenant_tags = []
tenants = null
tenanted_deployment_participation = "Untenanted"
private_key_file = "unused"
private_key_passphrase = "somepass"
username = "admin"
# Because of https://github.com/OctopusDeployLabs/terraform-provider-octopusdeploy/issues/343
private_key_passphrase = "LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnphQzFyWlhrdGRqRUFBQUFBQkc1dmJtVUFBQUFFYm05dVpRQUFBQUFBQUFBQkFBQUJGd0FBQUFkemMyZ3RjbgpOaEFBQUFBd0VBQVFBQUFRRUF5c25PVXhjN0tJK2pIRUc5RVEwQXFCMllGRWE5ZnpZakZOY1pqY1dwcjJQRkRza25oOUpTCm1NVjVuZ2VrbTRyNHJVQU5tU2dQMW1ZTGo5TFR0NUVZa0N3OUdyQ0paNitlQTkzTEowbEZUamFkWEJuQnNmb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