Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: env0_cost_credentials_project_assignment not working #369

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions client/cost_credentials_project_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ type CostCredentialProjectAssignment struct {
func (client *ApiClient) AssignCostCredentialsToProject(projectId string, credentialId string) (CostCredentialProjectAssignment, error) {
var result CostCredentialProjectAssignment

err := client.http.Put("/costs/project/"+projectId+"/credentials", credentialId, &result)
err := client.http.Put("/costs/project/"+projectId+"/credentials", map[string]string{
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

body passed was incorrect.

"credentialsId": credentialId,
}, &result)
if err != nil {
return result, err
}
Expand All @@ -22,7 +24,7 @@ func (client *ApiClient) RemoveCostCredentialsFromProject(projectId string, cred

func (client *ApiClient) CostCredentialIdsInProject(projectId string) ([]CostCredentialProjectAssignment, error) {
var result []CostCredentialProjectAssignment
err := client.http.Get("/costs/project/"+projectId, nil, &result)
err := client.http.Get("/costs/project/"+projectId+"/credentials", nil, &result)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

url path was incorrect.


if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions client/cost_credentials_project_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var _ = Describe(" Cost Credentials Project Assignment", func() {
BeforeEach(func() {

httpCall = mockHttpClient.EXPECT().
Put("/costs/project/"+projectId+"/credentials", credentialId, gomock.Any()).
Put("/costs/project/"+projectId+"/credentials", map[string]string{"credentialsId": credentialId}, gomock.Any()).
Do(func(path string, request interface{}, response *CostCredentialProjectAssignment) {
*response = expectedResponse
}).Times(1)
Expand All @@ -41,7 +41,7 @@ var _ = Describe(" Cost Credentials Project Assignment", func() {
var actualError error
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().
Put("/costs/project/"+projectId+"/credentials", credentialId, gomock.Any()).
Put("/costs/project/"+projectId+"/credentials", map[string]string{"credentialsId": credentialId}, gomock.Any()).
Return(errors.New(errorInfo)).
Times(1)
_, actualError = apiClient.AssignCostCredentialsToProject(projectId, credentialId)
Expand Down Expand Up @@ -93,7 +93,7 @@ var _ = Describe(" Cost Credentials Project Assignment", func() {
expectedResponse := []CostCredentialProjectAssignment{firstResulteResponse, secondResulteResponse}
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().
Get("/costs/project/"+projectId, nil, gomock.Any()).
Get("/costs/project/"+projectId+"/credentials", nil, gomock.Any()).
Do(func(path string, request interface{}, response *[]CostCredentialProjectAssignment) {
*response = expectedResponse
}).Times(1)
Expand All @@ -110,7 +110,7 @@ var _ = Describe(" Cost Credentials Project Assignment", func() {
var actualError error
BeforeEach(func() {
httpCall = mockHttpClient.EXPECT().
Get("/costs/project/"+projectId, nil, gomock.Any()).
Get("/costs/project/"+projectId+"/credentials", nil, gomock.Any()).
Return(errors.New(errorInfo)).
Times(1)
_, actualError = apiClient.CostCredentialIdsInProject(projectId)
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/023_cost_credentials_project_assignment/conf.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
backend "local" {
}
required_providers {
env0 = {
source = "terraform-registry.env0.com/env0/env0"
}
}
}

provider "env0" {}

variable "second_run" {
default = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
23 changes: 23 additions & 0 deletions tests/integration/023_cost_credentials_project_assignment/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
provider "random" {}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added an integration test to avoid issues moving forward.


resource "random_string" "random" {
length = 8
special = false
min_lower = 8
}

resource "env0_project" "project" {
name = "Test-Project-${random_string.random.result}"
description = "description"
}

resource "env0_aws_cost_credentials" "cost" {
name = "cost-${random_string.random.result}"
arn = "arn"
external_id = "externalid"
}

resource "env0_cost_credentials_project_assignment" "cost_project_assignment" {
credential_id = env0_aws_cost_credentials.cost.id
project_id = env0_project.project.id
}