Skip to content

Commit 76a7be3

Browse files
authored
Merge pull request #77 from Nkmol/fix-know-host-hostame-and-pub-key-syntax
docs(know_host) update `hostname` and `public_key.key` to the correct…
2 parents 850f8d4 + 069517e commit 76a7be3

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

bitbucket/resource_pipeline_ssh_known_host_test.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ func TestAccBitbucketPipelineSshKnownHost_basic(t *testing.T) {
1616

1717
rName := acctest.RandomWithPrefix("tf-test")
1818
owner := os.Getenv("BITBUCKET_TEAM")
19-
userEmail := os.Getenv("BITBUCKET_USERNAME")
20-
publicKey, _, err := RandSSHKeyPairSize(2048, userEmail)
19+
publicKey, err := RandPlainSSHKeyPairSize(2048)
2120
if err != nil {
2221
t.Fatalf("error generating random SSH key: %s", err)
2322
}
2423

25-
publicKey2, _, err := RandSSHKeyPairSize(2048, userEmail)
24+
publicKey2, err := RandPlainSSHKeyPairSize(2048)
2625
if err != nil {
2726
t.Fatalf("error generating random SSH key: %s", err)
2827
}
@@ -33,12 +32,12 @@ func TestAccBitbucketPipelineSshKnownHost_basic(t *testing.T) {
3332
CheckDestroy: testAccCheckBitbucketPipelineSshKnownHostDestroy,
3433
Steps: []resource.TestStep{
3534
{
36-
Config: testAccBitbucketPipelineSshKnownHostConfig(owner, rName, publicKey, "example.com"),
35+
Config: testAccBitbucketPipelineSshKnownHostConfig(owner, rName, publicKey, "[example.com]"),
3736
Check: resource.ComposeTestCheckFunc(
3837
testAccCheckBitbucketPipelineSshKnownHostExists(resourceName),
3938
resource.TestCheckResourceAttrPair(resourceName, "workspace", "bitbucket_repository.test", "owner"),
4039
resource.TestCheckResourceAttrPair(resourceName, "repository", "bitbucket_repository.test", "name"),
41-
resource.TestCheckResourceAttr(resourceName, "hostname", "example.com"),
40+
resource.TestCheckResourceAttr(resourceName, "hostname", "[example.com]"),
4241
resource.TestCheckResourceAttr(resourceName, "public_key.#", "1"),
4342
resource.TestCheckResourceAttr(resourceName, "public_key.0.key_type", "ssh-rsa"),
4443
resource.TestCheckResourceAttrSet(resourceName, "public_key.0.md5_fingerprint"),
@@ -51,11 +50,11 @@ func TestAccBitbucketPipelineSshKnownHost_basic(t *testing.T) {
5150
ImportStateVerify: true,
5251
},
5352
{
54-
Config: testAccBitbucketPipelineSshKnownHostConfig(owner, rName, publicKey2, "example2.com"),
53+
Config: testAccBitbucketPipelineSshKnownHostConfig(owner, rName, publicKey2, "[example2.com]:22"),
5554
Check: resource.ComposeTestCheckFunc(
5655
resource.TestCheckResourceAttrPair(resourceName, "workspace", "bitbucket_repository.test", "owner"),
5756
resource.TestCheckResourceAttrPair(resourceName, "repository", "bitbucket_repository.test", "name"),
58-
resource.TestCheckResourceAttr(resourceName, "hostname", "example2.com"),
57+
resource.TestCheckResourceAttr(resourceName, "hostname", "[example2.com]:22"),
5958
resource.TestCheckResourceAttr(resourceName, "public_key.#", "1"),
6059
resource.TestCheckResourceAttr(resourceName, "public_key.0.key_type", "ssh-rsa"),
6160
resource.TestCheckResourceAttrSet(resourceName, "public_key.0.md5_fingerprint"),
@@ -121,7 +120,7 @@ resource "bitbucket_pipeline_ssh_known_host" "test" {
121120
122121
public_key {
123122
key_type = "ssh-rsa"
124-
key = base64encode(%[3]q)
123+
key = %[3]q
125124
}
126125
}
127126
`, workspace, rName, pubKey, host)

bitbucket/utils.go

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ func RandSSHKeyPairSize(keySize int, comment string) (string, string, error) {
3131
return fmt.Sprintf("%s %s", keyMaterial, comment), privateKeyPEM, nil
3232
}
3333

34+
func RandPlainSSHKeyPairSize(keySize int) (string, error) {
35+
privateKey, _, err := RandSSHKeyPairSize(keySize, "")
36+
if err != nil {
37+
return "", err
38+
}
39+
40+
return strings.Split(privateKey, " ")[1], nil
41+
}
42+
3443
func genPrivateKey(keySize int) (*rsa.PrivateKey, string, error) {
3544
privateKey, err := rsa.GenerateKey(crand.Reader, keySize)
3645
if err != nil {

docs/resources/pipeline_ssh_known_host.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ This allows you to manage your Pipeline Ssh Known Hosts for a repository.
1818
resource "bitbucket_pipeline_ssh_known_host" "test" {
1919
workspace = "example"
2020
repository = bitbucket_repository.test.name
21-
hostname = "example.com"
21+
hostname = "[example.com]:22"
2222
2323
public_key {
2424
key_type = "ssh-ed25519"
25-
key = base64encode("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKqP3Cr632C2dNhhgKVcon4ldUSAeKiku2yP9O9/bDtY")
25+
key = "AAAAC3NzaC1lZDI1NTE5AAAAIKqP3Cr632C2dNhhgKVcon4ldUSAeKiku2yP9O9/bDtY"
2626
}
2727
}
2828
```
@@ -39,7 +39,7 @@ The following arguments are supported:
3939
### Public Key
4040

4141
* `key_type` - The type of the public key. Valid values are `ssh-ed25519`, `ecdsa-sha2-nistp256`, `ssh-rsa`, and `ssh-dss`.
42-
* `key` - The base64 encoded public key.
42+
* `key` - The plain public key.
4343

4444
## Attributes Reference
4545

0 commit comments

Comments
 (0)