Skip to content

Commit d4a520f

Browse files
committed
ref: use tfutils id helpers
1 parent 1a4ccfa commit d4a520f

15 files changed

+35
-135
lines changed

internal/provider/helpers.go

-42
This file was deleted.

internal/provider/resource_integration_opsgenie.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"fmt"
77
"net/http"
88

9-
"github.com/hashicorp/terraform-plugin-framework/path"
109
"github.com/hashicorp/terraform-plugin-framework/resource"
1110
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1211
"github.com/hashicorp/terraform-plugin-framework/types"
1312
"github.com/jianyuan/terraform-provider-sentry/internal/diagutils"
13+
"github.com/jianyuan/terraform-provider-sentry/internal/tfutils"
1414
)
1515

1616
type IntegrationOpsgenieModel struct {
@@ -368,18 +368,5 @@ func (r *IntegrationOpsgenie) Delete(ctx context.Context, req resource.DeleteReq
368368
}
369369

370370
func (r *IntegrationOpsgenie) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
371-
organization, integrationId, id, err := splitThreePartID(req.ID, "organization", "integration-id", "id")
372-
if err != nil {
373-
resp.Diagnostics.Append(diagutils.NewImportError(err))
374-
return
375-
}
376-
resp.Diagnostics.Append(resp.State.SetAttribute(
377-
ctx, path.Root("organization"), organization,
378-
)...)
379-
resp.Diagnostics.Append(resp.State.SetAttribute(
380-
ctx, path.Root("integration_id"), integrationId,
381-
)...)
382-
resp.Diagnostics.Append(resp.State.SetAttribute(
383-
ctx, path.Root("id"), id,
384-
)...)
371+
tfutils.ImportStateThreePartId(ctx, "organization", "integration_id", req, resp)
385372
}

internal/provider/resource_integration_opsgenie_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/hashicorp/terraform-plugin-testing/terraform"
1313
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
1414
"github.com/jianyuan/terraform-provider-sentry/internal/acctest"
15+
"github.com/jianyuan/terraform-provider-sentry/internal/tfutils"
1516
)
1617

1718
func TestAccIntegrationOpsgenieResource(t *testing.T) {
@@ -97,7 +98,7 @@ func TestAccIntegrationOpsgenieResource(t *testing.T) {
9798
organization := rs.Primary.Attributes["organization"]
9899
integrationId := rs.Primary.Attributes["integration_id"]
99100
id := rs.Primary.ID
100-
return buildThreePartID(organization, integrationId, id), nil
101+
return tfutils.BuildThreePartId(organization, integrationId, id), nil
101102
},
102103
ImportStateVerify: true,
103104
},

internal/provider/resource_integration_pagerduty.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"fmt"
77
"net/http"
88

9-
"github.com/hashicorp/terraform-plugin-framework/path"
109
"github.com/hashicorp/terraform-plugin-framework/resource"
1110
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1211
"github.com/hashicorp/terraform-plugin-framework/types"
1312
"github.com/jianyuan/terraform-provider-sentry/internal/diagutils"
13+
"github.com/jianyuan/terraform-provider-sentry/internal/tfutils"
1414
)
1515

1616
type IntegrationPagerDutyModel struct {
@@ -368,18 +368,5 @@ func (r *IntegrationPagerDuty) Delete(ctx context.Context, req resource.DeleteRe
368368
}
369369

370370
func (r *IntegrationPagerDuty) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
371-
organization, integrationId, id, err := splitThreePartID(req.ID, "organization", "integration-id", "id")
372-
if err != nil {
373-
resp.Diagnostics.Append(diagutils.NewImportError(err))
374-
return
375-
}
376-
resp.Diagnostics.Append(resp.State.SetAttribute(
377-
ctx, path.Root("organization"), organization,
378-
)...)
379-
resp.Diagnostics.Append(resp.State.SetAttribute(
380-
ctx, path.Root("integration_id"), integrationId,
381-
)...)
382-
resp.Diagnostics.Append(resp.State.SetAttribute(
383-
ctx, path.Root("id"), id,
384-
)...)
371+
tfutils.ImportStateThreePartId(ctx, "organization", "integration_id", req, resp)
385372
}

internal/provider/resource_integration_pagerduty_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/hashicorp/terraform-plugin-testing/terraform"
1313
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
1414
"github.com/jianyuan/terraform-provider-sentry/internal/acctest"
15+
"github.com/jianyuan/terraform-provider-sentry/internal/tfutils"
1516
)
1617

