Skip to content

Commit

Permalink
Merge pull request #70 from vantage-sh/mb/support-import
Browse files Browse the repository at this point in the history
Allow users to import resources.
  • Loading branch information
macb authored Oct 2, 2024
2 parents 6cdfb78 + ead7162 commit 01efd01
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 16 deletions.
11 changes: 11 additions & 0 deletions vantage/access_grant_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand All @@ -14,6 +15,12 @@ import (
accessgrantsv2 "github.com/vantage-sh/vantage-go/vantagev2/vantage/access_grants"
)

var (
_ resource.Resource = (*AccessGrantResource)(nil)
_ resource.ResourceWithConfigure = (*AccessGrantResource)(nil)
_ resource.ResourceWithImportState = (*AccessGrantResource)(nil)
)

type AccessGrantResource struct {
client *Client
}
Expand Down Expand Up @@ -126,6 +133,10 @@ func (r AccessGrantResource) Read(ctx context.Context, req resource.ReadRequest,
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

func (r AccessGrantResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r AccessGrantResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data *AccessGrantResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
Expand Down
12 changes: 10 additions & 2 deletions vantage/anomaly_notification_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vantage
import (
"context"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
Expand All @@ -14,8 +15,11 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
)

var _ resource.Resource = (*anomalyNotificationResource)(nil)
var _ resource.ResourceWithConfigure = (*anomalyNotificationResource)(nil)
var (
_ resource.Resource = (*anomalyNotificationResource)(nil)
_ resource.ResourceWithConfigure = (*anomalyNotificationResource)(nil)
_ resource.ResourceWithImportState = (*anomalyNotificationResource)(nil)
)

func NewAnomalyNotificationResource() resource.Resource {
return &anomalyNotificationResource{}
Expand Down Expand Up @@ -172,6 +176,10 @@ func (r *anomalyNotificationResource) Read(ctx context.Context, req resource.Rea
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

func (r *anomalyNotificationResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r *anomalyNotificationResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data resource_anomaly_notification.AnomalyNotificationModel

Expand Down
13 changes: 10 additions & 3 deletions vantage/billing_rule_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import (
billingrulesv2 "github.com/vantage-sh/vantage-go/vantagev2/vantage/billing_rules"
)

var _ resource.Resource = (*billingRuleResource)(nil)
var _ resource.ResourceWithConfigure = (*billingRuleResource)(nil)
var _ resource.ResourceWithValidateConfig = (*billingRuleResource)(nil)
var (
_ resource.Resource = (*billingRuleResource)(nil)
_ resource.ResourceWithConfigure = (*billingRuleResource)(nil)
_ resource.ResourceWithValidateConfig = (*billingRuleResource)(nil)
_ resource.ResourceWithImportState = (*billingRuleResource)(nil)
)

func NewBillingRuleResource() resource.Resource {
return &billingRuleResource{}
Expand Down Expand Up @@ -267,6 +270,10 @@ func (r *billingRuleResource) Read(ctx context.Context, req resource.ReadRequest
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

func (r *billingRuleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r *billingRuleResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data billingRuleModel

Expand Down
12 changes: 10 additions & 2 deletions vantage/budget_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vantage
import (
"context"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand All @@ -13,8 +14,11 @@ import (
budgetsv2 "github.com/vantage-sh/vantage-go/vantagev2/vantage/budgets"
)

var _ resource.Resource = (*budgetResource)(nil)
var _ resource.ResourceWithConfigure = (*budgetResource)(nil)
var (
_ resource.Resource = (*budgetResource)(nil)
_ resource.ResourceWithConfigure = (*budgetResource)(nil)
_ resource.ResourceWithImportState = (*budgetResource)(nil)
)

func NewBudgetResource() resource.Resource {
return &budgetResource{}
Expand Down Expand Up @@ -207,6 +211,10 @@ func (r *budgetResource) Read(ctx context.Context, req resource.ReadRequest, res
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

func (r *budgetResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r *budgetResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data budgetModel

Expand Down
10 changes: 8 additions & 2 deletions vantage/business_metric_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand All @@ -16,8 +17,9 @@ import (
)

var (
_ resource.Resource = (*businessMetricResource)(nil)
_ resource.ResourceWithConfigure = (*businessMetricResource)(nil)
_ resource.Resource = (*businessMetricResource)(nil)
_ resource.ResourceWithConfigure = (*businessMetricResource)(nil)
_ resource.ResourceWithImportState = (*businessMetricResource)(nil)
)

func NewBusinessMetricResource() resource.Resource {
Expand Down Expand Up @@ -205,6 +207,10 @@ func (r *businessMetricResource) Read(ctx context.Context, req resource.ReadRequ
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

func (r *businessMetricResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r *businessMetricResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data *businessMetricResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
Expand Down
11 changes: 10 additions & 1 deletion vantage/cost_report_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import (
costsv2 "github.com/vantage-sh/vantage-go/vantagev2/vantage/costs"
)

var _ resource.ResourceWithConfigValidators = &CostReportResource{}
var (
_ resource.Resource = (*CostReportResource)(nil)
_ resource.ResourceWithConfigure = (*CostReportResource)(nil)
_ resource.ResourceWithImportState = (*CostReportResource)(nil)
)

type CostReportResource struct {
client *Client
Expand Down Expand Up @@ -239,6 +243,7 @@ func (r CostReportResource) Read(ctx context.Context, req resource.ReadRequest,
state.ChartType = types.StringValue(out.Payload.ChartType)
state.DateBin = types.StringValue(out.Payload.DateBin)
state.WorkspaceToken = types.StringValue(out.Payload.WorkspaceToken)
state.FolderToken = types.StringValue(out.Payload.FolderToken)
savedFilterTokensValue, diag := types.ListValueFrom(ctx, types.StringType, out.Payload.SavedFilterTokens)
if diag.HasError() {
resp.Diagnostics.Append(diag...)
Expand All @@ -249,6 +254,10 @@ func (r CostReportResource) Read(ctx context.Context, req resource.ReadRequest,
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

func (r CostReportResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r CostReportResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data *CostReportResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
Expand Down
11 changes: 11 additions & 0 deletions vantage/dashboard_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vantage
import (
"context"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand All @@ -12,6 +13,12 @@ import (
dashboardsv2 "github.com/vantage-sh/vantage-go/vantagev2/vantage/dashboards"
)

var (
_ resource.Resource = (*DashboardResource)(nil)
_ resource.ResourceWithConfigure = (*DashboardResource)(nil)
_ resource.ResourceWithImportState = (*DashboardResource)(nil)
)

type DashboardResource struct {
client *Client
}
Expand Down Expand Up @@ -206,6 +213,10 @@ func (r DashboardResource) Read(ctx context.Context, req resource.ReadRequest, r
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

func (r DashboardResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r DashboardResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data *DashboardResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
Expand Down
10 changes: 9 additions & 1 deletion vantage/folder_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import (
foldersv2 "github.com/vantage-sh/vantage-go/vantagev2/vantage/folders"
)

var _ resource.ResourceWithConfigValidators = &FolderResource{}
var (
_ resource.Resource = (*FolderResource)(nil)
_ resource.ResourceWithConfigure = (*FolderResource)(nil)
_ resource.ResourceWithImportState = (*FolderResource)(nil)
)

type FolderResource struct {
client *Client
Expand Down Expand Up @@ -127,6 +131,10 @@ func (r FolderResource) Read(ctx context.Context, req resource.ReadRequest, resp
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

func (r FolderResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r FolderResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data *FolderResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
Expand Down
12 changes: 10 additions & 2 deletions vantage/managed_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand All @@ -13,8 +14,11 @@ import (
managedaccountsv2 "github.com/vantage-sh/vantage-go/vantagev2/vantage/managed_accounts"
)

var _ resource.Resource = (*managedAccountResource)(nil)
var _ resource.ResourceWithConfigure = (*managedAccountResource)(nil)
var (
_ resource.Resource = (*managedAccountResource)(nil)
_ resource.ResourceWithConfigure = (*managedAccountResource)(nil)
_ resource.ResourceWithImportState = (*managedAccountResource)(nil)
)

func NewManagedAccountResource() resource.Resource {
return &managedAccountResource{}
Expand Down Expand Up @@ -146,6 +150,10 @@ func (r *managedAccountResource) Read(ctx context.Context, req resource.ReadRequ
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

func (r *managedAccountResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r *managedAccountResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data *managedAccountModel

Expand Down
11 changes: 11 additions & 0 deletions vantage/report_notification_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vantage
import (
"context"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand All @@ -13,6 +14,12 @@ import (
notifsv2 "github.com/vantage-sh/vantage-go/vantagev2/vantage/report_notifications"
)

var (
_ resource.Resource = (*ReportNotificationResource)(nil)
_ resource.ResourceWithConfigure = (*ReportNotificationResource)(nil)
_ resource.ResourceWithImportState = (*ReportNotificationResource)(nil)
)

type ReportNotificationResource struct {
client *Client
}
Expand Down Expand Up @@ -174,6 +181,10 @@ func (r *ReportNotificationResource) Read(ctx context.Context, req resource.Read
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

func (r *ReportNotificationResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r *ReportNotificationResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data *ReportNotificationResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
Expand Down
11 changes: 11 additions & 0 deletions vantage/saved_filter_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vantage
import (
"context"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand All @@ -12,6 +13,12 @@ import (
filtersv2 "github.com/vantage-sh/vantage-go/vantagev2/vantage/saved_filters"
)

var (
_ resource.Resource = (*SavedFilterResource)(nil)
_ resource.ResourceWithConfigure = (*SavedFilterResource)(nil)
_ resource.ResourceWithImportState = (*SavedFilterResource)(nil)
)

type SavedFilterResource struct {
client *Client
}
Expand Down Expand Up @@ -120,6 +127,10 @@ func (r SavedFilterResource) Read(ctx context.Context, req resource.ReadRequest,
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

func (r SavedFilterResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r SavedFilterResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data *SavedFilterResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
Expand Down
10 changes: 9 additions & 1 deletion vantage/segment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import (
segmentsv2 "github.com/vantage-sh/vantage-go/vantagev2/vantage/segments"
)

var _ resource.ResourceWithConfigValidators = &SegmentResource{}
var (
_ resource.Resource = (*SegmentResource)(nil)
_ resource.ResourceWithConfigure = (*SegmentResource)(nil)
_ resource.ResourceWithImportState = (*SegmentResource)(nil)
)

type SegmentResource struct {
client *Client
Expand Down Expand Up @@ -177,6 +181,10 @@ func (r SegmentResource) Read(ctx context.Context, req resource.ReadRequest, res
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

func (r SegmentResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r SegmentResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data *SegmentResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
Expand Down
11 changes: 11 additions & 0 deletions vantage/team_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vantage
import (
"context"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand All @@ -13,6 +14,12 @@ import (
teamsv2 "github.com/vantage-sh/vantage-go/vantagev2/vantage/teams"
)

var (
_ resource.Resource = (*TeamResource)(nil)
_ resource.ResourceWithConfigure = (*TeamResource)(nil)
_ resource.ResourceWithImportState = (*TeamResource)(nil)
)

type TeamResource struct {
client *Client
}
Expand Down Expand Up @@ -238,6 +245,10 @@ func (r TeamResource) Read(ctx context.Context, req resource.ReadRequest, resp *
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

func (r TeamResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp)
}

func (r TeamResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var data *TeamResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
Expand Down
Loading

0 comments on commit 01efd01

Please sign in to comment.