forked from hashicorp/terraform-provider-azurerm
/
kusto.go
91 lines (81 loc) · 2.08 KB
/
kusto.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
package azure
import (
"github.com/Azure/azure-sdk-for-go/services/kusto/mgmt/2020-02-15/kusto"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
)
func SchemaKustoIdentity() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(kusto.IdentityTypeNone),
string(kusto.IdentityTypeSystemAssigned),
}, true),
DiffSuppressFunc: suppress.CaseDifference,
},
"principal_id": {
Type: schema.TypeString,
Computed: true,
},
"tenant_id": {
Type: schema.TypeString,
Computed: true,
},
"identity_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
}
}
func ExpandKustoIdentity(input []interface{}) *kusto.Identity {
if len(input) == 0 || input[0] == nil {
return nil
}
identity := input[0].(map[string]interface{})
identityType := kusto.IdentityType(identity["type"].(string))
kustoIdentity := kusto.Identity{
Type: identityType,
}
return &kustoIdentity
}
func FlattenKustoIdentity(input *kusto.Identity) []interface{} {
if input == nil || input.Type == kusto.IdentityTypeNone {
return []interface{}{}
}
identityIds := make([]string, 0)
if input.UserAssignedIdentities != nil {
for k := range input.UserAssignedIdentities {
identityIds = append(identityIds, k)
}
}
principalID := ""
if input.PrincipalID != nil {
principalID = *input.PrincipalID
}
tenantID := ""
if input.TenantID != nil {
tenantID = *input.TenantID
}
return []interface{}{
map[string]interface{}{
"type": string(input.Type),
"identity_ids": identityIds,
"principal_id": principalID,
"tenant_id": tenantID,
},
}
}