1718
func TestAccIntegrationPagerDutyResource(t *testing.T) {
@@ -95,7 +96,7 @@ func TestAccIntegrationPagerDutyResource(t *testing.T) {
9596
organization := rs.Primary.Attributes["organization"]
9697
integrationId := rs.Primary.Attributes["integration_id"]
9798
id := rs.Primary.ID
98-
return buildThreePartID(organization, integrationId, id), nil
99+
return tfutils.BuildThreePartId(organization, integrationId, id), nil
99100
},
100101
ImportStateVerify: true,
101102
},

internal/provider/resource_issue_alert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ func (r *IssueAlertResource) UpgradeState(ctx context.Context) map[int64]resourc
10431043
return
10441044
}
10451045

1046-
organization, project, actionId, err := splitThreePartID(priorStateData.Id.ValueString(), "organization", "project-slug", "alert-id")
1046+
organization, project, actionId, err := tfutils.SplitThreePartId(priorStateData.Id.ValueString(), "organization", "project-slug", "alert-id")
10471047
if err != nil {
10481048
resp.Diagnostics.AddError("Invalid ID", fmt.Sprintf("Error parsing ID: %s", err.Error()))
10491049
return

internal/provider/resource_notification_action.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88

99
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1010
"github.com/hashicorp/terraform-plugin-framework/attr"
11-
"github.com/hashicorp/terraform-plugin-framework/path"
1211
"github.com/hashicorp/terraform-plugin-framework/resource"
1312
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1413
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1514
"github.com/hashicorp/terraform-plugin-framework/types"
1615
"github.com/jianyuan/go-sentry/v2/sentry"
1716
"github.com/jianyuan/terraform-provider-sentry/internal/diagutils"
1817
"github.com/jianyuan/terraform-provider-sentry/internal/sentryclient"
18+
"github.com/jianyuan/terraform-provider-sentry/internal/tfutils"
1919
)
2020

2121
type NotificationActionResourceModel struct {
@@ -291,15 +291,5 @@ func (r *NotificationActionResource) Delete(ctx context.Context, req resource.De
291291
}
292292

293293
func (r *NotificationActionResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
294-
org, actionId, err := splitTwoPartID(req.ID, "organization", "action-id")
295-
if err != nil {
296-
resp.Diagnostics.Append(diagutils.NewImportError(err))
297-
return
298-
}
299-
resp.Diagnostics.Append(resp.State.SetAttribute(
300-
ctx, path.Root("organization"), org,
301-
)...)
302-
resp.Diagnostics.Append(resp.State.SetAttribute(
303-
ctx, path.Root("id"), actionId,
304-
)...)
294+
tfutils.ImportStateTwoPartId(ctx, "organization", req, resp)
305295
}

internal/provider/resource_notification_action_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
88
"github.com/hashicorp/terraform-plugin-testing/terraform"
99
"github.com/jianyuan/terraform-provider-sentry/internal/acctest"
10+
"github.com/jianyuan/terraform-provider-sentry/internal/tfutils"
1011
)
1112

1213
func TestAccNotificationActionResource(t *testing.T) {
@@ -53,7 +54,7 @@ func TestAccNotificationActionResource(t *testing.T) {
5354
}
5455
org := rs.Primary.Attributes["organization"]
5556
actionId := rs.Primary.ID
56-
return buildTwoPartID(org, actionId), nil
57+
return tfutils.BuildTwoPartId(org, actionId), nil
5758
},
5859
ImportStateVerify: true,
5960
},

internal/provider/resource_organization_repository.go

+2-19
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55
"net/http"
66

77
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
8-
"github.com/hashicorp/terraform-plugin-framework/path"
98
"github.com/hashicorp/terraform-plugin-framework/resource"
109
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1110
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1211
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
1312
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1413
"github.com/jianyuan/go-sentry/v2/sentry"
1514
"github.com/jianyuan/terraform-provider-sentry/internal/diagutils"
15+
"github.com/jianyuan/terraform-provider-sentry/internal/tfutils"
1616
)
1717

1818
var _ resource.Resource = &OrganizationRepositoryResource{}
@@ -170,22 +170,5 @@ func (r *OrganizationRepositoryResource) Delete(ctx context.Context, req resourc
170170
}
171171

