From ead7162344de96c8a7ae67b3cfd85cfe19431e7b Mon Sep 17 00:00:00 2001 From: Mac Browning Date: Tue, 1 Oct 2024 17:30:57 -0700 Subject: [PATCH] Allow users to import resources. --- vantage/access_grant_resource.go | 11 +++++++++++ vantage/anomaly_notification_resource.go | 12 ++++++++++-- vantage/billing_rule_resource.go | 13 ++++++++++--- vantage/budget_resource.go | 12 ++++++++++-- vantage/business_metric_resource.go | 10 ++++++++-- vantage/cost_report_resource.go | 11 ++++++++++- vantage/dashboard_resource.go | 11 +++++++++++ vantage/folder_resource.go | 10 +++++++++- vantage/managed_account_resource.go | 12 ++++++++++-- vantage/report_notification_resource.go | 11 +++++++++++ vantage/saved_filter_resource.go | 11 +++++++++++ vantage/segment_resource.go | 10 +++++++++- vantage/team_resource.go | 11 +++++++++++ vantage/virtual_tag_config_resource.go | 12 ++++++++++-- 14 files changed, 141 insertions(+), 16 deletions(-) diff --git a/vantage/access_grant_resource.go b/vantage/access_grant_resource.go index cd1dc0c..6e8bb08 100644 --- a/vantage/access_grant_resource.go +++ b/vantage/access_grant_resource.go @@ -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" @@ -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 } @@ -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)...) diff --git a/vantage/anomaly_notification_resource.go b/vantage/anomaly_notification_resource.go index 8ce34ab..46ffce4 100644 --- a/vantage/anomaly_notification_resource.go +++ b/vantage/anomaly_notification_resource.go @@ -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" @@ -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{} @@ -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 diff --git a/vantage/billing_rule_resource.go b/vantage/billing_rule_resource.go index a57fc8f..74213d1 100644 --- a/vantage/billing_rule_resource.go +++ b/vantage/billing_rule_resource.go @@ -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{} @@ -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 diff --git a/vantage/budget_resource.go b/vantage/budget_resource.go index 8a08116..b24636d 100644 --- a/vantage/budget_resource.go +++ b/vantage/budget_resource.go @@ -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" @@ -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{} @@ -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 diff --git a/vantage/business_metric_resource.go b/vantage/business_metric_resource.go index bf9054e..5cc86cf 100644 --- a/vantage/business_metric_resource.go +++ b/vantage/business_metric_resource.go @@ -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" @@ -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 { @@ -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)...) diff --git a/vantage/cost_report_resource.go b/vantage/cost_report_resource.go index bb91e77..aaefb28 100644 --- a/vantage/cost_report_resource.go +++ b/vantage/cost_report_resource.go @@ -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 @@ -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...) @@ -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)...) diff --git a/vantage/dashboard_resource.go b/vantage/dashboard_resource.go index bb44d77..40e8554 100644 --- a/vantage/dashboard_resource.go +++ b/vantage/dashboard_resource.go @@ -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" @@ -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 } @@ -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)...) diff --git a/vantage/folder_resource.go b/vantage/folder_resource.go index 598c126..1fa48a9 100644 --- a/vantage/folder_resource.go +++ b/vantage/folder_resource.go @@ -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 @@ -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)...) diff --git a/vantage/managed_account_resource.go b/vantage/managed_account_resource.go index 8f77a2a..1a7f25b 100644 --- a/vantage/managed_account_resource.go +++ b/vantage/managed_account_resource.go @@ -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" @@ -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{} @@ -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 diff --git a/vantage/report_notification_resource.go b/vantage/report_notification_resource.go index 543c8da..bb94b00 100644 --- a/vantage/report_notification_resource.go +++ b/vantage/report_notification_resource.go @@ -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" @@ -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 } @@ -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)...) diff --git a/vantage/saved_filter_resource.go b/vantage/saved_filter_resource.go index db74b51..9a6ea54 100644 --- a/vantage/saved_filter_resource.go +++ b/vantage/saved_filter_resource.go @@ -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" @@ -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 } @@ -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)...) diff --git a/vantage/segment_resource.go b/vantage/segment_resource.go index dd39995..6876810 100644 --- a/vantage/segment_resource.go +++ b/vantage/segment_resource.go @@ -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 @@ -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)...) diff --git a/vantage/team_resource.go b/vantage/team_resource.go index 40703d3..11e8aa8 100644 --- a/vantage/team_resource.go +++ b/vantage/team_resource.go @@ -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" @@ -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 } @@ -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)...) diff --git a/vantage/virtual_tag_config_resource.go b/vantage/virtual_tag_config_resource.go index 690ddee..cbf0a06 100644 --- a/vantage/virtual_tag_config_resource.go +++ b/vantage/virtual_tag_config_resource.go @@ -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" @@ -12,8 +13,11 @@ import ( tagsv2 "github.com/vantage-sh/vantage-go/vantagev2/vantage/virtual_tags" ) -var _ resource.Resource = (*VirtualTagConfigResource)(nil) -var _ resource.ResourceWithConfigure = (*VirtualTagConfigResource)(nil) +var ( + _ resource.Resource = (*VirtualTagConfigResource)(nil) + _ resource.ResourceWithConfigure = (*VirtualTagConfigResource)(nil) + _ resource.ResourceWithImportState = (*VirtualTagConfigResource)(nil) +) type VirtualTagConfigResource struct { client *Client @@ -195,6 +199,10 @@ func (r VirtualTagConfigResource) Read(ctx context.Context, req resource.ReadReq resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) } +func (r VirtualTagConfigResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("token"), req, resp) +} + func (r VirtualTagConfigResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { var data *virtualTagConfigModel resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)