Skip to content

Commit e3d891e

Browse files
fix: docs, unneeded args, missing description
1 parent 814cff9 commit e3d891e

7 files changed

Lines changed: 31 additions & 30 deletions

github/resource_github_user_ssh_key.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func resourceGithubUserSshKey() *schema.Resource {
2222
StateContext: resourceGithubUserSshKeyImport,
2323
},
2424

25+
Description: "Manages a SSH key for the authenticated user.",
26+
2527
SchemaVersion: 1,
2628
Schema: map[string]*schema.Schema{
2729
"title": {
@@ -106,7 +108,7 @@ func resourceGithubUserSshKeyRead(ctx context.Context, d *schema.ResourceData, m
106108
return nil
107109
}
108110
if ghErr.Response.StatusCode == http.StatusNotFound {
109-
tflog.Info(ctx, fmt.Sprintf("Removing user SSH key %s from state because it no longer exists in GitHub", d.Id()), map[string]any{
111+
tflog.Info(ctx, "Removing user SSH key from state because it no longer exists in GitHub", map[string]any{
110112
"ssh_key_id": d.Id(),
111113
})
112114
d.SetId("")

github/resource_github_user_ssh_key_migration.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ func resourceGithubUserSshKeyStateUpgradeV0(ctx context.Context, rawState map[st
5454
return nil, fmt.Errorf("resource state upgrade failed, invalid SSH key ID format: %w", err)
5555
}
5656
rawState["key_id"] = keyID
57-
} else {
58-
return nil, fmt.Errorf("resource state upgrade failed, missing or invalid 'id' field in state")
5957
}
6058

6159
return rawState, nil

github/resource_github_user_ssh_key_test.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"crypto/rand"
55
"crypto/rsa"
66
"fmt"
7-
"regexp"
87
"strings"
98
"testing"
109

1110
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1211
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
12+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
13+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
14+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
1315
"golang.org/x/crypto/ssh"
1416
)
1517

@@ -26,18 +28,16 @@ func TestAccGithubUserSshKey(t *testing.T) {
2628
}
2729
`, name, testKey)
2830

29-
check := resource.ComposeTestCheckFunc(
30-
resource.TestMatchResourceAttr("github_user_ssh_key.test", "title", regexp.MustCompile(randomID)),
31-
resource.TestMatchResourceAttr("github_user_ssh_key.test", "key", regexp.MustCompile("^ssh-rsa ")),
32-
)
33-
3431
resource.Test(t, resource.TestCase{
3532
PreCheck: func() { skipUnauthenticated(t) },
3633
ProviderFactories: providerFactories,
3734
Steps: []resource.TestStep{
3835
{
3936
Config: config,
40-
Check: check,
37+
ConfigStateChecks: []statecheck.StateCheck{
38+
statecheck.ExpectKnownValue("github_user_ssh_key.test", tfjsonpath.New("title"), knownvalue.StringExact(name)),
39+
statecheck.ExpectKnownValue("github_user_ssh_key.test", tfjsonpath.New("key"), knownvalue.StringExact(testKey)),
40+
},
4141
},
4242
},
4343
})
@@ -55,18 +55,16 @@ func TestAccGithubUserSshKey(t *testing.T) {
5555
}
5656
`, name, testKey)
5757

58-
check := resource.ComposeTestCheckFunc(
59-
resource.TestCheckResourceAttrSet("github_user_ssh_key.test", "title"),
60-
resource.TestCheckResourceAttrSet("github_user_ssh_key.test", "key"),
61-
)
62-
6358
resource.Test(t, resource.TestCase{
6459
PreCheck: func() { skipUnauthenticated(t) },
6560
ProviderFactories: providerFactories,
6661
Steps: []resource.TestStep{
6762
{
6863
Config: config,
69-
Check: check,
64+
ConfigStateChecks: []statecheck.StateCheck{
65+
statecheck.ExpectKnownValue("github_user_ssh_key.test", tfjsonpath.New("title"), knownvalue.StringExact(name)),
66+
statecheck.ExpectKnownValue("github_user_ssh_key.test", tfjsonpath.New("key"), knownvalue.StringExact(testKey)),
67+
},
7068
},
7169
{
7270
ResourceName: "github_user_ssh_key.test",

github/resource_github_user_ssh_signing_key.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func resourceGithubUserSshSigningKey() *schema.Resource {
2222
StateContext: resourceGithubUserSshSigningKeyImport,
2323
},
2424

25+
Description: "Manages a SSH signing key for the authenticated user.",
26+
2527
Schema: map[string]*schema.Schema{
2628
"title": {
2729
Type: schema.TypeString,
@@ -89,7 +91,7 @@ func resourceGithubUserSshSigningKeyRead(ctx context.Context, d *schema.Resource
8991
return nil
9092
}
9193
if ghErr.Response.StatusCode == http.StatusNotFound {
92-
tflog.Info(ctx, fmt.Sprintf("Removing user SSH signing key %s from state because it no longer exists in GitHub", d.Id()), map[string]any{
94+
tflog.Info(ctx, "Removing user SSH signing key from state because it no longer exists in GitHub", map[string]any{
9395
"ssh_signing_key_id": d.Id(),
9496
})
9597
d.SetId("")

github/resource_github_user_ssh_signing_key_test.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"crypto/rand"
55
"crypto/rsa"
66
"fmt"
7-
"regexp"
87
"strings"
98
"testing"
109

1110
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1211
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
12+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
13+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
14+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
1315
"golang.org/x/crypto/ssh"
1416
)
1517

@@ -26,18 +28,16 @@ func TestAccGithubUserSshSigningKey(t *testing.T) {
2628
}
2729
`, name, testKey)
2830

29-
check := resource.ComposeTestCheckFunc(
30-
resource.TestMatchResourceAttr("github_user_ssh_signing_key.test", "title", regexp.MustCompile(randomID)),
31-
resource.TestMatchResourceAttr("github_user_ssh_signing_key.test", "key", regexp.MustCompile("^ssh-rsa ")),
32-
)
33-
3431
resource.Test(t, resource.TestCase{
3532
PreCheck: func() { skipUnauthenticated(t) },
3633
ProviderFactories: providerFactories,
3734
Steps: []resource.TestStep{
3835
{
3936
Config: config,
40-
Check: check,
37+
ConfigStateChecks: []statecheck.StateCheck{
38+
statecheck.ExpectKnownValue("github_user_ssh_signing_key.test", tfjsonpath.New("title"), knownvalue.StringExact(name)),
39+
statecheck.ExpectKnownValue("github_user_ssh_signing_key.test", tfjsonpath.New("key"), knownvalue.StringExact(testKey)),
40+
},
4141
},
4242
},
4343
})
@@ -55,18 +55,16 @@ func TestAccGithubUserSshSigningKey(t *testing.T) {
5555
}
5656
`, name, testKey)
5757

58-
check := resource.ComposeTestCheckFunc(
59-
resource.TestCheckResourceAttrSet("github_user_ssh_signing_key.test", "title"),
60-
resource.TestCheckResourceAttrSet("github_user_ssh_signing_key.test", "key"),
61-
)
62-
6358
resource.Test(t, resource.TestCase{
6459
PreCheck: func() { skipUnauthenticated(t) },
6560
ProviderFactories: providerFactories,
6661
Steps: []resource.TestStep{
6762
{
6863
Config: config,
69-
Check: check,
64+
ConfigStateChecks: []statecheck.StateCheck{
65+
statecheck.ExpectKnownValue("github_user_ssh_signing_key.test", tfjsonpath.New("title"), knownvalue.StringExact(name)),
66+
statecheck.ExpectKnownValue("github_user_ssh_signing_key.test", tfjsonpath.New("key"), knownvalue.StringExact(testKey)),
67+
},
7068
},
7169
{
7270
ResourceName: "github_user_ssh_signing_key.test",

website/docs/r/user_ssh_key.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ resource "github_user_ssh_key" "example" {
2424

2525
The following arguments are supported:
2626

27+
* `id` - The ID of the SSH key
28+
* `url` - The URL of the SSH key
2729
* `title` - (Required) A descriptive name for the new key.
2830
* `key` - (Required) The public SSH key to add to your GitHub account.
2931

website/docs/r/user_ssh_signing_key.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ resource "github_user_ssh_signing_key" "example" {
2424

2525
The following arguments are supported:
2626

27+
* `id` - The ID of the SSH signing key
2728
* `title` - (Required) A descriptive name for the new key.
2829
* `key` - (Required) The public SSH signing key to add to your GitHub account.
2930

0 commit comments

Comments
 (0)