diff --git a/.changelog/1208.txt b/.changelog/1208.txt new file mode 100644 index 000000000..e293de534 --- /dev/null +++ b/.changelog/1208.txt @@ -0,0 +1,4 @@ +```release-note:deprecation +The following attribute is deprecated for Waypoint the add-on resource and data source: + - `hcp_waypoint_add_on_created_by` +``` \ No newline at end of file diff --git a/docs/data-sources/waypoint_add_on.md b/docs/data-sources/waypoint_add_on.md index 157831b1b..3ff0258d1 100644 --- a/docs/data-sources/waypoint_add_on.md +++ b/docs/data-sources/waypoint_add_on.md @@ -23,7 +23,7 @@ The Waypoint Add-on data source retrieves information on a given Add-on. ### Read-Only - `application_id` (String) The ID of the Application that this Add-on is created for. -- `created_by` (String) The user who created the Add-on. +- `created_by` (String, Deprecated) The user who created the Add-on. - `definition_id` (String) The ID of the Add-on Definition that this Add-on is created from. - `description` (String) A longer description of the Add-on. - `install_count` (Number) The number of installed Add-ons for the same Application that share the same Add-on Definition. diff --git a/docs/resources/waypoint_add_on.md b/docs/resources/waypoint_add_on.md index cae31e9f0..8b9ffd472 100644 --- a/docs/resources/waypoint_add_on.md +++ b/docs/resources/waypoint_add_on.md @@ -28,7 +28,7 @@ Waypoint Add-on resource ### Read-Only - `add_on_definition_input_variables` (Attributes Set) Input variables set for the add-on definition. (see [below for nested schema](#nestedatt--add_on_definition_input_variables)) -- `created_by` (String) The user who created the Add-on. +- `created_by` (String, Deprecated) The user who created the Add-on. - `description` (String) A longer description of the Add-on. - `id` (String) The ID of the Add-on. - `install_count` (Number) The number of installed Add-ons for the same Application that share the same Add-on Definition. diff --git a/internal/clients/client.go b/internal/clients/client.go index d672ce526..67ea95bd5 100644 --- a/internal/clients/client.go +++ b/internal/clients/client.go @@ -50,8 +50,8 @@ import ( cloud_vault_secrets "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client" "github.com/hashicorp/hcp-sdk-go/clients/cloud-vault-secrets/stable/2023-11-28/client/secret_service" - cloud_waypoint "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client" - "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service" + cloud_waypoint "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/client" + "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/client/waypoint_service" cloud_log_service "github.com/hashicorp/hcp-sdk-go/clients/cloud-log-service/preview/2021-03-30/client" "github.com/hashicorp/hcp-sdk-go/clients/cloud-log-service/preview/2021-03-30/client/log_service" diff --git a/internal/clients/waypoint.go b/internal/clients/waypoint.go index 45522d498..1765dc49c 100644 --- a/internal/clients/waypoint.go +++ b/internal/clients/waypoint.go @@ -7,37 +7,18 @@ import ( "context" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service" - waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" + "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/client/waypoint_service" + waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/models" ) -// getNamespaceByLocation will retrieve a namespace by location information -// provided by HCP -func getNamespaceByLocation(_ context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation) (*waypoint_models.HashicorpCloudWaypointNamespace, error) { - namespaceParams := &waypoint_service.WaypointServiceGetNamespaceParams{ - LocationOrganizationID: loc.OrganizationID, - LocationProjectID: loc.ProjectID, - } - // get namespace - ns, err := client.Waypoint.WaypointServiceGetNamespace(namespaceParams, nil) - if err != nil { - return nil, err - } - return ns.GetPayload().Namespace, nil -} - // GetAction will retrieve an Action using the provided ID by default // or by name if the ID is not provided func GetAction(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, actionID string, actionName string) (*waypoint_models.HashicorpCloudWaypointActionConfig, error) { - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - return nil, err - } - params := &waypoint_service.WaypointServiceGetActionConfigParams{ - ActionID: &actionID, - ActionName: &actionName, - NamespaceID: ns.ID, + ActionID: &actionID, + ActionName: &actionName, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, } getResp, err := client.Waypoint.WaypointServiceGetActionConfig(params, nil) @@ -49,14 +30,10 @@ func GetAction(ctx context.Context, client *Client, loc *sharedmodels.HashicorpC // GetApplicationTemplateByName will retrieve a template by name func GetApplicationTemplateByName(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, appName string) (*waypoint_models.HashicorpCloudWaypointApplicationTemplate, error) { - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - return nil, err - } - params := &waypoint_service.WaypointServiceGetApplicationTemplate2Params{ - ApplicationTemplateName: appName, - NamespaceID: ns.ID, + ApplicationTemplateName: appName, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, } getResp, err := client.Waypoint.WaypointServiceGetApplicationTemplate2(params, nil) @@ -68,14 +45,10 @@ func GetApplicationTemplateByName(ctx context.Context, client *Client, loc *shar // GetApplicationTemplateByID will retrieve a template by ID func GetApplicationTemplateByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, appID string) (*waypoint_models.HashicorpCloudWaypointApplicationTemplate, error) { - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - return nil, err - } - params := &waypoint_service.WaypointServiceGetApplicationTemplateParams{ - ApplicationTemplateID: appID, - NamespaceID: ns.ID, + ApplicationTemplateID: appID, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, } getResp, err := client.Waypoint.WaypointServiceGetApplicationTemplate(params, nil) @@ -87,14 +60,10 @@ func GetApplicationTemplateByID(ctx context.Context, client *Client, loc *shared // GetAddOnDefinitionByName will retrieve an add-on definition by name func GetAddOnDefinitionByName(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, defName string) (*waypoint_models.HashicorpCloudWaypointAddOnDefinition, error) { - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - return nil, err - } - params := &waypoint_service.WaypointServiceGetAddOnDefinition2Params{ - AddOnDefinitionName: defName, - NamespaceID: ns.ID, + AddOnDefinitionName: defName, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, } getResp, err := client.Waypoint.WaypointServiceGetAddOnDefinition2(params, nil) @@ -106,14 +75,10 @@ func GetAddOnDefinitionByName(ctx context.Context, client *Client, loc *sharedmo // GetAddOnDefinitionByID will retrieve an add-on definition by ID func GetAddOnDefinitionByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, defID string) (*waypoint_models.HashicorpCloudWaypointAddOnDefinition, error) { - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - return nil, err - } - params := &waypoint_service.WaypointServiceGetAddOnDefinitionParams{ - AddOnDefinitionID: defID, - NamespaceID: ns.ID, + AddOnDefinitionID: defID, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, } getResp, err := client.Waypoint.WaypointServiceGetAddOnDefinition(params, nil) @@ -125,14 +90,10 @@ func GetAddOnDefinitionByID(ctx context.Context, client *Client, loc *sharedmode // GetApplicationByName will retrieve an application by name func GetApplicationByName(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, appName string) (*waypoint_models.HashicorpCloudWaypointApplication, error) { - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - return nil, err - } - params := &waypoint_service.WaypointServiceGetApplication2Params{ - ApplicationName: appName, - NamespaceID: ns.ID, + ApplicationName: appName, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, } getResp, err := client.Waypoint.WaypointServiceGetApplication2(params, nil) @@ -144,14 +105,10 @@ func GetApplicationByName(ctx context.Context, client *Client, loc *sharedmodels // GetApplicationByID will retrieve an application by ID func GetApplicationByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, appID string) (*waypoint_models.HashicorpCloudWaypointApplication, error) { - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - return nil, err - } - params := &waypoint_service.WaypointServiceGetApplicationParams{ - ApplicationID: appID, - NamespaceID: ns.ID, + ApplicationID: appID, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, } getResp, err := client.Waypoint.WaypointServiceGetApplication(params, nil) @@ -163,14 +120,10 @@ func GetApplicationByID(ctx context.Context, client *Client, loc *sharedmodels.H // GetAddOnByName will retrieve an add-on by name func GetAddOnByName(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, defName string) (*waypoint_models.HashicorpCloudWaypointAddOn, error) { - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - return nil, err - } - params := &waypoint_service.WaypointServiceGetAddOn2Params{ - AddOnName: defName, - NamespaceID: ns.ID, + AddOnName: defName, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, } getResp, err := client.Waypoint.WaypointServiceGetAddOn2(params, nil) @@ -182,14 +135,10 @@ func GetAddOnByName(ctx context.Context, client *Client, loc *sharedmodels.Hashi // GetAddOnByID will retrieve an add-on by ID func GetAddOnByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, defID string) (*waypoint_models.HashicorpCloudWaypointAddOn, error) { - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - return nil, err - } - params := &waypoint_service.WaypointServiceGetAddOnParams{ - AddOnID: defID, - NamespaceID: ns.ID, + AddOnID: defID, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, } getResp, err := client.Waypoint.WaypointServiceGetAddOn(params, nil) @@ -200,14 +149,10 @@ func GetAddOnByID(ctx context.Context, client *Client, loc *sharedmodels.Hashico } func GetInputVariables(ctx context.Context, client *Client, workspaceName string, loc *sharedmodels.HashicorpCloudLocationLocation) ([]*waypoint_models.HashicorpCloudWaypointInputVariable, error) { - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - return nil, err - } - params := &waypoint_service.WaypointServiceGetTFRunStatusParams{ - WorkspaceName: workspaceName, - NamespaceID: ns.ID, + WorkspaceName: workspaceName, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, } getResp, err := client.Waypoint.WaypointServiceGetTFRunStatus(params, nil) diff --git a/internal/provider/waypoint/data_source_waypoint_action.go b/internal/provider/waypoint/data_source_waypoint_action.go index 512ebf6b3..d174d44e2 100644 --- a/internal/provider/waypoint/data_source_waypoint_action.go +++ b/internal/provider/waypoint/data_source_waypoint_action.go @@ -8,7 +8,7 @@ import ( "fmt" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" + waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/models" "github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" diff --git a/internal/provider/waypoint/data_source_waypoint_add_on.go b/internal/provider/waypoint/data_source_waypoint_add_on.go index 696e1ad6b..ccb4d6041 100644 --- a/internal/provider/waypoint/data_source_waypoint_add_on.go +++ b/internal/provider/waypoint/data_source_waypoint_add_on.go @@ -9,7 +9,7 @@ import ( "strconv" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" + waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/models" "github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" @@ -105,8 +105,9 @@ func (d *DataSourceAddOn) Schema(ctx context.Context, req datasource.SchemaReque ElementType: types.StringType, }, "created_by": schema.StringAttribute{ - Description: "The user who created the Add-on.", - Computed: true, + Description: "The user who created the Add-on.", + Computed: true, + DeprecationMessage: "This attribute is deprecated and will be removed in a future version of the provider.", }, "install_count": schema.Int64Attribute{ Description: "The number of installed Add-ons for the same Application that share the same " + @@ -256,7 +257,7 @@ func (d *DataSourceAddOn) Read(ctx context.Context, req datasource.ReadRequest, state.ReadmeMarkdown = types.StringNull() } - state.CreatedBy = types.StringValue(addOn.CreatedBy) + state.CreatedBy = types.StringNull() // If we can process status as an int64, add it to the plan statusNum, err := strconv.ParseInt(addOn.Count, 10, 64) diff --git a/internal/provider/waypoint/data_source_waypoint_add_on_definition.go b/internal/provider/waypoint/data_source_waypoint_add_on_definition.go index dd89872c3..629a69895 100644 --- a/internal/provider/waypoint/data_source_waypoint_add_on_definition.go +++ b/internal/provider/waypoint/data_source_waypoint_add_on_definition.go @@ -8,7 +8,7 @@ import ( "fmt" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - waypointModels "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" + waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/models" "github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" @@ -198,7 +198,7 @@ func (d *DataSourceAddOnDefinition) Read(ctx context.Context, req datasource.Rea ProjectID: projectID, } - var definition *waypointModels.HashicorpCloudWaypointAddOnDefinition + var definition *waypoint_models.HashicorpCloudWaypointAddOnDefinition var err error if state.ID.IsNull() { diff --git a/internal/provider/waypoint/data_source_waypoint_application.go b/internal/provider/waypoint/data_source_waypoint_application.go index d8158fd38..b4d9b52c4 100644 --- a/internal/provider/waypoint/data_source_waypoint_application.go +++ b/internal/provider/waypoint/data_source_waypoint_application.go @@ -8,7 +8,7 @@ import ( "fmt" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" + waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/models" "github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" diff --git a/internal/provider/waypoint/data_source_waypoint_template.go b/internal/provider/waypoint/data_source_waypoint_template.go index 2c7c17554..78a504ff6 100644 --- a/internal/provider/waypoint/data_source_waypoint_template.go +++ b/internal/provider/waypoint/data_source_waypoint_template.go @@ -8,7 +8,7 @@ import ( "fmt" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" + waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/models" "github.com/hashicorp/terraform-plugin-framework-validators/datasourcevalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" diff --git a/internal/provider/waypoint/resource_waypoint_action.go b/internal/provider/waypoint/resource_waypoint_action.go index ddf6d386a..ee185fe66 100644 --- a/internal/provider/waypoint/resource_waypoint_action.go +++ b/internal/provider/waypoint/resource_waypoint_action.go @@ -8,8 +8,8 @@ import ( "fmt" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service" - waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" + "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/client/waypoint_service" + waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/models" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" @@ -158,22 +158,8 @@ func (r *ActionResource) Create(ctx context.Context, req resource.CreateRequest, } orgID := r.client.Config.OrganizationID - loc := &sharedmodels.HashicorpCloudLocationLocation{ - OrganizationID: orgID, - ProjectID: projectID, - } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "error getting namespace by location", - err.Error(), - ) - return - } - - modelBody := &waypoint_models.HashicorpCloudWaypointWaypointServiceCreateActionConfigBody{ + modelBody := &waypoint_models.HashicorpCloudWaypointV20241122WaypointServiceCreateActionConfigBody{ ActionConfig: &waypoint_models.HashicorpCloudWaypointActionConfig{ Request: &waypoint_models.HashicorpCloudWaypointActionConfigRequest{}, }, @@ -218,8 +204,9 @@ func (r *ActionResource) Create(ctx context.Context, req resource.CreateRequest, } params := &waypoint_service.WaypointServiceCreateActionConfigParams{ - NamespaceID: ns.ID, - Body: modelBody, + NamespaceLocationOrganizationID: orgID, + NamespaceLocationProjectID: projectID, + Body: modelBody, } aCfg, err := r.client.Waypoint.WaypointServiceCreateActionConfig(params, nil) @@ -355,22 +342,8 @@ func (r *ActionResource) Update(ctx context.Context, req resource.UpdateRequest, } orgID := r.client.Config.OrganizationID - loc := &sharedmodels.HashicorpCloudLocationLocation{ - OrganizationID: orgID, - ProjectID: projectID, - } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "error getting namespace by location", - err.Error(), - ) - return - } - - modelBody := &waypoint_models.HashicorpCloudWaypointWaypointServiceUpdateActionConfigBody{ + modelBody := &waypoint_models.HashicorpCloudWaypointV20241122WaypointServiceUpdateActionConfigBody{ ActionConfig: &waypoint_models.HashicorpCloudWaypointActionConfig{ Request: &waypoint_models.HashicorpCloudWaypointActionConfigRequest{}, }, @@ -413,8 +386,9 @@ func (r *ActionResource) Update(ctx context.Context, req resource.UpdateRequest, } params := &waypoint_service.WaypointServiceUpdateActionConfigParams{ - NamespaceID: ns.ID, - Body: modelBody, + NamespaceLocationOrganizationID: orgID, + NamespaceLocationProjectID: projectID, + Body: modelBody, } actionCfg, err := r.client.Waypoint.WaypointServiceUpdateActionConfig(params, nil) @@ -485,23 +459,14 @@ func (r *ActionResource) Delete(ctx context.Context, req resource.DeleteRequest, ProjectID: projectID, } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "Error deleting Action", - err.Error(), - ) - return - } - params := &waypoint_service.WaypointServiceDeleteActionConfigParams{ - NamespaceID: ns.ID, - ActionID: data.ID.ValueStringPointer(), - ActionName: data.Name.ValueStringPointer(), + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + ActionID: data.ID.ValueStringPointer(), + ActionName: data.Name.ValueStringPointer(), } - _, err = r.client.Waypoint.WaypointServiceDeleteActionConfig(params, nil) + _, err := r.client.Waypoint.WaypointServiceDeleteActionConfig(params, nil) if err != nil { if clients.IsResponseCodeNotFound(err) { tflog.Info(ctx, "Action not found for organization during delete call, ignoring") diff --git a/internal/provider/waypoint/resource_waypoint_add_on.go b/internal/provider/waypoint/resource_waypoint_add_on.go index 3cbc4a5cb..0acd0fadc 100644 --- a/internal/provider/waypoint/resource_waypoint_add_on.go +++ b/internal/provider/waypoint/resource_waypoint_add_on.go @@ -9,8 +9,8 @@ import ( "strconv" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service" - waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" + "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/client/waypoint_service" + waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/models" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -133,8 +133,9 @@ func (r *AddOnResource) Schema(ctx context.Context, req resource.SchemaRequest, Computed: true, }, "created_by": schema.StringAttribute{ - Description: "The user who created the Add-on.", - Computed: true, + Description: "The user who created the Add-on.", + Computed: true, + DeprecationMessage: "This attribute is deprecated and will be removed in a future version of the provider.", }, "install_count": schema.Int64Attribute{ Description: "The number of installed Add-ons for the same Application that share the same " + @@ -268,14 +269,6 @@ func (r *AddOnResource) Create(ctx context.Context, req resource.CreateRequest, } client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "error getting namespace by location", - err.Error(), - ) - return - } // varTypes is used to store the variable type for each input variable // to be used later when fetching the input variables from the API @@ -343,7 +336,7 @@ func (r *AddOnResource) Create(ctx context.Context, req resource.CreateRequest, return } - modelBody := &waypoint_models.HashicorpCloudWaypointWaypointServiceCreateAddOnBody{ + modelBody := &waypoint_models.HashicorpCloudWaypointV20241122WaypointServiceCreateAddOnBody{ Name: plan.Name.ValueString(), Application: applicationRefModel, Definition: definitionRefModel, @@ -351,8 +344,9 @@ func (r *AddOnResource) Create(ctx context.Context, req resource.CreateRequest, } params := &waypoint_service.WaypointServiceCreateAddOnParams{ - NamespaceID: ns.ID, - Body: modelBody, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + Body: modelBody, } responseAddOn, err := r.client.Waypoint.WaypointServiceCreateAddOn(params, nil) if err != nil { @@ -408,7 +402,7 @@ func (r *AddOnResource) Create(ctx context.Context, req resource.CreateRequest, } } - plan.CreatedBy = types.StringValue(addOn.CreatedBy) + plan.CreatedBy = types.StringNull() // If we can process status as an int64, add it to the plan statusNum, err := strconv.ParseInt(addOn.Count, 10, 64) @@ -546,7 +540,7 @@ func (r *AddOnResource) Read(ctx context.Context, req resource.ReadRequest, resp } state.Labels = labels - state.CreatedBy = types.StringValue(addOn.CreatedBy) + state.CreatedBy = types.StringNull() // If we can process status as an int64, add it to the plan statusNum, err := strconv.ParseInt(addOn.Count, 10, 64) @@ -638,24 +632,15 @@ func (r *AddOnResource) Update(ctx context.Context, req resource.UpdateRequest, ProjectID: projectID, } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "error getting namespace by location", - err.Error(), - ) - return - } - - modelBody := &waypoint_models.HashicorpCloudWaypointWaypointServiceUpdateAddOnBody{ + modelBody := &waypoint_models.HashicorpCloudWaypointV20241122WaypointServiceUpdateAddOnBody{ Name: plan.Name.ValueString(), } params := &waypoint_service.WaypointServiceUpdateAddOnParams{ - NamespaceID: ns.ID, - Body: modelBody, - ExistingAddOnID: plan.ID.ValueString(), + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + Body: modelBody, + ExistingAddOnID: plan.ID.ValueString(), } def, err := r.client.Waypoint.WaypointServiceUpdateAddOn(params, nil) if err != nil { @@ -711,7 +696,7 @@ func (r *AddOnResource) Update(ctx context.Context, req resource.UpdateRequest, } } - plan.CreatedBy = types.StringValue(addOn.CreatedBy) + plan.CreatedBy = types.StringNull() // If we can process status as an int64, add it to the plan statusNum, err := strconv.ParseInt(addOn.Count, 10, 64) @@ -766,22 +751,13 @@ func (r *AddOnResource) Delete(ctx context.Context, req resource.DeleteRequest, ProjectID: projectID, } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "Error Deleting TFC Config", - err.Error(), - ) - return - } - params := &waypoint_service.WaypointServiceDestroyAddOnParams{ - NamespaceID: ns.ID, - AddOnID: state.ID.ValueString(), + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + AddOnID: state.ID.ValueString(), } - _, err = r.client.Waypoint.WaypointServiceDestroyAddOn(params, nil) + _, err := r.client.Waypoint.WaypointServiceDestroyAddOn(params, nil) if err != nil { if clients.IsResponseCodeNotFound(err) { tflog.Info(ctx, "Add-on not found for organization during delete call, ignoring") diff --git a/internal/provider/waypoint/resource_waypoint_add_on_definition.go b/internal/provider/waypoint/resource_waypoint_add_on_definition.go index baedfc520..4fb37fa9e 100644 --- a/internal/provider/waypoint/resource_waypoint_add_on_definition.go +++ b/internal/provider/waypoint/resource_waypoint_add_on_definition.go @@ -9,8 +9,8 @@ import ( "fmt" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service" - waypointModels "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" + "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/client/waypoint_service" + waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/models" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -228,20 +228,6 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat } orgID := r.client.Config.OrganizationID - loc := &sharedmodels.HashicorpCloudLocationLocation{ - OrganizationID: orgID, - ProjectID: projectID, - } - - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "error getting namespace by location", - err.Error(), - ) - return - } var stringLabels []string if !plan.Labels.IsNull() && !plan.Labels.IsUnknown() { @@ -255,7 +241,7 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat } } - var varOpts []*waypointModels.HashicorpCloudWaypointTFModuleVariable + var varOpts []*waypoint_models.HashicorpCloudWaypointTFModuleVariable for _, v := range plan.TerraformVariableOptions { strOpts := []string{} diags := v.Options.ElementsAs(ctx, &strOpts, false) @@ -264,7 +250,7 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat return } - varOpts = append(varOpts, &waypointModels.HashicorpCloudWaypointTFModuleVariable{ + varOpts = append(varOpts, &waypoint_models.HashicorpCloudWaypointTFModuleVariable{ Name: v.Name.ValueString(), VariableType: v.VariableType.ValueString(), Options: strOpts, @@ -272,8 +258,8 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat }) } - modelBody := &waypointModels.HashicorpCloudWaypointWaypointServiceCreateAddOnDefinitionBody{ - AddOnDefinition: &waypointModels.HashicorpCloudWaypointAddOnDefinition{ + modelBody := &waypoint_models.HashicorpCloudWaypointV20241122WaypointServiceCreateAddOnDefinitionBody{ + AddOnDefinition: &waypoint_models.HashicorpCloudWaypointAddOnDefinition{ Name: plan.Name.ValueString(), Summary: plan.Summary.ValueString(), Description: plan.Description.ValueString(), @@ -302,7 +288,7 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat // Set a default if none provided workspaceDetails.TerraformProjectID = plan.TerraformProjectID } - modelBody.AddOnDefinition.TerraformCloudWorkspaceDetails = &waypointModels.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{ + modelBody.AddOnDefinition.TerraformCloudWorkspaceDetails = &waypoint_models.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{ Name: workspaceDetails.Name.ValueString(), ProjectID: workspaceDetails.TerraformProjectID.ValueString(), } @@ -321,8 +307,9 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat } params := &waypoint_service.WaypointServiceCreateAddOnDefinitionParams{ - NamespaceID: ns.ID, - Body: modelBody, + NamespaceLocationOrganizationID: orgID, + NamespaceLocationProjectID: projectID, + Body: modelBody, } def, err := r.client.Waypoint.WaypointServiceCreateAddOnDefinition(params, nil) if err != nil { @@ -330,7 +317,7 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat return } - var addOnDefinition *waypointModels.HashicorpCloudWaypointAddOnDefinition + var addOnDefinition *waypoint_models.HashicorpCloudWaypointAddOnDefinition if def.Payload != nil { addOnDefinition = def.Payload.AddOnDefinition } @@ -505,20 +492,6 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat } orgID := r.client.Config.OrganizationID - loc := &sharedmodels.HashicorpCloudLocationLocation{ - OrganizationID: orgID, - ProjectID: projectID, - } - - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "error getting namespace by location", - err.Error(), - ) - return - } stringLabels := []string{} if !plan.Labels.IsNull() && !plan.Labels.IsUnknown() { @@ -532,7 +505,7 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat } } - varOpts := []*waypointModels.HashicorpCloudWaypointTFModuleVariable{} + varOpts := []*waypoint_models.HashicorpCloudWaypointTFModuleVariable{} for _, v := range plan.TerraformVariableOptions { strOpts := []string{} diags := v.Options.ElementsAs(ctx, &strOpts, false) @@ -540,7 +513,7 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat return } - varOpts = append(varOpts, &waypointModels.HashicorpCloudWaypointTFModuleVariable{ + varOpts = append(varOpts, &waypoint_models.HashicorpCloudWaypointTFModuleVariable{ Name: v.Name.ValueString(), VariableType: v.VariableType.ValueString(), Options: strOpts, @@ -549,8 +522,8 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat } // TODO: add support for Tags - modelBody := &waypointModels.HashicorpCloudWaypointWaypointServiceUpdateAddOnDefinitionBody{ - AddOnDefinition: &waypointModels.HashicorpCloudWaypointAddOnDefinition{ + modelBody := &waypoint_models.HashicorpCloudWaypointV20241122WaypointServiceUpdateAddOnDefinitionBody{ + AddOnDefinition: &waypoint_models.HashicorpCloudWaypointAddOnDefinition{ Name: plan.Name.ValueString(), Summary: plan.Summary.ValueString(), Description: plan.Description.ValueString(), @@ -579,7 +552,7 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat // Grab the top level project ID if this was not provided workspaceDetails.TerraformProjectID = plan.TerraformProjectID } - modelBody.AddOnDefinition.TerraformCloudWorkspaceDetails = &waypointModels.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{ + modelBody.AddOnDefinition.TerraformCloudWorkspaceDetails = &waypoint_models.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{ Name: workspaceDetails.Name.ValueString(), ProjectID: workspaceDetails.TerraformProjectID.ValueString(), } @@ -598,9 +571,10 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat } params := &waypoint_service.WaypointServiceUpdateAddOnDefinitionParams{ - NamespaceID: ns.ID, - Body: modelBody, - ExistingAddOnDefinitionID: plan.ID.ValueString(), + NamespaceLocationOrganizationID: orgID, + NamespaceLocationProjectID: projectID, + Body: modelBody, + ExistingAddOnDefinitionID: plan.ID.ValueString(), } def, err := r.client.Waypoint.WaypointServiceUpdateAddOnDefinition(params, nil) if err != nil { @@ -608,7 +582,7 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat return } - var addOnDefinition *waypointModels.HashicorpCloudWaypointAddOnDefinition + var addOnDefinition *waypoint_models.HashicorpCloudWaypointAddOnDefinition if def.Payload != nil { addOnDefinition = def.Payload.AddOnDefinition } @@ -696,22 +670,13 @@ func (r *AddOnDefinitionResource) Delete(ctx context.Context, req resource.Delet ProjectID: projectID, } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "Error Deleting TFC Config", - err.Error(), - ) - return - } - params := &waypoint_service.WaypointServiceDeleteAddOnDefinitionParams{ - NamespaceID: ns.ID, - AddOnDefinitionID: state.ID.ValueString(), + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + AddOnDefinitionID: state.ID.ValueString(), } - _, err = r.client.Waypoint.WaypointServiceDeleteAddOnDefinition(params, nil) + _, err := r.client.Waypoint.WaypointServiceDeleteAddOnDefinition(params, nil) if err != nil { if clients.IsResponseCodeNotFound(err) { tflog.Info(ctx, "Add-on Definition not found for organization during delete call, ignoring") diff --git a/internal/provider/waypoint/resource_waypoint_application.go b/internal/provider/waypoint/resource_waypoint_application.go index ab15f9728..178714515 100644 --- a/internal/provider/waypoint/resource_waypoint_application.go +++ b/internal/provider/waypoint/resource_waypoint_application.go @@ -9,8 +9,8 @@ import ( "fmt" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service" - waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" + "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/client/waypoint_service" + waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/models" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -317,7 +317,7 @@ func (r *ApplicationResource) Create(ctx context.Context, req resource.CreateReq }) } - modelBody := &waypoint_models.HashicorpCloudWaypointWaypointServiceCreateApplicationFromTemplateBody{ + modelBody := &waypoint_models.HashicorpCloudWaypointV20241122WaypointServiceCreateApplicationFromTemplateBody{ Name: plan.Name.ValueString(), ActionCfgRefs: actionRefs, ApplicationTemplate: &waypoint_models.HashicorpCloudWaypointRefApplicationTemplate{ @@ -327,8 +327,9 @@ func (r *ApplicationResource) Create(ctx context.Context, req resource.CreateReq } params := &waypoint_service.WaypointServiceCreateApplicationFromTemplateParams{ - NamespaceID: ns.ID, - Body: modelBody, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + Body: modelBody, } app, err := r.client.Waypoint.WaypointServiceCreateApplicationFromTemplate(params, nil) if err != nil { @@ -639,7 +640,7 @@ func (r *ApplicationResource) Update(ctx context.Context, req resource.UpdateReq }) } - modelBody := &waypoint_models.HashicorpCloudWaypointWaypointServiceUpdateApplicationBody{ + modelBody := &waypoint_models.HashicorpCloudWaypointV20241122WaypointServiceUpdateApplicationBody{ // this is the updated name Name: plan.Name.ValueString(), ReadmeMarkdown: readmeBytes, @@ -647,9 +648,10 @@ func (r *ApplicationResource) Update(ctx context.Context, req resource.UpdateReq } params := &waypoint_service.WaypointServiceUpdateApplicationParams{ - ApplicationID: plan.ID.ValueString(), - NamespaceID: ns.ID, - Body: modelBody, + ApplicationID: plan.ID.ValueString(), + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + Body: modelBody, } app, err := r.client.Waypoint.WaypointServiceUpdateApplication(params, nil) if err != nil { @@ -735,22 +737,13 @@ func (r *ApplicationResource) Delete(ctx context.Context, req resource.DeleteReq ProjectID: projectID, } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "error deleting application", - err.Error(), - ) - return - } - params := &waypoint_service.WaypointServiceDestroyApplicationParams{ - NamespaceID: ns.ID, - ApplicationID: data.ID.ValueString(), + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + ApplicationID: data.ID.ValueString(), } - _, err = r.client.Waypoint.WaypointServiceDestroyApplication(params, nil) + _, err := r.client.Waypoint.WaypointServiceDestroyApplication(params, nil) if err != nil { if clients.IsResponseCodeNotFound(err) { diff --git a/internal/provider/waypoint/resource_waypoint_template.go b/internal/provider/waypoint/resource_waypoint_template.go index 7f0aa103e..f47f10837 100644 --- a/internal/provider/waypoint/resource_waypoint_template.go +++ b/internal/provider/waypoint/resource_waypoint_template.go @@ -9,8 +9,8 @@ import ( "fmt" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service" - waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" + "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/client/waypoint_service" + waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/models" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -277,16 +277,6 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques ProjectID: projectID, } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "error getting namespace by location", - err.Error(), - ) - return - } - strLabels := []string{} diags := plan.Labels.ElementsAs(ctx, &strLabels, false) if diags.HasError() { @@ -330,7 +320,7 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques }) } - modelBody := &waypoint_models.HashicorpCloudWaypointWaypointServiceCreateApplicationTemplateBody{ + modelBody := &waypoint_models.HashicorpCloudWaypointV20241122WaypointServiceCreateApplicationTemplateBody{ ApplicationTemplate: &waypoint_models.HashicorpCloudWaypointApplicationTemplate{ ActionCfgRefs: actions, Name: plan.Name.ValueString(), @@ -360,8 +350,9 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques } params := &waypoint_service.WaypointServiceCreateApplicationTemplateParams{ - NamespaceID: ns.ID, - Body: modelBody, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + Body: modelBody, } createTplResp, err := r.client.Waypoint.WaypointServiceCreateApplicationTemplate(params, nil) if err != nil { @@ -607,16 +598,6 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques ProjectID: projectID, } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "error getting namespace by location", - err.Error(), - ) - return - } - strLabels := []string{} diags := plan.Labels.ElementsAs(ctx, &strLabels, false) if diags.HasError() { @@ -658,7 +639,7 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques ProjectID: tfProjID, } - modelBody := &waypoint_models.HashicorpCloudWaypointWaypointServiceUpdateApplicationTemplateBody{ + modelBody := &waypoint_models.HashicorpCloudWaypointV20241122WaypointServiceUpdateApplicationTemplateBody{ ApplicationTemplate: &waypoint_models.HashicorpCloudWaypointApplicationTemplate{ ActionCfgRefs: actions, Name: plan.Name.ValueString(), @@ -688,9 +669,10 @@ func (r *TemplateResource) Update(ctx context.Context, req resource.UpdateReques } params := &waypoint_service.WaypointServiceUpdateApplicationTemplateParams{ - NamespaceID: ns.ID, - Body: modelBody, - ExistingApplicationTemplateID: plan.ID.ValueString(), + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + Body: modelBody, + ExistingApplicationTemplateID: plan.ID.ValueString(), } app, err := r.client.Waypoint.WaypointServiceUpdateApplicationTemplate(params, nil) if err != nil { @@ -795,22 +777,13 @@ func (r *TemplateResource) Delete(ctx context.Context, req resource.DeleteReques ProjectID: projectID, } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "Error Deleting TFC Config", - err.Error(), - ) - return - } - params := &waypoint_service.WaypointServiceDeleteApplicationTemplateParams{ - NamespaceID: ns.ID, - ApplicationTemplateID: data.ID.ValueString(), + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + ApplicationTemplateID: data.ID.ValueString(), } - _, err = r.client.Waypoint.WaypointServiceDeleteApplicationTemplate(params, nil) + _, err := r.client.Waypoint.WaypointServiceDeleteApplicationTemplate(params, nil) if err != nil { if clients.IsResponseCodeNotFound(err) { tflog.Info(ctx, "Template not found for organization during delete call, ignoring") diff --git a/internal/provider/waypoint/resource_waypoint_tfc_config.go b/internal/provider/waypoint/resource_waypoint_tfc_config.go index bb575b76d..bdb771569 100644 --- a/internal/provider/waypoint/resource_waypoint_tfc_config.go +++ b/internal/provider/waypoint/resource_waypoint_tfc_config.go @@ -8,8 +8,8 @@ import ( "fmt" sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service" - waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models" + "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/client/waypoint_service" + waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/models" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" @@ -133,17 +133,7 @@ func (r *TfcConfigResource) Create(ctx context.Context, req resource.CreateReque ProjectID: projectID, } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "Error creating TFC Config", - err.Error(), - ) - return - } - - modelBody := &waypoint_models.HashicorpCloudWaypointWaypointServiceCreateTFCConfigBody{ + modelBody := &waypoint_models.HashicorpCloudWaypointV20241122WaypointServiceCreateTFCConfigBody{ TfcConfig: &waypoint_models.HashicorpCloudWaypointTFCConfig{ OrganizationName: plan.TfcOrgName.ValueString(), Token: plan.Token.ValueString(), @@ -151,8 +141,9 @@ func (r *TfcConfigResource) Create(ctx context.Context, req resource.CreateReque } params := &waypoint_service.WaypointServiceCreateTFCConfigParams{ - NamespaceID: ns.ID, - Body: modelBody, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + Body: modelBody, } config, err := r.client.Waypoint.WaypointServiceCreateTFCConfig(params, nil) @@ -197,18 +188,9 @@ func (r *TfcConfigResource) Read(ctx context.Context, req resource.ReadRequest, ProjectID: projectID, } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "error getting namespace by location", - err.Error(), - ) - return - } - params := &waypoint_service.WaypointServiceGetTFCConfigParams{ - NamespaceID: ns.ID, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, } config, err := r.client.Waypoint.WaypointServiceGetTFCConfig(params, nil) if err != nil { @@ -257,17 +239,7 @@ func (r *TfcConfigResource) Update(ctx context.Context, req resource.UpdateReque ProjectID: projectID, } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "Error updating TFC Config", - err.Error(), - ) - return - } - - modelBody := &waypoint_models.HashicorpCloudWaypointWaypointServiceUpdateTFCConfigBody{ + modelBody := &waypoint_models.HashicorpCloudWaypointV20241122WaypointServiceUpdateTFCConfigBody{ TfcConfig: &waypoint_models.HashicorpCloudWaypointTFCConfig{ OrganizationName: plan.TfcOrgName.ValueString(), Token: plan.Token.ValueString(), @@ -275,8 +247,9 @@ func (r *TfcConfigResource) Update(ctx context.Context, req resource.UpdateReque } params := &waypoint_service.WaypointServiceUpdateTFCConfigParams{ - NamespaceID: ns.ID, - Body: modelBody, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, + Body: modelBody, } config, err := r.client.Waypoint.WaypointServiceUpdateTFCConfig(params, nil) @@ -320,21 +293,12 @@ func (r *TfcConfigResource) Delete(ctx context.Context, req resource.DeleteReque ProjectID: projectID, } - client := r.client - ns, err := getNamespaceByLocation(ctx, client, loc) - if err != nil { - resp.Diagnostics.AddError( - "Error Deleting TFC Config", - err.Error(), - ) - return - } - params := &waypoint_service.WaypointServiceDeleteTFCConfigParams{ - NamespaceID: ns.ID, + NamespaceLocationOrganizationID: loc.OrganizationID, + NamespaceLocationProjectID: loc.ProjectID, } - _, err = r.client.Waypoint.WaypointServiceDeleteTFCConfig(params, nil) + _, err := r.client.Waypoint.WaypointServiceDeleteTFCConfig(params, nil) if err != nil { if clients.IsResponseCodeNotFound(err) { tflog.Info(ctx, "TFC Config not found for organization during delete call, ignoring") diff --git a/internal/provider/waypoint/resource_waypoint_tfc_config_test.go b/internal/provider/waypoint/resource_waypoint_tfc_config_test.go index 1e94091db..d28c6b48b 100644 --- a/internal/provider/waypoint/resource_waypoint_tfc_config_test.go +++ b/internal/provider/waypoint/resource_waypoint_tfc_config_test.go @@ -10,8 +10,7 @@ import ( "testing" "time" - sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models" - "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service" + "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2024-11-22/client/waypoint_service" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -66,26 +65,10 @@ func testAccCheckWaypointTfcConfigExists(t *testing.T, resourceName string, tfcC orgID := client.Config.OrganizationID tfcConfig.ProjectID = types.StringValue(projectID) - loc := &sharedmodels.HashicorpCloudLocationLocation{ - OrganizationID: orgID, - ProjectID: projectID, - } - // Fetch the project - - namespaceParams := &waypoint_service.WaypointServiceGetNamespaceParams{ - LocationOrganizationID: loc.OrganizationID, - LocationProjectID: loc.ProjectID, - } - // get namespace - ns, err := client.Waypoint.WaypointServiceGetNamespace(namespaceParams, nil) - if err != nil { - return err - } - - namespace := ns.GetPayload().Namespace params := &waypoint_service.WaypointServiceGetTFCConfigParams{ - NamespaceID: namespace.ID, + NamespaceLocationOrganizationID: projectID, + NamespaceLocationProjectID: orgID, } config, err := client.Waypoint.WaypointServiceGetTFCConfig(params, nil) if err != nil { @@ -104,19 +87,9 @@ func testAccCheckWaypointTfcConfigDestroy(t *testing.T, tfcConfig *waypoint.TfcC projectID := tfcConfig.ProjectID.ValueString() orgID := client.Config.OrganizationID - namespaceParams := &waypoint_service.WaypointServiceGetNamespaceParams{ - LocationOrganizationID: orgID, - LocationProjectID: projectID, - } - // get namespace - ns, err := client.Waypoint.WaypointServiceGetNamespace(namespaceParams, nil) - if err != nil { - return err - } - - namespace := ns.GetPayload().Namespace params := &waypoint_service.WaypointServiceGetTFCConfigParams{ - NamespaceID: namespace.ID, + NamespaceLocationOrganizationID: orgID, + NamespaceLocationProjectID: projectID, } // Fetch the config