-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add support for Environment Discovery API (#802)
* Feat: Add support for Environment Discovery API * added tests * add create and delete * added optional * added optional * adding tests - WIP * added tests * added tests * fix test * update go version * update go version * added import * Update env0/resource_environment_discovery_configuration.go Co-authored-by: Yaron Yarimi <[email protected]> * small rename refactoring * fix race condition * add sleep to avoid race condition --------- Co-authored-by: Yaron Yarimi <[email protected]>
- Loading branch information
1 parent
1b16141
commit 71032c4
Showing
24 changed files
with
1,518 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ env: | |
ENV0_API_ENDPOINT: ${{ secrets.ENV0_API_ENDPOINT }} | ||
ENV0_API_KEY: ${{ secrets.TF_PROVIDER_INTEGRATION_TEST_API_KEY }} # API Key for organization 'TF-provider-integration-tests' @ dev | ||
ENV0_API_SECRET: ${{ secrets.TF_PROVIDER_INTEGRATION_TEST_API_SECRET }} | ||
GO_VERSION: "1.20" | ||
GO_VERSION: "1.21" | ||
TERRAFORM_VERSION: 1.1.7 | ||
|
||
jobs: | ||
|
@@ -33,19 +33,14 @@ jobs: | |
- name: Go vet | ||
run: | | ||
! go vet ./... | read | ||
- name: Go staticcheck | ||
uses: dominikh/[email protected] | ||
with: | ||
version: "2023.1.3" | ||
install-go: false | ||
- name: Go Test | ||
run: go test -v ./... | ||
|
||
# See terraform-provider-env0 README for integration tests prerequisites | ||
integration-tests: | ||
name: Integration Tests | ||
runs-on: ubuntu-20.04 | ||
container: golang:1.20-alpine3.18 | ||
container: golang:1.21-alpine3.18 | ||
timeout-minutes: 20 | ||
steps: | ||
- name: Install Terraform | ||
|
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ on: | |
- main | ||
|
||
env: | ||
GO_VERSION: "1.20" | ||
GO_VERSION: "1.21" | ||
|
||
jobs: | ||
generate-docs: | ||
|
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ on: | |
- "v*.*.*" | ||
|
||
env: | ||
GO_VERSION: "1.20" | ||
GO_VERSION: "1.21" | ||
|
||
jobs: | ||
goreleaser: | ||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,68 @@ | ||
package client | ||
|
||
type EnvironmentDiscoveryPutPayload struct { | ||
GlobPattern string `json:"globPattern"` | ||
EnvironmentPlacement string `json:"environmentPlacement"` | ||
WorkspaceNaming string `json:"workspaceNaming"` | ||
AutoDeployByCustomGlob string `json:"autoDeployByCustomGlob,omitempty"` | ||
Repository string `json:"repository"` | ||
TerraformVersion string `json:"terraformVersion,omitempty"` | ||
OpentofuVersion string `json:"opentofuVersion,omitempty"` | ||
TerragruntVersion string `json:"terragruntVersion,omitempty"` | ||
TerragruntTfBinary string `json:"terragruntTfBinary,omitempty"` | ||
IsTerragruntRunAll bool `json:"is_terragrunt_run_all"` | ||
Type string `json:"type"` | ||
GitlabProjectId int `json:"gitlabProjectId,omitempty"` | ||
TokenId string `json:"tokenId,omitempty"` | ||
SshKeys []TemplateSshKey `json:"sshKeys,omitempty"` | ||
GithubInstallationId int `json:"githubInstallationId,omitempty"` | ||
BitbucketClientKey string `json:"bitbucketClientKey,omitempty"` | ||
IsAzureDevops bool `json:"isAzureDevOps"` | ||
Retry TemplateRetry `json:"retry"` | ||
} | ||
|
||
type EnvironmentDiscoveryPayload struct { | ||
Id string `json:"id"` | ||
GlobPattern string `json:"globPattern"` | ||
EnvironmentPlacement string `json:"environmentPlacement"` | ||
WorkspaceNaming string `json:"workspaceNaming"` | ||
AutoDeployByCustomGlob string `json:"autoDeployByCustomGlob"` | ||
Repository string `json:"repository"` | ||
TerraformVersion string `json:"terraformVersion"` | ||
OpentofuVersion string `json:"opentofuVersion"` | ||
TerragruntVersion string `json:"terragruntVersion"` | ||
TerragruntTfBinary string `json:"terragruntTfBinary" tfschema:",omitempty"` | ||
IsTerragruntRunAll bool `json:"is_terragrunt_run_all"` | ||
Type string `json:"type"` | ||
GitlabProjectId int `json:"gitlabProjectId"` | ||
TokenId string `json:"tokenId"` | ||
SshKeys []TemplateSshKey `json:"sshKeys" tfschema:"-"` | ||
GithubInstallationId int `json:"githubInstallationId"` | ||
BitbucketClientKey string `json:"bitbucketClientKey"` | ||
IsAzureDevops bool `json:"isAzureDevOps"` | ||
Retry TemplateRetry `json:"retry" tfschema:"-"` | ||
} | ||
|
||
func (client *ApiClient) PutEnvironmentDiscovery(projectId string, payload *EnvironmentDiscoveryPutPayload) (*EnvironmentDiscoveryPayload, error) { | ||
var result EnvironmentDiscoveryPayload | ||
|
||
if err := client.http.Put("/environment-discovery/projects/"+projectId, payload, &result); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &result, nil | ||
} | ||
|
||
func (client *ApiClient) GetEnvironmentDiscovery(projectId string) (*EnvironmentDiscoveryPayload, error) { | ||
var result EnvironmentDiscoveryPayload | ||
|
||
if err := client.http.Get("/environment-discovery/projects/"+projectId, nil, &result); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &result, nil | ||
} | ||
|
||
func (client *ApiClient) DeleteEnvironmentDiscovery(projectId string) error { | ||
return client.http.Delete("/environment-discovery/projects/"+projectId, nil) | ||
} |
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,130 @@ | ||
package client_test | ||
|
||
import ( | ||
"errors" | ||
|
||
. "github.com/env0/terraform-provider-env0/client" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
var _ = Describe("Environment Discovery", func() { | ||
mockError := errors.New("error") | ||
|
||
projectId := "pid" | ||
|
||
mockEnvironmentDiscovery := EnvironmentDiscoveryPayload{ | ||
Id: "id", | ||
GlobPattern: "**", | ||
EnvironmentPlacement: "topProject", | ||
WorkspaceNaming: "default", | ||
AutoDeployByCustomGlob: "**", | ||
Repository: "https://re.po", | ||
TerraformVersion: "1.5.6", | ||
Type: "terraform", | ||
GithubInstallationId: 1000, | ||
} | ||
|
||
Describe("PUT", func() { | ||
putPayload := EnvironmentDiscoveryPutPayload{ | ||
GlobPattern: mockEnvironmentDiscovery.GlobPattern, | ||
EnvironmentPlacement: mockEnvironmentDiscovery.EnvironmentPlacement, | ||
WorkspaceNaming: mockEnvironmentDiscovery.WorkspaceNaming, | ||
AutoDeployByCustomGlob: mockEnvironmentDiscovery.AutoDeployByCustomGlob, | ||
Repository: mockEnvironmentDiscovery.Repository, | ||
TerraformVersion: mockEnvironmentDiscovery.TerraformVersion, | ||
Type: mockEnvironmentDiscovery.Type, | ||
GithubInstallationId: mockEnvironmentDiscovery.GithubInstallationId, | ||
} | ||
|
||
Describe("success", func() { | ||
var ret *EnvironmentDiscoveryPayload | ||
|
||
BeforeEach(func() { | ||
httpCall = mockHttpClient.EXPECT(). | ||
Put("/environment-discovery/projects/"+projectId, &putPayload, gomock.Any()). | ||
Do(func(path string, request interface{}, response *EnvironmentDiscoveryPayload) { | ||
*response = mockEnvironmentDiscovery | ||
}).Times(1) | ||
ret, _ = apiClient.PutEnvironmentDiscovery(projectId, &putPayload) | ||
}) | ||
|
||
It("Should return environment discovery", func() { | ||
Expect(*ret).To(Equal(mockEnvironmentDiscovery)) | ||
}) | ||
}) | ||
|
||
Describe("failure", func() { | ||
var err error | ||
|
||
BeforeEach(func() { | ||
httpCall = mockHttpClient.EXPECT(). | ||
Put("/environment-discovery/projects/"+projectId, &putPayload, gomock.Any()).Return(mockError).Times(1) | ||
_, err = apiClient.PutEnvironmentDiscovery(projectId, &putPayload) | ||
}) | ||
|
||
It("Should return error", func() { | ||
Expect(err).To(Equal(mockError)) | ||
}) | ||
}) | ||
}) | ||
|
||
Describe("GET", func() { | ||
Describe("success", func() { | ||
var ret *EnvironmentDiscoveryPayload | ||
|
||
BeforeEach(func() { | ||
httpCall = mockHttpClient.EXPECT(). | ||
Get("/environment-discovery/projects/"+projectId, nil, gomock.Any()). | ||
Do(func(path string, request interface{}, response *EnvironmentDiscoveryPayload) { | ||
*response = mockEnvironmentDiscovery | ||
}).Times(1) | ||
ret, _ = apiClient.GetEnvironmentDiscovery(projectId) | ||
}) | ||
|
||
It("Should return environment discovery", func() { | ||
Expect(*ret).To(Equal(mockEnvironmentDiscovery)) | ||
}) | ||
}) | ||
|
||
Describe("failure", func() { | ||
var err error | ||
|
||
BeforeEach(func() { | ||
httpCall = mockHttpClient.EXPECT(). | ||
Get("/environment-discovery/projects/"+projectId, nil, gomock.Any()).Return(mockError).Times(1) | ||
_, err = apiClient.GetEnvironmentDiscovery(projectId) | ||
}) | ||
|
||
It("Should return error", func() { | ||
Expect(err).To(Equal(mockError)) | ||
}) | ||
}) | ||
}) | ||
|
||
Describe("DELETE", func() { | ||
Describe("success", func() { | ||
BeforeEach(func() { | ||
httpCall = mockHttpClient.EXPECT().Delete("/environment-discovery/projects/"+projectId, nil).Times(1) | ||
apiClient.DeleteEnvironmentDiscovery(projectId) | ||
}) | ||
|
||
It("Should send DELETE request", func() {}) | ||
}) | ||
|
||
Describe("failure", func() { | ||
var err error | ||
|
||
BeforeEach(func() { | ||
httpCall = mockHttpClient.EXPECT(). | ||
Delete("/environment-discovery/projects/"+projectId, nil).Return(mockError).Times(1) | ||
err = apiClient.DeleteEnvironmentDiscovery(projectId) | ||
}) | ||
|
||
It("Should return error", func() { | ||
Expect(err).To(Equal(mockError)) | ||
}) | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.