Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple redshift_datashare resource #18

Merged
merged 1 commit into from
Aug 19, 2021

Conversation

sworisbreathing
Copy link
Contributor

@sworisbreathing sworisbreathing commented Aug 13, 2021

This is a simplified version of #17. Effectively it's just the auto mode from that PR.

Adds a redshit_datashare resource to manage data sharing between Redshift clusters. This should be defined on the producer cluster.

resource "redshift_datashare" "share" {
  name = "my_datashare"
  owner = "fred" # optional
  publicly_accessible = true # optional. default is false
  schemas = [
    redshift_schema.schema.name,
    redshift_schema.other_schema.name,
  ]
}

For each schema, we ALTER DATASHARE ADD SCHEMA. We also add ALL TABLES IN SCHEMA and ALL FUNCTIONS IN SCHEMA and SET INCLUDENEW=true FOR SCHEMA, so that newly-created tables/functions are automatically exposed to the datashare by the redshift cluster itself, without needing to re-run terraform.

There is test coverage, however because data sharing only works on RA3 clusters, the test case is conditionally enabled on whether or not an environment variable named REDSHIFT_DATASHARE_SUPPORTED is set:

github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:13:      redshiftDatashare                               100.0%        
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:89:      resourceRedshiftDatashareExists                 75.0%
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:105:     resourceRedshiftDatashareCreate                 59.3%
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:153:     addSchemaToDatashare                            75.0%
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:166:     resourceRedshiftDatashareAddSchema              61.5%
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:188:     resourceRedshiftDatashareAddAllFunctions        100.0%        
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:195:     resourceRedshiftDatashareAddAllTables           100.0%        
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:202:     removeSchemaFromDatashare                       75.0%
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:215:     resourceRedshiftDatashareRemoveAllFunctions     100.0%        
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:222:     resourceRedshiftDatashareRemoveAllTables        100.0%        
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:229:     resourceRedshiftDatashareRemoveSchema           50.0%
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:248:     resourceRedshiftDatashareRead                   81.0%
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:293:     readDatashareSchemas                            83.3%
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:319:     resourceRedshiftDatashareUpdate                 61.5%
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:345:     setDatashareOwner                               84.6%
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:366:     setDatasharePubliclyAccessble                   75.0%
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:381:     setDatashareSchemas                             75.0%
github.com/brainly/terraform-provider-redshift/redshift/resource_redshift_datashare.go:411:     resourceRedshiftDatashareDelete                 63.2%

@sworisbreathing
Copy link
Contributor Author

sworisbreathing commented Aug 13, 2021

@winglot if you're happy with this approach it should be pretty quick for me to add a corresponding data source. I'll also need to add a datashare_privilege resource to GRANT USAGE ON DATASHARE to consumer clusters (that's somewhat dependent on #16 since you need to specify the namespace guid for the grant).

State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move the strings to consts as other resources have?

const (
  datashareNameAttr  = "name"
  datashareOwnerAttr = "owner"
  ...
)

In my opinion, this is a better approach rather than raw strings all around, it eliminates the possibility of a typo and makes it easier to rename an attribute in the future if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@winglot - I've moved the attribute names to constants and amended the commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased #20 on these changes as well.

@winglot winglot merged commit 6048f61 into brainly:master Aug 19, 2021
@sworisbreathing sworisbreathing deleted the data-sharing-simple branch August 19, 2021 23:54
StevenKGER pushed a commit to dbsystel/terraform-provider-redshift that referenced this pull request Oct 25, 2024
…aws-sdk-go-v2-config-1.x

Update module github.com/aws/aws-sdk-go-v2/config to v1.18.42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants