Skip to content

Commit 8d326db

Browse files
committed
Add TFE backwards compatibility docs
This document outlines how to handle unsupported TFE versions, TFE only behavior, and updating the documentation to reflect supported TFE versions.
1 parent 7de2508 commit 8d326db

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

docs/backwards-compatibility.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Maintaining Backwards Compatibility (Terraform Enterprise)
2+
3+
## Terraform Enterprise Version Checking
4+
5+
**Note:** If you are introducing a new resource that is only available at a certain TFE release, you do not need to perform any sort of checks.
6+
7+
### Implied Check (Recommended Approach)
8+
9+
The simplest solution when a particular attribute is not supported by a given TFE release is a `nil` check. These checks are TFE release agnostic and assume that if a field was not returned by the API, the TFE release does not support it. They are particularly important for fields that are structs, where attempting to dereference a nil pointer causes a panic.
10+
11+
You can use this implied checks when:
12+
13+
- The field is a pointer
14+
- When a `null` value is ignored by the API or by go-tfe (see if the struct tag has `omitempty`)
15+
16+
**Example:**
17+
18+
```go
19+
if tmAccess.ProjectAccess != nil {
20+
projectAccess := []map[string]interface{}{{
21+
"settings": tmAccess.ProjectAccess.ProjectSettingsPermission,
22+
"teams": tmAccess.ProjectAccess.ProjectTeamsPermission,
23+
}}
24+
// Write project access to state
25+
err := d.Set("project_access", projectAccess)
26+
}
27+
```
28+
29+
### Explicit Enterprise Checks
30+
31+
If a resource or attribute is **only** available in Terraform Enterprise, use the go-tfe helper [IsEnterprise()](https://pkg.go.dev/github.com/hashicorp/go-tfe#Client.IsEnterprise) to ensure the client is configured against a TFE instance. This check is derived from the `TFP-AppName` header that Terraform Cloud emits, of which if not present, indicates a Terraform Enterprise installation.
32+
33+
```go
34+
config := meta.(ConfiguredClient)
35+
36+
if config.Client.IsEnterprise() {
37+
// do something with TFE only behavior
38+
}
39+
```
40+
41+
### Documentation
42+
43+
It is important to communicate with practitioners which resources and fields are supported for a particular TFE release.
44+
45+
For a new resource, add the minimum release required to the top level documentation.
46+
47+
**Example:**
48+
49+
```md
50+
# my_new_resource
51+
52+
Provides a my new resource.
53+
54+
~> **NOTE:** Using this resource requires using the provider with Terraform Cloud or an instance of Terraform Enterprise at least as recent as v202302-1.
55+
```
56+
57+
58+
If an attribute has a TFE release constraint, add a second sentence to the attribute's description:
59+
60+
```md
61+
## Argument Reference
62+
63+
The following arguments are supported:
64+
65+
* `foo` - (Required) Foo is bar.
66+
* `bar` - (Optional) Bar is foo.
67+
* `foobar` - (Optional) Foobar is barfoo. This attribute requires Terraform Cloud or an instance of Terraform Enterprise at least as recent as `v202302-1`.
68+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ nav:
1515
- Testing: testing.md
1616
- Introducing Beta Features: beta.md
1717
- Debugging: debugging.md
18+
- Backwards Compatibility: backwards-compatibility.md
1819
- Acceptance Tests: writing-acceptance-tests.md
1920
- Changelog Process: changelog-process.md
2021

0 commit comments

Comments
 (0)