From c3adfe704889e00e94b31889605589d5e426704d Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Tue, 12 Sep 2023 12:16:23 -0500 Subject: [PATCH 1/6] Feat: add support for update credentials --- .github/workflows/ci.yml | 10 +++++----- .github/workflows/docs.yml | 22 +++++++++------------- .github/workflows/release.yml | 27 +++++++++++---------------- README.md | 2 +- go.mod | 2 +- 5 files changed, 27 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4098cc72..fa376d54 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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.19 + GO_VERSION: 1.20 TERRAFORM_VERSION: 1.1.7 jobs: @@ -18,11 +18,11 @@ jobs: runs-on: ubuntu-20.04 steps: - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Generate mocks run: | go install github.com/golang/mock/mockgen@v1.6.0 @@ -45,12 +45,12 @@ jobs: integration-tests: name: Integration Tests runs-on: ubuntu-20.04 - container: golang:1.19-alpine3.17 + container: golang:1.20-alpine3.18 timeout-minutes: 20 steps: - name: Install Terraform run: apk add terraform - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Run Harness tests run: go run tests/harness.go diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index fdf85e08..4d85a974 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -6,34 +6,30 @@ on: - main env: - GO_VERSION: 1.19 + GO_VERSION: 1.20 jobs: generate-docs: name: Generate Docs runs-on: ubuntu-latest steps: - - - name: Checkout - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v4 with: token: ${{ secrets.ENV0_BOT_PAT }} - name: Unshallow run: git fetch --prune --unshallow - - - name: Set up Go - uses: actions/setup-go@v3 + - name: Set up Go + uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} - - - name: Update generated docs + - name: Update generated docs run: ./generate-docs.sh - - - name: Commit changes + - name: Commit changes uses: EndBug/add-and-commit@v9 with: author_name: update generated docs action author_email: mail@example.com - message: 'Update docs' - add: 'docs/*' + message: "Update docs" + add: "docs/*" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 12a5ce15..be80378b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,36 +13,31 @@ name: release on: push: tags: - - 'v*.*.*' + - "v*.*.*" env: - GO_VERSION: 1.19 + GO_VERSION: 1.20 jobs: goreleaser: runs-on: ubuntu-latest steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Unshallow + - name: Checkout + uses: actions/checkout@v4 + - name: Unshallow run: git fetch --prune --unshallow - - - name: Set up Go - uses: actions/setup-go@v3 + - name: Set up Go + uses: actions/setup-go@v4 with: go-version: ${{ env.GO_VERSION }} - - - name: Import GPG key - uses: crazy-max/ghaction-import-gpg@v5 + - name: Import GPG key + uses: crazy-max/ghaction-import-gpg@v6 id: import_gpg with: gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} passphrase: ${{ secrets.PASSPHRASE }} - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v3 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 with: version: latest args: release --rm-dist diff --git a/README.md b/README.md index 63394260..fa5e3b72 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ resource "env0_template" "example" { ## Development Setup -> **Supported Go Version: 1.19** +> **Supported Go Version: 1.20** ### Build diff --git a/go.mod b/go.mod index a9b1f16a..cc48e969 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/env0/terraform-provider-env0 -go 1.19 +go 1.20 require ( github.com/Masterminds/semver/v3 v3.2.1 From 1c782ecb7f4c4143b93cfc5da963742ac6cd53fc Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Tue, 12 Sep 2023 12:22:38 -0500 Subject: [PATCH 2/6] update mockgen --- .github/workflows/ci.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa376d54..5871eba8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: uses: actions/checkout@v4 - name: Generate mocks run: | - go install github.com/golang/mock/mockgen@v1.6.0 + go install go.uber.org/mock/mockgen@v0.2.0 go generate client/api_client.go - name: Go fmt run: | diff --git a/README.md b/README.md index fa5e3b72..12fcc244 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ export PATH=$PATH:$(go env GOPATH) # if not 2. Install mockgen ``` -go install github.com/golang/mock/mockgen@v1.6.0 +go install go.uber.org/mock/mockgen@v0.2.0 ``` 3. Make sure to add this line in files that include the interface you'd wish to mock: From 7fbbfde35243fbff337818c714673688f6f6219c Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Tue, 12 Sep 2023 12:28:46 -0500 Subject: [PATCH 3/6] WIP --- client/agent_project_assignment_test.go | 2 +- client/agent_test.go | 2 +- client/api_client_mock.go | 2 +- client/api_key_test.go | 2 +- client/approval_policy_test.go | 2 +- client/client_test.go | 2 +- client/cloud_credentials_project_assignment_test.go | 2 +- client/cloud_credentials_test.go | 2 +- client/configuration_variable_test.go | 2 +- client/cost_credentials_project_assignment_test.go | 2 +- client/custom_flow_test.go | 2 +- client/environment_drift_detection_test.go | 2 +- client/environment_scheduling_test.go | 2 +- client/environment_test.go | 2 +- client/git_token_test.go | 2 +- client/gpg_key_test.go | 2 +- client/http/client_mock.go | 2 +- client/module_test.go | 2 +- client/notification_project_assignment_test.go | 2 +- client/notification_test.go | 2 +- client/organization_test.go | 2 +- client/project_budget_test.go | 2 +- client/project_policy_test.go | 2 +- client/project_test.go | 2 +- client/provider_test.go | 2 +- client/remote_state_access_test.go | 2 +- client/role_test.go | 2 +- client/sshkey_test.go | 2 +- client/team_environment_assignment_test.go | 2 +- client/team_project_assignment_test.go | 2 +- client/team_test.go | 2 +- client/template_test.go | 2 +- client/user_environment_assignment_test.go | 2 +- client/user_project_assignment_test.go | 2 +- client/user_test.go | 2 +- client/workflow_triggers_test.go | 2 +- env0/data_project_test.go | 2 +- env0/provider_test.go | 2 +- env0/resource_agent_project_assignment_test.go | 2 +- env0/resource_api_key_test.go | 2 +- env0/resource_approval_policy_assignment_test.go | 2 +- env0/resource_approval_policy_test.go | 2 +- env0/resource_aws_credentials_test.go | 2 +- env0/resource_azure_credentials_test.go | 2 +- ...ource_cloud_credentials_project_assignment_test.go | 2 +- env0/resource_configuration_variable_test.go | 2 +- ...source_cost_credentials_project_assignment_test.go | 2 +- env0/resource_cost_credentials_test.go | 2 +- env0/resource_custom_flow_assignment_test.go | 2 +- env0/resource_custom_flow_test.go | 2 +- env0/resource_custom_role_test.go | 2 +- env0/resource_drift_detection_test.go | 2 +- env0/resource_environment_state_access_test.go | 2 +- env0/resource_environment_test.go | 2 +- env0/resource_gcp_credentials_test.go | 2 +- env0/resource_git_token_test.go | 2 +- env0/resource_gpg_key_test.go | 2 +- env0/resource_module_test.go | 2 +- env0/resource_notification_project_assignment_test.go | 2 +- env0/resource_notification_test.go | 2 +- env0/resource_organization_policy_test.go | 2 +- env0/resource_project_policy_test.go | 2 +- env0/resource_project_test.go | 2 +- env0/resource_provider_test.go | 2 +- env0/resource_sshkey_test.go | 2 +- env0/resource_team_environment_assignment_test.go | 2 +- env0/resource_team_project_assignment_test.go | 2 +- env0/resource_team_test.go | 2 +- env0/resource_template_project_assignment_test.go | 2 +- env0/resource_template_test.go | 2 +- env0/resource_user_environment_assignment_test.go | 2 +- env0/resource_user_organization_assignment_test.go | 2 +- env0/resource_user_project_assignment_test.go | 2 +- env0/resource_user_team_assignment_test.go | 2 +- env0/resource_workflow_trigger_test.go | 2 +- env0/resource_workflow_triggers_test.go | 2 +- go.mod | 2 +- go.sum | 11 ++--------- 78 files changed, 79 insertions(+), 86 deletions(-) diff --git a/client/agent_project_assignment_test.go b/client/agent_project_assignment_test.go index a5e9ba53..37bc402d 100644 --- a/client/agent_project_assignment_test.go +++ b/client/agent_project_assignment_test.go @@ -4,9 +4,9 @@ import ( "errors" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Agent Project Assignment", func() { diff --git a/client/agent_test.go b/client/agent_test.go index e34781f9..561245e5 100644 --- a/client/agent_test.go +++ b/client/agent_test.go @@ -4,9 +4,9 @@ import ( "errors" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Agent Client", func() { diff --git a/client/api_client_mock.go b/client/api_client_mock.go index 7b7a3d1e..0956c62a 100644 --- a/client/api_client_mock.go +++ b/client/api_client_mock.go @@ -7,7 +7,7 @@ package client import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockApiClientInterface is a mock of ApiClientInterface interface. diff --git a/client/api_key_test.go b/client/api_key_test.go index 0768d4bf..5f930ea7 100644 --- a/client/api_key_test.go +++ b/client/api_key_test.go @@ -2,10 +2,10 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/jinzhu/copier" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("ApiKey Client", func() { diff --git a/client/approval_policy_test.go b/client/approval_policy_test.go index c4fdeac4..35d7a70f 100644 --- a/client/approval_policy_test.go +++ b/client/approval_policy_test.go @@ -4,9 +4,9 @@ import ( "fmt" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Approval Policy Client", func() { diff --git a/client/client_test.go b/client/client_test.go index 4b818892..3aa1239c 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -5,9 +5,9 @@ import ( . "github.com/env0/terraform-provider-env0/client" "github.com/env0/terraform-provider-env0/client/http" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) // This file wraps the test suite for the entire client folder diff --git a/client/cloud_credentials_project_assignment_test.go b/client/cloud_credentials_project_assignment_test.go index 20b5402b..17489de6 100644 --- a/client/cloud_credentials_project_assignment_test.go +++ b/client/cloud_credentials_project_assignment_test.go @@ -4,9 +4,9 @@ import ( "errors" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Credentials Project Assignment", func() { diff --git a/client/cloud_credentials_test.go b/client/cloud_credentials_test.go index ca451a31..8877fc3d 100644 --- a/client/cloud_credentials_test.go +++ b/client/cloud_credentials_test.go @@ -2,9 +2,9 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("CloudCredentials", func() { diff --git a/client/configuration_variable_test.go b/client/configuration_variable_test.go index 2b9b29e0..f15451ed 100644 --- a/client/configuration_variable_test.go +++ b/client/configuration_variable_test.go @@ -4,11 +4,11 @@ import ( "encoding/json" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/jinzhu/copier" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Configuration Variable", func() { diff --git a/client/cost_credentials_project_assignment_test.go b/client/cost_credentials_project_assignment_test.go index 764eeb1d..c70e4594 100644 --- a/client/cost_credentials_project_assignment_test.go +++ b/client/cost_credentials_project_assignment_test.go @@ -4,9 +4,9 @@ import ( "errors" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe(" Cost Credentials Project Assignment", func() { diff --git a/client/custom_flow_test.go b/client/custom_flow_test.go index 4a270e63..5115c144 100644 --- a/client/custom_flow_test.go +++ b/client/custom_flow_test.go @@ -2,10 +2,10 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/jinzhu/copier" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Custom Flow Client", func() { diff --git a/client/environment_drift_detection_test.go b/client/environment_drift_detection_test.go index 42332101..883b4ffe 100644 --- a/client/environment_drift_detection_test.go +++ b/client/environment_drift_detection_test.go @@ -4,9 +4,9 @@ import ( "errors" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("EnvironmentDriftDetection", func() { diff --git a/client/environment_scheduling_test.go b/client/environment_scheduling_test.go index 39cb5052..5d26a9bf 100644 --- a/client/environment_scheduling_test.go +++ b/client/environment_scheduling_test.go @@ -4,9 +4,9 @@ import ( "errors" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("EnvironmentScheduling", func() { diff --git a/client/environment_test.go b/client/environment_test.go index 689909b2..aeb14756 100644 --- a/client/environment_test.go +++ b/client/environment_test.go @@ -6,11 +6,11 @@ import ( "testing" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/jinzhu/copier" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" ) const full_page = 100 diff --git a/client/git_token_test.go b/client/git_token_test.go index c07cae44..4b8f0ac9 100644 --- a/client/git_token_test.go +++ b/client/git_token_test.go @@ -2,10 +2,10 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/jinzhu/copier" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("GitToken Client", func() { diff --git a/client/gpg_key_test.go b/client/gpg_key_test.go index 3535bbc8..87b85ccf 100644 --- a/client/gpg_key_test.go +++ b/client/gpg_key_test.go @@ -2,9 +2,9 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Gpg Token Client", func() { diff --git a/client/http/client_mock.go b/client/http/client_mock.go index 2589b7e4..2187c2fb 100644 --- a/client/http/client_mock.go +++ b/client/http/client_mock.go @@ -7,7 +7,7 @@ package http import ( reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockHttpClientInterface is a mock of HttpClientInterface interface. diff --git a/client/module_test.go b/client/module_test.go index 8e14c5de..6535c8d6 100644 --- a/client/module_test.go +++ b/client/module_test.go @@ -2,10 +2,10 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/jinzhu/copier" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Module Client", func() { diff --git a/client/notification_project_assignment_test.go b/client/notification_project_assignment_test.go index 9809bf11..4091a7f5 100644 --- a/client/notification_project_assignment_test.go +++ b/client/notification_project_assignment_test.go @@ -2,9 +2,9 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Notification Project Assignment Client", func() { diff --git a/client/notification_test.go b/client/notification_test.go index a91ed213..419ca231 100644 --- a/client/notification_test.go +++ b/client/notification_test.go @@ -2,10 +2,10 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - gomock "github.com/golang/mock/gomock" "github.com/jinzhu/copier" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + gomock "go.uber.org/mock/gomock" ) var _ = Describe("Notification Client", func() { diff --git a/client/organization_test.go b/client/organization_test.go index 3c2a3a49..8affa26e 100644 --- a/client/organization_test.go +++ b/client/organization_test.go @@ -4,9 +4,9 @@ import ( "errors" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Organization", func() { diff --git a/client/project_budget_test.go b/client/project_budget_test.go index a2cda4e1..cd228286 100644 --- a/client/project_budget_test.go +++ b/client/project_budget_test.go @@ -2,10 +2,10 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/jinzhu/copier" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Project Budget Client", func() { diff --git a/client/project_policy_test.go b/client/project_policy_test.go index b095741e..3e004516 100644 --- a/client/project_policy_test.go +++ b/client/project_policy_test.go @@ -5,9 +5,9 @@ import ( "fmt" . "github.com/env0/terraform-provider-env0/client" - gomock "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + gomock "go.uber.org/mock/gomock" ) const ( diff --git a/client/project_test.go b/client/project_test.go index 0279beb5..def86b93 100644 --- a/client/project_test.go +++ b/client/project_test.go @@ -2,9 +2,9 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) const projectName = "project_test" diff --git a/client/provider_test.go b/client/provider_test.go index 3e6d898c..e4051d5f 100644 --- a/client/provider_test.go +++ b/client/provider_test.go @@ -2,9 +2,9 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Provider Client", func() { diff --git a/client/remote_state_access_test.go b/client/remote_state_access_test.go index dafa2702..fdb68ab3 100644 --- a/client/remote_state_access_test.go +++ b/client/remote_state_access_test.go @@ -2,9 +2,9 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("RemoteStateAccess", func() { diff --git a/client/role_test.go b/client/role_test.go index 025fe65d..de5df4ab 100644 --- a/client/role_test.go +++ b/client/role_test.go @@ -2,10 +2,10 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/google/uuid" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Role", func() { diff --git a/client/sshkey_test.go b/client/sshkey_test.go index a4791920..a3c8ebac 100644 --- a/client/sshkey_test.go +++ b/client/sshkey_test.go @@ -2,9 +2,9 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("SshKey", func() { diff --git a/client/team_environment_assignment_test.go b/client/team_environment_assignment_test.go index e2126cad..19ea2db8 100644 --- a/client/team_environment_assignment_test.go +++ b/client/team_environment_assignment_test.go @@ -4,9 +4,9 @@ import ( "errors" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Team Envrionment Assignment", func() { diff --git a/client/team_project_assignment_test.go b/client/team_project_assignment_test.go index 719e15e1..e6a0327e 100644 --- a/client/team_project_assignment_test.go +++ b/client/team_project_assignment_test.go @@ -2,9 +2,9 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("TeamProjectAssignment", func() { diff --git a/client/team_test.go b/client/team_test.go index dd54b560..7e6f0dae 100644 --- a/client/team_test.go +++ b/client/team_test.go @@ -4,10 +4,10 @@ import ( "errors" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/jinzhu/copier" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Teams Client", func() { diff --git a/client/template_test.go b/client/template_test.go index a4707b05..4c66323c 100644 --- a/client/template_test.go +++ b/client/template_test.go @@ -6,12 +6,12 @@ import ( "strconv" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/jinzhu/copier" . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" "github.com/onsi/gomega/types" + "go.uber.org/mock/gomock" ) var _ = Describe("Templates Client", func() { diff --git a/client/user_environment_assignment_test.go b/client/user_environment_assignment_test.go index d3cd789f..2cfb3ce4 100644 --- a/client/user_environment_assignment_test.go +++ b/client/user_environment_assignment_test.go @@ -4,9 +4,9 @@ import ( "errors" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("User Envrionment Assignment", func() { diff --git a/client/user_project_assignment_test.go b/client/user_project_assignment_test.go index f2849b9f..f1caed0c 100644 --- a/client/user_project_assignment_test.go +++ b/client/user_project_assignment_test.go @@ -4,9 +4,9 @@ import ( "errors" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Agent Project Assignment", func() { diff --git a/client/user_test.go b/client/user_test.go index c264709e..77ffd0e3 100644 --- a/client/user_test.go +++ b/client/user_test.go @@ -4,9 +4,9 @@ import ( "errors" . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("User Client", func() { diff --git a/client/workflow_triggers_test.go b/client/workflow_triggers_test.go index eae1dde3..511a4edb 100644 --- a/client/workflow_triggers_test.go +++ b/client/workflow_triggers_test.go @@ -2,9 +2,9 @@ package client_test import ( . "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "go.uber.org/mock/gomock" ) var _ = Describe("Workflow Triggers", func() { diff --git a/env0/data_project_test.go b/env0/data_project_test.go index 7653dfe5..fb401977 100644 --- a/env0/data_project_test.go +++ b/env0/data_project_test.go @@ -6,8 +6,8 @@ import ( "github.com/env0/terraform-provider-env0/client" "github.com/env0/terraform-provider-env0/client/http" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestProjectDataSource(t *testing.T) { diff --git a/env0/provider_test.go b/env0/provider_test.go index c5a446d2..e80a9f72 100644 --- a/env0/provider_test.go +++ b/env0/provider_test.go @@ -9,11 +9,11 @@ import ( "github.com/env0/terraform-provider-env0/client" "github.com/env0/terraform-provider-env0/utils" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "go.uber.org/mock/gomock" ) func runUnitTest(t *testing.T, testCase resource.TestCase, mockFunc func(mockFunc *client.MockApiClientInterface)) { diff --git a/env0/resource_agent_project_assignment_test.go b/env0/resource_agent_project_assignment_test.go index 2de6a8e7..be41d7e8 100644 --- a/env0/resource_agent_project_assignment_test.go +++ b/env0/resource_agent_project_assignment_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitAgentProjectAssignmentResource(t *testing.T) { diff --git a/env0/resource_api_key_test.go b/env0/resource_api_key_test.go index 3b03c15d..1b213de8 100644 --- a/env0/resource_api_key_test.go +++ b/env0/resource_api_key_test.go @@ -7,9 +7,9 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitApiKeyResource(t *testing.T) { diff --git a/env0/resource_approval_policy_assignment_test.go b/env0/resource_approval_policy_assignment_test.go index 24f635ef..1cf60916 100644 --- a/env0/resource_approval_policy_assignment_test.go +++ b/env0/resource_approval_policy_assignment_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitResourceApprovalPolicyAssignmentResource(t *testing.T) { diff --git a/env0/resource_approval_policy_test.go b/env0/resource_approval_policy_test.go index 6bd7d599..4069bd82 100644 --- a/env0/resource_approval_policy_test.go +++ b/env0/resource_approval_policy_test.go @@ -9,10 +9,10 @@ import ( "github.com/env0/terraform-provider-env0/client" "github.com/env0/terraform-provider-env0/client/http" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/jinzhu/copier" + "go.uber.org/mock/gomock" ) func TestUnitApprovalPolicyResource(t *testing.T) { diff --git a/env0/resource_aws_credentials_test.go b/env0/resource_aws_credentials_test.go index 35e36e11..933e25ee 100644 --- a/env0/resource_aws_credentials_test.go +++ b/env0/resource_aws_credentials_test.go @@ -8,8 +8,8 @@ import ( "github.com/env0/terraform-provider-env0/client" "github.com/env0/terraform-provider-env0/client/http" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitAwsCredentialsResource(t *testing.T) { diff --git a/env0/resource_azure_credentials_test.go b/env0/resource_azure_credentials_test.go index 21442f0a..dba16995 100644 --- a/env0/resource_azure_credentials_test.go +++ b/env0/resource_azure_credentials_test.go @@ -8,8 +8,8 @@ import ( "github.com/env0/terraform-provider-env0/client" "github.com/env0/terraform-provider-env0/client/http" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitAzureCredentialsResource(t *testing.T) { diff --git a/env0/resource_cloud_credentials_project_assignment_test.go b/env0/resource_cloud_credentials_project_assignment_test.go index 2ff21127..907b3034 100644 --- a/env0/resource_cloud_credentials_project_assignment_test.go +++ b/env0/resource_cloud_credentials_project_assignment_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitResourceCloudCredentialsProjectAssignmentResource(t *testing.T) { diff --git a/env0/resource_configuration_variable_test.go b/env0/resource_configuration_variable_test.go index 61d6f359..639b267a 100644 --- a/env0/resource_configuration_variable_test.go +++ b/env0/resource_configuration_variable_test.go @@ -11,8 +11,8 @@ import ( "github.com/env0/terraform-provider-env0/client" "github.com/env0/terraform-provider-env0/client/http" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitConfigurationVariableResource(t *testing.T) { diff --git a/env0/resource_cost_credentials_project_assignment_test.go b/env0/resource_cost_credentials_project_assignment_test.go index ffc57647..6c1c1b46 100644 --- a/env0/resource_cost_credentials_project_assignment_test.go +++ b/env0/resource_cost_credentials_project_assignment_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitResourceCostCredentialsProjectAssignmentResource(t *testing.T) { diff --git a/env0/resource_cost_credentials_test.go b/env0/resource_cost_credentials_test.go index c285b457..3debc958 100644 --- a/env0/resource_cost_credentials_test.go +++ b/env0/resource_cost_credentials_test.go @@ -6,8 +6,8 @@ import ( "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitAwsCostCredentialsResource(t *testing.T) { diff --git a/env0/resource_custom_flow_assignment_test.go b/env0/resource_custom_flow_assignment_test.go index 56cb0213..4134b01d 100644 --- a/env0/resource_custom_flow_assignment_test.go +++ b/env0/resource_custom_flow_assignment_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitResourceCustomFlowAssignmentResource(t *testing.T) { diff --git a/env0/resource_custom_flow_test.go b/env0/resource_custom_flow_test.go index db1cf79b..3d716693 100644 --- a/env0/resource_custom_flow_test.go +++ b/env0/resource_custom_flow_test.go @@ -7,9 +7,9 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitCustomFlowResource(t *testing.T) { diff --git a/env0/resource_custom_role_test.go b/env0/resource_custom_role_test.go index 1bcb8207..40aa4841 100644 --- a/env0/resource_custom_role_test.go +++ b/env0/resource_custom_role_test.go @@ -8,9 +8,9 @@ import ( "github.com/env0/terraform-provider-env0/client" "github.com/env0/terraform-provider-env0/client/http" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitCustomRoleResource(t *testing.T) { diff --git a/env0/resource_drift_detection_test.go b/env0/resource_drift_detection_test.go index 9f09209b..3a18666b 100644 --- a/env0/resource_drift_detection_test.go +++ b/env0/resource_drift_detection_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitEnvironmentDriftDetectionResource(t *testing.T) { diff --git a/env0/resource_environment_state_access_test.go b/env0/resource_environment_state_access_test.go index 5aa041fc..77743691 100644 --- a/env0/resource_environment_state_access_test.go +++ b/env0/resource_environment_state_access_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitEnvironmentStateAccessResource(t *testing.T) { diff --git a/env0/resource_environment_test.go b/env0/resource_environment_test.go index c216fdfb..2eb677c6 100644 --- a/env0/resource_environment_test.go +++ b/env0/resource_environment_test.go @@ -10,9 +10,9 @@ import ( "github.com/env0/terraform-provider-env0/client" "github.com/env0/terraform-provider-env0/client/http" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitEnvironmentResource(t *testing.T) { diff --git a/env0/resource_gcp_credentials_test.go b/env0/resource_gcp_credentials_test.go index 65a7ec14..fe8a35eb 100644 --- a/env0/resource_gcp_credentials_test.go +++ b/env0/resource_gcp_credentials_test.go @@ -8,8 +8,8 @@ import ( "github.com/env0/terraform-provider-env0/client" "github.com/env0/terraform-provider-env0/client/http" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitGcpCredentialsResource(t *testing.T) { diff --git a/env0/resource_git_token_test.go b/env0/resource_git_token_test.go index e6bdea38..773e24d6 100644 --- a/env0/resource_git_token_test.go +++ b/env0/resource_git_token_test.go @@ -6,9 +6,9 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitGitTokenResource(t *testing.T) { diff --git a/env0/resource_gpg_key_test.go b/env0/resource_gpg_key_test.go index f1f3e625..cbc865a4 100644 --- a/env0/resource_gpg_key_test.go +++ b/env0/resource_gpg_key_test.go @@ -6,9 +6,9 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitGpgKeyyResource(t *testing.T) { diff --git a/env0/resource_module_test.go b/env0/resource_module_test.go index 522fe50f..9b14e241 100644 --- a/env0/resource_module_test.go +++ b/env0/resource_module_test.go @@ -6,9 +6,9 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitModuleResource(t *testing.T) { diff --git a/env0/resource_notification_project_assignment_test.go b/env0/resource_notification_project_assignment_test.go index 4ab0420a..28e00800 100644 --- a/env0/resource_notification_project_assignment_test.go +++ b/env0/resource_notification_project_assignment_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitNotificationProjectAssignmentResource(t *testing.T) { diff --git a/env0/resource_notification_test.go b/env0/resource_notification_test.go index c143a24b..ad3db033 100644 --- a/env0/resource_notification_test.go +++ b/env0/resource_notification_test.go @@ -6,9 +6,9 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitNotificationResource(t *testing.T) { diff --git a/env0/resource_organization_policy_test.go b/env0/resource_organization_policy_test.go index 8905bd86..cf5eccde 100644 --- a/env0/resource_organization_policy_test.go +++ b/env0/resource_organization_policy_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitOrganizationPolicyResource(t *testing.T) { diff --git a/env0/resource_project_policy_test.go b/env0/resource_project_policy_test.go index 5a270f09..4aeaad88 100644 --- a/env0/resource_project_policy_test.go +++ b/env0/resource_project_policy_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitPolicyResource(t *testing.T) { diff --git a/env0/resource_project_test.go b/env0/resource_project_test.go index 3b0362b7..6411495a 100644 --- a/env0/resource_project_test.go +++ b/env0/resource_project_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitProjectResource(t *testing.T) { diff --git a/env0/resource_provider_test.go b/env0/resource_provider_test.go index 407df8a0..4f7c5b97 100644 --- a/env0/resource_provider_test.go +++ b/env0/resource_provider_test.go @@ -6,9 +6,9 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitProviderResource(t *testing.T) { diff --git a/env0/resource_sshkey_test.go b/env0/resource_sshkey_test.go index 3869dae2..521cc7ae 100644 --- a/env0/resource_sshkey_test.go +++ b/env0/resource_sshkey_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitSshKeyResource(t *testing.T) { diff --git a/env0/resource_team_environment_assignment_test.go b/env0/resource_team_environment_assignment_test.go index 0057e795..c005d87a 100644 --- a/env0/resource_team_environment_assignment_test.go +++ b/env0/resource_team_environment_assignment_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitTeamEnvironmntAssignmentResource(t *testing.T) { diff --git a/env0/resource_team_project_assignment_test.go b/env0/resource_team_project_assignment_test.go index 5cf76e70..1c7a40f4 100644 --- a/env0/resource_team_project_assignment_test.go +++ b/env0/resource_team_project_assignment_test.go @@ -5,8 +5,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitTeamProjectAssignmentResource(t *testing.T) { diff --git a/env0/resource_team_test.go b/env0/resource_team_test.go index 967be206..767bbe1c 100644 --- a/env0/resource_team_test.go +++ b/env0/resource_team_test.go @@ -7,8 +7,8 @@ import ( "github.com/env0/terraform-provider-env0/client" "github.com/env0/terraform-provider-env0/client/http" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitTeamResource(t *testing.T) { diff --git a/env0/resource_template_project_assignment_test.go b/env0/resource_template_project_assignment_test.go index 27286ac1..14c72c15 100644 --- a/env0/resource_template_project_assignment_test.go +++ b/env0/resource_template_project_assignment_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitTemplateProjectAssignmentResource(t *testing.T) { diff --git a/env0/resource_template_test.go b/env0/resource_template_test.go index fb804528..b2fa7273 100644 --- a/env0/resource_template_test.go +++ b/env0/resource_template_test.go @@ -7,8 +7,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitTemplateResource(t *testing.T) { diff --git a/env0/resource_user_environment_assignment_test.go b/env0/resource_user_environment_assignment_test.go index ff6dd590..f373a4b3 100644 --- a/env0/resource_user_environment_assignment_test.go +++ b/env0/resource_user_environment_assignment_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitUserEnvironmntAssignmentResource(t *testing.T) { diff --git a/env0/resource_user_organization_assignment_test.go b/env0/resource_user_organization_assignment_test.go index 681a6294..cf71b681 100644 --- a/env0/resource_user_organization_assignment_test.go +++ b/env0/resource_user_organization_assignment_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func getOrgUser(userId, role string) client.OrganizationUser { diff --git a/env0/resource_user_project_assignment_test.go b/env0/resource_user_project_assignment_test.go index 6fcdaec1..2c64c8cc 100644 --- a/env0/resource_user_project_assignment_test.go +++ b/env0/resource_user_project_assignment_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitUserProjectAssignmentResource(t *testing.T) { diff --git a/env0/resource_user_team_assignment_test.go b/env0/resource_user_team_assignment_test.go index 6a179e60..24f359d2 100644 --- a/env0/resource_user_team_assignment_test.go +++ b/env0/resource_user_team_assignment_test.go @@ -8,8 +8,8 @@ import ( "github.com/env0/terraform-provider-env0/client" "github.com/env0/terraform-provider-env0/client/http" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitUserTeamAssignmentResource(t *testing.T) { diff --git a/env0/resource_workflow_trigger_test.go b/env0/resource_workflow_trigger_test.go index bd7f13ad..63852087 100644 --- a/env0/resource_workflow_trigger_test.go +++ b/env0/resource_workflow_trigger_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitWorkflowTriggerResource(t *testing.T) { diff --git a/env0/resource_workflow_triggers_test.go b/env0/resource_workflow_triggers_test.go index ab8e9c6c..d27510a9 100644 --- a/env0/resource_workflow_triggers_test.go +++ b/env0/resource_workflow_triggers_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/env0/terraform-provider-env0/client" - "github.com/golang/mock/gomock" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "go.uber.org/mock/gomock" ) func TestUnitWorkflowTriggersResource(t *testing.T) { diff --git a/go.mod b/go.mod index cc48e969..61a734f0 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/Masterminds/semver/v3 v3.2.1 github.com/adhocore/gronx v1.6.5 github.com/go-resty/resty/v2 v2.7.0 - github.com/golang/mock v1.6.0 github.com/google/uuid v1.3.0 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/terraform-plugin-docs v0.16.0 @@ -17,6 +16,7 @@ require ( github.com/onsi/ginkgo v1.16.2 github.com/onsi/gomega v1.12.0 github.com/stretchr/testify v1.7.2 + go.uber.org/mock v0.2.0 ) require ( diff --git a/go.sum b/go.sum index 2f3190cc..cf3b0c09 100644 --- a/go.sum +++ b/go.sum @@ -45,8 +45,6 @@ github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPr github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -209,10 +207,11 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zclconf/go-cty v1.13.2 h1:4GvrUxe/QUDYuJKAav4EYqdM47/kZa672LwmXFmEKT0= github.com/zclconf/go-cty v1.13.2/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= +go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU= +go.uber.org/mock v0.2.0/go.mod h1:J0y0rp9L3xiff1+ZBfKxlC1fz2+aO16tw0tsDOixfuM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -227,7 +226,6 @@ golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98y golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb h1:mIKbk8weKhSeLH2GmUTrvx8CjkyJmnU1wFmg59CUjFA= golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= @@ -239,7 +237,6 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= @@ -251,7 +248,6 @@ golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -266,9 +262,7 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -300,7 +294,6 @@ golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 69e44915ad3b79b23831a913c4fa5bb48c2236ad Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Tue, 12 Sep 2023 12:34:54 -0500 Subject: [PATCH 4/6] WIP --- .github/workflows/ci.yml | 2 +- .github/workflows/docs.yml | 2 +- .github/workflows/release.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5871eba8..f483ac9d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: - name: Install Go uses: actions/setup-go@v4 with: - go-version: ${{ env.GO_VERSION }} + go-version: "${{ env.GO_VERSION }}" - name: Checkout code uses: actions/checkout@v4 - name: Generate mocks diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 4d85a974..792e0438 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -23,7 +23,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: ${{ env.GO_VERSION }} + go-version: "${{ env.GO_VERSION }}" - name: Update generated docs run: ./generate-docs.sh - name: Commit changes diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index be80378b..ad312c43 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,7 +29,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: ${{ env.GO_VERSION }} + go-version: "${{ env.GO_VERSION }}" - name: Import GPG key uses: crazy-max/ghaction-import-gpg@v6 id: import_gpg From 96fe5c6e3808d10ae2336771095153a5b07eeba0 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Tue, 12 Sep 2023 12:36:14 -0500 Subject: [PATCH 5/6] WIP --- .github/workflows/ci.yml | 4 ++-- .github/workflows/docs.yml | 2 +- .github/workflows/release.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f483ac9d..813d6257 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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.20" TERRAFORM_VERSION: 1.1.7 jobs: @@ -20,7 +20,7 @@ jobs: - name: Install Go uses: actions/setup-go@v4 with: - go-version: "${{ env.GO_VERSION }}" + go-version: ${{ env.GO_VERSION }} - name: Checkout code uses: actions/checkout@v4 - name: Generate mocks diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 792e0438..2669916c 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -6,7 +6,7 @@ on: - main env: - GO_VERSION: 1.20 + GO_VERSION: "1.20" jobs: generate-docs: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ad312c43..138b321a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ on: - "v*.*.*" env: - GO_VERSION: 1.20 + GO_VERSION: "1.20" jobs: goreleaser: From 4e46031571683842f4e8b547ef4d3071c83d42bd Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Wed, 13 Sep 2023 11:16:18 -0500 Subject: [PATCH 6/6] Added update --- client/api_client.go | 1 + client/api_client_mock.go | 15 ++ client/cloud_credentials.go | 19 +- client/cloud_credentials_test.go | 40 ++++ env0/resource_cost_credentials.go | 249 +++++++++++++------------ env0/resource_cost_credentials_test.go | 15 +- 6 files changed, 206 insertions(+), 133 deletions(-) diff --git a/client/api_client.go b/client/api_client.go index b5d2eeda..06cd2b84 100644 --- a/client/api_client.go +++ b/client/api_client.go @@ -42,6 +42,7 @@ type ApiClientInterface interface { SshKeyCreate(payload SshKeyCreatePayload) (*SshKey, error) SshKeyDelete(id string) error CredentialsCreate(request CredentialCreatePayload) (Credentials, error) + CredentialsUpdate(id string, request CredentialCreatePayload) (Credentials, error) CloudCredentials(id string) (Credentials, error) CloudCredentialsList() ([]Credentials, error) CloudCredentialsDelete(id string) error diff --git a/client/api_client_mock.go b/client/api_client_mock.go index 0956c62a..62af3eec 100644 --- a/client/api_client_mock.go +++ b/client/api_client_mock.go @@ -434,6 +434,21 @@ func (mr *MockApiClientInterfaceMockRecorder) CredentialsCreate(arg0 interface{} return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CredentialsCreate", reflect.TypeOf((*MockApiClientInterface)(nil).CredentialsCreate), arg0) } +// CredentialsUpdate mocks base method. +func (m *MockApiClientInterface) CredentialsUpdate(arg0 string, arg1 CredentialCreatePayload) (Credentials, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CredentialsUpdate", arg0, arg1) + ret0, _ := ret[0].(Credentials) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CredentialsUpdate indicates an expected call of CredentialsUpdate. +func (mr *MockApiClientInterfaceMockRecorder) CredentialsUpdate(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CredentialsUpdate", reflect.TypeOf((*MockApiClientInterface)(nil).CredentialsUpdate), arg0, arg1) +} + // CustomFlow mocks base method. func (m *MockApiClientInterface) CustomFlow(arg0 string) (*CustomFlow, error) { m.ctrl.T.Helper() diff --git a/client/cloud_credentials.go b/client/cloud_credentials.go index 3fa759c6..636db3a2 100644 --- a/client/cloud_credentials.go +++ b/client/cloud_credentials.go @@ -143,10 +143,27 @@ func (client *ApiClient) CredentialsCreate(request CredentialCreatePayload) (Cre request.SetOrganizationId(organizationId) var result Credentials - err = client.http.Post("/credentials", request, &result) + if err := client.http.Post("/credentials", request, &result); err != nil { + return Credentials{}, err + } + + return result, nil +} + +func (client *ApiClient) CredentialsUpdate(id string, request CredentialCreatePayload) (Credentials, error) { + organizationId, err := client.OrganizationId() if err != nil { return Credentials{}, err } + + request.SetOrganizationId(organizationId) + + var result Credentials + + if err := client.http.Patch("/credentials/"+id, request, &result); err != nil { + return Credentials{}, err + } + return result, nil } diff --git a/client/cloud_credentials_test.go b/client/cloud_credentials_test.go index 8877fc3d..c43f1e3c 100644 --- a/client/cloud_credentials_test.go +++ b/client/cloud_credentials_test.go @@ -115,6 +115,46 @@ var _ = Describe("CloudCredentials", func() { }) }) + Describe("AwsCredentialsUpdate", func() { + BeforeEach(func() { + mockOrganizationIdCall(organizationId) + + payloadValue := AwsCredentialsValuePayload{ + RoleArn: "role", + } + + httpCall = mockHttpClient.EXPECT(). + Patch("/credentials/"+mockCredentials.Id, &AwsCredentialsCreatePayload{ + Name: credentialsName, + OrganizationId: organizationId, + Type: "AWS_ASSUMED_ROLE_FOR_DEPLOYMENT", + Value: payloadValue, + }, + gomock.Any()). + Do(func(path string, request interface{}, response *Credentials) { + *response = mockCredentials + }) + + credentials, _ = apiClient.CredentialsUpdate(credentials.Id, &AwsCredentialsCreatePayload{ + Name: credentialsName, + Value: payloadValue, + Type: "AWS_ASSUMED_ROLE_FOR_DEPLOYMENT", + }) + }) + + It("Should get organization id", func() { + organizationIdCall.Times(1) + }) + + It("Should send PATCH request with params", func() { + httpCall.Times(1) + }) + + It("Should return key", func() { + Expect(credentials).To(Equal(mockCredentials)) + }) + }) + Describe("GcpCredentialsCreate", func() { const gcpRequestType = "GCP_SERVICE_ACCOUNT_FOR_DEPLOYMENT" mockGcpCredentials := mockCredentials diff --git a/env0/resource_cost_credentials.go b/env0/resource_cost_credentials.go index f5350021..a40ee9fa 100644 --- a/env0/resource_cost_credentials.go +++ b/env0/resource_cost_credentials.go @@ -2,7 +2,6 @@ package env0 import ( "context" - "errors" "fmt" "github.com/env0/terraform-provider-env0/client" @@ -15,104 +14,152 @@ const AZURE = "azure" const GOOGLE = "google" func resourceCostCredentials(providerName string) *schema.Resource { - - awsSchema := map[string]*schema.Schema{ - "arn": { - Type: schema.TypeString, - Description: "the aws role arn", - ForceNew: true, - Required: true, - }, + getSchema := func() map[string]*schema.Schema { + switch providerName { + case AWS: + return map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Description: "the aws role arn", + Required: true, + }, + } + case AZURE: + return map[string]*schema.Schema{ + "client_id": { + Type: schema.TypeString, + Description: "the azure client id", + Required: true, + }, + "client_secret": { + Type: schema.TypeString, + Description: "the azure client secret", + Sensitive: true, + Required: true, + }, + "tenant_id": { + Type: schema.TypeString, + Description: "the azure tenant id", + Required: true, + }, + "subscription_id": { + Type: schema.TypeString, + Description: "the azure subscription id", + Required: true, + }, + } + case GOOGLE: + return map[string]*schema.Schema{ + "table_id": { + Type: schema.TypeString, + Description: "the full BigQuery table id of the exported billing data", + Required: true, + }, + "secret": { + Type: schema.TypeString, + Description: "the GCP service account key", + Sensitive: true, + Required: true, + }, + } + default: + panic(fmt.Sprintf("unhandled provider name: %s", providerName)) + } } - azureSchema := map[string]*schema.Schema{ - "client_id": { - Type: schema.TypeString, - Description: "the azure client id", - ForceNew: true, - Required: true, - }, - "client_secret": { - Type: schema.TypeString, - Description: "the azure client secret", - Sensitive: true, - ForceNew: true, - Required: true, - }, - "tenant_id": { - Type: schema.TypeString, - Description: "the azure tenant id", - ForceNew: true, - Required: true, - }, - "subscription_id": { - Type: schema.TypeString, - Description: "the azure subscription id", - ForceNew: true, - Required: true, - }, - } + getPayload := func(d *schema.ResourceData) (client.CredentialCreatePayload, error) { + var payload client.CredentialCreatePayload + var value interface{} + + switch providerName { + case AWS: + payload = &client.AwsCredentialsCreatePayload{ + Type: client.AwsCostCredentialsType, + } + value = &payload.(*client.AwsCredentialsCreatePayload).Value + case AZURE: + payload = &client.AzureCredentialsCreatePayload{ + Type: client.AzureCostCredentialsType, + } + value = &payload.(*client.AzureCredentialsCreatePayload).Value + case GOOGLE: + payload = &client.GoogleCostCredentialsCreatePayload{ + Type: client.GoogleCostCredentialsType, + } + value = &payload.(*client.GoogleCostCredentialsCreatePayload).Value + default: + panic(fmt.Sprintf("unhandled provider name: %s", providerName)) + } - googleSchema := map[string]*schema.Schema{ - "table_id": { - Type: schema.TypeString, - Description: "the full BigQuery table id of the exported billing data", - ForceNew: true, - Required: true, - }, - "secret": { - Type: schema.TypeString, - Description: "the GCP service account key", - Sensitive: true, - ForceNew: true, - Required: true, - }, - } + if err := readResourceData(value, d); err != nil { + return nil, fmt.Errorf("schema resource data deserialization failed: %w", err) + } - schemaMap := map[string]map[string]*schema.Schema{AWS: awsSchema, AZURE: azureSchema, GOOGLE: googleSchema} + if err := readResourceData(payload, d); err != nil { + return nil, fmt.Errorf("schema resource data deserialization failed: %w", err) + } - return &schema.Resource{ - CreateContext: resourceCostCredentialsCreate, - ReadContext: resourceCostCredentialsRead, - DeleteContext: resourceCostCredentialsDelete, - Schema: extendSchema(schemaMap[providerName]), + return payload, nil } -} -func extendSchema(schemaToReadFrom map[string]*schema.Schema) map[string]*schema.Schema { + getResourceCreate := func() func(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + return func(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + payload, err := getPayload(d) + if err != nil { + return diag.FromErr(err) + } + + apiClient := meta.(client.ApiClientInterface) + + res, err := apiClient.CredentialsCreate(payload) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(res.Id) - resultsSchema := map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Description: "the name for the credentials", - Required: true, - ForceNew: true, - }, + return nil + } } - for index, element := range schemaToReadFrom { - resultsSchema[index] = element + getResourceUpdate := func() func(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + return func(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + payload, err := getPayload(d) + if err != nil { + return diag.FromErr(err) + } + + apiClient := meta.(client.ApiClientInterface) + + if _, err := apiClient.CredentialsUpdate(d.Id(), payload); err != nil { + return diag.FromErr(err) + } + + return nil + } } - return resultsSchema -} + resourceSchema := getSchema() -func resourceCostCredentialsCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + resourceSchema["name"] = &schema.Schema{ + Type: schema.TypeString, + Description: "the name for the credentials", + Required: true, + } - apiKey, err := sendApiCallToCreateCred(d, meta) - if err != nil { - return diag.Errorf("Cost credential failed: %v", err) + return &schema.Resource{ + CreateContext: getResourceCreate(), + UpdateContext: getResourceUpdate(), + ReadContext: resourceCostCredentialsRead, + DeleteContext: resourceCostCredentialsDelete, + Schema: resourceSchema, } - d.SetId(apiKey.Id) - return nil } func resourceCostCredentialsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { apiClient := meta.(client.ApiClientInterface) - id := d.Id() - _, err := apiClient.CloudCredentials(id) - if err != nil { + if _, err := apiClient.CloudCredentials(d.Id()); err != nil { return ResourceGetFailure(ctx, "cost credentials", d, err) } return nil @@ -128,47 +175,3 @@ func resourceCostCredentialsDelete(ctx context.Context, d *schema.ResourceData, return nil } - -func sendApiCallToCreateCred(d *schema.ResourceData, meta interface{}) (client.Credentials, error) { - apiClient := meta.(client.ApiClientInterface) - _, awsOk := d.GetOk("arn") - _, azureOk := d.GetOk("client_id") - _, googleOk := d.GetOk("table_id") - switch { - case awsOk: - var value client.AwsCredentialsValuePayload - if err := readResourceData(&value, d); err != nil { - return client.Credentials{}, fmt.Errorf("schema resource data deserialization failed: %v", err) - } - - return apiClient.CredentialsCreate(&client.AwsCredentialsCreatePayload{ - Name: d.Get("name").(string), - Type: client.AwsCostCredentialsType, - Value: value, - }) - case azureOk: - var value client.AzureCredentialsValuePayload - if err := readResourceData(&value, d); err != nil { - return client.Credentials{}, fmt.Errorf("schema resource data deserialization failed: %v", err) - } - - return apiClient.CredentialsCreate(&client.AzureCredentialsCreatePayload{ - Name: d.Get("name").(string), - Type: client.AzureCostCredentialsType, - Value: value, - }) - case googleOk: - var value client.GoogleCostCredentialsValuePayload - if err := readResourceData(&value, d); err != nil { - return client.Credentials{}, fmt.Errorf("schema resource data deserialization failed: %v", err) - } - - return apiClient.CredentialsCreate(&client.GoogleCostCredentialsCreatePayload{ - Name: d.Get("name").(string), - Type: client.GoogleCostCredentialsType, - Value: value, - }) - default: - return client.Credentials{}, errors.New("error in schema, no required value defined") - } -} diff --git a/env0/resource_cost_credentials_test.go b/env0/resource_cost_credentials_test.go index 3debc958..e6443a87 100644 --- a/env0/resource_cost_credentials_test.go +++ b/env0/resource_cost_credentials_test.go @@ -50,7 +50,7 @@ func TestUnitAwsCostCredentialsResource(t *testing.T) { } updateReturnValues := client.Credentials{ - Id: "id2", + Id: "id", Name: "update", OrganizationId: "id", Type: "AWS_ASSUMED_ROLE", @@ -114,8 +114,7 @@ func TestUnitAwsCostCredentialsResource(t *testing.T) { runUnitTest(t, testCaseForUpdate, func(mock *client.MockApiClientInterface) { gomock.InOrder( mock.EXPECT().CredentialsCreate(&awsCredCreatePayload).Times(1).Return(returnValues, nil), - mock.EXPECT().CloudCredentialsDelete(returnValues.Id).Times(1).Return(nil), - mock.EXPECT().CredentialsCreate(&updateAwsCredCreatePayload).Times(1).Return(updateReturnValues, nil), + mock.EXPECT().CredentialsUpdate(returnValues.Id, &updateAwsCredCreatePayload).Times(1).Return(updateReturnValues, nil), ) gomock.InOrder( mock.EXPECT().CloudCredentials(returnValues.Id).Times(2).Return(returnValues, nil), @@ -183,7 +182,7 @@ func TestUnitAzureCostCredentialsResource(t *testing.T) { } updateReturnValues := client.Credentials{ - Id: "id2", + Id: "id", Name: "update", OrganizationId: "id", Type: string(client.AzureCostCredentialsType), @@ -244,8 +243,7 @@ func TestUnitAzureCostCredentialsResource(t *testing.T) { runUnitTest(t, testCaseForUpdate, func(mock *client.MockApiClientInterface) { gomock.InOrder( mock.EXPECT().CredentialsCreate(&azureCredCreatePayload).Times(1).Return(returnValues, nil), - mock.EXPECT().CloudCredentialsDelete(returnValues.Id).Times(1).Return(nil), - mock.EXPECT().CredentialsCreate(&updateAzureCredCreatePayload).Times(1).Return(updateReturnValues, nil), + mock.EXPECT().CredentialsUpdate(returnValues.Id, &updateAzureCredCreatePayload).Times(1).Return(updateReturnValues, nil), ) gomock.InOrder( mock.EXPECT().CloudCredentials(returnValues.Id).Times(2).Return(returnValues, nil), @@ -318,7 +316,7 @@ func TestUnitGoogleCostCredentialsResource(t *testing.T) { } updateReturnValues := client.Credentials{ - Id: "id2", + Id: "id", Name: "update", OrganizationId: "id", Type: string(client.GoogleCostCredentialsType), @@ -373,8 +371,7 @@ func TestUnitGoogleCostCredentialsResource(t *testing.T) { runUnitTest(t, testCaseForUpdate, func(mock *client.MockApiClientInterface) { gomock.InOrder( mock.EXPECT().CredentialsCreate(&googleCostCredCreatePayload).Times(1).Return(returnValues, nil), - mock.EXPECT().CloudCredentialsDelete(returnValues.Id).Times(1).Return(nil), - mock.EXPECT().CredentialsCreate(&updateGoogleCostCredCreatePayload).Times(1).Return(updateReturnValues, nil), + mock.EXPECT().CredentialsUpdate(returnValues.Id, &updateGoogleCostCredCreatePayload).Times(1).Return(updateReturnValues, nil), ) gomock.InOrder( mock.EXPECT().CloudCredentials(returnValues.Id).Times(2).Return(returnValues, nil),