-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added team/teams data resource (#64)
Co-authored-by: Nico Gelders <[email protected]> Co-authored-by: Quinten Bruynseraede <[email protected]>
- Loading branch information
1 parent
79fb6fb
commit 82e4a7a
Showing
12 changed files
with
437 additions
and
2 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
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,30 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "dagster_team Data Source - dagster" | ||
subcategory: "" | ||
description: |- | ||
Retrieve information about a Dagster Cloud team. | ||
--- | ||
|
||
# dagster_team (Data Source) | ||
|
||
Retrieve information about a Dagster Cloud team. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "dagster_team" "team" { | ||
name = "my-team-name" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) Name of the Dagster Cloud team | ||
|
||
### Read-Only | ||
|
||
- `id` (String) Team id |
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,41 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "dagster_teams Data Source - dagster" | ||
subcategory: "" | ||
description: |- | ||
Retrieve information about a Dagster Cloud teams. | ||
--- | ||
|
||
# dagster_teams (Data Source) | ||
|
||
Retrieve information about a Dagster Cloud teams. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "dagster_teams" "teams" { | ||
regex_filter = "^my-team" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `regex_filter` (String) Regex filter to select the Dagster Cloud teams based on the name of the team. (regex matching is done using `https://pkg.go.dev/regexp`) | ||
|
||
### Read-Only | ||
|
||
- `teams` (Attributes List) Teams (see [below for nested schema](#nestedatt--teams)) | ||
|
||
<a id="nestedatt--teams"></a> | ||
### Nested Schema for `teams` | ||
|
||
Required: | ||
|
||
- `name` (String) Name of the Dagster Cloud team | ||
|
||
Read-Only: | ||
|
||
- `id` (String) Team id |
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,3 @@ | ||
data "dagster_team" "team" { | ||
name = "my-team-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "dagster_teams" "teams" { | ||
regex_filter = "^my-team" | ||
} |
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,98 @@ | ||
package datasources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/datarootsio/terraform-provider-dagster/internal/client" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
// Ensure the implementation satisfies the expected interfaces. | ||
var ( | ||
_ datasource.DataSource = &TeamDataSource{} | ||
_ datasource.DataSourceWithConfigure = &TeamDataSource{} | ||
) | ||
|
||
type TeamDataSource struct { | ||
client client.DagsterClient | ||
} | ||
|
||
type TeamDataSourceModel struct { | ||
Name types.String `tfsdk:"name"` | ||
Id types.String `tfsdk:"id"` | ||
} | ||
|
||
//nolint:ireturn // required by Terraform API | ||
func NewTeamDataSource() datasource.DataSource { | ||
return &TeamDataSource{} | ||
} | ||
|
||
// Metadata returns the data source type name. | ||
func (d *TeamDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_team" | ||
} | ||
|
||
var teamAttributes = map[string]schema.Attribute{ | ||
"name": schema.StringAttribute{ | ||
Required: true, | ||
Computed: false, | ||
Description: "Name of the Dagster Cloud team", | ||
}, | ||
"id": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "Team id", | ||
}, | ||
} | ||
|
||
// Schema defines the schema for the data source. | ||
func (d *TeamDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Description: `Retrieve information about a Dagster Cloud team.`, | ||
Attributes: teamAttributes, | ||
} | ||
} | ||
|
||
// Configure adds the provider-configured client to the data source. | ||
func (d *TeamDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
client, ok := req.ProviderData.(client.DagsterClient) | ||
if !ok { | ||
resp.Diagnostics.AddError( | ||
"Unexpected Data Source Configure Type", | ||
fmt.Sprintf("Expected client.DagsterClient, got: %T. Please report this issue to the provider developers.", req.ProviderData), | ||
) | ||
|
||
return | ||
} | ||
|
||
d.client = client | ||
} | ||
|
||
// Read refreshes the Terraform state with the latest data. | ||
func (d *TeamDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var data TeamDataSourceModel | ||
|
||
// Read Terraform configuration data into the model | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) | ||
|
||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
team, err := d.client.TeamsClient.GetTeamByName(ctx, data.Name.ValueString()) | ||
if err != nil { | ||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to get team information, got error: %s", err)) | ||
return | ||
} | ||
|
||
data.Id = types.StringValue(team.Id) | ||
data.Name = types.StringValue(team.Name) | ||
|
||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} |
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,61 @@ | ||
package datasources_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/datarootsio/terraform-provider-dagster/internal/testutils" | ||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/terraform" | ||
) | ||
|
||
func testAccTeamConfig(name string) string { | ||
return fmt.Sprintf(testutils.ProviderConfig+` | ||
data "dagster_team" "this" { | ||
name = "%s" | ||
} | ||
`, name) | ||
} | ||
|
||
func TestAccTeam(t *testing.T) { | ||
name := "test-team" | ||
var teamId string | ||
var teamName string | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testutils.AccTestPreCheck(t) }, | ||
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccTeamConfig(name), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testutils.FetchValueFromState("data.dagster_team.this", "id", &teamId), | ||
testutils.FetchValueFromState("data.dagster_team.this", "name", &teamName), | ||
testTeamProperties(&teamName, &teamId), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testTeamProperties(name *string, id *string) resource.TestCheckFunc { | ||
return func(state *terraform.State) error { | ||
client := testutils.GetDagsterClientFromEnvVars() | ||
|
||
team, err := client.TeamsClient.GetTeamByName(context.Background(), *name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if team.Name != *name { | ||
return fmt.Errorf("expected team name to be %s, got %s", *name, team.Name) | ||
} | ||
|
||
if team.Id != *id { | ||
return fmt.Errorf("expected team id to be %s, got %s", *id, team.Id) | ||
} | ||
|
||
return nil | ||
} | ||
} |
Oops, something went wrong.