Skip to content

Commit fe7f72c

Browse files
committed
update from main
2 parents 34b3a11 + 736b359 commit fe7f72c

File tree

92 files changed

+1644
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1644
-255
lines changed

.github/pull_request_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Please fill out the remaining template to assist code reviewers and testers with
3333
<!--
3434
_Include any links here that might be helpful for people reviewing your PR. If there are none, feel free to delete this section._
3535
36-
- [API documentation](https://www.terraform.io/docs/cloud/api/xxxx.html)
36+
- [API documentation](https://developer.hashicorp.com/terraform/cloud-docs/api-docs/xxxx)
3737
- [Related PR](https://github.com/terraform-providers/terraform-provider-tfe/pull/xxxx)
3838
3939
-->

.github/scripts/fetch_outputs/main.go

+4-29
Original file line numberDiff line numberDiff line change
@@ -52,52 +52,27 @@ func newRunnerConfiguration(ctx context.Context, outputs []*tfe.StateVersionOutp
5252
return nil, fmt.Errorf("tfe_address output variable is not set")
5353
}
5454

55-
tfeCfg := &tfe.Config{
56-
Address: config["TFE_ADDRESS"],
57-
Token: config["TFE_TOKEN"],
58-
RetryServerErrors: true,
59-
}
60-
61-
// We need to create a new tfe client that will talk to the tflocal instance
62-
// since we need to fetch TFE_USER1 and TFE_USER2
63-
client, err := tfe.NewClient(tfeCfg)
64-
if err != nil {
65-
return nil, err
66-
}
67-
68-
oml, err := client.OrganizationMemberships.List(ctx, "hashicorp", &tfe.OrganizationMembershipListOptions{
69-
Include: []tfe.OrgMembershipIncludeOpt{tfe.OrgMembershipUser},
70-
})
71-
if err != nil {
72-
return nil, err
73-
}
74-
75-
for i, orgMember := range oml.Items {
76-
key := fmt.Sprintf("TFE_USER%d", i+1)
77-
config[key] = orgMember.User.Username
78-
}
79-
8055
return config, nil
8156
}
8257

8358
// writeToEnv writes the WorkflowRunnerConfiguration to $GITHUB_ENV
8459
func writeToEnv(ctx context.Context, config WorkflowRunnerConfiguration) error {
8560
homeDir, err := os.UserHomeDir()
8661
if err != nil {
87-
return err
62+
return fmt.Errorf("unable to get the current home directory: %w", err)
8863
}
8964

9065
name := filepath.Join(homeDir, ".env")
9166
f, err := os.OpenFile(name, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
9267
if err != nil {
93-
return err
68+
return fmt.Errorf("unable to open the file: %w", err)
9469
}
9570
defer f.Close()
9671

9772
for k := range config {
9873
envVar := fmt.Sprintf("export %s=%s\n", k, config[k])
9974
if _, err := f.WriteString(envVar); err != nil {
100-
return err
75+
return fmt.Errorf("unable to write to the file: %w", err)
10176
}
10277
}
10378

@@ -117,7 +92,7 @@ func main() {
11792

11893
client, err := tfe.NewClient(tfe.DefaultConfig())
11994
if err != nil {
120-
log.Fatal(err)
95+
log.Fatalf("client initialization error: %v", err)
12196
}
12297

12398
outputs, err := fetchOutputs(ctx, client, organization, workspace)

.github/workflows/create-jira-issue.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Create Jira Issue
1+
name: Jira Issue Sync
22

33
on:
44
issues:
@@ -8,9 +8,8 @@ on:
88

99
jobs:
1010
call-workflow:
11-
uses: hashicorp/terraform-random-tfe-utility/.github/workflows/create-jira-issue.yml@main
11+
uses: hashicorp/terraform-provider-tfe/.github/workflows/jira-issue-sync.yml@main
1212
with:
13-
github-team: Terraform-Enterprise
1413
project: TF
1514
issue-extra-fields: |
1615
{ "customfield_10091": ["TF-CLI"] }
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Jira PR Transition
2+
3+
on:
4+
pull_request:
5+
types: [opened, closed, reopened, converted_to_draft, ready_for_review]
6+
7+
jobs:
8+
call-workflow:
9+
uses: hashicorp/terraform-provider-tfe/.github/workflows/jira-pr-transition.yml@main
10+
secrets: inherit

.github/workflows/nightly-tfe-ci.yml

+32-31
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ jobs:
9292
env:
9393
TFE_TOKEN: "${{ secrets.TF_WORKFLOW_TFLOCAL_CLOUD_TFC_TOKEN }}"
9494
run: |
95+
set -euo pipefail
9596
go run .github/scripts/fetch_outputs/main.go hashicorp-v2 tflocal-go-tfe-nightly
9697
9798
- name: Run Tests
@@ -106,37 +107,37 @@ jobs:
106107
source $HOME/.env
107108
gotestsum --format short-verbose -- -timeout=40m
108109
109-
slack-notify:
110-
needs: tests
111-
if: always() && (needs.tests.result == 'failure')
112-
runs-on: ubuntu-latest
113-
steps:
114-
- name: Send slack notification on failure
115-
uses: slackapi/[email protected]
116-
with:
117-
payload: |
118-
{
119-
"text": ":x::moon::sob: Nightly TFE tests *FAILED*",
120-
"attachments": [
121-
{
122-
"color": "#C41E3A",
123-
"blocks": [
124-
{
125-
"type": "section",
126-
"fields": [
127-
{
128-
"type": "mrkdwn",
129-
"text": "*Workflow:*\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
130-
}
131-
]
132-
}
133-
]
134-
}
135-
]
136-
}
137-
env:
138-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
139-
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
110+
# slack-notify:
111+
# needs: tests
112+
# if: always() && (needs.tests.result == 'failure')
113+
# runs-on: ubuntu-latest
114+
# steps:
115+
# - name: Send slack notification on failure
116+
# uses: slackapi/[email protected]
117+
# with:
118+
# payload: |
119+
# {
120+
# "text": ":x::moon::sob: Nightly TFE tests *FAILED*",
121+
# "attachments": [
122+
# {
123+
# "color": "#C41E3A",
124+
# "blocks": [
125+
# {
126+
# "type": "section",
127+
# "fields": [
128+
# {
129+
# "type": "mrkdwn",
130+
# "text": "*Workflow:*\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
131+
# }
132+
# ]
133+
# }
134+
# ]
135+
# }
136+
# ]
137+
# }
138+
# env:
139+
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
140+
# SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
140141

141142
cleanup:
142143
runs-on: ubuntu-latest

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
.out
55
.vscode/*.log
66
.idea/
7+
.envrc

CHANGELOG.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Unreleased
2+
3+
## Enhancements
4+
* Adds `BaseURL` and `BaseRegistryURL` methods to `Client` to expose its configuration by @brandonc [#638](https://github.com/hashicorp/go-tfe/pull/638)
5+
6+
## Bug Fixes
7+
8+
# v1.17.0
9+
10+
## Enhancements
11+
* Add Beta endpoint `TeamProjectAccesses` to manage Project Access for Teams by @hs26gill [#599](https://github.com/hashicorp/go-tfe/pull/599)
12+
* Updates api doc links from terraform.io to developer.hashicorp domain by @uk1288 [#629](https://github.com/hashicorp/go-tfe/pull/629)
13+
* Adds `UploadTarGzip()` method to `RegistryModules` and `ConfigurationVersions` interface by @sebasslash [#623](https://github.com/hashicorp/go-tfe/pull/623)
14+
* Adds `ManageProjects` field to `OrganizationAccess` struct by @hs26gill [#633](https://github.com/hashicorp/go-tfe/pull/633)
15+
* Adds agent-count to `AgentPools` endpoint. @evilensky [#611](https://github.com/hashicorp/go-tfe/pull/611)
16+
* Adds `Links` to `Workspace`, (currently contains "self" and "self-html" paths) @brandonc [#622](https://github.com/hashicorp/go-tfe/pull/622)
17+
118
# v1.16.0
219

320
## Bug Fixes
@@ -9,8 +26,6 @@
926
* Adds `ProviderBinaryUploaded` field to `RegistryPlatforms` struct by @sebasslash [#602](https://github.com/hashicorp/go-tfe/pull/602)
1027
* Adds `ReadWorkspaces` and `ReadProjects` permissions to `Organizations` by @JuliannaTetreault [#614](https://github.com/hashicorp/go-tfe/pull/614)
1128

12-
* Adds agent-count to `AgentPools` endpoint. @evilensky [#611](https://github.com/hashicorp/go-tfe/pull/611)
13-
1429
# v1.15.0
1530

1631
## Enhancements

README.md

+67-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Terraform Cloud/Enterprise Go Client
99

1010
The official Go API client for [Terraform Cloud/Enterprise](https://www.hashicorp.com/products/terraform).
1111

12-
This client supports the [Terraform Cloud V2 API](https://www.terraform.io/docs/cloud/api/index.html).
12+
This client supports the [Terraform Cloud V2 API](https://developer.hashicorp.com/terraform/cloud-docs/api-docs).
1313
As Terraform Enterprise is a self-hosted distribution of Terraform Cloud, this
1414
client supports both Cloud and Enterprise use cases. In all package
1515
documentation and API, the platform will always be stated as 'Terraform
@@ -20,27 +20,82 @@ the other, if applicable (rare).
2020

2121
Almost always, minor version changes will indicate backwards-compatible features and enhancements. Occasionally, function signature changes that reflect a bug fix may appear as a minor version change. Patch version changes will be used for bug fixes, performance improvements, and otherwise unimpactful changes.
2222

23-
## Installation
23+
## Example Usage
2424

25-
Installation can be done with a normal `go get`:
25+
Construct a new TFE client, then use the various endpoints on the client to
26+
access different parts of the Terraform Enterprise API. The following example lists
27+
all organizations.
2628

27-
```
28-
go get -u github.com/hashicorp/go-tfe
29+
### (Recommended Approach) Using custom config to provide configuration details to the API client
30+
31+
```go
32+
import (
33+
"context"
34+
"log"
35+
36+
"github.com/hashicorp/go-tfe"
37+
)
38+
39+
config := &tfe.Config{
40+
Address: "https://tfe.local",
41+
Token: "insert-your-token-here",
42+
RetryServerErrors: true,
43+
}
44+
45+
client, err := tfe.NewClient(config)
46+
if err != nil {
47+
log.Fatal(err)
48+
}
49+
50+
orgs, err := client.Organizations.List(context.Background(), nil)
51+
if err != nil {
52+
log.Fatal(err)
53+
}
2954
```
3055

31-
## Usage
56+
### Using the default config with env vars
57+
The default configuration makes use of the `TFE_ADDRESS` and `TFE_TOKEN` environment variables.
3258

59+
1. `TFE_ADDRESS` - URL of a Terraform Cloud or Terraform Enterprise instance. Example: `https://tfe.local`
60+
1. `TFE_TOKEN` - An [API token](https://developer.hashicorp.com/terraform/cloud-docs/users-teams-organizations/api-tokens) for the Terraform Cloud or Terraform Enterprise instance.
61+
62+
**Note:** Alternatively, you can set `TFE_HOSTNAME` which serves as a fallback for `TFE_ADDRESS`. It will only be used if `TFE_ADDRESS` is not set and will resolve the host to an `https` scheme. Example: `tfe.local` => resolves to `https://tfe.local`
63+
64+
The environment variables are used as a fallback to configure TFE client if the Address or Token values are not provided as in the cases below:
65+
66+
#### Using the default configuration
3367
```go
34-
import tfe "github.com/hashicorp/go-tfe"
35-
```
68+
import (
69+
"context"
70+
"log"
3671

37-
Construct a new TFE client, then use the various endpoints on the client to
38-
access different parts of the Terraform Enterprise API. For example, to list
39-
all organizations:
72+
"github.com/hashicorp/go-tfe"
73+
)
74+
75+
// Passing nil to tfe.NewClient method will also use the default configuration
76+
client, err := tfe.NewClient(tfe.DefaultConfig())
77+
if err != nil {
78+
log.Fatal(err)
79+
}
4080

81+
orgs, err := client.Organizations.List(context.Background(), nil)
82+
if err != nil {
83+
log.Fatal(err)
84+
}
85+
```
86+
87+
#### When Address or Token has no value
4188
```go
89+
import (
90+
"context"
91+
"log"
92+
93+
"github.com/hashicorp/go-tfe"
94+
)
95+
4296
config := &tfe.Config{
43-
Token: "insert-your-token-here",
97+
Address: "",
98+
Token: "",
4499
}
45100

46101
client, err := tfe.NewClient(config)

admin_organization.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var _ AdminOrganizations = (*adminOrganizations)(nil)
1212
// AdminOrganizations describes all of the admin organization related methods that the Terraform
1313
// Enterprise API supports. Note that admin settings are only available in Terraform Enterprise.
1414
//
15-
// TFE API docs: https://www.terraform.io/docs/cloud/api/admin/organizations.html
15+
// TFE API docs: https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/organizations
1616
type AdminOrganizations interface {
1717
// List all the organizations visible to the current user.
1818
List(ctx context.Context, options *AdminOrganizationListOptions) (*AdminOrganizationList, error)
@@ -57,7 +57,7 @@ type AdminOrganization struct {
5757
}
5858

5959
// AdminOrganizationUpdateOptions represents the admin options for updating an organization.
60-
// https://www.terraform.io/docs/cloud/api/admin/organizations.html#request-body
60+
// https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/organizations#request-body
6161
type AdminOrganizationUpdateOptions struct {
6262
AccessBetaTools *bool `jsonapi:"attr,access-beta-tools,omitempty"`
6363
GlobalModuleSharing *bool `jsonapi:"attr,global-module-sharing,omitempty"`
@@ -75,7 +75,7 @@ type AdminOrganizationList struct {
7575
}
7676

7777
// AdminOrgIncludeOpt represents the available options for include query params.
78-
// https://www.terraform.io/docs/cloud/api/admin/organizations.html#available-related-resources
78+
// https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/organizations#available-related-resources
7979
type AdminOrgIncludeOpt string
8080

8181
const AdminOrgOwners AdminOrgIncludeOpt = "owners"
@@ -88,7 +88,7 @@ type AdminOrganizationListOptions struct {
8888
// Any organizations with a name or notification email partially matching this value will be returned.
8989
Query string `url:"q,omitempty"`
9090
// Optional: A list of relations to include. See available resources
91-
// https://www.terraform.io/docs/cloud/api/admin/organizations.html#available-related-resources
91+
// https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/organizations#available-related-resources
9292
Include []AdminOrgIncludeOpt `url:"include,omitempty"`
9393
}
9494

0 commit comments

Comments
 (0)