Skip to content

Commit

Permalink
updates to stating
Browse files Browse the repository at this point in the history
  • Loading branch information
ShocOne committed Jul 22, 2024
1 parent 277d9a9 commit f5d5744
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package assignmentFilter

import (
"fmt"

"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/microsoftgraph/msgraph-beta-sdk-go/models"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ func (r *AssignmentFilterResource) Create(ctx context.Context, req resource.Crea
tflog.Debug(ctx, fmt.Sprintf("Finished creation of resource: %s_%s", r.ProviderTypeName, r.TypeName))
}

// Read handles the Read operation.
func (r *AssignmentFilterResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()
Expand All @@ -194,18 +193,7 @@ func (r *AssignmentFilterResource) Read(ctx context.Context, req resource.ReadRe
return
}

data.DisplayName = types.StringValue(*filter.GetDisplayName())
data.Description = types.StringValue(*filter.GetDescription())
platformStr, err := DevicePlatformTypeToString(filter.GetPlatform())
if err != nil {
resp.Diagnostics.AddError(
"Error reading assignment filter",
fmt.Sprintf("Could not convert platform: %s", err.Error()),
)
return
}
data.Platform = types.StringValue(platformStr)
data.Rule = types.StringValue(*filter.GetRule())
setTerraformState(&data, filter, resp)

tflog.Debug(ctx, fmt.Sprintf("READ: %s_environment with id %s", r.ProviderTypeName, data.ID.ValueString()))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package assignmentFilter

import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/microsoftgraph/msgraph-beta-sdk-go/models"
)

func setTerraformState(data *AssignmentFilterResourceModel, filter models.DeviceAndAppManagementAssignmentFilterable, resp *resource.ReadResponse) {
data.DisplayName = types.StringValue(*filter.GetDisplayName())
data.Description = types.StringValue(*filter.GetDescription())
data.Platform = types.StringValue(filter.GetPlatform().String())
data.Rule = types.StringValue(*filter.GetRule())
data.AssignmentFilterManagementType = types.StringValue(filter.GetAssignmentFilterManagementType().String())
data.CreatedDateTime = types.StringValue(filter.GetCreatedDateTime().String())
data.LastModifiedDateTime = types.StringValue(filter.GetLastModifiedDateTime().String())

// Set RoleScopeTags
roleScopeTags := filter.GetRoleScopeTags()
if roleScopeTags != nil {
tagList := make([]attr.Value, len(roleScopeTags))
for i, tag := range roleScopeTags {
tagList[i] = types.StringValue(tag)
}
roleScopeTagsList := types.ListValueMust(types.StringType, tagList)
data.RoleScopeTags = roleScopeTagsList
} else {
roleScopeTagsList := types.ListValueMust(types.StringType, []attr.Value{})
data.RoleScopeTags = roleScopeTagsList
}

}

0 comments on commit f5d5744

Please sign in to comment.