Skip to content

Commit

Permalink
New Resource: Waypoint Add-on (#807)
Browse files Browse the repository at this point in the history
Added new Waypoint Add-on resource and data source, with accompanying acceptance tests
---------
Co-authored-by: catsby <[email protected]>
  • Loading branch information
HenryEstberg authored Apr 17, 2024
1 parent 4b46b4d commit d928631
Show file tree
Hide file tree
Showing 12 changed files with 1,330 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .changelog/807.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:feature
New resource: Add `hcp_waypoint_add_on` resource for managing Waypoint Add-ons.
New data-source: Add `data.hcp_waypoint_add_on` data-source for Waypoint Add-ons.
```
44 changes: 44 additions & 0 deletions docs/data-sources/waypoint_add_on.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "hcp_waypoint_add_on Data Source - terraform-provider-hcp"
subcategory: ""
description: |-
The Waypoint Add-on data source retrieves information on a given Add-on.
---

# hcp_waypoint_add_on (Data Source)

The Waypoint Add-on data source retrieves information on a given Add-on.



<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `id` (String) The ID of the Add-on.
- `name` (String) The name of the 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.
- `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.
- `labels` (List of String) List of labels attached to this Add-on.
- `organization_id` (String) The ID of the HCP organization where the Waypoint AddOn is located.
- `project_id` (String) The ID of the HCP project where the Waypoint AddOn is located.
- `readme_markdown` (String) Instructions for using the Add-on (markdown format supported).
- `status` (Number) The status of the Terraform run for the Add-on.
- `summary` (String) A short summary of the Add-on.
- `terraform_no_code_module` (Attributes) Terraform Cloud no-code Module details. (see [below for nested schema](#nestedatt--terraform_no_code_module))

<a id="nestedatt--terraform_no_code_module"></a>
### Nested Schema for `terraform_no_code_module`

Read-Only:

- `source` (String) Terraform Cloud no-code Module Source
- `version` (String) Terraform Cloud no-code Module Version
46 changes: 46 additions & 0 deletions docs/resources/waypoint_add_on.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
page_title: "hcp_waypoint_add_on Resource - terraform-provider-hcp"
subcategory: "HCP Waypoint"
description: |-
Waypoint Add-on resource
---

# hcp_waypoint_add_on `Resource`

-> **Note:** HCP Waypoint is currently in public beta.

Waypoint Add-on resource

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `application_id` (String) The ID of the Application that this Add-on is created for.
- `definition_id` (String) The ID of the Add-on Definition that this Add-on is created from.
- `name` (String) The name of the Add-on.

### Optional

- `project_id` (String) The ID of the HCP project where the Waypoint AddOn is located.

### Read-Only

- `created_by` (String) 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.
- `labels` (List of String) List of labels attached to this Add-on.
- `organization_id` (String) The ID of the HCP organization where the Waypoint AddOn is located.
- `readme_markdown` (String) The markdown for the Add-on README.
- `status` (Number) The status of the Terraform run for the Add-on.
- `summary` (String) A short summary of the Add-on.
- `terraform_no_code_module` (Attributes) Terraform Cloud no-code Module details. (see [below for nested schema](#nestedatt--terraform_no_code_module))

<a id="nestedatt--terraform_no_code_module"></a>
### Nested Schema for `terraform_no_code_module`

Read-Only:

- `source` (String) Terraform Cloud no-code Module Source
- `version` (String) Terraform Cloud no-code Module Version
9 changes: 9 additions & 0 deletions internal/clients/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ func IsResponseCodeNotFound(err error) bool {
return strings.Contains(err.Error(), fmt.Sprintf("[%d]", http.StatusNotFound))
}
}

func IsResponseCodeInternalError(erro error) bool {
var apiErr *runtime.APIError
if errors.As(erro, &apiErr) {
return apiErr.Code == http.StatusInternalServerError
} else {
return strings.Contains(erro.Error(), fmt.Sprintf("[%d]", http.StatusInternalServerError))
}
}
38 changes: 38 additions & 0 deletions internal/clients/waypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,41 @@ func GetApplicationByID(ctx context.Context, client *Client, loc *sharedmodels.H
}
return getResp.GetPayload().Application, nil
}

// 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,
}

getResp, err := client.Waypoint.WaypointServiceGetAddOn2(params, nil)
if err != nil {
return nil, err
}
return getResp.GetPayload().AddOn, nil
}

// 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,
}

getResp, err := client.Waypoint.WaypointServiceGetAddOn(params, nil)
if err != nil {
return nil, err
}
return getResp.GetPayload().AddOn, nil
}
2 changes: 2 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (p *ProviderFramework) Resources(ctx context.Context) []func() resource.Res
// Waypoint
waypoint.NewApplicationResource,
waypoint.NewApplicationTemplateResource,
waypoint.NewAddOnResource,
waypoint.NewAddOnDefinitionResource,
waypoint.NewTfcConfigResource,
}, packer.ResourceSchemaBuilders...)
Expand All @@ -174,6 +175,7 @@ func (p *ProviderFramework) DataSources(ctx context.Context) []func() datasource
// Waypoint
waypoint.NewApplicationDataSource,
waypoint.NewApplicationTemplateDataSource,
waypoint.NewAddOnDataSource,
waypoint.NewAddOnDefinitionDataSource,
}, packer.DataSourceSchemaBuilders...)
}
Expand Down
Loading

0 comments on commit d928631

Please sign in to comment.