-
Notifications
You must be signed in to change notification settings - Fork 8
/
apiroles_state.go
32 lines (25 loc) · 954 Bytes
/
apiroles_state.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
// apiroles_state.go
package apiroles
import (
"fmt"
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
// updateTerraformState updates the Terraform state with the latest API Role information from the Jamf Pro API.
func updateTerraformState(d *schema.ResourceData, resource *jamfpro.ResourceAPIRole) diag.Diagnostics {
var diags diag.Diagnostics
// Map the configuration fields from the API response to a structured map
apiRoleData := map[string]interface{}{
"id": resource.ID,
"display_name": resource.DisplayName,
"privileges": resource.Privileges,
}
// Set the structured map in the Terraform state
for key, val := range apiRoleData {
if err := d.Set(key, val); err != nil {
diags = append(diags, diag.FromErr(fmt.Errorf("failed to set '%s': %v", key, err))...)
}
}
return diags
}