Skip to content

Commit

Permalink
Merge pull request brainly#117 from mmichaelb/fix-deprecated-errors
Browse files Browse the repository at this point in the history
fix deprecated errors
  • Loading branch information
mmichaelb authored Apr 28, 2024
2 parents c491cda + a6f7d50 commit 87369e6
Show file tree
Hide file tree
Showing 30 changed files with 299 additions and 294 deletions.
2 changes: 1 addition & 1 deletion redshift/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

var (
dbRegistryLock sync.Mutex
dbRegistry map[string]*DBConnection = make(map[string]*DBConnection, 1)
dbRegistry = make(map[string]*DBConnection, 1)
)

// Config - provider config
Expand Down
10 changes: 5 additions & 5 deletions redshift/data_source_redshift_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func dataSourceRedshiftDatabase() *schema.Resource {
return &schema.Resource{
Description: `Fetches information about a Redshift database.`,
Read: RedshiftResourceFunc(dataSourceRedshiftDatabaseRead),
ReadContext: RedshiftResourceFunc(dataSourceRedshiftDatabaseRead),
Schema: map[string]*schema.Schema{
databaseNameAttr: {
Type: schema.TypeString,
Expand Down Expand Up @@ -73,12 +73,12 @@ func dataSourceRedshiftDatabaseRead(db *DBConnection, d *schema.ResourceData) er

err := db.QueryRow(`SELECT
pg_database_info.datid,
trim(pg_user_info.usename),
TRIM(pg_user_info.usename),
COALESCE(pg_database_info.datconnlimit::text, 'UNLIMITED'),
svv_redshift_databases.database_type,
trim(COALESCE(svv_datashares.share_name, '')),
trim(COALESCE(svv_datashares.producer_account, '')),
trim(COALESCE(svv_datashares.producer_namespace, ''))
TRIM(COALESCE(svv_datashares.share_name, '')),
TRIM(COALESCE(svv_datashares.producer_account, '')),
TRIM(COALESCE(svv_datashares.producer_namespace, ''))
FROM
svv_redshift_databases
LEFT JOIN pg_database_info
Expand Down
4 changes: 2 additions & 2 deletions redshift/data_source_redshift_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
func TestAccDataSourceRedshiftDatabase_basic(t *testing.T) {
dbName := strings.ReplaceAll(acctest.RandomWithPrefix("tf_acc_data_basic"), "-", "_")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceRedshiftDatabaseConfig_basic(dbName),
Expand Down
2 changes: 1 addition & 1 deletion redshift/data_source_redshift_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func dataSourceRedshiftGroup() *schema.Resource {
Description: `
Groups are collections of users who are all granted whatever privileges are associated with the group. You can use groups to assign privileges by role. For example, you can create different groups for sales, administration, and support and give the users in each group the appropriate access to the data they require for their work. You can grant or revoke privileges at the group level, and those changes will apply to all members of the group, except for superusers.
`,
Read: RedshiftResourceFunc(dataSourceRedshiftGroupRead),
ReadContext: RedshiftResourceFunc(dataSourceRedshiftGroupRead),
Schema: map[string]*schema.Schema{
groupNameAttr: {
Type: schema.TypeString,
Expand Down
6 changes: 3 additions & 3 deletions redshift/data_source_redshift_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ func TestAccDataSourceRedshiftGroup_basic(t *testing.T) {
groupName := strings.ReplaceAll(acctest.RandomWithPrefix("tf_acc_data_basic"), "-", "_")
userName := strings.ReplaceAll(acctest.RandomWithPrefix("tf_acc_data_basic"), "-", "_")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRedshiftGroupDestroy,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckRedshiftGroupDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataSourceRedshiftGroupConfig_basic(groupName, userName),
Expand Down
2 changes: 1 addition & 1 deletion redshift/data_source_redshift_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
func dataSourceRedshiftNamespace() *schema.Resource {
return &schema.Resource{
Description: `Gets the cluster namespace (unique ID) of the Amazon Redshift cluster.`,
Read: RedshiftResourceFunc(dataSourceRedshiftNamespaceRead),
ReadContext: RedshiftResourceFunc(dataSourceRedshiftNamespaceRead),
Schema: map[string]*schema.Schema{},
}
}
Expand Down
4 changes: 2 additions & 2 deletions redshift/data_source_redshift_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ data "redshift_namespace" "namespace" {
}
`
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Expand Down
12 changes: 6 additions & 6 deletions redshift/data_source_redshift_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func dataSourceRedshiftSchema() *schema.Resource {
Description: `
A database contains one or more named schemas. Each schema in a database contains tables and other kinds of named objects. By default, a database has a single schema, which is named PUBLIC. You can use schemas to group database objects under a common name. Schemas are similar to file system directories, except that schemas cannot be nested.
`,
Read: RedshiftResourceFunc(dataSourceRedshiftSchemaRead),
ReadContext: RedshiftResourceFunc(dataSourceRedshiftSchemaRead),
Schema: map[string]*schema.Schema{
schemaNameAttr: {
Type: schema.TypeString,
Expand Down Expand Up @@ -269,13 +269,13 @@ func dataSourceRedshiftSchemaRead(db *DBConnection, d *schema.ResourceData) erro
err := db.QueryRow(`
SELECT
pg_namespace.oid,
trim(pg_user_info.usename),
trim(svv_all_schemas.schema_type)
TRIM(pg_user_info.usename),
TRIM(svv_all_schemas.schema_type)
FROM svv_all_schemas
INNER JOIN pg_namespace ON (svv_all_schemas.database_name = $1 and svv_all_schemas.schema_name = pg_namespace.nspname)
INNER JOIN pg_namespace ON (svv_all_schemas.database_name = $1 AND svv_all_schemas.schema_name = pg_namespace.nspname)
LEFT JOIN pg_user_info
ON (svv_all_schemas.database_name = $1 and pg_user_info.usesysid = svv_all_schemas.schema_owner)
where svv_all_schemas.database_name = $1
ON (svv_all_schemas.database_name = $1 AND pg_user_info.usesysid = svv_all_schemas.schema_owner)
WHERE svv_all_schemas.database_name = $1
AND svv_all_schemas.schema_name = $2`, db.client.databaseName, d.Get(schemaNameAttr).(string)).Scan(&schemaId, &schemaOwner, &schemaType)
if err != nil {
return err
Expand Down
36 changes: 18 additions & 18 deletions redshift/data_source_redshift_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
func TestAccDataSourceRedshiftSchema_basic(t *testing.T) {
schemaName := strings.ReplaceAll(acctest.RandomWithPrefix("tf_acc_data_basic"), "-", "_")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRedshiftSchemaDestroy,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckRedshiftSchemaDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataSourceRedshiftSchemaConfig_basic(schemaName),
Expand Down Expand Up @@ -68,9 +68,9 @@ data "redshift_schema" "spectrum" {
`,
schemaNameAttr, schemaName, schemaExternalSchemaAttr, dbName, tfArray(iamRoleArns))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRedshiftSchemaDestroy,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckRedshiftSchemaDestroy,
Steps: []resource.TestStep{
{
Config: configCreate,
Expand Down Expand Up @@ -133,9 +133,9 @@ data "redshift_schema" "hive" {
`,
schemaNameAttr, schemaName, schemaExternalSchemaAttr, dbName, dbHostname, dbPort, tfArray(iamRoleArns))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRedshiftSchemaDestroy,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckRedshiftSchemaDestroy,
Steps: []resource.TestStep{
{
Config: configCreate,
Expand Down Expand Up @@ -209,9 +209,9 @@ data "redshift_schema" "postgres" {
`,
schemaNameAttr, schemaName, schemaExternalSchemaAttr, dbName, dbHostname, dbPort, dbSchema, tfArray(iamRoleArns), dbSecretArn)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRedshiftSchemaDestroy,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckRedshiftSchemaDestroy,
Steps: []resource.TestStep{
{
Config: configCreate,
Expand Down Expand Up @@ -281,9 +281,9 @@ data "redshift_schema" "mysql" {
`,
schemaNameAttr, schemaName, schemaExternalSchemaAttr, dbName, dbHostname, dbPort, tfArray(iamRoleArns), dbSecretArn)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRedshiftSchemaDestroy,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckRedshiftSchemaDestroy,
Steps: []resource.TestStep{
{
Config: configCreate,
Expand Down Expand Up @@ -342,9 +342,9 @@ data "redshift_schema" "redshift" {
`,
schemaNameAttr, schemaName, schemaExternalSchemaAttr, dbName, dbSchema)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRedshiftSchemaDestroy,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckRedshiftSchemaDestroy,
Steps: []resource.TestStep{
{
Config: configCreate,
Expand Down
4 changes: 2 additions & 2 deletions redshift/data_source_redshift_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func dataSourceRedshiftUser() *schema.Resource {
Description: `
This data source can be used to fetch information about a specific database user. Users are authenticated when they login to Amazon Redshift. They can own databases and database objects (for example, tables) and can grant privileges on those objects to users, groups, and schemas to control who has access to which object. Users with CREATE DATABASE rights can create databases and grant privileges to those databases. Superusers have database ownership privileges for all databases.
`,
Read: RedshiftResourceFunc(dataSourceRedshiftUserRead),
ReadContext: RedshiftResourceFunc(dataSourceRedshiftUserRead),
Schema: map[string]*schema.Schema{
userNameAttr: {
Type: schema.TypeString,
Expand Down Expand Up @@ -71,7 +71,7 @@ func dataSourceRedshiftUserRead(db *DBConnection, d *schema.ResourceData) error
"superuser",
"syslog_access",
`COALESCE(connection_limit::TEXT, 'UNLIMITED')`,
"sessiontimeout",
"session_timeout",
}

values := []interface{}{
Expand Down
6 changes: 3 additions & 3 deletions redshift/data_source_redshift_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
func TestAccDataSourceRedshiftUser_Basic(t *testing.T) {
userName := strings.ReplaceAll(acctest.RandomWithPrefix("tf_acc_data_user_basic"), "-", "_")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRedshiftUserDestroy,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckRedshiftUserDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataSourceRedshiftUserConfig_Basic(userName),
Expand Down
10 changes: 6 additions & 4 deletions redshift/helpers.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package redshift

import (
"context"
"database/sql"
"encoding/csv"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"log"
"strings"
"time"
Expand Down Expand Up @@ -80,16 +82,16 @@ func getSchemaIDFromName(tx *sql.Tx, schema string) (schemaID int, err error) {
return
}

func RedshiftResourceFunc(fn func(*DBConnection, *schema.ResourceData) error) func(*schema.ResourceData, interface{}) error {
return func(d *schema.ResourceData, meta interface{}) error {
func RedshiftResourceFunc(fn func(*DBConnection, *schema.ResourceData) error) func(context.Context, *schema.ResourceData, interface{}) diag.Diagnostics {
return func(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*Client)

db, err := client.Connect()
if err != nil {
return err
return diag.FromErr(err)
}

return fn(db, d)
return diag.FromErr(fn(db, d))
}
}

Expand Down
9 changes: 5 additions & 4 deletions redshift/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package redshift
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"log"
"regexp"
"time"
Expand Down Expand Up @@ -143,14 +144,14 @@ func Provider() *schema.Provider {
"redshift_database": dataSourceRedshiftDatabase(),
"redshift_namespace": dataSourceRedshiftNamespace(),
},
ConfigureFunc: providerConfigure,
ConfigureContextFunc: providerConfigure,
}
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
username, password, err := resolveCredentials(d)
if err != nil {
return nil, err
return nil, diag.FromErr(err)
}
config := Config{
Host: d.Get("host").(string),
Expand All @@ -173,7 +174,7 @@ func resolveCredentials(d *schema.ResourceData) (string, string, error) {
if (!ok) || username == nil {
return "", "", fmt.Errorf("Username is required")
}
if _, useTemporaryCredentials := d.GetOk("temporary_credentials.0"); useTemporaryCredentials {
if _, useTemporaryCredentials := d.GetOk("temporary_credentials"); useTemporaryCredentials {
log.Println("[DEBUG] using temporary credentials authentication")
dbUser, dbPassword, err := temporaryCredentials(username.(string), d)
log.Printf("[DEBUG] got temporary credentials with username %s\n", dbUser)
Expand Down
8 changes: 4 additions & 4 deletions redshift/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
)

var (
testAccProviders map[string]*schema.Provider
testAccProviders map[string]func() (*schema.Provider, error)
testAccProvider *schema.Provider
)

func init() {
testAccProvider = Provider()
testAccProviders = map[string]*schema.Provider{
"redshift": testAccProvider,
testAccProviders = map[string]func() (*schema.Provider, error){
"redshift": func() (*schema.Provider, error) { return testAccProvider, nil },
}
}

Expand All @@ -32,7 +32,7 @@ func TestProvider(t *testing.T) {
}

func TestProvider_impl(t *testing.T) {
var _ *schema.Provider = Provider()
var _ = Provider()
}

func testAccPreCheck(t *testing.T) {
Expand Down
24 changes: 12 additions & 12 deletions redshift/resource_redshift_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const databaseDatashareSourceAccountAttr = "account_id"

func redshiftDatabase() *schema.Resource {
return &schema.Resource{
Description: `Defines a local database.`,
Exists: RedshiftResourceExistsFunc(resourceRedshiftDatabaseExists),
Create: RedshiftResourceFunc(resourceRedshiftDatabaseCreate),
Read: RedshiftResourceFunc(resourceRedshiftDatabaseRead),
Update: RedshiftResourceFunc(resourceRedshiftDatabaseUpdate),
Delete: RedshiftResourceFunc(resourceRedshiftDatabaseDelete),
Description: `Defines a local database.`,
Exists: RedshiftResourceExistsFunc(resourceRedshiftDatabaseExists),
CreateContext: RedshiftResourceFunc(resourceRedshiftDatabaseCreate),
ReadContext: RedshiftResourceFunc(resourceRedshiftDatabaseRead),
UpdateContext: RedshiftResourceFunc(resourceRedshiftDatabaseUpdate),
DeleteContext: RedshiftResourceFunc(resourceRedshiftDatabaseDelete),
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
StateContext: schema.ImportStatePassthroughContext,
},
CustomizeDiff: forceNewIfListSizeChanged(databaseDatashareSourceAttr),
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -203,13 +203,13 @@ func resourceRedshiftDatabaseRead(db *DBConnection, d *schema.ResourceData) erro
var name, owner, connLimit, databaseType, shareName, producerAccount, producerNamespace string

query := `SELECT
trim(svv_redshift_databases.database_name),
trim(pg_user_info.usename),
TRIM(svv_redshift_databases.database_name),
TRIM(pg_user_info.usename),
COALESCE(pg_database_info.datconnlimit::text, 'UNLIMITED'),
svv_redshift_databases.database_type,
trim(COALESCE(svv_datashares.share_name, '')),
trim(COALESCE(svv_datashares.producer_account, '')),
trim(COALESCE(svv_datashares.producer_namespace, ''))
TRIM(COALESCE(svv_datashares.share_name, '')),
TRIM(COALESCE(svv_datashares.producer_account, '')),
TRIM(COALESCE(svv_datashares.producer_namespace, ''))
FROM
svv_redshift_databases
LEFT JOIN pg_database_info
Expand Down
14 changes: 7 additions & 7 deletions redshift/resource_redshift_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
func TestAccResourceRedshiftDatabase_Basic(t *testing.T) {
dbName := strings.ReplaceAll(acctest.RandomWithPrefix("tf_acc_resource_basic"), "-", "_")
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRedshiftDatabaseDestroy,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckRedshiftDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: testAccResourceRedshiftDatabaseConfig_Basic(dbName),
Expand Down Expand Up @@ -69,9 +69,9 @@ resource "redshift_user" "user" {
`, databaseNameAttr, dbNameNew, databaseOwnerAttr, userNameAttr, databaseConnLimitAttr, userName)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckRedshiftDatabaseDestroy,
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckRedshiftDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: configCreate,
Expand Down Expand Up @@ -148,7 +148,7 @@ func checkDatabaseExists(client *Client, database string) (bool, error) {
return false, err
}
var _rez int
err = db.QueryRow("SELECT 1 from pg_database WHERE datname=$1", strings.ToLower(database)).Scan(&_rez)
err = db.QueryRow("SELECT 1 FROM pg_database WHERE datname=$1", strings.ToLower(database)).Scan(&_rez)
switch {
case err == sql.ErrNoRows:
return false, nil
Expand Down
Loading

0 comments on commit 87369e6

Please sign in to comment.