-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Kusto Cluster System Managed Identity
- Loading branch information
1 parent
4067298
commit 0401151
Showing
4 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 { | ||
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, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters