Skip to content

Commit

Permalink
Feat: add the resource configuration_set (#859)
Browse files Browse the repository at this point in the history
* Feat: add the resource configuration_set - WIP

* added more tests

* add integration test

* pass organization id

* fix test

* added update and more tests - wip

* added more tests

* fix test and example

* fix test and example

* add scope id
  • Loading branch information
TomerHeber authored May 29, 2024
1 parent 345934b commit f8e8343
Show file tree
Hide file tree
Showing 9 changed files with 1,292 additions and 5 deletions.
16 changes: 12 additions & 4 deletions client/configuration_set.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package client

import "fmt"

type CreateConfigurationSetPayload struct {
Name string `json:"name"`
Description string `json:"description"`
// if Scope is "organization", scopeId will be calculated in the functions.
Scope string `json:"scope"` // "project" or "organization".
ScopeId string `json:"scopeId"` // project id or organization id.
ConfigurationProperties []ConfigurationVariable `json:"configurationProperties"`
ConfigurationProperties []ConfigurationVariable `json:"configurationProperties" tfschema:"-"`
}

type UpdateConfigurationSetPayload struct {
Name string `json:"name"`
Description string `json:"description"`
ConfigurationPropertiesChanges []ConfigurationVariable `json:"configurationPropertiesChanges"` // delta changes.
ConfigurationPropertiesChanges []ConfigurationVariable `json:"configurationPropertiesChanges" tfschema:"-"` // delta changes.
}

type ConfigurationSet struct {
Expand All @@ -25,7 +27,7 @@ func (client *ApiClient) ConfigurationSetCreate(payload *CreateConfigurationSetP
var result ConfigurationSet
var err error

if payload.Scope == "organization" {
if payload.Scope == "organization" && payload.ScopeId == "" {
payload.ScopeId, err = client.OrganizationId()
if err != nil {
return nil, err
Expand Down Expand Up @@ -64,10 +66,16 @@ func (client *ApiClient) ConfigurationSetDelete(id string) error {
}

func (client *ApiClient) ConfigurationVariablesBySetId(setId string) ([]ConfigurationVariable, error) {
organizationId, err := client.OrganizationId()
if err != nil {
return nil, fmt.Errorf("failed to get organization id: %w", err)
}

var result []ConfigurationVariable

if err := client.http.Get("/configuration", map[string]string{
"setId": setId,
"setId": setId,
"organizationId": organizationId,
}, &result); err != nil {
return nil, err
}
Expand Down
7 changes: 6 additions & 1 deletion client/configuration_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ var _ = Describe("Configuration Set", func() {
var variables []ConfigurationVariable

BeforeEach(func() {
mockOrganizationIdCall(organizationId)

httpCall = mockHttpClient.EXPECT().
Get("/configuration", map[string]string{
"setId": id,
"setId": id,
"organizationId": organizationId,
}, gomock.Any()).
Do(func(path string, request interface{}, response *[]ConfigurationVariable) {
*response = mockVariables
Expand All @@ -152,3 +155,5 @@ var _ = Describe("Configuration Set", func() {
})
})
})

// TODO add more tests...
1 change: 1 addition & 0 deletions env0/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func Provider(version string) plugin.ProviderFunc {
"env0_aws_eks_credentials": resourceAwsEksCredentials(),
"env0_azure_aks_credentials": resourceAzureAksCredentials(),
"env0_gcp_gke_credentials": resourceGcpGkeCredentials(),
"env0_variable_set": resourceVariableSet(),
},
}

Expand Down
Loading

0 comments on commit f8e8343

Please sign in to comment.