-
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.
Merge branch 'main' into chore-filter-out-scopes-#751
- Loading branch information
Showing
22 changed files
with
712 additions
and
10 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
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
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
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,21 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "env0_custom_flow Data Source - terraform-provider-env0" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# env0_custom_flow (Data Source) | ||
|
||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `id` (String) ID of the custom flow | ||
- `name` (String) The name of the custom flow |
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,46 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "env0_aws_oidc_credentials Resource - terraform-provider-env0" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# env0_aws_oidc_credentials (Resource) | ||
|
||
|
||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "env0_aws_oidc_credentials" "credentials" { | ||
name = "example" | ||
role_arn = "arn::role::34" | ||
duration = 3600 | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) name for the oidc credentials | ||
- `role_arn` (String) the aws role arn | ||
|
||
### Optional | ||
|
||
- `duration` (Number) the session duration in seconds. If set must be one of the following: 3600 (1h), 7200 (2h), 14400 (4h), 18000 (5h default), 28800 (8h), 43200 (12h) | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
terraform import env0_aws_oidc_credentials.by_id d31a6b30-5f69-4d24-937c-22322754934e | ||
terraform import env0_aws_oidc_credentials.by_name "credentials name" | ||
``` |
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
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
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,55 @@ | ||
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" | ||
) | ||
|
||
func dataCustomFlow() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataCustomFlowRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Description: "The name of the custom flow", | ||
Optional: true, | ||
ExactlyOneOf: []string{"name", "id"}, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Description: "ID of the custom flow", | ||
Optional: true, | ||
ExactlyOneOf: []string{"name", "id"}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataCustomFlowRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
var err error | ||
var customFlow *client.CustomFlow | ||
|
||
id, ok := d.GetOk("id") | ||
if ok { | ||
customFlow, err = meta.(client.ApiClientInterface).CustomFlow(id.(string)) | ||
if err != nil { | ||
return diag.Errorf("failed to get custom flow by id: %v", err) | ||
} | ||
} else { | ||
name := d.Get("name") | ||
customFlow, err = getCustomFlowByName(name.(string), meta) | ||
if err != nil { | ||
return diag.Errorf("failed to get custom flow by name: %v", err) | ||
} | ||
} | ||
|
||
if err := writeResourceData(customFlow, d); err != nil { | ||
return diag.Errorf("schema resource data serialization failed: %v", err) | ||
} | ||
|
||
return 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,100 @@ | ||
package env0 | ||
|
||
import ( | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/env0/terraform-provider-env0/client" | ||
"github.com/env0/terraform-provider-env0/client/http" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestCustomFlowDataSource(t *testing.T) { | ||
customFlow := client.CustomFlow{ | ||
Id: "id0", | ||
Name: "name0", | ||
Repository: "rep1", | ||
Path: "path", | ||
} | ||
|
||
otherCustomFlow := client.CustomFlow{ | ||
Id: "id1", | ||
Name: "name1", | ||
Repository: "rep2", | ||
Path: "path", | ||
} | ||
|
||
customFlowFieldsByName := map[string]interface{}{"name": customFlow.Name} | ||
customFlowFieldsById := map[string]interface{}{"id": customFlow.Id} | ||
|
||
resourceType := "env0_custom_flow" | ||
resourceName := "test_custom_flow" | ||
accessor := dataSourceAccessor(resourceType, resourceName) | ||
|
||
getValidTestCase := func(input map[string]interface{}) resource.TestCase { | ||
return resource.TestCase{ | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: dataSourceConfigCreate(resourceType, resourceName, input), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr(accessor, "id", customFlow.Id), | ||
resource.TestCheckResourceAttr(accessor, "name", customFlow.Name), | ||
), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
getErrorTestCase := func(input map[string]interface{}, expectedError string) resource.TestCase { | ||
return resource.TestCase{ | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: dataSourceConfigCreate(resourceType, resourceName, input), | ||
ExpectError: regexp.MustCompile(expectedError), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
mockListCustomFlowsCall := func(returnValue []client.CustomFlow) func(mockFunc *client.MockApiClientInterface) { | ||
return func(mock *client.MockApiClientInterface) { | ||
mock.EXPECT().CustomFlows(customFlow.Name).AnyTimes().Return(returnValue, nil) | ||
} | ||
} | ||
|
||
mockCustomFlowCall := func(returnValue *client.CustomFlow) func(mockFunc *client.MockApiClientInterface) { | ||
return func(mock *client.MockApiClientInterface) { | ||
mock.EXPECT().CustomFlow(customFlow.Id).AnyTimes().Return(returnValue, nil) | ||
} | ||
} | ||
|
||
t.Run("By ID", func(t *testing.T) { | ||
runUnitTest(t, | ||
getValidTestCase(customFlowFieldsById), | ||
mockCustomFlowCall(&customFlow), | ||
) | ||
}) | ||
|
||
t.Run("By Name", func(t *testing.T) { | ||
runUnitTest(t, | ||
getValidTestCase(customFlowFieldsByName), | ||
mockListCustomFlowsCall([]client.CustomFlow{customFlow}), | ||
) | ||
}) | ||
|
||
t.Run("Throw error when by name and more than one custom flow exists", func(t *testing.T) { | ||
runUnitTest(t, | ||
getErrorTestCase(customFlowFieldsByName, "found multiple custom flows with name"), | ||
mockListCustomFlowsCall([]client.CustomFlow{customFlow, otherCustomFlow, customFlow}), | ||
) | ||
}) | ||
|
||
t.Run("Throw error when by id and no custom flow found with that id", func(t *testing.T) { | ||
runUnitTest(t, | ||
getErrorTestCase(customFlowFieldsById, "failed to get custom flow by id"), | ||
func(mock *client.MockApiClientInterface) { | ||
mock.EXPECT().CustomFlow(customFlow.Id).Times(1).Return(nil, http.NewMockFailedResponseError(404)) | ||
}, | ||
) | ||
}) | ||
} |
Oops, something went wrong.