-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the stages attribute for the Workspace Run Task resource (#1459)
* Add a client capabilites resolver This commit adds a resolver interface which will be used within the codebase to determine what the capabilities of the remote service are (e.g. Is is Enterprise, if so what version). Note this is an interface, not a struct to make testing easier. Later commits will use this resolver. * Use the new stages attribute for run tasks Previously the schema for workspace run tasks was updated for the new stages property however it wasn't actually used. This commit updates the Workspace Run Task resource to aware of the stages attributes. In particular; * Attempts to detect if the remote service supports the stages property. Stages is available in HCP Terraform and TFE v202404-1 onwards. * Munges the Stages and Stage attribtue depending on the remote capability. * Emits a warning about the remove server capability. * Adds some automated tests. Unfortunately we can't test older TFE versions, to ensure the munging is correct, however manual testing was performed in a local development enivronment to confirm the behaviour. * Removes the default value for the Stage property in the Schema. This will not cause issues with existing state and allows the provider to determine if the attribute was passed in via configuration as opposed to defaulting. * Update changelog * Memoize the result for supportsStagesProperty * Remove pointer for slice Removing the pointer reference as it's not required. * Do not reuse test subject for workspace run task Previously the test subject for the stagesSupport unit tests would reuse the subject and resolver however this led to timing issues when parallel tests were run. This commit changes the test to create new objects per test.
- Loading branch information
1 parent
275c68c
commit 9ff07e2
Showing
6 changed files
with
318 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package provider | ||
|
||
import ( | ||
tfe "github.com/hashicorp/go-tfe" | ||
) | ||
|
||
type capabilitiesResolver interface { | ||
IsCloud() bool | ||
RemoteTFEVersion() string | ||
} | ||
|
||
func newDefaultCapabilityResolver(client *tfe.Client) capabilitiesResolver { | ||
return &defaultCapabilityResolver{ | ||
client: client, | ||
} | ||
} | ||
|
||
type defaultCapabilityResolver struct { | ||
client *tfe.Client | ||
} | ||
|
||
func (r *defaultCapabilityResolver) IsCloud() bool { | ||
return r.client.IsCloud() | ||
} | ||
|
||
func (r *defaultCapabilityResolver) RemoteTFEVersion() string { | ||
return r.client.RemoteTFEVersion() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package provider | ||
|
||
var _ capabilitiesResolver = &staticCapabilityResolver{} | ||
|
||
// A mock capability resolver used for testing to set specific capabilities | ||
type staticCapabilityResolver struct { | ||
isCloud bool | ||
tfeVer string | ||
} | ||
|
||
func (r *staticCapabilityResolver) IsCloud() bool { | ||
return r.isCloud | ||
} | ||
|
||
func (r *staticCapabilityResolver) RemoteTFEVersion() string { | ||
return r.tfeVer | ||
} | ||
|
||
func (r *staticCapabilityResolver) SetIsCloud(val bool) { | ||
r.isCloud = val | ||
} | ||
|
||
func (r *staticCapabilityResolver) SetRemoteTFEVersion(val string) { | ||
r.tfeVer = val | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.