diff --git a/CHANGELOG.md b/CHANGELOG.md index 5207937..16c2f7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [v1.0.3](https://github.com/brainly/terraform-provider-redshift/tree/v1.0.3) (2022-11-15) + +[Full Changelog](https://github.com/brainly/terraform-provider-redshift/compare/v1.0.2...v1.0.3) + +**Fixed bugs:** + +- Fix non-idempotent reapplying grants for entities with ascii chars 33-126 in their names ([rg00d](https://github.com/rg00d)) + ## [v1.0.2](https://github.com/brainly/terraform-provider-redshift/tree/v1.0.2) (2022-09-02) [Full Changelog](https://github.com/brainly/terraform-provider-redshift/compare/v1.0.1...v1.0.2) diff --git a/redshift/resource_redshift_grant.go b/redshift/resource_redshift_grant.go index 0ede967..3165070 100644 --- a/redshift/resource_redshift_grant.go +++ b/redshift/resource_redshift_grant.go @@ -210,8 +210,8 @@ func readDatabaseGrants(db *DBConnection, d *schema.ResourceData) error { entityName = d.Get(grantUserAttr).(string) query = ` SELECT - decode(charindex('C',split_part(split_part(regexp_replace(array_to_string(db.datacl, '|'),'group '||u.usename,'__avoidGroupPrivs__'), u.usename||'=', 2) ,'/',1)), 0,0,1) as create, - decode(charindex('T',split_part(split_part(regexp_replace(array_to_string(db.datacl, '|'),'group '||u.usename,'__avoidGroupPrivs__'), u.usename||'=', 2) ,'/',1)), 0,0,1) as temporary + decode(charindex('C',split_part(split_part(replace(regexp_replace(array_to_string(db.datacl, '|'),'group '||u.usename,'__avoidGroupPrivs__'), '"', ''), u.usename||'=', 2) ,'/',1)), 0,0,1) as create, + decode(charindex('T',split_part(split_part(replace(regexp_replace(array_to_string(db.datacl, '|'),'group '||u.usename,'__avoidGroupPrivs__'), '"', ''), u.usename||'=', 2) ,'/',1)), 0,0,1) as temporary FROM pg_database db, pg_user u WHERE db.datname=$1 @@ -221,8 +221,8 @@ func readDatabaseGrants(db *DBConnection, d *schema.ResourceData) error { entityName = d.Get(grantGroupAttr).(string) query = ` SELECT - decode(charindex('C',split_part(split_part(array_to_string(db.datacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), 0,0,1) as create, - decode(charindex('T',split_part(split_part(array_to_string(db.datacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), 0,0,1) as temporary + decode(charindex('C',split_part(split_part(replace(array_to_string(db.datacl, '|'), '"', ''),'group ' || gr.groname,2 ) ,'/',1)), 0,0,1) as create, + decode(charindex('T',split_part(split_part(replace(array_to_string(db.datacl, '|'), '"', ''),'group ' || gr.groname,2 ) ,'/',1)), 0,0,1) as temporary FROM pg_database db, pg_group gr WHERE db.datname=$1 @@ -256,8 +256,8 @@ func readSchemaGrants(db *DBConnection, d *schema.ResourceData) error { entityName = d.Get(grantUserAttr).(string) query = ` SELECT - decode(charindex('C',split_part(split_part(regexp_replace(array_to_string(ns.nspacl, '|'),'group '||u.usename,'__avoidGroupPrivs__'), u.usename||'=', 2) ,'/',1)), 0,0,1) as create, - decode(charindex('U',split_part(split_part(regexp_replace(array_to_string(ns.nspacl, '|'),'group '||u.usename,'__avoidGroupPrivs__'), u.usename||'=', 2) ,'/',1)), 0,0,1) as usage + decode(charindex('C',split_part(split_part(replace(regexp_replace(array_to_string(ns.nspacl, '|'),'group '||u.usename,'__avoidGroupPrivs__'), '"', ''), u.usename||'=', 2) ,'/',1)), 0,0,1) as create, + decode(charindex('U',split_part(split_part(replace(regexp_replace(array_to_string(ns.nspacl, '|'),'group '||u.usename,'__avoidGroupPrivs__'), '"', ''), u.usename||'=', 2) ,'/',1)), 0,0,1) as usage FROM pg_namespace ns, pg_user u WHERE ns.nspname=$1 @@ -267,8 +267,8 @@ func readSchemaGrants(db *DBConnection, d *schema.ResourceData) error { entityName = d.Get(grantGroupAttr).(string) query = ` SELECT - decode(charindex('C',split_part(split_part(array_to_string(ns.nspacl, '|'),'group ' || gr.groname || '=',2 ) ,'/',1)), 0,0,1) as create, - decode(charindex('U',split_part(split_part(array_to_string(ns.nspacl, '|'),'group ' || gr.groname || '=',2 ) ,'/',1)), 0,0,1) as usage + decode(charindex('C',split_part(split_part(replace(array_to_string(ns.nspacl, '|'), '"', ''),'group ' || gr.groname || '=',2 ) ,'/',1)), 0,0,1) as create, + decode(charindex('U',split_part(split_part(replace(array_to_string(ns.nspacl, '|'), '"', ''),'group ' || gr.groname || '=',2 ) ,'/',1)), 0,0,1) as usage FROM pg_namespace ns, pg_group gr WHERE ns.nspname=$1 @@ -300,14 +300,14 @@ func readTableGrants(db *DBConnection, d *schema.ResourceData) error { query = ` SELECT relname, - decode(charindex('r',split_part(split_part(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as select, - decode(charindex('w',split_part(split_part(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as update, - decode(charindex('a',split_part(split_part(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as insert, - decode(charindex('d',split_part(split_part(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as delete, - decode(charindex('D',split_part(split_part(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as drop, - decode(charindex('x',split_part(split_part(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as references, - decode(charindex('R',split_part(split_part(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as rule, - decode(charindex('t',split_part(split_part(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as trigger + decode(charindex('r',split_part(split_part(replace(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), '"', ''), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as select, + decode(charindex('w',split_part(split_part(replace(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), '"', ''), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as update, + decode(charindex('a',split_part(split_part(replace(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), '"', ''), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as insert, + decode(charindex('d',split_part(split_part(replace(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), '"', ''), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as delete, + decode(charindex('D',split_part(split_part(replace(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), '"', ''), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as drop, + decode(charindex('x',split_part(split_part(replace(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), '"', ''), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as references, + decode(charindex('R',split_part(split_part(replace(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), '"', ''), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as rule, + decode(charindex('t',split_part(split_part(replace(regexp_replace(array_to_string(relacl, '|'),'group '||u.usename), '"', ''), u.usename||'=', 2) ,'/',1)),null,0,0,0,1) as trigger FROM pg_user u, pg_class cl JOIN pg_namespace nsp ON nsp.oid = cl.relnamespace WHERE @@ -320,14 +320,14 @@ func readTableGrants(db *DBConnection, d *schema.ResourceData) error { query = ` SELECT relname, - decode(charindex('r',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as select, - decode(charindex('w',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as update, - decode(charindex('a',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as insert, - decode(charindex('d',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as delete, - decode(charindex('D',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as drop, - decode(charindex('x',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as references, - decode(charindex('R',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as rule, - decode(charindex('t',split_part(split_part(array_to_string(relacl, '|'),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as trigger + decode(charindex('r',split_part(split_part(replace(array_to_string(relacl, '|'), '"', ''),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as select, + decode(charindex('w',split_part(split_part(replace(array_to_string(relacl, '|'), '"', ''),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as update, + decode(charindex('a',split_part(split_part(replace(array_to_string(relacl, '|'), '"', ''),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as insert, + decode(charindex('d',split_part(split_part(replace(array_to_string(relacl, '|'), '"', ''),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as delete, + decode(charindex('D',split_part(split_part(replace(array_to_string(relacl, '|'), '"', ''),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as drop, + decode(charindex('x',split_part(split_part(replace(array_to_string(relacl, '|'), '"', ''),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as references, + decode(charindex('R',split_part(split_part(replace(array_to_string(relacl, '|'), '"', ''),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as rule, + decode(charindex('t',split_part(split_part(replace(array_to_string(relacl, '|'), '"', ''),'group ' || gr.groname || '=',2 ) ,'/',1)), null,0, 0,0, 1) as trigger FROM pg_group gr, pg_class cl JOIN pg_namespace nsp ON nsp.oid = cl.relnamespace WHERE @@ -404,7 +404,7 @@ func readCallableGrants(db *DBConnection, d *schema.ResourceData) error { query = ` SELECT proname, - decode(nvl(charindex('X',split_part(split_part(regexp_replace(array_to_string(pr.proacl, '|'),'group '||u.usename,'__avoidGroupPrivs__'), u.usename||'=', 2) ,'/',1)), 0), 0,0,1) as execute + decode(nvl(charindex('X',split_part(split_part(regexp_replace(replace(array_to_string(pr.proacl, '|'), '"', ''),'group '||u.usename,'__avoidGroupPrivs__'), u.usename||'=', 2) ,'/',1)), 0), 0,0,1) as execute FROM pg_proc_info pr JOIN pg_namespace nsp ON nsp.oid = pr.pronamespace, pg_user u @@ -418,7 +418,7 @@ func readCallableGrants(db *DBConnection, d *schema.ResourceData) error { query = ` SELECT proname, - decode(nvl(charindex('X',split_part(split_part(array_to_string(pr.proacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), 0), 0,0,1) as execute + decode(nvl(charindex('X',split_part(split_part(replace(array_to_string(pr.proacl, '|'), '"', ''),'group ' || gr.groname,2 ) ,'/',1)), 0), 0,0,1) as execute FROM pg_proc_info pr JOIN pg_namespace nsp ON nsp.oid = pr.pronamespace, pg_group gr @@ -480,7 +480,7 @@ func readLanguageGrants(db *DBConnection, d *schema.ResourceData) error { query = ` SELECT lanname, - decode(nvl(charindex('U',split_part(split_part(regexp_replace(array_to_string(lg.lanacl, '|'),'group '||u.usename,'__avoidGroupPrivs__'), u.usename||'=', 2) ,'/',1)), 0), 0,0,1) as usage + decode(nvl(charindex('U',split_part(split_part(regexp_replace(replace(array_to_string(lg.lanacl, '|'), '"', ''),'group '||u.usename,'__avoidGroupPrivs__'), u.usename||'=', 2) ,'/',1)), 0), 0,0,1) as usage FROM pg_language lg, pg_user u WHERE u.usename=$1 @@ -490,7 +490,7 @@ func readLanguageGrants(db *DBConnection, d *schema.ResourceData) error { query = ` SELECT lanname, - decode(nvl(charindex('U',split_part(split_part(array_to_string(lg.lanacl, '|'),'group ' || gr.groname,2 ) ,'/',1)), 0), 0,0,1) as usage + decode(nvl(charindex('U',split_part(split_part(replace(array_to_string(lg.lanacl, '|'), '"', ''),'group ' || gr.groname,2 ) ,'/',1)), 0), 0,0,1) as usage FROM pg_language lg, pg_group gr WHERE gr.groname=$1