-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add resource aws_cloud_configuration (#923)
* Feat: add resource aws_cloud_configuration * added import and added tests. fixed errors handling. * added examples * updated description * updated description
- Loading branch information
1 parent
c7ba92b
commit ed2b945
Showing
14 changed files
with
924 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package client | ||
|
||
import "fmt" | ||
|
||
type CloudAccountCreatePayload struct { | ||
Provider string `json:"provider"` | ||
Name string `json:"name"` | ||
Configuration interface{} `json:"configuration" tfschema:"-"` | ||
} | ||
|
||
type CloudAccountUpdatePayload struct { | ||
Name string `json:"name"` | ||
Configuration interface{} `json:"configuration" tfschema:"-"` | ||
} | ||
|
||
type AWSCloudAccountConfiguration struct { | ||
AccountId string `json:"accountId"` | ||
BucketName string `json:"bucketName"` | ||
Prefix string `json:"prefix,omitempty"` | ||
Regions []string `json:"regions"` | ||
} | ||
|
||
type CloudAccount struct { | ||
Id string `json:"id"` | ||
Provider string `json:"provider"` | ||
Name string `json:"name"` | ||
Health bool `json:"health"` | ||
Configuration interface{} `json:"configuration" tfschema:"-"` | ||
} | ||
|
||
func (client *ApiClient) CloudAccountCreate(payload *CloudAccountCreatePayload) (*CloudAccount, error) { | ||
organizationId, err := client.OrganizationId() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get organization id: %w", err) | ||
} | ||
|
||
payloadWithOrganizationId := struct { | ||
*CloudAccountCreatePayload | ||
OrganizationId string `json:"organizationId"` | ||
}{ | ||
payload, | ||
organizationId, | ||
} | ||
|
||
var cloudAccount CloudAccount | ||
if err := client.http.Post("/cloud/configurations", &payloadWithOrganizationId, &cloudAccount); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &cloudAccount, nil | ||
} | ||
|
||
func (client *ApiClient) CloudAccountUpdate(id string, payload *CloudAccountUpdatePayload) (*CloudAccount, error) { | ||
var cloudAccount CloudAccount | ||
if err := client.http.Put("/cloud/configurations/"+id, payload, &cloudAccount); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &cloudAccount, nil | ||
} | ||
|
||
func (client *ApiClient) CloudAccountDelete(id string) error { | ||
return client.http.Delete("/cloud/configurations/"+id, nil) | ||
} | ||
|
||
func (client *ApiClient) CloudAccount(id string) (*CloudAccount, error) { | ||
var cloudAccount CloudAccount | ||
|
||
if err := client.http.Get("/cloud/configurations/"+id, nil, &cloudAccount); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &cloudAccount, nil | ||
} | ||
|
||
func (client *ApiClient) CloudAccounts() ([]CloudAccount, error) { | ||
organizationId, err := client.OrganizationId() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get organization id: %w", err) | ||
} | ||
|
||
var cloudAccounts []CloudAccount | ||
if err := client.http.Get("/cloud/configurations", map[string]string{"organizationId": organizationId}, &cloudAccounts); err != nil { | ||
return nil, err | ||
} | ||
|
||
return cloudAccounts, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package client_test | ||
|
||
import ( | ||
. "github.com/env0/terraform-provider-env0/client" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"go.uber.org/mock/gomock" | ||
) | ||
|
||
var _ = Describe("CloudAccount", func() { | ||
var account *CloudAccount | ||
var accounts []CloudAccount | ||
var err error | ||
|
||
awsConfiguration := AWSCloudAccountConfiguration{ | ||
AccountId: "a", | ||
BucketName: "b", | ||
Prefix: "prefix", | ||
Regions: []string{"us-east-10", "us-west-24"}, | ||
} | ||
|
||
awsConfigurationUpdated := AWSCloudAccountConfiguration{ | ||
AccountId: "c", | ||
BucketName: "d", | ||
Prefix: "prefix2", | ||
Regions: []string{"us-east-10"}, | ||
} | ||
|
||
account1 := CloudAccount{ | ||
Id: "id1", | ||
Provider: "AWS", | ||
Name: "name1", | ||
Health: true, | ||
Configuration: &awsConfiguration, | ||
} | ||
|
||
account1Updated := account1 | ||
account1Updated.Name = "updatedname1" | ||
account1Updated.Configuration = awsConfigurationUpdated | ||
|
||
account2 := CloudAccount{ | ||
Id: "id2", | ||
Provider: "GCP", | ||
Name: "name2", | ||
Configuration: []string{"some random configuration"}, | ||
} | ||
|
||
Describe("create", func() { | ||
BeforeEach(func() { | ||
mockOrganizationIdCall(organizationId) | ||
|
||
payload := CloudAccountCreatePayload{ | ||
Provider: account1.Provider, | ||
Name: account1.Name, | ||
Configuration: account1.Configuration, | ||
} | ||
|
||
payloadWithOrganizationId := struct { | ||
*CloudAccountCreatePayload | ||
OrganizationId string `json:"organizationId"` | ||
}{ | ||
&payload, | ||
organizationId, | ||
} | ||
|
||
httpCall = mockHttpClient.EXPECT(). | ||
Post("/cloud/configurations", &payloadWithOrganizationId, gomock.Any()). | ||
Do(func(path string, request interface{}, response *CloudAccount) { | ||
*response = account1 | ||
}).Times(1) | ||
|
||
account, err = apiClient.CloudAccountCreate(&payload) | ||
}) | ||
|
||
It("should get organization id", func() { | ||
organizationIdCall.Times(1) | ||
}) | ||
|
||
It("should return account", func() { | ||
Expect(*account).To(Equal(account1)) | ||
}) | ||
|
||
It("should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
}) | ||
|
||
Describe("update", func() { | ||
BeforeEach(func() { | ||
payload := CloudAccountUpdatePayload{ | ||
Name: account1Updated.Name, | ||
Configuration: account1Updated.Configuration, | ||
} | ||
|
||
httpCall = mockHttpClient.EXPECT(). | ||
Put("/cloud/configurations/"+account.Id, &payload, gomock.Any()). | ||
Do(func(path string, request interface{}, response *CloudAccount) { | ||
*response = account1Updated | ||
}).Times(1) | ||
|
||
account, err = apiClient.CloudAccountUpdate(account.Id, &payload) | ||
}) | ||
|
||
It("should return updated account", func() { | ||
Expect(*account).To(Equal(account1Updated)) | ||
}) | ||
|
||
It("should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
}) | ||
|
||
Describe("delete", func() { | ||
BeforeEach(func() { | ||
httpCall = mockHttpClient.EXPECT(). | ||
Delete("/cloud/configurations/"+account.Id, nil). | ||
Do(func(path string, request interface{}) {}).Times(1) | ||
|
||
err = apiClient.CloudAccountDelete(account.Id) | ||
}) | ||
|
||
It("should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
}) | ||
|
||
Describe("get", func() { | ||
BeforeEach(func() { | ||
httpCall = mockHttpClient.EXPECT(). | ||
Get("/cloud/configurations/"+account.Id, nil, gomock.Any()). | ||
Do(func(path string, request interface{}, response *CloudAccount) { | ||
*response = account1 | ||
}).Times(1) | ||
|
||
account, err = apiClient.CloudAccount(account.Id) | ||
}) | ||
|
||
It("should return account", func() { | ||
Expect(*account).To(Equal(account1)) | ||
}) | ||
|
||
It("should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
}) | ||
|
||
Describe("list", func() { | ||
mockedAccounts := []CloudAccount{ | ||
account1, | ||
account2, | ||
} | ||
|
||
BeforeEach(func() { | ||
mockOrganizationIdCall(organizationId) | ||
|
||
httpCall = mockHttpClient.EXPECT(). | ||
Get("/cloud/configurations", map[string]string{"organizationId": organizationId}, gomock.Any()). | ||
Do(func(path string, request interface{}, response *[]CloudAccount) { | ||
*response = mockedAccounts | ||
}).Times(1) | ||
|
||
accounts, err = apiClient.CloudAccounts() | ||
}) | ||
|
||
It("should return accounts", func() { | ||
Expect(accounts).To(Equal(mockedAccounts)) | ||
}) | ||
|
||
It("should not return error", func() { | ||
Expect(err).To(BeNil()) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.