@@ -8,26 +8,38 @@ import (
8
8
"text/template"
9
9
10
10
"github.com/coder/terraform-provider-coderd/integration"
11
+ "github.com/google/uuid"
11
12
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
12
13
"github.com/stretchr/testify/require"
13
14
)
14
15
15
- func TestAccLicenseResource (t * testing.T ) {
16
+ func TestAccProvisionerKeyResource (t * testing.T ) {
16
17
if os .Getenv ("TF_ACC" ) == "" {
17
18
t .Skip ("Acceptance tests are disabled." )
18
19
}
19
20
ctx := context .Background ()
20
- client := integration .StartCoder (ctx , t , "license_acc" , false )
21
+ client := integration .StartCoder (ctx , t , "license_acc" , true )
22
+ orgs , err := client .Organizations (ctx )
23
+ require .NoError (t , err )
24
+ firstOrg := orgs [0 ].ID
21
25
22
26
license := os .Getenv ("CODER_ENTERPRISE_LICENSE" )
23
27
if license == "" {
24
28
t .Skip ("No license found for license resource tests, skipping" )
25
29
}
26
30
27
- cfg1 := testAccLicenseResourceconfig {
28
- URL : client .URL .String (),
29
- Token : client .SessionToken (),
30
- License : license ,
31
+ cfg1 := testAccProvisionerKeyResourceConfig {
32
+ URL : client .URL .String (),
33
+ Token : client .SessionToken (),
34
+
35
+ OrganizationID : firstOrg ,
36
+ Name : "example-provisioner-key" ,
37
+ }
38
+
39
+ cfg2 := cfg1
40
+ cfg2 .Name = "different-provisioner-key"
41
+ cfg2 .Tags = map [string ]string {
42
+ "wibble" : "wobble" ,
31
43
}
32
44
33
45
resource .Test (t , resource.TestCase {
@@ -38,34 +50,44 @@ func TestAccLicenseResource(t *testing.T) {
38
50
{
39
51
Config : cfg1 .String (t ),
40
52
},
53
+ {
54
+ Config : cfg2 .String (t ),
55
+ },
41
56
},
42
57
})
43
58
}
44
59
45
- type testAccLicenseResourceconfig struct {
46
- URL string
47
- Token string
48
- License string
60
+ type testAccProvisionerKeyResourceConfig struct {
61
+ URL string
62
+ Token string
63
+
64
+ OrganizationID uuid.UUID
65
+ Name string
66
+ Tags map [string ]string
49
67
}
50
68
51
- func (c testAccLicenseResourceconfig ) String (t * testing.T ) string {
69
+ func (c testAccProvisionerKeyResourceConfig ) String (t * testing.T ) string {
52
70
t .Helper ()
53
71
tpl := `
54
72
provider coderd {
55
73
url = "{{.URL}}"
56
74
token = "{{.Token}}"
57
75
}
58
76
59
- resource "coderd_license" "test" {
60
- license = "{{.License}}"
77
+ resource "coderd_provisioner_key" "test" {
78
+ organization_id = "{{.OrganizationID}}"
79
+ name = "{{.Name}}"
80
+
81
+ tags = {
82
+ {{- range $key, $value := .Tags}}
83
+ {{$key}} = "{{$value}}"
84
+ {{- end}}
85
+ }
61
86
}
62
87
`
63
- funcMap := template.FuncMap {
64
- "orNull" : PrintOrNull ,
65
- }
66
88
67
89
buf := strings.Builder {}
68
- tmpl , err := template .New ("licenseResource" ). Funcs ( funcMap ).Parse (tpl )
90
+ tmpl , err := template .New ("provisionerKeyResource" ).Parse (tpl )
69
91
require .NoError (t , err )
70
92
71
93
err = tmpl .Execute (& buf , c )
0 commit comments