Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for TFE_HOSTNAME and TFE_TOKEN environment variables #78

Merged
merged 4 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ $ $GOPATH/bin/terraform-provider-tfe
...
```

Testing
-------

In order to test the provider, you can simply run `make test`.

```sh
Expand All @@ -61,13 +64,19 @@ $ make test

In order to run the full suite of Acceptance tests, run `make testacc`.

*Note:* Acceptance tests create real resources, and often cost money to run.

```sh
$ make testacc
```

Testing
-------
A hostname and token must be provided in order to run the acceptance tests. We recomment configuring
the required `credentials` in the [CLI config file](https://www.terraform.io/docs/commands/cli-config.html).
A hostname and token must be provided in order to run the acceptance tests. By
default, these are loaded from the the `credentials` in the [CLI config
file](https://www.terraform.io/docs/commands/cli-config.html). You can override
these values with the environment variables specified below: `TFE_HOSTNAME` and
`TFE_TOKEN`.

To run all tests, you will need to set the following environment variables:

- `TFE_HOSTNAME`: the hostname of your test TFE instance; for example, `tfe-test.local`
- `TFE_TOKEN`: a user token for an administrator account on your TFE instance
- `GITHUB_TOKEN`: a GitHub personal access token, used to establish a VCS provider connection
- `TFE_USER1` and `TFE_USER2`: the usernames of two pre-existing TFE users, for testing team membership
3 changes: 2 additions & 1 deletion tfe/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ func Provider() terraform.ResourceProvider {
Type: schema.TypeString,
Optional: true,
Description: descriptions["hostname"],
Default: defaultHostname,
DefaultFunc: schema.EnvDefaultFunc("TFE_HOSTNAME", defaultHostname),
},

"token": {
Type: schema.TypeString,
Optional: true,
Description: descriptions["token"],
DefaultFunc: schema.EnvDefaultFunc("TFE_TOKEN", nil),
},
},

Expand Down
11 changes: 7 additions & 4 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ organizations, and organization tokens cannot manage certain resource types
[Terraform Enterprise API documentation](/docs/enterprise/api/index.html)
for more details about access to specific resources.

There are two ways to provide the required token:
There are three ways to provide the required token:

- On the CLI, omit the `token` argument and set a `credentials` block in your
[CLI config file](/docs/commands/cli-config.html#credentials).
- Set the `TFE_TOKEN` environment variable.
- In a Terraform Enterprise workspace, set `token` in the provider
configuration. Use an input variable for the token and mark the corresponding
variable in the workspace as sensitive.
Expand All @@ -61,9 +62,11 @@ resource "tfe_organization" "org" {
The following arguments are supported:

* `hostname` - (Optional) The Terraform Enterprise hostname to connect to.
Defaults to `app.terraform.io`.
Defaults to `app.terraform.io`. Can be overridden by setting the
`TFE_HOSTNAME` environment variable.
* `token` - (Optional) The token used to authenticate with Terraform Enterprise.
Only set this argument when running in a Terraform Enterprise workspace; for
CLI usage, omit the token from the configuration and set it as `credentials`
in the [CLI config file](/docs/commands/cli-config.html#credentials). See
[Authentication](#authentication) above for more.
in the [CLI config file](/docs/commands/cli-config.html#credentials) or set
the `TFE_TOKEN` environment variable. See [Authentication](#authentication)
above for more.