-
Notifications
You must be signed in to change notification settings - Fork 10
/
apiintegration_state.go
36 lines (28 loc) · 1.21 KB
/
apiintegration_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
33
34
35
36
// apiintegrations_state.go
package apiintegrations
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 Integration information from the Jamf Pro API.
func updateTerraformState(d *schema.ResourceData, resource *jamfpro.ResourceApiIntegration) diag.Diagnostics {
var diags diag.Diagnostics
// Map the configuration fields from the API response to a structured map
apiIntegrationData := map[string]interface{}{
"display_name": resource.DisplayName,
"enabled": resource.Enabled,
"access_token_lifetime_seconds": resource.AccessTokenLifetimeSeconds,
"app_type": resource.AppType,
"authorization_scopes": resource.AuthorizationScopes,
"client_id": resource.ClientID,
}
// Set the structured map in the Terraform state
for key, val := range apiIntegrationData {
if err := d.Set(key, val); err != nil {
diags = append(diags, diag.FromErr(fmt.Errorf("failed to set '%s': %v", key, err))...)
}
}
return diags
}