Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauschenbusch committed Jul 1, 2020
1 parent 6ea3fa1 commit 7775e5e
Showing 1 changed file with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,13 @@ func resourceArmKustoDatabasePrincipalAssignmentCreateUpdate(d *schema.ResourceD
principalType := d.Get("principal_type").(string)
role := d.Get("role").(string)

props := kusto.DatabasePrincipalProperties{
TenantID: utils.String(tenantID),
PrincipalID: utils.String(principalID),
PrincipalType: kusto.PrincipalType(principalType),
Role: kusto.DatabasePrincipalRole(role),
}

principalAssignment := kusto.DatabasePrincipalAssignment{
DatabasePrincipalProperties: &props,
DatabasePrincipalProperties: &kusto.DatabasePrincipalProperties{
TenantID: utils.String(tenantID),
PrincipalID: utils.String(principalID),
PrincipalType: kusto.PrincipalType(principalType),
Role: kusto.DatabasePrincipalRole(role),
},
}

future, err := client.CreateOrUpdate(ctx, resourceGroup, clusterName, databaseName, name, principalAssignment)
Expand Down Expand Up @@ -197,12 +195,36 @@ func resourceArmKustoDatabasePrincipalAssignmentRead(d *schema.ResourceData, met
d.Set("cluster_name", id.Cluster)
d.Set("database_name", id.Database)
d.Set("name", id.Name)
d.Set("tenant_id", *resp.TenantID)
d.Set("tenant_name", *resp.TenantName)
d.Set("principal_id", *resp.PrincipalID)
d.Set("principal_name", *resp.PrincipalName)
d.Set("principal_type", string(resp.PrincipalType))
d.Set("role", string(resp.Role))

tenantID := ""
if resp.TenantID != nil {
tenantID = *resp.TenantID
}

tenantName := ""
if resp.TenantName != nil {
tenantName = *resp.TenantName
}

principalID := ""
if resp.PrincipalID != nil {
principalID = *resp.PrincipalID
}

principalName := ""
if resp.PrincipalName != nil {
principalName = *resp.PrincipalName
}

principalType := string(resp.PrincipalType)
role := string(resp.Role)

d.Set("tenant_id", tenantID)
d.Set("tenant_name", tenantName)
d.Set("principal_id", principalID)
d.Set("principal_name", principalName)
d.Set("principal_type", principalType)
d.Set("role", role)

return nil
}
Expand Down

0 comments on commit 7775e5e

Please sign in to comment.