172172
func (r *OrganizationRepositoryResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
173-
organization, integrationType, integrationId, id, err := splitFourPartID(req.ID, "organization", "integration_type", "integration_id", "id")
174-
if err != nil {
175-
resp.Diagnostics.Append(diagutils.NewImportError(err))
176-
return
177-
}
178-
179-
resp.Diagnostics.Append(resp.State.SetAttribute(
180-
ctx, path.Root("organization"), organization,
181-
)...)
182-
resp.Diagnostics.Append(resp.State.SetAttribute(
183-
ctx, path.Root("integration_type"), integrationType,
184-
)...)
185-
resp.Diagnostics.Append(resp.State.SetAttribute(
186-
ctx, path.Root("integration_id"), integrationId,
187-
)...)
188-
resp.Diagnostics.Append(resp.State.SetAttribute(
189-
ctx, path.Root("id"), id,
190-
)...)
173+
tfutils.ImportStateFourPartId(ctx, "organization", "integration_type", "integration_id", req, resp)
191174
}

internal/provider/resource_organization_repository_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/jianyuan/go-sentry/v2/sentry"
1818
"github.com/jianyuan/go-utils/must"
1919
"github.com/jianyuan/terraform-provider-sentry/internal/acctest"
20+
"github.com/jianyuan/terraform-provider-sentry/internal/tfutils"
2021
)
2122

2223
func init() {
@@ -128,7 +129,7 @@ func TestAccOrganizationRepositoryResource_GitHub(t *testing.T) {
128129
integrationType := rs.Primary.Attributes["integration_type"]
129130
integrationId := rs.Primary.Attributes["integration_id"]
130131
id := rs.Primary.ID
131-
return buildFourPartID(organization, integrationType, integrationId, id), nil
132+
return tfutils.BuildFourPartId(organization, integrationType, integrationId, id), nil
132133
},
133134
ImportStateVerify: true,
134135
},
@@ -180,7 +181,7 @@ func TestAccOrganizationRepositoryResource_GitLab(t *testing.T) {
180181
integrationType := rs.Primary.Attributes["integration_type"]
181182
integrationId := rs.Primary.Attributes["integration_id"]
182183
id := rs.Primary.ID
183-
return buildFourPartID(organization, integrationType, integrationId, id), nil
184+
return tfutils.BuildFourPartId(organization, integrationType, integrationId, id), nil
184185
},
185186
ImportStateVerify: true,
186187
},
@@ -232,7 +233,7 @@ func TestAccOrganizationRepositoryResource_VSTS(t *testing.T) {
232233
integrationType := rs.Primary.Attributes["integration_type"]
233234
integrationId := rs.Primary.Attributes["integration_id"]
234235
id := rs.Primary.ID
235-
return buildFourPartID(organization, integrationType, integrationId, id), nil
236+
return tfutils.BuildFourPartId(organization, integrationType, integrationId, id), nil
236237
},
237238
ImportStateVerify: true,
238239
},

internal/provider/resource_project_inbound_data_filter.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/hashicorp/terraform-plugin-framework/types"
1717
"github.com/jianyuan/go-sentry/v2/sentry"
1818
"github.com/jianyuan/terraform-provider-sentry/internal/diagutils"
19+
"github.com/jianyuan/terraform-provider-sentry/internal/tfutils"
1920
)
2021

2122
type ProjectInboundDataFilterResourceModel struct {
@@ -28,7 +29,7 @@ type ProjectInboundDataFilterResourceModel struct {
2829
}
2930

3031
func (m *ProjectInboundDataFilterResourceModel) Fill(organization string, project string, filterId string, filter sentry.ProjectInboundDataFilter) error {
31-
m.Id = types.StringValue(buildThreePartID(organization, project, filterId))
32+
m.Id = types.StringValue(tfutils.BuildThreePartId(organization, project, filterId))
3233
m.Organization = types.StringValue(organization)
3334
m.Project = types.StringValue(project)
3435
m.FilterId = types.StringValue(filterId)
@@ -125,7 +126,7 @@ func (r *ProjectInboundDataFilterResource) Create(ctx context.Context, req resou
125126
return
126127
}
127128

128-
data.Id = types.StringValue(buildThreePartID(data.Organization.ValueString(), data.Project.ValueString(), data.FilterId.ValueString()))
129+
data.Id = types.StringValue(tfutils.BuildThreePartId(data.Organization.ValueString(), data.Project.ValueString(), data.FilterId.ValueString()))
129130

130131
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
131132
}
@@ -204,7 +205,7 @@ func (r *ProjectInboundDataFilterResource) Update(ctx context.Context, req resou
204205
return
205206
}
206207

207-
plan.Id = types.StringValue(buildThreePartID(plan.Organization.ValueString(), plan.Project.ValueString(), plan.FilterId.ValueString()))
208+
plan.Id = types.StringValue(tfutils.BuildThreePartId(plan.Organization.ValueString(), plan.Project.ValueString(), plan.FilterId.ValueString()))
208209

209210
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
210211
}
@@ -236,7 +237,7 @@ func (r *ProjectInboundDataFilterResource) Delete(ctx context.Context, req resou
236237
}
237238

