Skip to content

Commit

Permalink
feat: fix issue with datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
lechnerc77 committed Jul 24, 2024
1 parent a82a77e commit 106c4db
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/provider/datasource_subaccount_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ You must be assigned to the admin or viewer role of the subaccount.`,
}

func (ds *subaccountSubscriptionDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data subaccountSubscriptionType
var data subaccountSubscriptionDataSourceType

diags := req.Config.Get(ctx, &data)

Expand All @@ -182,7 +182,7 @@ func (ds *subaccountSubscriptionDataSource) Read(ctx context.Context, req dataso
return
}

data, diags = subaccountSubscriptionValueFrom(ctx, cliRes)
data, diags = subaccountSubscriptionDataSourceValueFrom(ctx, cliRes)
resp.Diagnostics.Append(diags...)

diags = resp.State.Set(ctx, &data)
Expand Down
70 changes: 70 additions & 0 deletions internal/provider/type_subaccount_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,73 @@ func subaccountSubscriptionValueFrom(ctx context.Context, value saas_manager_ser

return subscription, diagnostics
}

type subaccountSubscriptionDataSourceType struct {
SubaccountId types.String `tfsdk:"subaccount_id"`
Id types.String `tfsdk:"id"`
AppName types.String `tfsdk:"app_name"`
PlanName types.String `tfsdk:"plan_name"`
Parameters types.String `tfsdk:"parameters"`
AdditionalPlanFeatures types.Set `tfsdk:"additional_plan_features"`
AppId types.String `tfsdk:"app_id"`
AuthenticationProvider types.String `tfsdk:"authentication_provider"`
Category types.String `tfsdk:"category"`
CommercialAppName types.String `tfsdk:"commercial_app_name"`
CreatedDate types.String `tfsdk:"created_date"`
CustomerDeveloped types.Bool `tfsdk:"customer_developed"`
Description types.String `tfsdk:"description"`
DisplayName types.String `tfsdk:"display_name"`
FormationSolutionName types.String `tfsdk:"formation_solution_name"`
GlobalAccountId types.String `tfsdk:"globalaccount_id"`
Labels types.Map `tfsdk:"labels"`
LastModified types.String `tfsdk:"last_modified"`
PlatformEntityId types.String `tfsdk:"platform_entity_id"`
Quota types.Int64 `tfsdk:"quota"`
State types.String `tfsdk:"state"`
SubscribedSubaccountId types.String `tfsdk:"subscribed_subaccount_id"`
SubscribedTenantId types.String `tfsdk:"subscribed_tenant_id"`
SubscriptionUrl types.String `tfsdk:"subscription_url"`
SupportsParametersUpdates types.Bool `tfsdk:"supports_parameters_updates"`
SupportsPlanUpdates types.Bool `tfsdk:"supports_plan_updates"`
TenantId types.String `tfsdk:"tenant_id"`
}

func subaccountSubscriptionDataSourceValueFrom(ctx context.Context, value saas_manager_service.EntitledApplicationsResponseObject) (subaccountSubscriptionDataSourceType, diag.Diagnostics) {
subscription := subaccountSubscriptionDataSourceType{
SubaccountId: types.StringValue(value.SubscribedSubaccountId),
Id: types.StringValue(value.SubscriptionGUID),
AppId: types.StringValue(value.AppId),
AppName: types.StringValue(value.AppName),
AuthenticationProvider: types.StringValue(value.AuthenticationProvider),
Category: types.StringValue(value.Category),
CommercialAppName: types.StringValue(value.CommercialAppName),
CreatedDate: timeToValue(value.CreatedDate.Time()),
CustomerDeveloped: types.BoolValue(value.CustomerDeveloped),
Description: types.StringValue(value.Description),
DisplayName: types.StringValue(value.DisplayName),
FormationSolutionName: types.StringValue(value.FormationSolutionName),
GlobalAccountId: types.StringValue(value.GlobalAccountId),
LastModified: timeToValue(value.ModifiedDate.Time()),
Parameters: types.StringNull(),
PlanName: types.StringValue(value.PlanName),
PlatformEntityId: types.StringValue(value.PlatformEntityId),
Quota: types.Int64Value(int64(value.Quota)),
State: types.StringValue(value.State),
SubscribedSubaccountId: types.StringValue(value.SubscribedSubaccountId),
SubscribedTenantId: types.StringValue(value.SubscribedTenantId),
SubscriptionUrl: types.StringValue(value.SubscriptionUrl),
SupportsParametersUpdates: types.BoolValue(value.SupportsParametersUpdates),
SupportsPlanUpdates: types.BoolValue(value.SupportsPlanUpdates),
TenantId: types.StringValue(value.TenantId),
}

var diags, diagnostics diag.Diagnostics

subscription.AdditionalPlanFeatures, diags = types.SetValueFrom(ctx, types.StringType, value.AdditionalPlanFeatures)
diagnostics.Append(diags...)

subscription.Labels, diags = types.MapValueFrom(ctx, types.SetType{ElemType: types.StringType}, value.Labels)
diagnostics.Append(diags...)

return subscription, diagnostics
}

0 comments on commit 106c4db

Please sign in to comment.