-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from dbt-labs/release-0.3.4
- Loading branch information
Showing
63 changed files
with
1,451 additions
and
435 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
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,40 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "dbtcloud_environments Data Source - dbtcloud" | ||
subcategory: "" | ||
description: |- | ||
Retrieve data for multiple environments | ||
--- | ||
|
||
# dbtcloud_environments (Data Source) | ||
|
||
Retrieve data for multiple environments | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `project_id` (Number) The project ID to filter the environments for [Optional] | ||
|
||
### Read-Only | ||
|
||
- `environments` (Attributes Set) The list of environments (see [below for nested schema](#nestedatt--environments)) | ||
|
||
<a id="nestedatt--environments"></a> | ||
### Nested Schema for `environments` | ||
|
||
Read-Only: | ||
|
||
- `credentials_id` (Number) The project ID to which the environment belong | ||
- `custom_branch` (String) The type of deployment environment (currently 'production', 'staging' or empty) | ||
- `dbt_version` (String) Version number of dbt to use in this environment, usually in the format 1.2.0-latest rather than core versions | ||
- `deployment_type` (String) The name of the environment | ||
- `environment_id` (Number) The ID of the environment | ||
- `extended_attributes_id` (Number) The ID of the extended attributes applied | ||
- `name` (String) The name of the environment | ||
- `project_id` (Number) The project ID to which the environment belong | ||
- `type` (String) The name of the environment | ||
- `use_custom_branch` (Boolean) Whether to use a custom git branch in this environment |
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,87 @@ | ||
package environment | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/dbt_cloud" | ||
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var ( | ||
_ datasource.DataSource = &environmentDataSource{} | ||
_ datasource.DataSourceWithConfigure = &environmentDataSource{} | ||
) | ||
|
||
func EnvironmentDataSource() datasource.DataSource { | ||
return &environmentDataSource{} | ||
} | ||
|
||
type environmentDataSource struct { | ||
client *dbt_cloud.Client | ||
} | ||
|
||
func (d *environmentDataSource) Metadata( | ||
_ context.Context, | ||
req datasource.MetadataRequest, | ||
resp *datasource.MetadataResponse, | ||
) { | ||
resp.TypeName = req.ProviderTypeName + "_environment" | ||
} | ||
|
||
func (d *environmentDataSource) Read( | ||
ctx context.Context, | ||
req datasource.ReadRequest, | ||
resp *datasource.ReadResponse, | ||
) { | ||
var config EnvironmentDataSourceModel | ||
|
||
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...) | ||
|
||
environment, err := d.client.GetEnvironment( | ||
int(config.ProjectID.ValueInt64()), | ||
int(config.EnvironmentID.ValueInt64()), | ||
) | ||
if err != nil { | ||
resp.Diagnostics.AddError( | ||
fmt.Sprintf("Did not find environment with this ID: %s", config.EnvironmentID), | ||
err.Error(), | ||
) | ||
return | ||
} | ||
|
||
state := config | ||
|
||
state.CredentialsID = types.Int64PointerValue( | ||
helper.IntPointerToInt64Pointer(environment.Credential_Id), | ||
) | ||
state.Name = types.StringValue(environment.Name) | ||
state.DbtVersion = types.StringValue(environment.Dbt_Version) | ||
state.Type = types.StringValue(environment.Type) | ||
state.UseCustomBranch = types.BoolValue(environment.Use_Custom_Branch) | ||
state.CustomBranch = types.StringPointerValue(environment.Custom_Branch) | ||
state.DeploymentType = types.StringPointerValue(environment.DeploymentType) | ||
state.ExtendedAttributesID = types.Int64PointerValue( | ||
helper.IntPointerToInt64Pointer(environment.ExtendedAttributesID), | ||
) | ||
|
||
diags := resp.State.Set(ctx, &state) | ||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
} | ||
|
||
func (d *environmentDataSource) Configure( | ||
_ context.Context, | ||
req datasource.ConfigureRequest, | ||
_ *datasource.ConfigureResponse, | ||
) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
d.client = req.ProviderData.(*dbt_cloud.Client) | ||
} |
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,103 @@ | ||
package environment | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/dbt_cloud" | ||
"github.com/dbt-labs/terraform-provider-dbtcloud/pkg/helper" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var ( | ||
_ datasource.DataSource = &environmentsDataSources{} | ||
_ datasource.DataSourceWithConfigure = &environmentsDataSources{} | ||
) | ||
|
||
func EnvironmentsDataSources() datasource.DataSource { | ||
return &environmentsDataSources{} | ||
} | ||
|
||
type environmentsDataSources struct { | ||
client *dbt_cloud.Client | ||
} | ||
|
||
func (d *environmentsDataSources) Metadata( | ||
_ context.Context, | ||
req datasource.MetadataRequest, | ||
resp *datasource.MetadataResponse, | ||
) { | ||
resp.TypeName = req.ProviderTypeName + "_environments" | ||
} | ||
|
||
func (d *environmentsDataSources) Read( | ||
ctx context.Context, | ||
req datasource.ReadRequest, | ||
resp *datasource.ReadResponse, | ||
) { | ||
var config EnvironmentsDataSourceModel | ||
|
||
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...) | ||
|
||
var projectID int | ||
if config.ProjectID.IsNull() { | ||
projectID = 0 | ||
} else { | ||
projectID = int(config.ProjectID.ValueInt64()) | ||
} | ||
|
||
environments, err := d.client.GetAllEnvironments(projectID) | ||
|
||
if err != nil { | ||
resp.Diagnostics.AddError( | ||
"Issue when retrieving environments", | ||
err.Error(), | ||
) | ||
return | ||
} | ||
|
||
state := config | ||
|
||
allEnvs := []EnvironmentDataSourceModel{} | ||
for _, environment := range environments { | ||
currentEnv := EnvironmentDataSourceModel{} | ||
|
||
currentEnv.EnvironmentID = types.Int64PointerValue( | ||
helper.IntPointerToInt64Pointer(environment.Environment_Id), | ||
) | ||
currentEnv.ProjectID = types.Int64Value(int64(environment.Project_Id)) | ||
|
||
currentEnv.CredentialsID = types.Int64PointerValue( | ||
helper.IntPointerToInt64Pointer(environment.Credential_Id), | ||
) | ||
currentEnv.Name = types.StringValue(environment.Name) | ||
currentEnv.DbtVersion = types.StringValue(environment.Dbt_Version) | ||
currentEnv.Type = types.StringValue(environment.Type) | ||
currentEnv.UseCustomBranch = types.BoolValue(environment.Use_Custom_Branch) | ||
currentEnv.CustomBranch = types.StringPointerValue(environment.Custom_Branch) | ||
currentEnv.DeploymentType = types.StringPointerValue(environment.DeploymentType) | ||
currentEnv.ExtendedAttributesID = types.Int64PointerValue( | ||
helper.IntPointerToInt64Pointer(environment.ExtendedAttributesID), | ||
) | ||
allEnvs = append(allEnvs, currentEnv) | ||
} | ||
state.Environments = allEnvs | ||
|
||
diags := resp.State.Set(ctx, &state) | ||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
} | ||
|
||
func (d *environmentsDataSources) Configure( | ||
_ context.Context, | ||
req datasource.ConfigureRequest, | ||
_ *datasource.ConfigureResponse, | ||
) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
d.client = req.ProviderData.(*dbt_cloud.Client) | ||
} |
Oops, something went wrong.