forked from rework-space-com/terraform-provider-freeipa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_sudo_rule_host_membership_test.go
82 lines (69 loc) · 2.11 KB
/
resource_sudo_rule_host_membership_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
package main
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccFreeIPASudoRuleHost(t *testing.T) {
testSudoRuleHost := map[string]string{
"name": "sudo-rule-test",
"host": "host.testacc.ipatest.lan",
"hostip": "192.168.10.1",
"hostgroup": "test-hosts",
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccFreeIPASudoRuleHostResource_basic(testSudoRuleHost),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("freeipa_sudo_rule_host_membership.hostmember", "name", testSudoRuleHost["name"]),
resource.TestCheckResourceAttr("freeipa_sudo_rule_host_membership.hostmember", "host", testSudoRuleHost["host"]),
),
},
},
})
}
func testAccFreeIPASudoRuleHostResource_basic(dataset map[string]string) string {
provider_host := os.Getenv("FREEIPA_HOST")
provider_user := os.Getenv("FREEIPA_USERNAME")
provider_pass := os.Getenv("FREEIPA_PASSWORD")
return fmt.Sprintf(`
provider "freeipa" {
host = "%s"
username = "%s"
password = "%s"
insecure = true
}
resource "freeipa_dns_zone" "testacc_ipatest_lan" {
zone_name = "testacc.ipatest.lan"
}
resource "freeipa_host" "host" {
name = "%s"
ip_address = "%s"
depends_on = [
freeipa_dns_zone.testacc_ipatest_lan
]
}
resource "freeipa_hostgroup" "hostgroup" {
name = "%s"
}
resource freeipa_host_hostgroup_membership "groupmembership" {
name = freeipa_hostgroup.hostgroup.id
host = freeipa_host.host.id
}
resource "freeipa_sudo_rule" "test_rule" {
name = "%s"
}
resource freeipa_sudo_rule_host_membership "hostmember" {
name = freeipa_sudo_rule.test_rule.name
host = freeipa_host.host.name
}
resource freeipa_sudo_rule_host_membership "hostgroupmember" {
name = freeipa_sudo_rule.test_rule.name
hostgroup = freeipa_hostgroup.hostgroup.name
}
`, provider_host, provider_user, provider_pass, dataset["host"], dataset["hostip"], dataset["hostgroup"], dataset["name"])
}