Skip to content

Commit a42be3e

Browse files
New provider for Rundeck, a runbook automation system.
1 parent 7d14213 commit a42be3e

3 files changed

Lines changed: 161 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import (
4+
"github.com/hashicorp/terraform/builtin/providers/rundeck"
5+
"github.com/hashicorp/terraform/plugin"
6+
)
7+
8+
func main() {
9+
plugin.Serve(&plugin.ServeOpts{
10+
ProviderFunc: rundeck.Provider,
11+
})
12+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package rundeck
2+
3+
import (
4+
"github.com/hashicorp/terraform/helper/schema"
5+
"github.com/hashicorp/terraform/terraform"
6+
7+
"github.com/apparentlymart/go-rundeck-api/rundeck"
8+
)
9+
10+
func Provider() terraform.ResourceProvider {
11+
return &schema.Provider{
12+
Schema: map[string]*schema.Schema{
13+
"url": &schema.Schema{
14+
Type: schema.TypeString,
15+
Required: true,
16+
DefaultFunc: schema.EnvDefaultFunc("RUNDECK_URL", nil),
17+
Description: "URL of the root of the target Rundeck server.",
18+
},
19+
"auth_token": &schema.Schema{
20+
Type: schema.TypeString,
21+
Required: true,
22+
DefaultFunc: schema.EnvDefaultFunc("RUNDECK_AUTH_TOKEN", nil),
23+
Description: "Auth token to use with the Rundeck API.",
24+
},
25+
"allow_unverified_ssl": &schema.Schema{
26+
Type: schema.TypeBool,
27+
Optional: true,
28+
Description: "If set, the Rundeck client will permit unverifiable SSL certificates.",
29+
},
30+
},
31+
32+
ResourcesMap: map[string]*schema.Resource{
33+
//"rundeck_project": resourceRundeckProject(),
34+
//"rundeck_job": resourceRundeckJob(),
35+
//"rundeck_private_key": resourceRundeckPrivateKey(),
36+
//"rundeck_public_key": resourceRundeckPublicKey(),
37+
},
38+
39+
ConfigureFunc: providerConfigure,
40+
}
41+
}
42+
43+
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
44+
config := &rundeck.ClientConfig{
45+
BaseURL: d.Get("url").(string),
46+
AuthToken: d.Get("auth_token").(string),
47+
AllowUnverifiedSSL: d.Get("allow_unverified_ssl").(bool),
48+
}
49+
50+
return rundeck.NewClient(config)
51+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package rundeck
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform/helper/schema"
8+
"github.com/hashicorp/terraform/terraform"
9+
)
10+
11+
// To run these acceptance tests, you will need a Rundeck server.
12+
// An easy way to get one is to use Rundeck's "Anvils" demo, which includes a Vagrantfile
13+
// to get it running easily:
14+
// https://github.com/rundeck/anvils-demo
15+
// The anvils demo ships with some example security policies that don't have enough access to
16+
// run the tests, so you need to either modify one of the stock users to have full access or
17+
// create a new user with such access. The following block is an example that gives the
18+
// 'admin' user and API clients open access.
19+
// In the anvils demo the admin password is "admin" by default.
20+
21+
// Place the contents of the following comment in /etc/rundeck/terraform-test.aclpolicy
22+
/*
23+
description: Admin, all access.
24+
context:
25+
project: '.*' # all projects
26+
for:
27+
resource:
28+
- allow: '*' # allow read/create all kinds
29+
adhoc:
30+
- allow: '*' # allow read/running/killing adhoc jobs
31+
job:
32+
- allow: '*' # allow read/write/delete/run/kill of all jobs
33+
node:
34+
- allow: '*' # allow read/run for all nodes
35+
by:
36+
group: admin
37+
---
38+
description: Admin, all access.
39+
context:
40+
application: 'rundeck'
41+
for:
42+
resource:
43+
- allow: '*' # allow create of projects
44+
project:
45+
- allow: '*' # allow view/admin of all projects
46+
storage:
47+
- allow: '*' # allow read/create/update/delete for all /keys/* storage content
48+
by:
49+
group: admin
50+
---
51+
description: Admin API, all access.
52+
context:
53+
application: 'rundeck'
54+
for:
55+
resource:
56+
- allow: '*' # allow create of projects
57+
project:
58+
- allow: '*' # allow view/admin of all projects
59+
storage:
60+
- allow: '*' # allow read/create/update/delete for all /keys/* storage content
61+
by:
62+
group: api_token_group
63+
*/
64+
65+
// Once you've got a user set up, put that user's API auth token in the RUNDECK_AUTH_TOKEN
66+
// environment variable, and put the URL of the Rundeck home page in the RUNDECK_URL variable.
67+
// If you're using the Anvils demo in its default configuration, you can find or generate an API
68+
// token at http://192.168.50.2:4440/user/profile once you've logged in, and RUNDECK_URL will
69+
// be http://192.168.50.2:4440/ .
70+
71+
var testAccProviders map[string]terraform.ResourceProvider
72+
var testAccProvider *schema.Provider
73+
74+
func init() {
75+
testAccProvider = Provider().(*schema.Provider)
76+
testAccProviders = map[string]terraform.ResourceProvider{
77+
"rundeck": testAccProvider,
78+
}
79+
}
80+
81+
func TestProvider(t *testing.T) {
82+
if err := Provider().(*schema.Provider).InternalValidate(); err != nil {
83+
t.Fatalf("err: %s", err)
84+
}
85+
}
86+
87+
func TestProvider_impl(t *testing.T) {
88+
var _ terraform.ResourceProvider = Provider()
89+
}
90+
91+
func testAccPreCheck(t *testing.T) {
92+
if v := os.Getenv("RUNDECK_URL"); v == "" {
93+
t.Fatal("RUNDECK_URL must be set for acceptance tests")
94+
}
95+
if v := os.Getenv("RUNDECK_AUTH_TOKEN"); v == "" {
96+
t.Fatal("RUNDECK_AUTH_TOKEN must be set for acceptance tests")
97+
}
98+
}

0 commit comments

Comments
 (0)