-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathworkspace_resources.go
79 lines (67 loc) · 2.44 KB
/
workspace_resources.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package tfe
import (
"context"
"fmt"
"net/url"
)
// Compile-time proof of interface implementation.
var _ WorkspaceResources = (*workspaceResources)(nil)
// WorkspaceResources describes all the workspace resources related methods that the Terraform
// Enterprise API supports.
//
// TFE API docs: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/workspace-resources
type WorkspaceResources interface {
// List all the workspaces resources within a workspace
List(ctx context.Context, workspaceID string, options *WorkspaceResourceListOptions) (*WorkspaceResourcesList, error)
}
// workspaceResources implements WorkspaceResources.
type workspaceResources struct {
client *Client
}
// WorkspaceResourcesList represents a list of workspace resources.
type WorkspaceResourcesList struct {
*Pagination
Items []*WorkspaceResource
}
// WorkspaceResource represents a Terraform Enterprise workspace resource.
type WorkspaceResource struct {
ID string `jsonapi:"primary,resources"`
Address string `jsonapi:"attr,address"`
Name string `jsonapi:"attr,name"`
CreatedAt string `jsonapi:"attr,created-at"`
UpdatedAt string `jsonapi:"attr,updated-at"`
Module string `jsonapi:"attr,module"`
Provider string `jsonapi:"attr,provider"`
ProviderType string `jsonapi:"attr,provider-type"`
ModifiedByStateVersionID string `jsonapi:"attr,modified-by-state-version-id"`
NameIndex *string `jsonapi:"attr,name-index"`
}
// WorkspaceResourceListOptions represents the options for listing workspace resources.
type WorkspaceResourceListOptions struct {
ListOptions
}
// List all the workspaces resources within a workspace
func (s *workspaceResources) List(ctx context.Context, workspaceID string, options *WorkspaceResourceListOptions) (*WorkspaceResourcesList, error) {
if !validStringID(&workspaceID) {
return nil, ErrInvalidWorkspaceID
}
if err := options.valid(); err != nil {
return nil, err
}
u := fmt.Sprintf("workspaces/%s/resources", url.PathEscape(workspaceID))
req, err := s.client.NewRequest("GET", u, options)
if err != nil {
return nil, err
}
wl := &WorkspaceResourcesList{}
err = req.Do(ctx, wl)
if err != nil {
return nil, err
}
return wl, nil
}
func (o *WorkspaceResourceListOptions) valid() error {
return nil
}