Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions internal/provider/data_source_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/jianyuan/terraform-provider-sentry/internal/apiclient"
"github.com/jianyuan/terraform-provider-sentry/internal/diagutils"
Expand All @@ -21,13 +22,13 @@ type OrganizationDataSourceModel struct {
InternalId types.String `tfsdk:"internal_id"`
}

func (m *OrganizationDataSourceModel) Fill(org apiclient.Organization) error {
func (m *OrganizationDataSourceModel) Fill(ctx context.Context, org apiclient.Organization) (diags diag.Diagnostics) {
m.Id = types.StringValue(org.Slug)
m.Slug = types.StringValue(org.Slug)
m.Name = types.StringValue(org.Name)
m.InternalId = types.StringValue(org.Id)

return nil
return
}

func NewOrganizationDataSource() datasource.DataSource {
Expand Down Expand Up @@ -85,16 +86,13 @@ func (d *OrganizationDataSource) Read(ctx context.Context, req datasource.ReadRe
resp.Diagnostics.Append(diagutils.NewNotFoundError("organization"))
resp.State.RemoveResource(ctx)
return
} else if httpResp.StatusCode() != http.StatusOK {
} else if httpResp.StatusCode() != http.StatusOK || httpResp.JSON200 == nil {
resp.Diagnostics.Append(diagutils.NewClientStatusError("read", httpResp.StatusCode(), httpResp.Body))
return
} else if httpResp.JSON200 == nil {
resp.Diagnostics.Append(diagutils.NewClientError("read", diagutils.ErrEmptyResponse))
return
}

if err := data.Fill(*httpResp.JSON200); err != nil {
resp.Diagnostics.Append(diagutils.NewFillError(err))
resp.Diagnostics.Append(data.Fill(ctx, *httpResp.JSON200)...)
if resp.Diagnostics.HasError() {
return
}

Expand Down
42 changes: 16 additions & 26 deletions internal/provider/resource_client_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ func (m ClientKeyJavascriptLoaderScriptResourceModel) AttributeTypes() map[strin
}
}

func (m *ClientKeyJavascriptLoaderScriptResourceModel) Fill(ctx context.Context, key apiclient.ProjectKey) diag.Diagnostics {
var diags diag.Diagnostics

func (m *ClientKeyJavascriptLoaderScriptResourceModel) Fill(ctx context.Context, key apiclient.ProjectKey) (diags diag.Diagnostics) {
m.BrowserSdkVersion = types.StringValue(key.BrowserSdkVersion)
m.PerformanceMonitoringEnabled = types.BoolValue(key.DynamicSdkLoaderOptions.HasPerformance)
m.SessionReplayEnabled = types.BoolValue(key.DynamicSdkLoaderOptions.HasReplay)
m.DebugEnabled = types.BoolValue(key.DynamicSdkLoaderOptions.HasDebug)

return diags
return
}

type ClientKeyResourceModel struct {
Expand All @@ -67,9 +65,7 @@ type ClientKeyResourceModel struct {
DsnCsp types.String `tfsdk:"dsn_csp"`
}

func (m *ClientKeyResourceModel) Fill(ctx context.Context, key apiclient.ProjectKey) diag.Diagnostics {
var diags diag.Diagnostics

func (m *ClientKeyResourceModel) Fill(ctx context.Context, key apiclient.ProjectKey) (diags diag.Diagnostics) {
m.Id = types.StringValue(key.Id)
m.ProjectId = types.StringValue(key.ProjectId.String())
m.Name = types.StringValue(key.Name)
Expand Down Expand Up @@ -114,7 +110,7 @@ func (m *ClientKeyResourceModel) Fill(ctx context.Context, key apiclient.Project
m.DsnCsp = types.StringNull()
}

return diags
return
}

var _ resource.Resource = &ClientKeyResource{}
Expand Down Expand Up @@ -382,28 +378,22 @@ func (r *ClientKeyResource) Update(ctx context.Context, req resource.UpdateReque
}

if !plan.JavascriptLoaderScript.Equal(state.JavascriptLoaderScript) {
var javascriptLoaderScriptPlan, javascriptLoaderScriptState ClientKeyJavascriptLoaderScriptResourceModel
resp.Diagnostics.Append(plan.JavascriptLoaderScript.As(ctx, &javascriptLoaderScriptPlan, basetypes.ObjectAsOptions{})...)
var javascriptLoaderScript ClientKeyJavascriptLoaderScriptResourceModel
resp.Diagnostics.Append(plan.JavascriptLoaderScript.As(ctx, &javascriptLoaderScript, basetypes.ObjectAsOptions{})...)
if resp.Diagnostics.HasError() {
return
}

if !javascriptLoaderScriptPlan.BrowserSdkVersion.Equal(javascriptLoaderScriptState.BrowserSdkVersion) {
body.BrowserSdkVersion = javascriptLoaderScriptPlan.BrowserSdkVersion.ValueStringPointer()
}

if !javascriptLoaderScriptPlan.SessionReplayEnabled.Equal(javascriptLoaderScriptState.SessionReplayEnabled) ||
!javascriptLoaderScriptPlan.PerformanceMonitoringEnabled.Equal(javascriptLoaderScriptState.PerformanceMonitoringEnabled) ||
!javascriptLoaderScriptPlan.DebugEnabled.Equal(javascriptLoaderScriptState.DebugEnabled) {
body.DynamicSdkLoaderOptions = &struct {
HasDebug *bool `json:"hasDebug,omitempty"`
HasPerformance *bool `json:"hasPerformance,omitempty"`
HasReplay *bool `json:"hasReplay,omitempty"`
}{
HasReplay: javascriptLoaderScriptPlan.SessionReplayEnabled.ValueBoolPointer(),
HasDebug: javascriptLoaderScriptPlan.DebugEnabled.ValueBoolPointer(),
HasPerformance: javascriptLoaderScriptPlan.PerformanceMonitoringEnabled.ValueBoolPointer(),
}
// NOTE: Both `BrowserSdkVersion` and `DynamicSdkLoaderOptions` must be set together.
body.BrowserSdkVersion = javascriptLoaderScript.BrowserSdkVersion.ValueStringPointer()
body.DynamicSdkLoaderOptions = &struct {
HasDebug *bool `json:"hasDebug,omitempty"`
HasPerformance *bool `json:"hasPerformance,omitempty"`
HasReplay *bool `json:"hasReplay,omitempty"`
}{
HasReplay: javascriptLoaderScript.SessionReplayEnabled.ValueBoolPointer(),
HasDebug: javascriptLoaderScript.DebugEnabled.ValueBoolPointer(),
HasPerformance: javascriptLoaderScript.PerformanceMonitoringEnabled.ValueBoolPointer(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_client_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func TestAccClientKeyResource(t *testing.T) {
RateLimitCount: ptr.Ptr(2),
Extras: `
javascript_loader_script = {
browser_sdk_version = "7.x"
browser_sdk_version = "7.x"
}
`,
}),
Expand Down
Loading
Loading