-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
resource_kafka_acl.go
109 lines (96 loc) · 2.18 KB
/
resource_kafka_acl.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package kafka
import (
"log"
"github.com/hashicorp/terraform/helper/schema"
)
func kafkaACLResource() *schema.Resource {
return &schema.Resource{
Create: aclCreate,
Read: aclRead,
Delete: aclDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"resource_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The name of the resouce",
},
"resource_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"acl_principal": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"acl_host": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"acl_operation": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"acl_permission_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
}
}
func aclCreate(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Client)
a := aclInfo(d)
log.Printf("[INFO] Creating ACL %s", a)
err := c.CreateACL(a)
if err != nil {
log.Println("[ERROR] Failed to create ACL")
return err
}
d.SetId(a.String())
return nil
}
func aclDelete(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Client)
a := aclInfo(d)
log.Printf("[INFO] Deleteing ACL %s", a)
return c.DeleteACL(a)
}
func aclRead(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Client)
a := aclInfo(d)
currentAcls, err := c.ListACLs()
if err != nil {
return err
}
for _, c := range currentAcls {
if c.ResourceName == a.Resource.Name {
return nil
}
}
//panic(fmt.Sprintf("ACL read not implmented: %v", d))
return nil
}
func aclInfo(d *schema.ResourceData) stringlyTypedACL {
s := stringlyTypedACL{
ACL: ACL{
Principal: d.Get("acl_principal").(string),
Host: d.Get("acl_host").(string),
Operation: d.Get("acl_operation").(string),
PermissionType: d.Get("acl_permission_type").(string),
},
Resource: Resource{
Type: d.Get("resource_type").(string),
Name: d.Get("resource_name").(string),
},
}
return s
}