Skip to content

Commit

Permalink
Added support for import of harness_ssh_credential
Browse files Browse the repository at this point in the history
  • Loading branch information
micahlmartin committed Sep 21, 2021
1 parent 88f6b7a commit 2bcedf4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
2 changes: 2 additions & 0 deletions examples/resources/harness_ssh_credential/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Import using the Harness ssh credential id
terraform import harness_ssh_credential.example <credential_id>
32 changes: 32 additions & 0 deletions examples/resources/harness_ssh_credential/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
resource "tls_private_key" "harness_deploy_key" {
algorithm = "RSA"
rsa_bits = 4096
}

data "harness_secret_manager" "secret_manager" {
default = true
}

resource "harness_encrypted_text" "my_secret" {
name = "my_secret"
value = tls_private_key.harness_deploy_key.private_key_pem
secret_manager_id = data.harness_secret_manager.secret_manager.id
}

resource "harness_ssh_credential" "ssh_creds" {
name = "ssh-test"

ssh_authentication {
port = 22
username = "git"
inline_ssh {
ssh_key_file_id = harness_encrypted_text.my_secret.id
}
}

// This is a workaround until https://harness.atlassian.net/browse/PL-17967 is resolved
// The graphql API currently doesn't return all the fields in the query.
lifecycle {
ignore_changes = ["ssh_authentication"]
}
}
12 changes: 6 additions & 6 deletions internal/provider/resource_ssh_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func resourceSSHCredential() *schema.Resource {
Optional: true,
MaxItems: 1,
ExactlyOneOf: validSSHAuthenticationTypes,
// ForceNew: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"passphrase_secret_id": {
Expand All @@ -92,7 +92,7 @@ func resourceSSHCredential() *schema.Resource {
Optional: true,
MaxItems: 1,
ExactlyOneOf: validSSHAuthenticationTypes,
// ForceNew: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"path": {
Expand All @@ -114,7 +114,7 @@ func resourceSSHCredential() *schema.Resource {
Optional: true,
MaxItems: 1,
ExactlyOneOf: validSSHAuthenticationTypes,
// ForceNew: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"password_secret_id": {
Expand Down Expand Up @@ -186,9 +186,9 @@ func resourceSSHCredential() *schema.Resource {
"usage_scope": usageScopeSchema(),
},

// Importer: &schema.ResourceImporter{
// StateContext: schema.ImportStatePassthroughContext,
// },
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
}
}

Expand Down
10 changes: 5 additions & 5 deletions internal/provider/resource_ssh_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ func TestAccResourceSSHCredential_SSHAuthentication(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "usage_scope.0.application_filter_type", string(graphql.ApplicationFilterTypes.All)),
),
},
// {
// ResourceName: resourceName,
// ImportState: true,
// ImportStateVerify: true,
// },
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down

0 comments on commit 2bcedf4

Please sign in to comment.