Skip to content

Commit

Permalink
New Resource: Waypoint Application Template (#778)
Browse files Browse the repository at this point in the history
* CRUD for application template and data source

- labels still can't be completely removed due to API bug

* add data source and test updates

* add generated docs for waypoint app template data source

* update docs

* changelog

* revert go/toolchain update

* Update internal/provider/waypoint/data_source_waypoint_application_template.go

Co-authored-by: Brian Cain <[email protected]>

* Update internal/provider/waypoint/data_source_waypoint_application_template.go

Co-authored-by: Brian Cain <[email protected]>

* Update internal/provider/waypoint/resource_waypoint_application_template.go

Co-authored-by: Brian Cain <[email protected]>

* update docs

* update data source fields to be computed not optional; regen docs

---------

Co-authored-by: Brian Cain <[email protected]>
  • Loading branch information
catsby and briancain authored Mar 13, 2024
1 parent fcbb47d commit 3011bca
Show file tree
Hide file tree
Showing 9 changed files with 1,192 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .changelog/778.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:feature
New resource: Add `hcp_waypoint_application_template` resource for managing Waypoint Application Templates.
New data-source: Add `data.hcp_waypoint_application_template` data-source for Waypoint Application Templates.
```
49 changes: 49 additions & 0 deletions docs/data-sources/waypoint_application_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "hcp_waypoint_application_template Data Source - terraform-provider-hcp"
subcategory: ""
description: |-
The Waypoint Template data source retrieves information on a given Application Template.
---

# hcp_waypoint_application_template (Data Source)

The Waypoint Template data source retrieves information on a given Application Template.



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

### Optional

- `id` (String) The ID of the Application Template.
- `name` (String) The name of the Application Template.
- `project_id` (String) The ID of the HCP project where the Waypoint Application Template is located.

### Read-Only

- `description` (String) A description of the template, along with when and why it should be used, up to 500 characters
- `labels` (List of String) List of labels attached to this Application Template.
- `organization_id` (String) The ID of the HCP organization where the Waypoint Application Template is located.
- `readme_markdown_template` (String) Instructions for using the template (markdown format supported
- `summary` (String) A brief description of the template, up to 110 characters
- `terraform_cloud_workspace_details` (Attributes) Terraform Cloud Workspace details (see [below for nested schema](#nestedatt--terraform_cloud_workspace_details))
- `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_cloud_workspace_details"></a>
### Nested Schema for `terraform_cloud_workspace_details`

Read-Only:

- `name` (String) Name of the Terraform Cloud Workspace
- `terraform_project_id` (String) Terraform Cloud Project ID


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

Read-Only:

- `source` (String) No-Code Module Source
- `version` (String) No-Code Module Version
52 changes: 52 additions & 0 deletions docs/resources/waypoint_application_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "hcp_waypoint_application_template Resource - terraform-provider-hcp"
subcategory: ""
description: |-
Waypoint Application Template resource
---

# hcp_waypoint_application_template (Resource)

Waypoint Application Template resource



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

### Required

- `name` (String) The name of the Application Template.
- `summary` (String) A brief description of the template, up to 110 characters
- `terraform_cloud_workspace_details` (Attributes) Terraform Cloud Workspace details (see [below for nested schema](#nestedatt--terraform_cloud_workspace_details))
- `terraform_no_code_module` (Attributes) Terraform Cloud No-Code Module details (see [below for nested schema](#nestedatt--terraform_no_code_module))

### Optional

- `description` (String) A description of the template, along with when and why it should be used, up to 500 characters
- `labels` (List of String) List of labels attached to this Application Template.
- `project_id` (String) The ID of the HCP project where the Waypoint Application Template is located.
- `readme_markdown_template` (String) Instructions for using the template (markdown format supported

### Read-Only

- `id` (String) The ID of the Application Template.
- `organization_id` (String) The ID of the HCP organization where the Waypoint Application Template is located.

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

Required:

- `name` (String) Name of the Terraform Cloud Workspace
- `terraform_project_id` (String) Tetraform Cloud Project ID


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

Required:

- `source` (String) No-Code Module Source
- `version` (String) No-Code Module Version
65 changes: 65 additions & 0 deletions internal/clients/waypoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package clients

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"
)

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

// GetApplicationTemplateByName will retrieve an application 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,
}

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

// GetApplicationTemplateByID will retrieve an application 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,
}

getResp, err := client.Waypoint.WaypointServiceGetApplicationTemplate(params, nil)
if err != nil {
return nil, err
}
return getResp.GetPayload().ApplicationTemplate, nil
}
3 changes: 3 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func (p *ProviderFramework) Resources(ctx context.Context) []func() resource.Res
// Webhook
webhook.NewNotificationsWebhookResource,
// Waypoint
waypoint.NewApplicationTemplateResource,
waypoint.NewTfcConfigResource,
}, packer.ResourceSchemaBuilders...)
}
Expand All @@ -164,6 +165,8 @@ func (p *ProviderFramework) DataSources(ctx context.Context) []func() datasource
vaultsecrets.NewVaultSecretsSecretDataSource,
// IAM
iam.NewServicePrincipalDataSource,
// Waypoint
waypoint.NewApplicationTemplateDataSource,
}, packer.DataSourceSchemaBuilders...)
}

Expand Down
Loading

0 comments on commit 3011bca

Please sign in to comment.