Skip to content

Commit

Permalink
Feat: data env0_template missing fields (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed May 12, 2022
1 parent 8b35d86 commit 303301d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
64 changes: 64 additions & 0 deletions env0/data_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,44 @@ func dataTemplate() *schema.Resource {
Optional: true,
Computed: true,
},
"bitbucket_client_key": {
Type: schema.TypeString,
Description: "the bitbucket client key used for integration",
Optional: true,
Computed: true,
},
"is_bitbucket_server": {
Type: schema.TypeBool,
Description: "true if this template uses bitbucket server repository",
Optional: true,
Computed: true,
},
"is_github_enterprise": {
Type: schema.TypeBool,
Description: "true if this template uses github enterprise repository",
Optional: true,
Computed: true,
},
"ssh_keys": {
Type: schema.TypeList,
Description: "an array of references to 'data_ssh_key' to use when accessing git over ssh",
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Description: "ssh key id",
Required: true,
},
"name": {
Type: schema.TypeString,
Description: "ssh key name",
Required: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -159,6 +197,11 @@ func dataTemplateRead(ctx context.Context, d *schema.ResourceData, meta interfac
if template.TokenId != "" {
d.Set("token_id", template.TokenId)
}

if template.BitbucketClientKey != "" {
d.Set("bitbucket_client_key", template.BitbucketClientKey)
}

if template.GitlabProjectId != 0 {
d.Set("gitlab_project_id", template.GitlabProjectId)
}
Expand All @@ -167,6 +210,27 @@ func dataTemplateRead(ctx context.Context, d *schema.ResourceData, meta interfac
d.Set("is_gitlab_enterprise", template.IsGitlabEnterprise)
}

if template.IsBitbucketServer {
d.Set("is_bitbucket_server", template.IsBitbucketServer)
}

if template.IsGitHubEnterprise {
d.Set("is_github_enterprise", template.IsGitHubEnterprise)
}

var sshKeys []interface{}

for _, sshKey := range template.SshKeys {
newSshKey := make(map[string]interface{})
newSshKey["id"] = sshKey.Id
newSshKey["name"] = sshKey.Name
sshKeys = append(sshKeys, newSshKey)
}

if sshKeys != nil {
d.Set("ssh_keys", sshKeys)
}

return nil
}

Expand Down
9 changes: 9 additions & 0 deletions env0/data_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func TestUnitTemplateData(t *testing.T) {
Retry: templateRetry,
ProjectIds: []string{"pId1", "pId2"},
GithubInstallationId: 123,
BitbucketClientKey: "12345",
SshKeys: []client.TemplateSshKey{
{Id: "id", Name: "name"},
},
IsBitbucketServer: true,
}

getValidTestCase := func(input map[string]interface{}) resource.TestCase {
Expand All @@ -58,6 +63,10 @@ func TestUnitTemplateData(t *testing.T) {
resource.TestCheckResourceAttr(resourceFullName, "github_installation_id", strconv.Itoa(template.GithubInstallationId)),
resource.TestCheckResourceAttr(resourceFullName, "project_ids.0", template.ProjectIds[0]),
resource.TestCheckResourceAttr(resourceFullName, "project_ids.1", template.ProjectIds[1]),
resource.TestCheckResourceAttr(resourceFullName, "bitbucket_client_key", template.BitbucketClientKey),
resource.TestCheckResourceAttr(resourceFullName, "ssh_keys.0.id", template.SshKeys[0].Id),
resource.TestCheckResourceAttr(resourceFullName, "ssh_keys.0.name", template.SshKeys[0].Name),
resource.TestCheckResourceAttr(resourceFullName, "is_bitbucket_server", "true"),
),
},
},
Expand Down

0 comments on commit 303301d

Please sign in to comment.