-
Notifications
You must be signed in to change notification settings - Fork 14
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
Feat: environment resource does not support new templateless creation #420
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,188 @@ | ||
package env0 | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
type TemplateType int | ||
|
||
const ( | ||
TemplateTypeSingle = 1 | ||
TemplateTypeShared = 2 | ||
) | ||
|
||
func getTemplateSchema(templateType TemplateType) map[string]*schema.Schema { | ||
/* | ||
* VCS Constraints: | ||
* GitHub - githubInstallationId | ||
* GitLab - gitlabProjectId and tokenId | ||
* Bitbucket - bitbucketClientKey | ||
* GH Enterprise - isGitHubEnterprise | ||
* GL Enterprise - isGitLabEnterprise | ||
* BB Server - isBitbucketServer | ||
* Other - tokenId (optional field) | ||
*/ | ||
|
||
allVCSAttributes := []string{ | ||
"token_id", | ||
"gitlab_project_id", | ||
"github_installation_id", | ||
"bitbucket_client_key", | ||
"is_gitlab_enterprise", | ||
"is_bitbucket_server", | ||
"is_github_enterprise", | ||
} | ||
|
||
allVCSAttributesBut := func(strs ...string) []string { | ||
sort.Strings(strs) | ||
ret := []string{} | ||
|
||
for _, attr := range allVCSAttributes { | ||
if sort.SearchStrings(strs, attr) >= len(strs) { | ||
ret = append(ret, attr) | ||
} | ||
} | ||
|
||
return ret | ||
} | ||
|
||
s := map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Description: "name to give the template", | ||
Required: templateType == TemplateTypeShared, | ||
Computed: templateType == TemplateTypeSingle, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Description: "description for the template", | ||
Optional: true, | ||
Computed: templateType == TemplateTypeSingle, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. varying behavior... |
||
}, | ||
"repository": { | ||
Type: schema.TypeString, | ||
Description: "git repository url for the template source code", | ||
Required: true, | ||
}, | ||
"path": { | ||
Type: schema.TypeString, | ||
Description: "terraform / terragrunt file folder inside source code", | ||
Optional: true, | ||
}, | ||
"revision": { | ||
Type: schema.TypeString, | ||
Description: "source code revision (branch / tag) to use", | ||
Optional: true, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Description: "'terraform' or 'terragrunt'", | ||
Optional: true, | ||
Default: "terraform", | ||
}, | ||
"ssh_keys": { | ||
Type: schema.TypeList, | ||
Description: "an array of references to 'data_ssh_key' to use when accessing git over ssh", | ||
Optional: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeMap, | ||
Description: "a map of env0_ssh_key.id and env0_ssh_key.name for each project", | ||
}, | ||
}, | ||
"retries_on_deploy": { | ||
Type: schema.TypeInt, | ||
Description: "number of times to retry when deploying an environment based on this template", | ||
Optional: true, | ||
ValidateDiagFunc: ValidateRetries, | ||
}, | ||
"retry_on_deploy_only_when_matches_regex": { | ||
Type: schema.TypeString, | ||
Description: "if specified, will only retry (on deploy) if error matches specified regex", | ||
Optional: true, | ||
RequiredWith: []string{"retries_on_deploy"}, | ||
}, | ||
"retries_on_destroy": { | ||
Type: schema.TypeInt, | ||
Description: "number of times to retry when destroying an environment based on this template", | ||
Optional: true, | ||
ValidateDiagFunc: ValidateRetries, | ||
}, | ||
"retry_on_destroy_only_when_matches_regex": { | ||
Type: schema.TypeString, | ||
Description: "if specified, will only retry (on destroy) if error matches specified regex", | ||
Optional: true, | ||
RequiredWith: []string{"retries_on_destroy"}, | ||
}, | ||
"github_installation_id": { | ||
Type: schema.TypeInt, | ||
Description: "the env0 application installation id on the relevant github repository", | ||
Optional: true, | ||
ConflictsWith: allVCSAttributesBut("github_installation_id"), | ||
}, | ||
"token_id": { | ||
Type: schema.TypeString, | ||
Description: "the token id used for private git repos or for integration with GitLab, you can get this value by using a data resource of an existing Gitlab template or contact our support team", | ||
Optional: true, | ||
ConflictsWith: allVCSAttributesBut("token_id", "gitlab_project_id"), | ||
}, | ||
"gitlab_project_id": { | ||
Type: schema.TypeInt, | ||
Description: "the project id of the relevant repository", | ||
Optional: true, | ||
ConflictsWith: allVCSAttributesBut("token_id", "gitlab_project_id"), | ||
RequiredWith: []string{"token_id"}, | ||
}, | ||
"terraform_version": { | ||
Type: schema.TypeString, | ||
Description: "the Terraform version to use (example: 0.15.1). Setting to `RESOLVE_FROM_TERRAFORM_CODE` defaults to the version of `terraform.required_version` during run-time (resolve from terraform code).", | ||
Optional: true, | ||
ValidateDiagFunc: NewRegexValidator(`^(?:[0-9]\.[0-9]{1,2}\.[0-9]{1,2})|RESOLVE_FROM_TERRAFORM_CODE$`), | ||
Default: "0.15.1", | ||
}, | ||
"terragrunt_version": { | ||
Type: schema.TypeString, | ||
Description: "the Terragrunt version to use (example: 0.36.5)", | ||
ValidateDiagFunc: NewRegexValidator(`^[0-9]\.[0-9]{1,2}\.[0-9]{1,2}$`), | ||
Optional: true, | ||
}, | ||
"is_gitlab_enterprise": { | ||
Type: schema.TypeBool, | ||
Description: "true if this template uses gitlab enterprise repository", | ||
Optional: true, | ||
Default: "false", | ||
ConflictsWith: allVCSAttributesBut("is_gitlab_enterprise"), | ||
}, | ||
"bitbucket_client_key": { | ||
Type: schema.TypeString, | ||
Description: "the bitbucket client key used for integration", | ||
Optional: true, | ||
ConflictsWith: allVCSAttributesBut("bitbucket_client_key"), | ||
}, | ||
"is_bitbucket_server": { | ||
Type: schema.TypeBool, | ||
Description: "true if this template uses bitbucket server repository", | ||
Optional: true, | ||
Default: "false", | ||
ConflictsWith: allVCSAttributesBut("is_bitbucket_server"), | ||
}, | ||
"is_github_enterprise": { | ||
Type: schema.TypeBool, | ||
Description: "true if this template uses github enterprise repository", | ||
Optional: true, | ||
Default: "false", | ||
ConflictsWith: allVCSAttributesBut("is_github_enterprise"), | ||
}, | ||
} | ||
|
||
if templateType == TemplateTypeSingle { | ||
s["id"] = &schema.Schema{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. varying behavior... |
||
Type: schema.TypeString, | ||
Description: "id of the template", | ||
Computed: true, | ||
} | ||
} | ||
|
||
return s | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
varying behavior...