diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 954d45f6..0d291d50 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,14 @@ jobs: - name: Go fmt run: | ! go fmt ./... | read + - name: Go vet + run: | + ! go vet ./... | read + - name: Go staticcheck + uses: dominikh/staticcheck-action@v1.2.0 + with: + version: "2021.1.2" + install-go: false - name: Go Test run: go test -v ./... diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..e1938fed --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 + hooks: + - id: trailing-whitespace + exclude: ^docs/|examples|tests/integration/ + - id: end-of-file-fixer + exclude: ^docs/|examples/|tests/integration/ + - id: check-yaml + - repo: https://github.com/dnephin/pre-commit-golang + rev: v0.5.0 + hooks: + - id: go-fmt + - id: go-vet + - id: go-imports + - id: go-mod-tidy + - repo: https://github.com/TekWizely/pre-commit-golang + rev: v1.0.0-beta.5 + hooks: + - id: go-staticcheck-mod diff --git a/README.md b/README.md index a3d2f092..004b4e89 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ See [here](https://developer.env0.com/docs/api/YXBpOjY4Njc2-env0-api#creating-an ```terraform variable "env0_api_key" {} variable "env0_api_secret" {} - + provider "env0" { api_key = var.env0_api_key api_secret = var.env0_api_secret @@ -77,7 +77,7 @@ See [here](https://developer.env0.com/docs/api/YXBpOjY4Njc2-env0-api#creating-an - Build - `./build.sh` - Create the plugins folder - `mkdir -p ~/.terraform.d/plugins/terraform.env0.com/local/env0/6.6.6/darwin_amd64` - Copy the built binary - `cp ./terraform-provider-env0 ~/.terraform.d/plugins/terraform.env0.com/local/env0/6.6.6/darwin_amd64` (Replace `darwin` with `linux` on Linux) -- Require the local provider in your `main.tf` - +- Require the local provider in your `main.tf` - ``` terraform { required_providers { @@ -89,10 +89,21 @@ terraform { } ``` +### Installing pre-commit hooks +For consistent coding style, install [pre-commit](https://pre-commit.com/#install) hooks. + +``` +go install golang.org/x/tools/...@latest +go install honnef.co/go/tools/cmd/staticcheck@latest +pre-commit install +pre-commit install --hook-type pre-push +``` + + ## Testing ### Integration tests -- The integration tests run against the real env0 API +- The integration tests run against the real env0 API - Have `ENV0_API_KEY` and `ENV0_API_SECRET` environment variables defined. - Also set `ENV0_API_ENDPOINT` if you want to run against a non-prod environment. - Run `go run tests/harness.go` (from the project root folder) to run all the tests. @@ -110,7 +121,7 @@ Afterwards, when cleanup is required, just set `DESTROY_MODE` to `DESTROY_ONLY` #### Integration Test Prerequisites - An env0 organization -- An API Key +- An API Key - A Github.com integrated template name `Github Integrated Template` for https://github.com/env0/templates - A Gitlab.com integrated template name `Gitlab Integrated Template` for https://gitlab.com/env0/gitlab-vcs-integration-tests diff --git a/client/api_key.go b/client/api_key.go index 2779cac6..82e930e7 100644 --- a/client/api_key.go +++ b/client/api_key.go @@ -21,8 +21,8 @@ type ApiKeyCreatePayloadWith struct { OrganizationId string `json:"organizationId"` } -func (ac *ApiClient) ApiKeyCreate(payload ApiKeyCreatePayload) (*ApiKey, error) { - organizationId, err := ac.organizationId() +func (client *ApiClient) ApiKeyCreate(payload ApiKeyCreatePayload) (*ApiKey, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } @@ -33,25 +33,25 @@ func (ac *ApiClient) ApiKeyCreate(payload ApiKeyCreatePayload) (*ApiKey, error) } var result ApiKey - if err := ac.http.Post("/api-keys", payloadWith, &result); err != nil { + if err := client.http.Post("/api-keys", payloadWith, &result); err != nil { return nil, err } return &result, nil } -func (ac *ApiClient) ApiKeyDelete(id string) error { - return ac.http.Delete("/api-keys/" + id) +func (client *ApiClient) ApiKeyDelete(id string) error { + return client.http.Delete("/api-keys/" + id) } -func (ac *ApiClient) ApiKeys() ([]ApiKey, error) { - organizationId, err := ac.organizationId() +func (client *ApiClient) ApiKeys() ([]ApiKey, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } var result []ApiKey - if err := ac.http.Get("/api-keys", map[string]string{"organizationId": organizationId}, &result); err != nil { + if err := client.http.Get("/api-keys", map[string]string{"organizationId": organizationId}, &result); err != nil { return nil, err } diff --git a/client/cloud_credentials.go b/client/cloud_credentials.go index 1d48c809..14b186db 100644 --- a/client/cloud_credentials.go +++ b/client/cloud_credentials.go @@ -77,8 +77,8 @@ const ( AzureServicePrincipalCredentialsType AzureCredentialsType = "AZURE_SERVICE_PRINCIPAL_FOR_DEPLOYMENT" ) -func (self *ApiClient) CloudCredentials(id string) (Credentials, error) { - var credentials, err = self.CloudCredentialsList() +func (client *ApiClient) CloudCredentials(id string) (Credentials, error) { + var credentials, err = client.CloudCredentialsList() if err != nil { return Credentials{}, err } @@ -92,14 +92,14 @@ func (self *ApiClient) CloudCredentials(id string) (Credentials, error) { return Credentials{}, fmt.Errorf("CloudCredentials: [%s] not found ", id) } -func (self *ApiClient) CloudCredentialsList() ([]Credentials, error) { - organizationId, err := self.organizationId() +func (client *ApiClient) CloudCredentialsList() ([]Credentials, error) { + organizationId, err := client.organizationId() if err != nil { return []Credentials{}, err } var credentials []Credentials - err = self.http.Get("/credentials", map[string]string{"organizationId": organizationId}, &credentials) + err = client.http.Get("/credentials", map[string]string{"organizationId": organizationId}, &credentials) if err != nil { return []Credentials{}, err } @@ -107,8 +107,8 @@ func (self *ApiClient) CloudCredentialsList() ([]Credentials, error) { return credentials, nil } -func (self *ApiClient) AwsCredentialsCreate(request AwsCredentialsCreatePayload) (Credentials, error) { - organizationId, err := self.organizationId() +func (client *ApiClient) AwsCredentialsCreate(request AwsCredentialsCreatePayload) (Credentials, error) { + organizationId, err := client.organizationId() if err != nil { return Credentials{}, err } @@ -116,15 +116,15 @@ func (self *ApiClient) AwsCredentialsCreate(request AwsCredentialsCreatePayload) request.OrganizationId = organizationId var result Credentials - err = self.http.Post("/credentials", request, &result) + err = client.http.Post("/credentials", request, &result) if err != nil { return Credentials{}, err } return result, nil } -func (self *ApiClient) GcpCredentialsCreate(request GcpCredentialsCreatePayload) (Credentials, error) { - organizationId, err := self.organizationId() +func (client *ApiClient) GcpCredentialsCreate(request GcpCredentialsCreatePayload) (Credentials, error) { + organizationId, err := client.organizationId() if err != nil { return Credentials{}, err } @@ -132,15 +132,15 @@ func (self *ApiClient) GcpCredentialsCreate(request GcpCredentialsCreatePayload) request.OrganizationId = organizationId var result Credentials - err = self.http.Post("/credentials", request, &result) + err = client.http.Post("/credentials", request, &result) if err != nil { return Credentials{}, err } return result, nil } -func (self *ApiClient) AzureCredentialsCreate(request AzureCredentialsCreatePayload) (Credentials, error) { - organizationId, err := self.organizationId() +func (client *ApiClient) AzureCredentialsCreate(request AzureCredentialsCreatePayload) (Credentials, error) { + organizationId, err := client.organizationId() if err != nil { return Credentials{}, err } @@ -148,26 +148,26 @@ func (self *ApiClient) AzureCredentialsCreate(request AzureCredentialsCreatePayl request.OrganizationId = organizationId var result Credentials - err = self.http.Post("/credentials", request, &result) + err = client.http.Post("/credentials", request, &result) if err != nil { return Credentials{}, err } return result, nil } -func (self *ApiClient) CloudCredentialsDelete(id string) error { - return self.http.Delete("/credentials/" + id) +func (client *ApiClient) CloudCredentialsDelete(id string) error { + return client.http.Delete("/credentials/" + id) } -func (self *ApiClient) GoogleCostCredentialsCreate(request GoogleCostCredentialsCreatePayload) (Credentials, error) { - organizationId, err := self.organizationId() +func (client *ApiClient) GoogleCostCredentialsCreate(request GoogleCostCredentialsCreatePayload) (Credentials, error) { + organizationId, err := client.organizationId() if err != nil { return Credentials{}, err } request.OrganizationId = organizationId var result Credentials - err = self.http.Post("/credentials", request, &result) + err = client.http.Post("/credentials", request, &result) if err != nil { return Credentials{}, err } diff --git a/client/cloud_credentials_project_assignment.go b/client/cloud_credentials_project_assignment.go index 15b83b9a..10e0ec28 100644 --- a/client/cloud_credentials_project_assignment.go +++ b/client/cloud_credentials_project_assignment.go @@ -10,23 +10,23 @@ type CloudCredentialsProjectAssignment struct { ProjectId string `json:"projectId"` } -func (self *ApiClient) AssignCloudCredentialsToProject(projectId string, credentialId string) (CloudCredentialsProjectAssignment, error) { +func (client *ApiClient) AssignCloudCredentialsToProject(projectId string, credentialId string) (CloudCredentialsProjectAssignment, error) { var result CloudCredentialsProjectAssignment - err := self.http.Put("/credentials/deployment/"+credentialId+"/project/"+projectId, nil, &result) + err := client.http.Put("/credentials/deployment/"+credentialId+"/project/"+projectId, nil, &result) if err != nil { return result, err } return result, nil } -func (self *ApiClient) RemoveCloudCredentialsFromProject(projectId string, credentialId string) error { - return self.http.Delete("/credentials/deployment/" + credentialId + "/project/" + projectId) +func (client *ApiClient) RemoveCloudCredentialsFromProject(projectId string, credentialId string) error { + return client.http.Delete("/credentials/deployment/" + credentialId + "/project/" + projectId) } -func (self *ApiClient) CloudCredentialIdsInProject(projectId string) ([]string, error) { +func (client *ApiClient) CloudCredentialIdsInProject(projectId string) ([]string, error) { var result CloudCredentialIdsInProjectResponse - err := self.http.Get("/credentials/deployment/project/"+projectId, nil, &result) + err := client.http.Get("/credentials/deployment/project/"+projectId, nil, &result) if err != nil { return nil, err diff --git a/client/cloud_credentials_project_assignment_test.go b/client/cloud_credentials_project_assignment_test.go index 7198a917..8229586a 100644 --- a/client/cloud_credentials_project_assignment_test.go +++ b/client/cloud_credentials_project_assignment_test.go @@ -2,6 +2,7 @@ package client_test import ( "errors" + . "github.com/env0/terraform-provider-env0/client" "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" diff --git a/client/configuration_variable.go b/client/configuration_variable.go index 72647ef5..7ff57d70 100644 --- a/client/configuration_variable.go +++ b/client/configuration_variable.go @@ -65,10 +65,10 @@ type ConfigurationVariableUpdateParams struct { Id string } -func (self *ApiClient) ConfigurationVariablesById(id string) (ConfigurationVariable, error) { +func (client *ApiClient) ConfigurationVariablesById(id string) (ConfigurationVariable, error) { var result ConfigurationVariable - err := self.http.Get("/configuration/"+id, nil, &result) + err := client.http.Get("/configuration/"+id, nil, &result) if err != nil { return ConfigurationVariable{}, err @@ -76,8 +76,8 @@ func (self *ApiClient) ConfigurationVariablesById(id string) (ConfigurationVaria return result, nil } -func (self *ApiClient) ConfigurationVariablesByScope(scope Scope, scopeId string) ([]ConfigurationVariable, error) { - organizationId, err := self.organizationId() +func (client *ApiClient) ConfigurationVariablesByScope(scope Scope, scopeId string) ([]ConfigurationVariable, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } @@ -92,22 +92,22 @@ func (self *ApiClient) ConfigurationVariablesByScope(scope Scope, scopeId string case scope == ScopeEnvironment: params["environmentId"] = scopeId case scope == ScopeDeployment: - return nil, errors.New("No api to fetch configuration variables by deployment") + return nil, errors.New("no api to fetch configuration variables by deployment") case scope == ScopeDeploymentLog: params["deploymentLogId"] = scopeId } - err = self.http.Get("/configuration", params, &result) + err = client.http.Get("/configuration", params, &result) if err != nil { return []ConfigurationVariable{}, err } return result, nil } -func (self *ApiClient) ConfigurationVariableCreate(params ConfigurationVariableCreateParams) (ConfigurationVariable, error) { +func (client *ApiClient) ConfigurationVariableCreate(params ConfigurationVariableCreateParams) (ConfigurationVariable, error) { if params.Scope == ScopeDeploymentLog || params.Scope == ScopeDeployment { - return ConfigurationVariable{}, errors.New("Must not create variable on scope deployment / deploymentLog") + return ConfigurationVariable{}, errors.New("must not create variable on scope deployment / deploymentLog") } - organizationId, err := self.organizationId() + organizationId, err := client.organizationId() if err != nil { return ConfigurationVariable{}, err } @@ -130,7 +130,7 @@ func (self *ApiClient) ConfigurationVariableCreate(params ConfigurationVariableC request["schema"] = getSchema(params) requestInArray := []map[string]interface{}{request} - err = self.http.Post("configuration", requestInArray, &result) + err = client.http.Post("configuration", requestInArray, &result) if err != nil { return ConfigurationVariable{}, err } @@ -150,16 +150,16 @@ func getSchema(params ConfigurationVariableCreateParams) map[string]interface{} return schema } -func (self *ApiClient) ConfigurationVariableDelete(id string) error { - return self.http.Delete("configuration/" + id) +func (client *ApiClient) ConfigurationVariableDelete(id string) error { + return client.http.Delete("configuration/" + id) } -func (self *ApiClient) ConfigurationVariableUpdate(updateParams ConfigurationVariableUpdateParams) (ConfigurationVariable, error) { +func (client *ApiClient) ConfigurationVariableUpdate(updateParams ConfigurationVariableUpdateParams) (ConfigurationVariable, error) { commonParams := updateParams.CommonParams if commonParams.Scope == ScopeDeploymentLog || commonParams.Scope == ScopeDeployment { - return ConfigurationVariable{}, errors.New("Must not create variable on scope deployment / deploymentLog") + return ConfigurationVariable{}, errors.New("must not create variable on scope deployment / deploymentLog") } - organizationId, err := self.organizationId() + organizationId, err := client.organizationId() if err != nil { return ConfigurationVariable{}, err } @@ -183,7 +183,7 @@ func (self *ApiClient) ConfigurationVariableUpdate(updateParams ConfigurationVar request["schema"] = getSchema(updateParams.CommonParams) requestInArray := []map[string]interface{}{request} - err = self.http.Post("/configuration", requestInArray, &result) + err = client.http.Post("/configuration", requestInArray, &result) if err != nil { return ConfigurationVariable{}, err } diff --git a/client/cost_credentials_project_assignment.go b/client/cost_credentials_project_assignment.go index ef5ad748..f9f5d5b7 100644 --- a/client/cost_credentials_project_assignment.go +++ b/client/cost_credentials_project_assignment.go @@ -6,23 +6,23 @@ type CostCredentialProjectAssignment struct { CredentialsType string `json:"credentialsType"` } -func (self *ApiClient) AssignCostCredentialsToProject(projectId string, credentialId string) (CostCredentialProjectAssignment, error) { +func (client *ApiClient) AssignCostCredentialsToProject(projectId string, credentialId string) (CostCredentialProjectAssignment, error) { var result CostCredentialProjectAssignment - err := self.http.Put("/costs/project/"+projectId+"/credentials", credentialId, &result) + err := client.http.Put("/costs/project/"+projectId+"/credentials", credentialId, &result) if err != nil { return result, err } return result, nil } -func (self *ApiClient) RemoveCostCredentialsFromProject(projectId string, credentialId string) error { - return self.http.Delete("/costs/project/" + projectId + "/credentials/" + credentialId) +func (client *ApiClient) RemoveCostCredentialsFromProject(projectId string, credentialId string) error { + return client.http.Delete("/costs/project/" + projectId + "/credentials/" + credentialId) } -func (self *ApiClient) CostCredentialIdsInProject(projectId string) ([]CostCredentialProjectAssignment, error) { +func (client *ApiClient) CostCredentialIdsInProject(projectId string) ([]CostCredentialProjectAssignment, error) { var result []CostCredentialProjectAssignment - err := self.http.Get("/costs/project/"+projectId, nil, &result) + err := client.http.Get("/costs/project/"+projectId, nil, &result) if err != nil { return nil, err diff --git a/client/environment.go b/client/environment.go index 83108263..766adcb4 100644 --- a/client/environment.go +++ b/client/environment.go @@ -92,19 +92,19 @@ type EnvironmentDeployResponse struct { Id string `json:"id"` } -func (self *ApiClient) Environments() ([]Environment, error) { +func (client *ApiClient) Environments() ([]Environment, error) { var result []Environment - err := self.http.Get("/environments", nil, &result) + err := client.http.Get("/environments", nil, &result) if err != nil { return []Environment{}, err } return result, nil } -func (self *ApiClient) ProjectEnvironments(projectId string) ([]Environment, error) { +func (client *ApiClient) ProjectEnvironments(projectId string) ([]Environment, error) { var result []Environment - err := self.http.Get("/environments", map[string]string{"projectId": projectId}, &result) + err := client.http.Get("/environments", map[string]string{"projectId": projectId}, &result) if err != nil { return []Environment{}, err @@ -112,37 +112,37 @@ func (self *ApiClient) ProjectEnvironments(projectId string) ([]Environment, err return result, nil } -func (self *ApiClient) Environment(id string) (Environment, error) { +func (client *ApiClient) Environment(id string) (Environment, error) { var result Environment - err := self.http.Get("/environments/"+id, nil, &result) + err := client.http.Get("/environments/"+id, nil, &result) if err != nil { return Environment{}, err } return result, nil } -func (self *ApiClient) EnvironmentCreate(payload EnvironmentCreate) (Environment, error) { +func (client *ApiClient) EnvironmentCreate(payload EnvironmentCreate) (Environment, error) { var result Environment - err := self.http.Post("/environments", payload, &result) + err := client.http.Post("/environments", payload, &result) if err != nil { return Environment{}, err } return result, nil } -func (self *ApiClient) EnvironmentDestroy(id string) (EnvironmentDeployResponse, error) { +func (client *ApiClient) EnvironmentDestroy(id string) (EnvironmentDeployResponse, error) { var result EnvironmentDeployResponse - err := self.http.Post("/environments/"+id+"/destroy", nil, &result) + err := client.http.Post("/environments/"+id+"/destroy", nil, &result) if err != nil { return EnvironmentDeployResponse{}, err } return result, nil } -func (self *ApiClient) EnvironmentUpdate(id string, payload EnvironmentUpdate) (Environment, error) { +func (client *ApiClient) EnvironmentUpdate(id string, payload EnvironmentUpdate) (Environment, error) { var result Environment - err := self.http.Put("/environments/"+id, payload, &result) + err := client.http.Put("/environments/"+id, payload, &result) if err != nil { return Environment{}, err @@ -150,9 +150,9 @@ func (self *ApiClient) EnvironmentUpdate(id string, payload EnvironmentUpdate) ( return result, nil } -func (self *ApiClient) EnvironmentUpdateTTL(id string, payload TTL) (Environment, error) { +func (client *ApiClient) EnvironmentUpdateTTL(id string, payload TTL) (Environment, error) { var result Environment - err := self.http.Put("/environments/"+id+"/ttl", payload, &result) + err := client.http.Put("/environments/"+id+"/ttl", payload, &result) if err != nil { return Environment{}, err @@ -160,9 +160,9 @@ func (self *ApiClient) EnvironmentUpdateTTL(id string, payload TTL) (Environment return result, nil } -func (self *ApiClient) EnvironmentDeploy(id string, payload DeployRequest) (EnvironmentDeployResponse, error) { +func (client *ApiClient) EnvironmentDeploy(id string, payload DeployRequest) (EnvironmentDeployResponse, error) { var result EnvironmentDeployResponse - err := self.http.Post("/environments/"+id+"/deployments", payload, &result) + err := client.http.Post("/environments/"+id+"/deployments", payload, &result) if err != nil { return EnvironmentDeployResponse{}, err @@ -170,9 +170,9 @@ func (self *ApiClient) EnvironmentDeploy(id string, payload DeployRequest) (Envi return result, nil } -func (self *ApiClient) Deployment(id string) (DeploymentLog, error) { +func (client *ApiClient) Deployment(id string) (DeploymentLog, error) { var result DeploymentLog - err := self.http.Get("/environments/deployments/"+id, nil, &result) + err := client.http.Get("/environments/deployments/"+id, nil, &result) if err != nil { return DeploymentLog{}, err diff --git a/client/environment_drift_detection.go b/client/environment_drift_detection.go index 2e1c42fe..2f7477d5 100644 --- a/client/environment_drift_detection.go +++ b/client/environment_drift_detection.go @@ -1,19 +1,19 @@ package client -func (self *ApiClient) EnvironmentDriftDetection(environmentId string) (EnvironmentSchedulingExpression, error) { +func (client *ApiClient) EnvironmentDriftDetection(environmentId string) (EnvironmentSchedulingExpression, error) { var result EnvironmentSchedulingExpression - err := self.http.Get("/scheduling/drift-detection/environments/"+environmentId, nil, &result) + err := client.http.Get("/scheduling/drift-detection/environments/"+environmentId, nil, &result) if err != nil { return result, err } return result, nil } -func (self *ApiClient) EnvironmentUpdateDriftDetection(environmentId string, payload EnvironmentSchedulingExpression) (EnvironmentSchedulingExpression, error) { +func (client *ApiClient) EnvironmentUpdateDriftDetection(environmentId string, payload EnvironmentSchedulingExpression) (EnvironmentSchedulingExpression, error) { var result EnvironmentSchedulingExpression - err := self.http.Patch("/scheduling/drift-detection/environments/"+environmentId, payload, &result) + err := client.http.Patch("/scheduling/drift-detection/environments/"+environmentId, payload, &result) if err != nil { return EnvironmentSchedulingExpression{}, err } @@ -21,8 +21,8 @@ func (self *ApiClient) EnvironmentUpdateDriftDetection(environmentId string, pay return result, nil } -func (self *ApiClient) EnvironmentStopDriftDetection(environmentId string) error { - err := self.http.Patch("/scheduling/drift-detection/environments/"+environmentId, EnvironmentSchedulingExpression{Enabled: false}, &EnvironmentScheduling{}) +func (client *ApiClient) EnvironmentStopDriftDetection(environmentId string) error { + err := client.http.Patch("/scheduling/drift-detection/environments/"+environmentId, EnvironmentSchedulingExpression{Enabled: false}, &EnvironmentScheduling{}) if err != nil { return err } diff --git a/client/environment_drift_detection_test.go b/client/environment_drift_detection_test.go index 2ccb12cd..42332101 100644 --- a/client/environment_drift_detection_test.go +++ b/client/environment_drift_detection_test.go @@ -2,6 +2,7 @@ package client_test import ( "errors" + . "github.com/env0/terraform-provider-env0/client" "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" diff --git a/client/environment_scheduling.go b/client/environment_scheduling.go index c9c701c6..4a7bd95a 100644 --- a/client/environment_scheduling.go +++ b/client/environment_scheduling.go @@ -12,17 +12,17 @@ type EnvironmentScheduling struct { Destroy *EnvironmentSchedulingExpression `json:"destroy,omitempty"` } -func (self *ApiClient) EnvironmentScheduling(environmentId string) (EnvironmentScheduling, error) { +func (client *ApiClient) EnvironmentScheduling(environmentId string) (EnvironmentScheduling, error) { var result EnvironmentScheduling - err := self.http.Get("/scheduling/environments/"+environmentId, nil, &result) + err := client.http.Get("/scheduling/environments/"+environmentId, nil, &result) if err != nil { return result, err } return result, nil } -func (self *ApiClient) EnvironmentSchedulingUpdate(environmentId string, payload EnvironmentScheduling) (EnvironmentScheduling, error) { +func (client *ApiClient) EnvironmentSchedulingUpdate(environmentId string, payload EnvironmentScheduling) (EnvironmentScheduling, error) { var result EnvironmentScheduling if payload.Deploy != nil && payload.Destroy != nil { @@ -31,7 +31,7 @@ func (self *ApiClient) EnvironmentSchedulingUpdate(environmentId string, payload } } - err := self.http.Put("/scheduling/environments/"+environmentId, payload, &result) + err := client.http.Put("/scheduling/environments/"+environmentId, payload, &result) if err != nil { return EnvironmentScheduling{}, err } @@ -39,8 +39,8 @@ func (self *ApiClient) EnvironmentSchedulingUpdate(environmentId string, payload return result, nil } -func (self *ApiClient) EnvironmentSchedulingDelete(environmentId string) error { - err := self.http.Put("/scheduling/environments/"+environmentId, EnvironmentScheduling{}, &EnvironmentScheduling{}) +func (client *ApiClient) EnvironmentSchedulingDelete(environmentId string) error { + err := client.http.Put("/scheduling/environments/"+environmentId, EnvironmentScheduling{}, &EnvironmentScheduling{}) if err != nil { return err } diff --git a/client/environment_scheduling_test.go b/client/environment_scheduling_test.go index 142ff347..39cb5052 100644 --- a/client/environment_scheduling_test.go +++ b/client/environment_scheduling_test.go @@ -2,6 +2,7 @@ package client_test import ( "errors" + . "github.com/env0/terraform-provider-env0/client" "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" diff --git a/client/environment_test.go b/client/environment_test.go index 73909e32..a07fdda7 100644 --- a/client/environment_test.go +++ b/client/environment_test.go @@ -2,6 +2,7 @@ package client_test import ( "errors" + . "github.com/env0/terraform-provider-env0/client" "github.com/golang/mock/gomock" "github.com/jinzhu/copier" diff --git a/client/git_token.go b/client/git_token.go index 66fe3dc4..2fc9cf27 100644 --- a/client/git_token.go +++ b/client/git_token.go @@ -18,8 +18,8 @@ type GitTokenCreatePayloadWith struct { Type string `json:"type"` } -func (ac *ApiClient) GitTokenCreate(payload GitTokenCreatePayload) (*GitToken, error) { - organizationId, err := ac.organizationId() +func (client *ApiClient) GitTokenCreate(payload GitTokenCreatePayload) (*GitToken, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } @@ -31,34 +31,34 @@ func (ac *ApiClient) GitTokenCreate(payload GitTokenCreatePayload) (*GitToken, e } var result GitToken - if err := ac.http.Post("/tokens", payloadWith, &result); err != nil { + if err := client.http.Post("/tokens", payloadWith, &result); err != nil { return nil, err } return &result, nil } -func (ac *ApiClient) GitToken(id string) (*GitToken, error) { +func (client *ApiClient) GitToken(id string) (*GitToken, error) { var result GitToken - if err := ac.http.Get("/tokens/"+id, nil, &result); err != nil { + if err := client.http.Get("/tokens/"+id, nil, &result); err != nil { return nil, err } return &result, nil } -func (ac *ApiClient) GitTokenDelete(id string) error { - return ac.http.Delete("/tokens/" + id) +func (client *ApiClient) GitTokenDelete(id string) error { + return client.http.Delete("/tokens/" + id) } -func (ac *ApiClient) GitTokens() ([]GitToken, error) { - organizationId, err := ac.organizationId() +func (client *ApiClient) GitTokens() ([]GitToken, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } var result []GitToken - if err := ac.http.Get("/tokens", map[string]string{"organizationId": organizationId, "type": "GIT"}, &result); err != nil { + if err := client.http.Get("/tokens", map[string]string{"organizationId": organizationId, "type": "GIT"}, &result); err != nil { return nil, err } diff --git a/client/http/client.go b/client/http/client.go index fce36ded..0fc9b182 100644 --- a/client/http/client.go +++ b/client/http/client.go @@ -37,11 +37,11 @@ func NewHttpClient(config HttpClientConfig) (*HttpClient, error) { }, nil } -func (self *HttpClient) request() *resty.Request { - return self.client.R().SetBasicAuth(self.ApiKey, self.ApiSecret) +func (client *HttpClient) request() *resty.Request { + return client.client.R().SetBasicAuth(client.ApiKey, client.ApiSecret) } -func (self *HttpClient) httpResult(response *resty.Response, err error) error { +func (client *HttpClient) httpResult(response *resty.Response, err error) error { if err != nil { return err } @@ -51,39 +51,39 @@ func (self *HttpClient) httpResult(response *resty.Response, err error) error { return nil } -func (self *HttpClient) Post(path string, request interface{}, response interface{}) error { - result, err := self.request(). +func (client *HttpClient) Post(path string, request interface{}, response interface{}) error { + result, err := client.request(). SetBody(request). SetResult(response). Post(path) - return self.httpResult(result, err) + return client.httpResult(result, err) } -func (self *HttpClient) Put(path string, request interface{}, response interface{}) error { - result, err := self.request(). +func (client *HttpClient) Put(path string, request interface{}, response interface{}) error { + result, err := client.request(). SetBody(request). SetResult(response). Put(path) - return self.httpResult(result, err) + return client.httpResult(result, err) } -func (self *HttpClient) Get(path string, params map[string]string, response interface{}) error { - result, err := self.request(). +func (client *HttpClient) Get(path string, params map[string]string, response interface{}) error { + result, err := client.request(). SetQueryParams(params). SetResult(response). Get(path) - return self.httpResult(result, err) + return client.httpResult(result, err) } -func (self *HttpClient) Delete(path string) error { - result, err := self.request().Delete(path) - return self.httpResult(result, err) +func (client *HttpClient) Delete(path string) error { + result, err := client.request().Delete(path) + return client.httpResult(result, err) } -func (self *HttpClient) Patch(path string, request interface{}, response interface{}) error { - result, err := self.request(). +func (client *HttpClient) Patch(path string, request interface{}, response interface{}) error { + result, err := client.request(). SetBody(request). SetResult(response). Patch(path) - return self.httpResult(result, err) + return client.httpResult(result, err) } diff --git a/client/http/client_test.go b/client/http/client_test.go index acabc7ab..7111a258 100644 --- a/client/http/client_test.go +++ b/client/http/client_test.go @@ -2,17 +2,18 @@ package http_test import ( "encoding/json" + "io" + "net/http" + "strconv" + "strings" + "testing" + httpModule "github.com/env0/terraform-provider-env0/client/http" "github.com/go-resty/resty/v2" "github.com/jarcoal/httpmock" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" - "io" - "net/http" - "strconv" - "strings" - "testing" ) // The JSON here returns camelCase keys diff --git a/client/module.go b/client/module.go index e09130c9..10b46e07 100644 --- a/client/module.go +++ b/client/module.go @@ -61,8 +61,8 @@ type ModuleUpdatePayload struct { SshKeys []ModuleSshKey `json:"sshkeys"` } -func (ac *ApiClient) ModuleCreate(payload ModuleCreatePayload) (*Module, error) { - organizationId, err := ac.organizationId() +func (client *ApiClient) ModuleCreate(payload ModuleCreatePayload) (*Module, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } @@ -74,43 +74,43 @@ func (ac *ApiClient) ModuleCreate(payload ModuleCreatePayload) (*Module, error) } var result Module - if err := ac.http.Post("/modules", payloadWith, &result); err != nil { + if err := client.http.Post("/modules", payloadWith, &result); err != nil { return nil, err } return &result, nil } -func (ac *ApiClient) Module(id string) (*Module, error) { +func (client *ApiClient) Module(id string) (*Module, error) { var result Module - if err := ac.http.Get("/modules/"+id, nil, &result); err != nil { + if err := client.http.Get("/modules/"+id, nil, &result); err != nil { return nil, err } return &result, nil } -func (ac *ApiClient) ModuleDelete(id string) error { - return ac.http.Delete("/modules/" + id) +func (client *ApiClient) ModuleDelete(id string) error { + return client.http.Delete("/modules/" + id) } -func (ac *ApiClient) ModuleUpdate(id string, payload ModuleUpdatePayload) (*Module, error) { +func (client *ApiClient) ModuleUpdate(id string, payload ModuleUpdatePayload) (*Module, error) { var result Module - if err := ac.http.Patch("/modules/"+id, payload, &result); err != nil { + if err := client.http.Patch("/modules/"+id, payload, &result); err != nil { return nil, err } return &result, nil } -func (ac *ApiClient) Modules() ([]Module, error) { - organizationId, err := ac.organizationId() +func (client *ApiClient) Modules() ([]Module, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } var result []Module - if err := ac.http.Get("/modules", map[string]string{"organizationId": organizationId}, &result); err != nil { + if err := client.http.Get("/modules", map[string]string{"organizationId": organizationId}, &result); err != nil { return nil, err } diff --git a/client/notification.go b/client/notification.go index 8fcdf9d4..d736f83e 100644 --- a/client/notification.go +++ b/client/notification.go @@ -34,23 +34,23 @@ type NotificationUpdatePayload struct { Value string `json:"value,omitempty"` } -func (ac *ApiClient) Notifications() ([]Notification, error) { - organizationId, err := ac.organizationId() +func (client *ApiClient) Notifications() ([]Notification, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } var result []Notification - if err := ac.http.Get("/notifications/endpoints", map[string]string{"organizationId": organizationId}, &result); err != nil { + if err := client.http.Get("/notifications/endpoints", map[string]string{"organizationId": organizationId}, &result); err != nil { return nil, err } return result, nil } -func (ac *ApiClient) NotificationCreate(payload NotificationCreatePayload) (*Notification, error) { +func (client *ApiClient) NotificationCreate(payload NotificationCreatePayload) (*Notification, error) { var result Notification - organizationId, err := ac.organizationId() + organizationId, err := client.organizationId() if err != nil { return nil, err } @@ -60,23 +60,23 @@ func (ac *ApiClient) NotificationCreate(payload NotificationCreatePayload) (*Not OrganizationId: organizationId, } - if err = ac.http.Post("/notifications/endpoints", payloadWithOrganizationId, &result); err != nil { + if err = client.http.Post("/notifications/endpoints", payloadWithOrganizationId, &result); err != nil { return nil, err } return &result, nil } -func (ac *ApiClient) NotificationDelete(id string) error { - if err := ac.http.Delete("/notifications/endpoints/" + id); err != nil { +func (client *ApiClient) NotificationDelete(id string) error { + if err := client.http.Delete("/notifications/endpoints/" + id); err != nil { return err } return nil } -func (ac *ApiClient) NotificationUpdate(id string, payload NotificationUpdatePayload) (*Notification, error) { +func (client *ApiClient) NotificationUpdate(id string, payload NotificationUpdatePayload) (*Notification, error) { var result Notification - if err := ac.http.Patch("/notifications/endpoints/"+id, payload, &result); err != nil { + if err := client.http.Patch("/notifications/endpoints/"+id, payload, &result); err != nil { return nil, err } return &result, nil diff --git a/client/notification_project_assignment.go b/client/notification_project_assignment.go index 59febf40..3eb74cc7 100644 --- a/client/notification_project_assignment.go +++ b/client/notification_project_assignment.go @@ -14,18 +14,18 @@ type NotificationProjectAssignmentUpdatePayload struct { EventNames []string `json:"eventNames"` } -func (ac *ApiClient) NotificationProjectAssignments(projectId string) ([]NotificationProjectAssignment, error) { +func (client *ApiClient) NotificationProjectAssignments(projectId string) ([]NotificationProjectAssignment, error) { var result []NotificationProjectAssignment - if err := ac.http.Get("/notifications/projects/"+projectId, nil, &result); err != nil { + if err := client.http.Get("/notifications/projects/"+projectId, nil, &result); err != nil { return nil, err } return result, nil } -func (ac *ApiClient) NotificationProjectAssignmentUpdate(projectId string, endpointId string, payload NotificationProjectAssignmentUpdatePayload) (*NotificationProjectAssignment, error) { +func (client *ApiClient) NotificationProjectAssignmentUpdate(projectId string, endpointId string, payload NotificationProjectAssignmentUpdatePayload) (*NotificationProjectAssignment, error) { var result NotificationProjectAssignment url := fmt.Sprintf("/notifications/projects/%s/endpoints/%s", projectId, endpointId) - if err := ac.http.Put(url, payload, &result); err != nil { + if err := client.http.Put(url, payload, &result); err != nil { return nil, err } return &result, nil diff --git a/client/organization.go b/client/organization.go index 445d8282..8a0c28ba 100644 --- a/client/organization.go +++ b/client/organization.go @@ -28,9 +28,9 @@ type OrganizationPolicyUpdatePayload struct { DoNotConsiderMergeCommitsForPrPlans *bool `json:"doNotConsiderMergeCommitsForPrPlans,omitempty"` } -func (ac *ApiClient) Organization() (Organization, error) { +func (client *ApiClient) Organization() (Organization, error) { var result []Organization - err := ac.http.Get("/organizations", nil, &result) + err := client.http.Get("/organizations", nil, &result) if err != nil { return Organization{}, err } @@ -40,26 +40,26 @@ func (ac *ApiClient) Organization() (Organization, error) { return result[0], nil } -func (ac *ApiClient) organizationId() (string, error) { - if ac.cachedOrganizationId != "" { - return ac.cachedOrganizationId, nil +func (client *ApiClient) organizationId() (string, error) { + if client.cachedOrganizationId != "" { + return client.cachedOrganizationId, nil } - organization, err := ac.Organization() + organization, err := client.Organization() if err != nil { return "", nil } - ac.cachedOrganizationId = organization.Id - return ac.cachedOrganizationId, nil + client.cachedOrganizationId = organization.Id + return client.cachedOrganizationId, nil } -func (ac *ApiClient) OrganizationPolicyUpdate(payload OrganizationPolicyUpdatePayload) (*Organization, error) { - id, err := ac.organizationId() +func (client *ApiClient) OrganizationPolicyUpdate(payload OrganizationPolicyUpdatePayload) (*Organization, error) { + id, err := client.organizationId() if err != nil { return nil, err } var result Organization - if err := ac.http.Post("/organizations/"+id+"/policies", payload, &result); err != nil { + if err := client.http.Post("/organizations/"+id+"/policies", payload, &result); err != nil { return nil, err } diff --git a/client/project.go b/client/project.go index a643e074..d805047c 100644 --- a/client/project.go +++ b/client/project.go @@ -18,50 +18,50 @@ type ProjectCreatePayload struct { Description string `json:"description"` } -func (self *ApiClient) Projects() ([]Project, error) { - organizationId, err := self.organizationId() +func (client *ApiClient) Projects() ([]Project, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } var result []Project - err = self.http.Get("/projects", map[string]string{"organizationId": organizationId}, &result) + err = client.http.Get("/projects", map[string]string{"organizationId": organizationId}, &result) if err != nil { return []Project{}, err } return result, nil } -func (self *ApiClient) Project(id string) (Project, error) { +func (client *ApiClient) Project(id string) (Project, error) { var result Project - err := self.http.Get("/projects/"+id, nil, &result) + err := client.http.Get("/projects/"+id, nil, &result) if err != nil { return Project{}, err } return result, nil } -func (self *ApiClient) ProjectCreate(payload ProjectCreatePayload) (Project, error) { +func (client *ApiClient) ProjectCreate(payload ProjectCreatePayload) (Project, error) { var result Project - organizationId, err := self.organizationId() + organizationId, err := client.organizationId() if err != nil { return Project{}, err } request := map[string]interface{}{"name": payload.Name, "organizationId": organizationId, "description": payload.Description} - err = self.http.Post("/projects", request, &result) + err = client.http.Post("/projects", request, &result) if err != nil { return Project{}, err } return result, nil } -func (self *ApiClient) ProjectDelete(id string) error { - return self.http.Delete("/projects/" + id) +func (client *ApiClient) ProjectDelete(id string) error { + return client.http.Delete("/projects/" + id) } -func (self *ApiClient) ProjectUpdate(id string, payload ProjectCreatePayload) (Project, error) { +func (client *ApiClient) ProjectUpdate(id string, payload ProjectCreatePayload) (Project, error) { var result Project - err := self.http.Put("/projects/"+id, payload, &result) + err := client.http.Put("/projects/"+id, payload, &result) if err != nil { return Project{}, err diff --git a/client/project_policy.go b/client/project_policy.go index 8727151b..7cff7c09 100644 --- a/client/project_policy.go +++ b/client/project_policy.go @@ -66,14 +66,14 @@ func (p PolicyUpdatePayload) MarshalJSON() ([]byte, error) { } // Policy retrieves a policy from the API -func (self *ApiClient) Policy(projectId string) (Policy, error) { +func (client *ApiClient) Policy(projectId string) (Policy, error) { u, err := newQueryURL("/policies", parameter{"projectId", projectId}) if err != nil { return Policy{}, err } var result Policy - err = self.http.Get(u.String(), nil, &result) + err = client.http.Get(u.String(), nil, &result) if err != nil { return Policy{}, err } @@ -81,9 +81,9 @@ func (self *ApiClient) Policy(projectId string) (Policy, error) { } // PolicyUpdate updates a policy through the API -func (self *ApiClient) PolicyUpdate(payload PolicyUpdatePayload) (Policy, error) { +func (client *ApiClient) PolicyUpdate(payload PolicyUpdatePayload) (Policy, error) { var result Policy - err := self.http.Put("/policies", payload, &result) + err := client.http.Put("/policies", payload, &result) if err != nil { return Policy{}, err } diff --git a/client/sshkey.go b/client/sshkey.go index a2efdf45..2f326e7e 100644 --- a/client/sshkey.go +++ b/client/sshkey.go @@ -18,31 +18,31 @@ type SshKeyCreatePayload struct { Value string `json:"value"` } -func (self *ApiClient) SshKeyCreate(payload SshKeyCreatePayload) (*SshKey, error) { - organizationId, err := self.organizationId() +func (client *ApiClient) SshKeyCreate(payload SshKeyCreatePayload) (*SshKey, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } payload.OrganizationId = organizationId var result SshKey - if err := self.http.Post("/ssh-keys", payload, &result); err != nil { + if err := client.http.Post("/ssh-keys", payload, &result); err != nil { return nil, err } return &result, nil } -func (self *ApiClient) SshKeyDelete(id string) error { - return self.http.Delete("/ssh-keys/" + id) +func (client *ApiClient) SshKeyDelete(id string) error { + return client.http.Delete("/ssh-keys/" + id) } -func (self *ApiClient) SshKeys() ([]SshKey, error) { - organizationId, err := self.organizationId() +func (client *ApiClient) SshKeys() ([]SshKey, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } var result []SshKey - err = self.http.Get("/ssh-keys", map[string]string{"organizationId": organizationId}, &result) + err = client.http.Get("/ssh-keys", map[string]string{"organizationId": organizationId}, &result) if err != nil { return nil, err } diff --git a/client/team.go b/client/team.go index d5f4a7c8..e8ec68c9 100644 --- a/client/team.go +++ b/client/team.go @@ -20,60 +20,60 @@ type Team struct { OrganizationId string `json:"organizationId"` } -func (self *ApiClient) TeamCreate(payload TeamCreatePayload) (Team, error) { +func (client *ApiClient) TeamCreate(payload TeamCreatePayload) (Team, error) { if payload.Name == "" { - return Team{}, errors.New("Must specify team name on creation") + return Team{}, errors.New("must specify team name on creation") } if payload.OrganizationId != "" { - return Team{}, errors.New("Must not specify organizationId") + return Team{}, errors.New("must not specify organizationId") } - organizationId, err := self.organizationId() + organizationId, err := client.organizationId() if err != nil { return Team{}, err } payload.OrganizationId = organizationId var result Team - err = self.http.Post("/teams", payload, &result) + err = client.http.Post("/teams", payload, &result) if err != nil { return Team{}, err } return result, nil } -func (self *ApiClient) Team(id string) (Team, error) { +func (client *ApiClient) Team(id string) (Team, error) { var result Team - err := self.http.Get("/teams/"+id, nil, &result) + err := client.http.Get("/teams/"+id, nil, &result) if err != nil { return Team{}, err } return result, nil } -func (self *ApiClient) TeamDelete(id string) error { - return self.http.Delete("/teams/" + id) +func (client *ApiClient) TeamDelete(id string) error { + return client.http.Delete("/teams/" + id) } -func (self *ApiClient) TeamUpdate(id string, payload TeamUpdatePayload) (Team, error) { +func (client *ApiClient) TeamUpdate(id string, payload TeamUpdatePayload) (Team, error) { if payload.Name == "" { - return Team{}, errors.New("Must specify team name on update") + return Team{}, errors.New("must specify team name on update") } var result Team - err := self.http.Put("/teams/"+id, payload, &result) + err := client.http.Put("/teams/"+id, payload, &result) if err != nil { return Team{}, err } return result, nil } -func (self *ApiClient) Teams() ([]Team, error) { - organizationId, err := self.organizationId() +func (client *ApiClient) Teams() ([]Team, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } var result []Team - err = self.http.Get("/teams/organizations/"+organizationId, nil, &result) + err = client.http.Get("/teams/organizations/"+organizationId, nil, &result) if err != nil { return nil, err } diff --git a/client/team_project_assignment.go b/client/team_project_assignment.go index f1ae26d6..d22c55fe 100644 --- a/client/team_project_assignment.go +++ b/client/team_project_assignment.go @@ -26,7 +26,7 @@ type TeamProjectAssignment struct { ProjectRole Role `json:"projectRole"` } -func (self *ApiClient) TeamProjectAssignmentCreateOrUpdate(payload TeamProjectAssignmentPayload) (TeamProjectAssignment, error) { +func (client *ApiClient) TeamProjectAssignmentCreateOrUpdate(payload TeamProjectAssignmentPayload) (TeamProjectAssignment, error) { if payload.ProjectId == "" { return TeamProjectAssignment{}, errors.New("must specify project_id") } @@ -42,7 +42,7 @@ func (self *ApiClient) TeamProjectAssignmentCreateOrUpdate(payload TeamProjectAs } var result TeamProjectAssignment - var err = self.http.Post("/teams/assignments", payload, &result) + var err = client.http.Post("/teams/assignments", payload, &result) if err != nil { return TeamProjectAssignment{}, err @@ -50,17 +50,17 @@ func (self *ApiClient) TeamProjectAssignmentCreateOrUpdate(payload TeamProjectAs return result, nil } -func (self *ApiClient) TeamProjectAssignmentDelete(assignmentId string) error { +func (client *ApiClient) TeamProjectAssignmentDelete(assignmentId string) error { if assignmentId == "" { return errors.New("empty assignmentId") } - return self.http.Delete("/teams/assignments/" + assignmentId) + return client.http.Delete("/teams/assignments/" + assignmentId) } -func (self *ApiClient) TeamProjectAssignments(projectId string) ([]TeamProjectAssignment, error) { +func (client *ApiClient) TeamProjectAssignments(projectId string) ([]TeamProjectAssignment, error) { var result []TeamProjectAssignment - err := self.http.Get("/teams/assignments", map[string]string{"projectId": projectId}, &result) + err := client.http.Get("/teams/assignments", map[string]string{"projectId": projectId}, &result) if err != nil { return []TeamProjectAssignment{}, err diff --git a/client/team_project_assignment_test.go b/client/team_project_assignment_test.go index 5aa1a817..fa1ea03f 100644 --- a/client/team_project_assignment_test.go +++ b/client/team_project_assignment_test.go @@ -2,6 +2,7 @@ package client_test import ( "errors" + . "github.com/env0/terraform-provider-env0/client" "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" diff --git a/client/team_test.go b/client/team_test.go index 20f84005..2fb12330 100644 --- a/client/team_test.go +++ b/client/team_test.go @@ -2,6 +2,7 @@ package client_test import ( "errors" + . "github.com/env0/terraform-provider-env0/client" "github.com/golang/mock/gomock" "github.com/jinzhu/copier" @@ -107,13 +108,13 @@ var _ = Describe("Teams Client", func() { It("Should fail when team has no name", func() { teamWithoutNamePayload := TeamCreatePayload{Description: "team-without-name"} _, err := apiClient.TeamCreate(teamWithoutNamePayload) - Expect(err).To(BeEquivalentTo(errors.New("Must specify team name on creation"))) + Expect(err).To(BeEquivalentTo(errors.New("must specify team name on creation"))) }) It("Should fail if request includes organizationId (should be inferred automatically)", func() { payloadWithOrgId := TeamCreatePayload{Name: "team-name", OrganizationId: "org-id"} _, err := apiClient.TeamCreate(payloadWithOrgId) - Expect(err).To(BeEquivalentTo(errors.New("Must not specify organizationId"))) + Expect(err).To(BeEquivalentTo(errors.New("must not specify organizationId"))) }) }) }) @@ -163,7 +164,7 @@ var _ = Describe("Teams Client", func() { It("Should fail if team has no name", func() { payloadWithNoName := TeamUpdatePayload{Description: "team-without-name"} _, err := apiClient.TeamUpdate(mockTeam.Id, payloadWithNoName) - Expect(err).To(BeEquivalentTo(errors.New("Must specify team name on update"))) + Expect(err).To(BeEquivalentTo(errors.New("must specify team name on update"))) }) }) }) diff --git a/client/template.go b/client/template.go index 3d71f458..5ddb7526 100644 --- a/client/template.go +++ b/client/template.go @@ -93,98 +93,98 @@ type TemplateAssignmentToProject struct { ProjectId string `json:"projectId"` } -func (self *ApiClient) TemplateCreate(payload TemplateCreatePayload) (Template, error) { +func (client *ApiClient) TemplateCreate(payload TemplateCreatePayload) (Template, error) { if payload.Name == "" { - return Template{}, errors.New("Must specify template name on creation") + return Template{}, errors.New("must specify template name on creation") } if payload.OrganizationId != "" { - return Template{}, errors.New("Must not specify organizationId") + return Template{}, errors.New("must not specify organizationId") } if payload.Type != "terragrunt" && payload.TerragruntVersion != "" { - return Template{}, errors.New("Can't define terragrunt version for non-terragrunt blueprint") + return Template{}, errors.New("can't define terragrunt version for non-terragrunt blueprint") } if payload.Type == "terragrunt" && payload.TerragruntVersion == "" { - return Template{}, errors.New("Must supply Terragrunt version") + return Template{}, errors.New("must supply Terragrunt version") } - organizationId, err := self.organizationId() + organizationId, err := client.organizationId() if err != nil { return Template{}, nil } payload.OrganizationId = organizationId var result Template - err = self.http.Post("/blueprints", payload, &result) + err = client.http.Post("/blueprints", payload, &result) if err != nil { return Template{}, err } return result, nil } -func (self *ApiClient) Template(id string) (Template, error) { +func (client *ApiClient) Template(id string) (Template, error) { var result Template - err := self.http.Get("/blueprints/"+id, nil, &result) + err := client.http.Get("/blueprints/"+id, nil, &result) if err != nil { return Template{}, err } return result, nil } -func (self *ApiClient) TemplateDelete(id string) error { - return self.http.Delete("/blueprints/" + id) +func (client *ApiClient) TemplateDelete(id string) error { + return client.http.Delete("/blueprints/" + id) } -func (self *ApiClient) TemplateUpdate(id string, payload TemplateCreatePayload) (Template, error) { +func (client *ApiClient) TemplateUpdate(id string, payload TemplateCreatePayload) (Template, error) { if payload.Name == "" { - return Template{}, errors.New("Must specify template name on creation") + return Template{}, errors.New("must specify template name on creation") } if payload.OrganizationId != "" { - return Template{}, errors.New("Must not specify organizationId") + return Template{}, errors.New("must not specify organizationId") } if payload.Type != "terragrunt" && payload.TerragruntVersion != "" { - return Template{}, errors.New("Can't define terragrunt version for non-terragrunt blueprint") + return Template{}, errors.New("can't define terragrunt version for non-terragrunt blueprint") } if payload.Type == "terragrunt" && payload.TerragruntVersion == "" { - return Template{}, errors.New("Must supply Terragrunt version") + return Template{}, errors.New("must supply Terragrunt version") } - organizationId, err := self.organizationId() + organizationId, err := client.organizationId() if err != nil { return Template{}, err } payload.OrganizationId = organizationId var result Template - err = self.http.Put("/blueprints/"+id, payload, &result) + err = client.http.Put("/blueprints/"+id, payload, &result) if err != nil { return Template{}, err } return result, nil } -func (self *ApiClient) Templates() ([]Template, error) { - organizationId, err := self.organizationId() +func (client *ApiClient) Templates() ([]Template, error) { + organizationId, err := client.organizationId() if err != nil { return nil, err } var result []Template - err = self.http.Get("/blueprints", map[string]string{"organizationId": organizationId}, &result) + err = client.http.Get("/blueprints", map[string]string{"organizationId": organizationId}, &result) if err != nil { return nil, err } return result, err } -func (self *ApiClient) AssignTemplateToProject(id string, payload TemplateAssignmentToProjectPayload) (Template, error) { +func (client *ApiClient) AssignTemplateToProject(id string, payload TemplateAssignmentToProjectPayload) (Template, error) { var result Template if payload.ProjectId == "" { - return result, errors.New("Must specify projectId on assignment to a template") + return result, errors.New("must specify projectId on assignment to a template") } - err := self.http.Patch("/blueprints/"+id+"/projects", payload, &result) + err := client.http.Patch("/blueprints/"+id+"/projects", payload, &result) if err != nil { return result, err } return result, nil } -func (self *ApiClient) RemoveTemplateFromProject(templateId string, projectId string) error { - return self.http.Delete("/blueprints/" + templateId + "/projects/" + projectId) +func (client *ApiClient) RemoveTemplateFromProject(templateId string, projectId string) error { + return client.http.Delete("/blueprints/" + templateId + "/projects/" + projectId) } diff --git a/client/template_test.go b/client/template_test.go index 5e6f328c..d902697d 100644 --- a/client/template_test.go +++ b/client/template_test.go @@ -203,7 +203,7 @@ var _ = Describe("Templates Client", func() { }) It("should return an error on empty projectId", func() { assignedTemplate, err = apiClient.AssignTemplateToProject(mockTemplate.Id, TemplateAssignmentToProjectPayload{}) - Expect(err).To(BeEquivalentTo(errors.New("Must specify projectId on assignment to a template"))) + Expect(err).To(BeEquivalentTo(errors.New("must specify projectId on assignment to a template"))) }) }) diff --git a/client/workflow_triggers.go b/client/workflow_triggers.go index 10f752b0..f99d6710 100644 --- a/client/workflow_triggers.go +++ b/client/workflow_triggers.go @@ -8,9 +8,9 @@ type WorkflowTriggerUpsertPayload struct { DownstreamEnvironmentIds []string `json:"downstreamEnvironmentIds"` } -func (self *ApiClient) WorkflowTrigger(environmentId string) ([]WorkflowTrigger, error) { +func (client *ApiClient) WorkflowTrigger(environmentId string) ([]WorkflowTrigger, error) { var result []WorkflowTrigger - err := self.http.Get("environments/"+environmentId+"/downstream", nil, &result) + err := client.http.Get("environments/"+environmentId+"/downstream", nil, &result) if err != nil { return []WorkflowTrigger{}, err } @@ -18,10 +18,10 @@ func (self *ApiClient) WorkflowTrigger(environmentId string) ([]WorkflowTrigger, return result, nil } -func (self *ApiClient) WorkflowTriggerUpsert(environmentId string, request WorkflowTriggerUpsertPayload) ([]WorkflowTrigger, error) { +func (client *ApiClient) WorkflowTriggerUpsert(environmentId string, request WorkflowTriggerUpsertPayload) ([]WorkflowTrigger, error) { var result []WorkflowTrigger - err := self.http.Put("/environments/"+environmentId+"/downstream", request, &result) + err := client.http.Put("/environments/"+environmentId+"/downstream", request, &result) if err != nil { return []WorkflowTrigger{}, err } diff --git a/env0/data_organization.go b/env0/data_organization.go index b73464ed..38d1af2b 100644 --- a/env0/data_organization.go +++ b/env0/data_organization.go @@ -2,6 +2,7 @@ package env0 import ( "context" + "github.com/env0/terraform-provider-env0/client" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/env0/data_organization_test.go b/env0/data_organization_test.go index efafbb15..ca6d058f 100644 --- a/env0/data_organization_test.go +++ b/env0/data_organization_test.go @@ -1,10 +1,11 @@ package env0 import ( - "github.com/env0/terraform-provider-env0/client" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "strconv" "testing" + + "github.com/env0/terraform-provider-env0/client" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestUnitOrganizationData(t *testing.T) { diff --git a/env0/data_team.go b/env0/data_team.go index dde86c0b..b04b1dd4 100644 --- a/env0/data_team.go +++ b/env0/data_team.go @@ -2,6 +2,7 @@ package env0 import ( "context" + "github.com/env0/terraform-provider-env0/client" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/env0/data_template.go b/env0/data_template.go index b597b5d7..a9243bf6 100644 --- a/env0/data_template.go +++ b/env0/data_template.go @@ -163,7 +163,7 @@ func dataTemplateRead(ctx context.Context, d *schema.ResourceData, meta interfac d.Set("gitlab_project_id", template.GitlabProjectId) } - if template.IsGitlabEnterprise == true { + if template.IsGitlabEnterprise { d.Set("is_gitlab_enterprise", template.IsGitlabEnterprise) } diff --git a/env0/data_workflow_triggers.go b/env0/data_workflow_triggers.go index 1b8c6a86..fe518650 100644 --- a/env0/data_workflow_triggers.go +++ b/env0/data_workflow_triggers.go @@ -2,6 +2,7 @@ package env0 import ( "context" + "github.com/env0/terraform-provider-env0/client" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/env0/resource_drift_detection.go b/env0/resource_drift_detection.go index 80e9bbff..7c29d9a2 100644 --- a/env0/resource_drift_detection.go +++ b/env0/resource_drift_detection.go @@ -2,7 +2,8 @@ package env0 import ( "context" - . "github.com/env0/terraform-provider-env0/client" + + "github.com/env0/terraform-provider-env0/client" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -32,7 +33,7 @@ func resourceDriftDetection() *schema.Resource { } func resourceEnvironmentDriftRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - apiClient := meta.(ApiClientInterface) + apiClient := meta.(client.ApiClientInterface) environmentId := d.Id() @@ -51,12 +52,12 @@ func resourceEnvironmentDriftRead(_ context.Context, d *schema.ResourceData, met } func resourceEnvironmentDriftCreateOrUpdate(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - apiClient := meta.(ApiClientInterface) + apiClient := meta.(client.ApiClientInterface) environmentId := d.Get("environment_id").(string) cron := d.Get("cron").(string) - payload := EnvironmentSchedulingExpression{Cron: cron, Enabled: true} + payload := client.EnvironmentSchedulingExpression{Cron: cron, Enabled: true} _, err := apiClient.EnvironmentUpdateDriftDetection(environmentId, payload) @@ -69,7 +70,7 @@ func resourceEnvironmentDriftCreateOrUpdate(_ context.Context, d *schema.Resourc } func resourceEnvironmentDriftDelete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - apiClient := meta.(ApiClientInterface) + apiClient := meta.(client.ApiClientInterface) environmentId := d.Id() diff --git a/env0/resource_drift_detection_test.go b/env0/resource_drift_detection_test.go index 17d63fac..9f09209b 100644 --- a/env0/resource_drift_detection_test.go +++ b/env0/resource_drift_detection_test.go @@ -1,10 +1,11 @@ package env0 import ( + "testing" + "github.com/env0/terraform-provider-env0/client" "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "testing" ) func TestUnitEnvironmentDriftDetectionResource(t *testing.T) { diff --git a/env0/resource_environment.go b/env0/resource_environment.go index 90a7dd99..59912a3d 100644 --- a/env0/resource_environment.go +++ b/env0/resource_environment.go @@ -468,11 +468,10 @@ func getCreatePayload(d *schema.ResourceData, apiClient client.ApiClientInterfac func assertDeploymentTriggers(autoDeployByCustomGlob string, continuousDeployment bool, pullRequestPlanDeployments bool, autoDeployOnPathChangesOnly bool) diag.Diagnostics { if autoDeployByCustomGlob != "" { - if (continuousDeployment == false) && - (pullRequestPlanDeployments == false) { + if !continuousDeployment && !pullRequestPlanDeployments { return diag.Errorf("run_plan_on_pull_requests or deploy_on_push must be enabled for auto_deploy_by_custom_glob") } - if autoDeployOnPathChangesOnly == false { + if !autoDeployOnPathChangesOnly { return diag.Errorf("cannot set auto_deploy_by_custom_glob when auto_deploy_on_path_changes_only is disabled") } } @@ -530,7 +529,7 @@ func getDeployPayload(d *schema.ResourceData, apiClient client.ApiClientInterfac payload.ConfigurationChanges = &configurationChanges } - if userRequiresApproval, ok := d.GetOkExists("requires_approval"); ok { + if userRequiresApproval, ok := d.GetOk("requires_approval"); ok { userRequiresApproval := userRequiresApproval.(bool) payload.UserRequiresApproval = &userRequiresApproval } @@ -573,7 +572,7 @@ func getConfigurationVariables(configuration []interface{}) client.Configuration func deleteUnusedConfigurationVariables(configurationChanges client.ConfigurationChanges, existVariables client.ConfigurationChanges) client.ConfigurationChanges { for _, existVariable := range existVariables { - if isExist, _ := isVariableExist(configurationChanges, existVariable); isExist != true { + if isExist, _ := isVariableExist(configurationChanges, existVariable); !isExist { toDelete := true existVariable.ToDelete = &toDelete configurationChanges = append(configurationChanges, existVariable) @@ -703,7 +702,7 @@ func resourceEnvironmentImport(ctx context.Context, d *schema.ResourceData, meta d.SetId(environment.Id) environmentConfigurationVariables, err := apiClient.ConfigurationVariablesByScope(client.ScopeEnvironment, environment.Id) if err != nil { - return nil, errors.New(fmt.Sprintf("could not get environment configuration variables: %v", err)) + return nil, fmt.Errorf("could not get environment configuration variables: %v", err) } d.Set("deployment_id", environment.LatestDeploymentLogId) setEnvironmentSchema(d, environment, environmentConfigurationVariables) diff --git a/env0/resource_environment_scheduling.go b/env0/resource_environment_scheduling.go index 24f4ec14..538fccd3 100644 --- a/env0/resource_environment_scheduling.go +++ b/env0/resource_environment_scheduling.go @@ -3,7 +3,7 @@ package env0 import ( "context" - . "github.com/env0/terraform-provider-env0/client" + "github.com/env0/terraform-provider-env0/client" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -41,7 +41,7 @@ func resourceEnvironmentScheduling() *schema.Resource { } func resourceEnvironmentSchedulingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - apiClient := meta.(ApiClientInterface) + apiClient := meta.(client.ApiClientInterface) environmentId := d.Id() @@ -68,20 +68,20 @@ func resourceEnvironmentSchedulingRead(ctx context.Context, d *schema.ResourceDa } func resourceEnvironmentSchedulingCreateOrUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - apiClient := meta.(ApiClientInterface) + apiClient := meta.(client.ApiClientInterface) environmentId := d.Get("environment_id").(string) deployCron := d.Get("deploy_cron").(string) destroyCron := d.Get("destroy_cron").(string) - payload := EnvironmentScheduling{} + payload := client.EnvironmentScheduling{} if deployCron != "" { - payload.Deploy = &EnvironmentSchedulingExpression{Cron: deployCron, Enabled: true} + payload.Deploy = &client.EnvironmentSchedulingExpression{Cron: deployCron, Enabled: true} } if destroyCron != "" { - payload.Destroy = &EnvironmentSchedulingExpression{Cron: destroyCron, Enabled: true} + payload.Destroy = &client.EnvironmentSchedulingExpression{Cron: destroyCron, Enabled: true} } _, err := apiClient.EnvironmentSchedulingUpdate(environmentId, payload) @@ -95,7 +95,7 @@ func resourceEnvironmentSchedulingCreateOrUpdate(ctx context.Context, d *schema. } func resourceEnvironmentSchedulingDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - apiClient := meta.(ApiClientInterface) + apiClient := meta.(client.ApiClientInterface) environmentId := d.Id() diff --git a/env0/resource_environment_scheduling_test.go b/env0/resource_environment_scheduling_test.go index 94f8c42e..1c7922c3 100644 --- a/env0/resource_environment_scheduling_test.go +++ b/env0/resource_environment_scheduling_test.go @@ -2,10 +2,11 @@ package env0 import ( "fmt" - "github.com/env0/terraform-provider-env0/client" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "regexp" "testing" + + "github.com/env0/terraform-provider-env0/client" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) func TestUnitEnvironmentSchedulingResource(t *testing.T) { diff --git a/env0/resource_environment_test.go b/env0/resource_environment_test.go index 9571b841..ead16c6c 100644 --- a/env0/resource_environment_test.go +++ b/env0/resource_environment_test.go @@ -178,7 +178,7 @@ func TestUnitEnvironmentResource(t *testing.T) { type = "%s" %s } - + `, variable.Name, variable.Value, varType, schemaFormat) } @@ -194,7 +194,7 @@ func TestUnitEnvironmentResource(t *testing.T) { revision = "%s" force_destroy = true %s - + }`, resourceType, resourceName, env.Name, env.ProjectId, env.LatestDeploymentLog.BlueprintId, diff --git a/env0/resource_team_project_assignment.go b/env0/resource_team_project_assignment.go index a5514b8f..604487f3 100644 --- a/env0/resource_team_project_assignment.go +++ b/env0/resource_team_project_assignment.go @@ -5,7 +5,7 @@ import ( "fmt" "log" - . "github.com/env0/terraform-provider-env0/client" + "github.com/env0/terraform-provider-env0/client" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -35,12 +35,12 @@ func resourceTeamProjectAssignment() *schema.Resource { Description: "the assigned role (Admin, Planner, Viewer, Deployer)", Required: true, ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { - role := Role(val.(string)) + role := client.Role(val.(string)) if role == "" || - role != Admin && - role != Deployer && - role != Viewer && - role != Planner { + role != client.Admin && + role != client.Deployer && + role != client.Viewer && + role != client.Planner { errs = append(errs, fmt.Errorf("%v must be one of [Admin, Deployer, Viewer, Planner], got: %v", key, role)) } return @@ -51,7 +51,7 @@ func resourceTeamProjectAssignment() *schema.Resource { } func resourceTeamProjectAssignmentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - apiClient := meta.(ApiClientInterface) + apiClient := meta.(client.ApiClientInterface) id := d.Id() projectId := d.Get("project_id").(string) @@ -79,12 +79,12 @@ func resourceTeamProjectAssignmentRead(ctx context.Context, d *schema.ResourceDa } func resourceTeamProjectAssignmentCreateOrUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - apiClient := meta.(ApiClientInterface) + apiClient := meta.(client.ApiClientInterface) - request := TeamProjectAssignmentPayload{ + request := client.TeamProjectAssignmentPayload{ TeamId: d.Get("team_id").(string), ProjectId: d.Get("project_id").(string), - ProjectRole: Role(d.Get("role").(string)), + ProjectRole: client.Role(d.Get("role").(string)), } response, err := apiClient.TeamProjectAssignmentCreateOrUpdate(request) if err != nil { @@ -97,7 +97,7 @@ func resourceTeamProjectAssignmentCreateOrUpdate(ctx context.Context, d *schema. } func resourceTeamProjectAssignmentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - apiClient := meta.(ApiClientInterface) + apiClient := meta.(client.ApiClientInterface) err := apiClient.TeamProjectAssignmentDelete(d.Id()) if err != nil { diff --git a/env0/resource_workflow_triggers.go b/env0/resource_workflow_triggers.go index 89147e9c..6c0ab54d 100644 --- a/env0/resource_workflow_triggers.go +++ b/env0/resource_workflow_triggers.go @@ -3,7 +3,7 @@ package env0 import ( "context" - . "github.com/env0/terraform-provider-env0/client" + "github.com/env0/terraform-provider-env0/client" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -36,7 +36,7 @@ func resourceWorkflowTriggers() *schema.Resource { } func resourceWorkflowTriggersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - apiClient := meta.(ApiClientInterface) + apiClient := meta.(client.ApiClientInterface) environmentId := d.Get("environment_id").(string) @@ -56,7 +56,7 @@ func resourceWorkflowTriggersRead(ctx context.Context, d *schema.ResourceData, m } func resourceWorkflowTriggersCreateOrUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - apiClient := meta.(ApiClientInterface) + apiClient := meta.(client.ApiClientInterface) environmentId := d.Get("environment_id").(string) rawDownstreamIds := d.Get("downstream_environment_ids").([]interface{}) var requestDownstreamIds []string @@ -64,7 +64,7 @@ func resourceWorkflowTriggersCreateOrUpdate(ctx context.Context, d *schema.Resou for _, rawId := range rawDownstreamIds { requestDownstreamIds = append(requestDownstreamIds, rawId.(string)) } - request := WorkflowTriggerUpsertPayload{ + request := client.WorkflowTriggerUpsertPayload{ DownstreamEnvironmentIds: requestDownstreamIds, } triggers, err := apiClient.WorkflowTriggerUpsert(environmentId, request) @@ -83,9 +83,9 @@ func resourceWorkflowTriggersCreateOrUpdate(ctx context.Context, d *schema.Resou } func resourceWorkflowTriggersDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - apiClient := meta.(ApiClientInterface) + apiClient := meta.(client.ApiClientInterface) - _, err := apiClient.WorkflowTriggerUpsert(d.Id(), WorkflowTriggerUpsertPayload{DownstreamEnvironmentIds: []string{}}) + _, err := apiClient.WorkflowTriggerUpsert(d.Id(), client.WorkflowTriggerUpsertPayload{DownstreamEnvironmentIds: []string{}}) if err != nil { return diag.Errorf("could not remove workflow triggers: %v", err) } diff --git a/env0/resource_workflow_triggers_test.go b/env0/resource_workflow_triggers_test.go index 0ffb9ef7..fd043634 100644 --- a/env0/resource_workflow_triggers_test.go +++ b/env0/resource_workflow_triggers_test.go @@ -2,11 +2,12 @@ package env0 import ( "errors" + "regexp" + "testing" + "github.com/env0/terraform-provider-env0/client" "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "regexp" - "testing" ) func TestUnitWorkflowTriggerResource(t *testing.T) { diff --git a/env0/test_helpers.go b/env0/test_helpers.go index 93432532..fe9fb9e3 100644 --- a/env0/test_helpers.go +++ b/env0/test_helpers.go @@ -2,8 +2,9 @@ package env0 import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "regexp" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) // TFSource Enum diff --git a/main.go b/main.go index 256e01f3..c3568023 100644 --- a/main.go +++ b/main.go @@ -3,9 +3,10 @@ package main import ( "context" "flag" + "log" + "github.com/env0/terraform-provider-env0/env0" "github.com/hashicorp/terraform-plugin-sdk/v2/plugin" - "log" ) //go:generate terraform fmt -recursive ./examples/ diff --git a/tests/harness.go b/tests/harness.go index b8420dc9..39112537 100644 --- a/tests/harness.go +++ b/tests/harness.go @@ -184,9 +184,7 @@ func testNamesFromCommandLineArguments() []string { if strings.HasPrefix(testName, TESTS_FOLDER+"/") { testName = testName[len(TESTS_FOLDER+"/"):] } - if strings.HasSuffix(testName, "/") { - testName = testName[:len(testName)-1] - } + testName = strings.TrimSuffix(testName, "/") testNames = append(testNames, testName) } } else { diff --git a/utils/external_tools.go b/utils/external_tools.go index 5817c2ad..42c92f7b 100644 --- a/utils/external_tools.go +++ b/utils/external_tools.go @@ -1,4 +1,5 @@ // This file is used to add external tools as dependencies +//go:build utils // +build utils package utils