forked from ovh/terraform-provider-ovh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_source_ovh_me_ssh_keys_test.go
87 lines (76 loc) · 2.08 KB
/
data_source_ovh_me_ssh_keys_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package ovh
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)
func TestAccMeSshKeysDataSource_basic(t *testing.T) {
sshKey1Name := acctest.RandomWithPrefix(test_prefix)
sshKey1 := "ssh-ed25519 AAAAC3NzaC1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
sshKey2Name := acctest.RandomWithPrefix(test_prefix)
sshKey2 := "ssh-ed25519 AAAAC3NzaC1yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
preSetup := fmt.Sprintf(
testAccMeSshKeysDatasourceConfig_preSetup,
sshKey1Name,
sshKey1,
sshKey2Name,
sshKey2,
)
config := fmt.Sprintf(
testAccMeSshKeysDatasourceConfig_keys,
sshKey1Name,
sshKey1,
sshKey2Name,
sshKey2,
)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCredentials(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: preSetup,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"ovh_me_ssh_key.key_1", "key_name", sshKey1Name),
resource.TestCheckResourceAttr(
"ovh_me_ssh_key.key_1", "key", sshKey1),
resource.TestCheckResourceAttr(
"ovh_me_ssh_key.key_2", "key_name", sshKey2Name),
resource.TestCheckResourceAttr(
"ovh_me_ssh_key.key_2", "key", sshKey2),
),
}, {
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckOutput(
"keys_present", "true"),
),
},
},
})
}
const testAccMeSshKeysDatasourceConfig_preSetup = `
resource "ovh_me_ssh_key" "key_1" {
key_name = "%s"
key = "%s"
}
resource "ovh_me_ssh_key" "key_2" {
key_name = "%s"
key = "%s"
}
`
const testAccMeSshKeysDatasourceConfig_keys = `
resource "ovh_me_ssh_key" "key_1" {
key_name = "%s"
key = "%s"
}
resource "ovh_me_ssh_key" "key_2" {
key_name = "%s"
key = "%s"
}
data "ovh_me_ssh_keys" "keys" {}
output "keys_present" {
value = tostring(contains(data.ovh_me_ssh_keys.keys.names, ovh_me_ssh_key.key_1.key_name) && contains(data.ovh_me_ssh_keys.keys.names, ovh_me_ssh_key.key_2.key_name))
}
`