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

Feat: support newly added template types - pulumi, k8s & workflow #428

Merged
merged 4 commits into from
Jun 26, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion env0/data_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package env0

import (
"context"
"fmt"
"strings"

"github.com/env0/terraform-provider-env0/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -42,7 +44,7 @@ func dataTemplate() *schema.Resource {
},
"type": {
Type: schema.TypeString,
Description: "'terraform' or 'terragrunt'",
Description: fmt.Sprintf("template type (allowed values: %s)", strings.Join(allowedTemplateTypes, ", ")),
Computed: true,
},
"project_ids": {
Expand Down
2 changes: 1 addition & 1 deletion env0/resource_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func TestUnitTemplateResource(t *testing.T) {
"repository": template.Repository,
"type": "gruntyform",
}),
ExpectError: regexp.MustCompile(`must be one of: terragrunt, terraform`),
ExpectError: regexp.MustCompile(`must be one of`),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? shouldn't it list all of the available types

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works. I didn't want us to modify the test every time a new type was added.
(This test isn't beneficial, to begin with).

Since it's a regex match, it passes because the prefix never changes.

},
},
}
Expand Down
14 changes: 12 additions & 2 deletions env0/templates.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package env0

import (
"fmt"
"sort"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand All @@ -13,6 +15,14 @@ const (
TemplateTypeShared = 2
)

var allowedTemplateTypes = []string{
"terraform",
"terragrunt",
"pulumi",
"k8s",
"complex",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we renamed complex to workflow

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

}

func getTemplateSchema(templateType TemplateType) map[string]*schema.Schema {
/*
* VCS Constraints:
Expand Down Expand Up @@ -78,10 +88,10 @@ func getTemplateSchema(templateType TemplateType) map[string]*schema.Schema {
},
"type": {
Type: schema.TypeString,
Description: "'terraform' or 'terragrunt'",
Description: fmt.Sprintf("template type (allowed values: %s)", strings.Join(allowedTemplateTypes, ", ")),
Optional: true,
Default: "terraform",
ValidateDiagFunc: NewStringInValidator([]string{"terragrunt", "terraform"}),
ValidateDiagFunc: NewStringInValidator(allowedTemplateTypes),
},
"ssh_keys": {
Type: schema.TypeList,
Expand Down