238239
func (r *ProjectInboundDataFilterResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
239-
organization, project, filterID, err := splitThreePartID(req.ID, "organization", "project-slug", "filter-id")
240+
organization, project, filterID, err := tfutils.SplitThreePartId(req.ID, "organization", "project-slug", "filter-id")
240241
if err != nil {
241242
resp.Diagnostics.Append(diagutils.NewImportError(err))
242243
return

internal/provider/resource_project_spike_protection.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/jianyuan/go-sentry/v2/sentry"
1212
"github.com/jianyuan/terraform-provider-sentry/internal/apiclient"
1313
"github.com/jianyuan/terraform-provider-sentry/internal/diagutils"
14+
"github.com/jianyuan/terraform-provider-sentry/internal/tfutils"
1415
)
1516

1617
type ProjectSpikeProtectionResourceModel struct {
@@ -21,7 +22,7 @@ type ProjectSpikeProtectionResourceModel struct {
2122
}
2223

2324
func (data *ProjectSpikeProtectionResourceModel) Fill(project apiclient.Project) error {
24-
data.Id = types.StringValue(buildTwoPartID(project.Organization.Slug, project.Slug))
25+
data.Id = types.StringValue(tfutils.BuildTwoPartId(project.Organization.Slug, project.Slug))
2526
data.Organization = types.StringValue(project.Organization.Slug)
2627
data.Project = types.StringValue(project.Slug)
2728
if disabled, ok := project.Options["quotas:spike-protection-disabled"].(bool); ok {
@@ -99,7 +100,7 @@ func (r *ProjectSpikeProtectionResource) Create(ctx context.Context, req resourc
99100
}
100101
}
101102

102-
data.Id = types.StringValue(buildTwoPartID(data.Organization.ValueString(), data.Project.ValueString()))
103+
data.Id = types.StringValue(tfutils.BuildTwoPartId(data.Organization.ValueString(), data.Project.ValueString()))
103104

104105
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
105106
}
@@ -203,7 +204,7 @@ func (r *ProjectSpikeProtectionResource) Delete(ctx context.Context, req resourc
203204
}
204205

205206
func (r *ProjectSpikeProtectionResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
206-
organization, project, err := splitTwoPartID(req.ID, "organization", "project-slug")
207+
organization, project, err := tfutils.SplitTwoPartId(req.ID, "organization", "project-slug")
207208
if err != nil {
208209
resp.Diagnostics.Append(diagutils.NewFillError(err))
209210
return

internal/provider/resource_project_symbol_source.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
88
"github.com/hashicorp/terraform-plugin-framework/attr"
9-
"github.com/hashicorp/terraform-plugin-framework/path"
109
"github.com/hashicorp/terraform-plugin-framework/resource"
1110
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
1211
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
@@ -15,6 +14,7 @@ import (
1514
"github.com/hashicorp/terraform-plugin-framework/types"
1615
"github.com/jianyuan/go-sentry/v2/sentry"
1716
"github.com/jianyuan/terraform-provider-sentry/internal/diagutils"
17+
"github.com/jianyuan/terraform-provider-sentry/internal/tfutils"
1818
)
1919

2020
type ProjectSymbolSourcesResourceModel struct {
@@ -394,18 +394,5 @@ func (r *ProjectSymbolSourcesResource) Delete(ctx context.Context, req resource.
394394
}
395395

396396
func (r *ProjectSymbolSourcesResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
397-
organization, project, symbolSourceId, err := splitThreePartID(req.ID, "organization", "project-slug", "symbol-source-id")
398-
if err != nil {
399-
resp.Diagnostics.Append(diagutils.NewImportError(err))
400-
return
401-
}
402-
resp.Diagnostics.Append(resp.State.SetAttribute(
403-
ctx, path.Root("organization"), organization,
404-
)...)
405-
resp.Diagnostics.Append(resp.State.SetAttribute(
406-
ctx, path.Root("project"), project,
407-
)...)
408-
resp.Diagnostics.Append(resp.State.SetAttribute(
409-
ctx, path.Root("id"), symbolSourceId,
410-
)...)
397+
tfutils.ImportStateThreePartId(ctx, "organization", "project", req, resp)
411398
}

0 commit comments

Comments
 (0)