generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #14
- Loading branch information
Showing
9 changed files
with
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "sql_driver Data Source - terraform-provider-sql" | ||
subcategory: "" | ||
description: |- | ||
The sql_driver datasource allows you to determine which driver is in use by the provider. This is mostly useful for module development when you may communicate with multiple types of databases. | ||
--- | ||
|
||
# sql_driver (Data Source) | ||
|
||
The `sql_driver` datasource allows you to determine which driver is in use by the provider. This is mostly useful for module development when you may communicate with multiple types of databases. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Read-Only | ||
|
||
- **id** (String, Deprecated) This attribute is only present for some compatibility issues and should not be used. It will be removed in a future version. | ||
- **name** (String) The name of the driver, currently this will be one of `pgx`, `mysql`, or `sqlserver`. | ||
|
||
|
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,61 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5/tftypes" | ||
"github.com/paultyng/terraform-provider-sql/internal/server" | ||
) | ||
|
||
type dataDriver struct { | ||
driver string | ||
} | ||
|
||
var _ server.DataSource = (*dataDriver)(nil) | ||
|
||
func newDataDriver(driver driverName) (*dataDriver, error) { | ||
return &dataDriver{ | ||
driver: string(driver), | ||
}, nil | ||
} | ||
|
||
func (d *dataDriver) Schema(context.Context) *tfprotov5.Schema { | ||
return &tfprotov5.Schema{ | ||
Block: &tfprotov5.SchemaBlock{ | ||
Description: "The `sql_driver` datasource allows you to determine which driver is in use by the provider. This " + | ||
"is mostly useful for module development when you may communicate with multiple types of databases.", | ||
DescriptionKind: tfprotov5.StringKindMarkdown, | ||
Attributes: []*tfprotov5.SchemaAttribute{ | ||
{ | ||
Name: "name", | ||
Computed: true, | ||
Description: "The name of the driver, currently this will be one of `pgx`, `mysql`, or `sqlserver`.", | ||
DescriptionKind: tfprotov5.StringKindMarkdown, | ||
Type: tftypes.String, | ||
}, | ||
|
||
deprecatedIDAttribute(), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *dataDriver) Validate(ctx context.Context, config map[string]tftypes.Value) ([]*tfprotov5.Diagnostic, error) { | ||
return nil, nil | ||
} | ||
|
||
func (d *dataDriver) Read(ctx context.Context, config map[string]tftypes.Value) (map[string]tftypes.Value, []*tfprotov5.Diagnostic, error) { | ||
return map[string]tftypes.Value{ | ||
"name": tftypes.NewValue( | ||
tftypes.String, | ||
d.driver, | ||
), | ||
|
||
// just a placeholder, see deprecatedIDAttribute | ||
"id": tftypes.NewValue( | ||
tftypes.String, | ||
"", | ||
), | ||
}, nil, 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,54 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
helperresource "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
func TestDataDriver(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping long test") | ||
} | ||
|
||
for _, server := range testServers { | ||
// TODO: check nulls for all these | ||
t.Run(server.ServerType, func(t *testing.T) { | ||
url, _, err := server.URL() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
helperresource.UnitTest(t, helperresource.TestCase{ | ||
ProtoV5ProviderFactories: protoV5ProviderFactories, | ||
Steps: []helperresource.TestStep{ | ||
{ | ||
|
||
Config: fmt.Sprintf(` | ||
provider "sql" { | ||
url = %q | ||
max_idle_conns = 0 | ||
} | ||
data "sql_driver" "test" { | ||
} | ||
`, url), | ||
Check: helperresource.ComposeTestCheckFunc( | ||
func(s *terraform.State) error { | ||
rs := s.RootModule().Resources["data.sql_driver.test"] | ||
att := rs.Primary.Attributes["name"] | ||
if att != server.ExpectedDriver { | ||
return fmt.Errorf("expected %q, got %q", server.ExpectedDriver, att) | ||
} | ||
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
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