-
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.
- Loading branch information
Showing
20 changed files
with
1,276 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.46 | ||
0.0.69 |
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,37 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "dbt_cloud_environment Data Source - terraform-provider-dbt-cloud" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# dbt_cloud_environment (Data Source) | ||
|
||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- **environment_id** (Number) Project ID to create the environment in | ||
- **project_id** (Number) Project ID to create the environment in | ||
|
||
### Optional | ||
|
||
- **id** (String) The ID of this resource. | ||
|
||
### Read-Only | ||
|
||
- **credential_id** (Number) Credential ID to create the environment with | ||
- **custom_branch** (String) Which custom branch to use in this environment | ||
- **dbt_version** (String) Version number of dbt to use in this environment | ||
- **is_active** (Boolean) Whether the environment is active | ||
- **name** (String) Environment name | ||
- **type** (String) The type of environment (must be either development or deployment) | ||
- **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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "dbt_cloud_snowflake_credential Data Source - terraform-provider-dbt-cloud" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# dbt_cloud_snowflake_credential (Data Source) | ||
|
||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- **credential_id** (Number) Credential ID | ||
- **project_id** (Number) Project ID | ||
|
||
### Optional | ||
|
||
- **id** (String) The ID of this resource. | ||
|
||
### Read-Only | ||
|
||
- **auth_type** (String) The type of Snowflake credential ('password' only currently supported in Terraform) | ||
- **is_active** (Boolean) Whether the Snowflake credential is active | ||
- **num_threads** (Number) Number of threads to use | ||
- **password** (String, Sensitive) Password for Snowflake | ||
- **schema** (String) Default schema name | ||
- **user** (String) Username for Snowflake | ||
|
||
|
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,33 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "dbt_cloud_environment Resource - terraform-provider-dbt-cloud" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# dbt_cloud_environment (Resource) | ||
|
||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- **dbt_version** (String) Version number of dbt to use in this environment | ||
- **name** (String) Environment name | ||
- **project_id** (Number) Project ID to create the environment in | ||
- **type** (String) The type of environment (must be either development or deployment) | ||
|
||
### Optional | ||
|
||
- **credential_id** (Number) Credential ID to create the environment with | ||
- **custom_branch** (String) Which custom branch to use in this environment | ||
- **id** (String) The ID of this resource. | ||
- **is_active** (Boolean) Whether the environment is active | ||
- **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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "dbt_cloud_snowflake_credential Resource - terraform-provider-dbt-cloud" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# dbt_cloud_snowflake_credential (Resource) | ||
|
||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- **auth_type** (String) The type of Snowflake credential ('password' only currently supported in Terraform) | ||
- **num_threads** (Number) Number of threads to use | ||
- **password** (String, Sensitive) Password for Snowflake | ||
- **project_id** (Number) Project ID to create the Snowflake credential in | ||
- **schema** (String) Default schema name | ||
- **user** (String) Username for Snowflake | ||
|
||
### Optional | ||
|
||
- **id** (String) The ID of this resource. | ||
- **is_active** (Boolean) Whether the Snowflake credential is active | ||
|
||
### Read-Only | ||
|
||
- **credential_id** (Number) The system Snowflake credential 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,119 @@ | ||
package data_sources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/gthesheep/terraform-provider-dbt-cloud/pkg/dbt_cloud" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
var environmentSchema = map[string]*schema.Schema{ | ||
"environment_id": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Required: true, | ||
Description: "Project ID to create the environment in", | ||
}, | ||
"project_id": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Required: true, | ||
Description: "Project ID to create the environment in", | ||
}, | ||
"is_active": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Whether the environment is active", | ||
}, | ||
"credential_id": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Credential ID to create the environment with", | ||
}, | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Environment name", | ||
}, | ||
"dbt_version": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Version number of dbt to use in this environment", | ||
}, | ||
"type": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The type of environment (must be either development or deployment)", | ||
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { | ||
type_ := val.(string) | ||
switch type_ { | ||
case | ||
"development", | ||
"deployment": | ||
return | ||
} | ||
errs = append(errs, fmt.Errorf("%q must be either development or deployment, got: %q", key, type_)) | ||
return | ||
}, | ||
}, | ||
"use_custom_branch": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Whether to use a custom git branch in this environment", | ||
}, | ||
"custom_branch": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Which custom branch to use in this environment", | ||
}, | ||
} | ||
|
||
func DatasourceEnvironment() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: datasourceEnvironmentRead, | ||
Schema: environmentSchema, | ||
} | ||
} | ||
|
||
func datasourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*dbt_cloud.Client) | ||
|
||
var diags diag.Diagnostics | ||
|
||
environmentID := d.Get("environment_id").(int) | ||
projectID := d.Get("project_id").(int) | ||
|
||
environment, err := c.GetEnvironment(projectID, environmentID) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if err := d.Set("is_active", environment.State == dbt_cloud.STATE_ACTIVE); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := d.Set("project_id", environment.Project_Id); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := d.Set("credential_id", environment.Credential_Id); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := d.Set("name", environment.Name); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := d.Set("dbt_version", environment.Dbt_Version); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := d.Set("type", environment.Type); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := d.Set("use_custom_branch", environment.Use_Custom_Branch); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if err := d.Set("custom_branch", environment.Custom_Branch); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(fmt.Sprintf("%d%s%d", environment.Project_Id, dbt_cloud.ID_DELIMITER, *environment.ID)) | ||
|
||
return diags | ||
} |
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,45 @@ | ||
package data_sources_test | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDbtCloudEnvironmentDataSource(t *testing.T) { | ||
|
||
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) | ||
randomIDInt, _ := strconv.Atoi(randomID) | ||
|
||
config := fmt.Sprintf(` | ||
data "dbt_cloud_environment" "test" { | ||
project_id = 123 | ||
environment_id = %d | ||
} | ||
`, randomIDInt) | ||
|
||
check := resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.dbt_cloud_environment.test", "environment_id", randomID), | ||
resource.TestCheckResourceAttr("data.dbt_cloud_environment.test", "project_id", "123"), | ||
resource.TestCheckResourceAttrSet("data.dbt_cloud_project.test", "name"), | ||
resource.TestCheckResourceAttrSet("data.dbt_cloud_project.test", "is_active"), | ||
resource.TestCheckResourceAttrSet("data.dbt_cloud_project.test", "credential_id"), | ||
resource.TestCheckResourceAttrSet("data.dbt_cloud_project.test", "dbt_version"), | ||
resource.TestCheckResourceAttrSet("data.dbt_cloud_project.test", "type"), | ||
resource.TestCheckResourceAttrSet("data.dbt_cloud_project.test", "use_custom_branch"), | ||
resource.TestCheckResourceAttrSet("data.dbt_cloud_project.test", "custom_branch"), | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
Providers: providers(), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: check, | ||
}, | ||
}, | ||
}) | ||
} |
Oops, something went wrong.