Skip to content

Commit 60658fd

Browse files
authored
Merge pull request hashicorp#10707 from hashicorp/b-postgresql-schema-auth
Dept of second thoughts: remove authorization support ASAP.
2 parents a04ce1d + 56a193f commit 60658fd

3 files changed

Lines changed: 3 additions & 83 deletions

File tree

builtin/providers/postgresql/resource_postgresql_schema.go

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import (
1313
)
1414

1515
const (
16-
schemaNameAttr = "name"
17-
schemaAuthorizationAttr = "authorization"
16+
schemaNameAttr = "name"
1817
)
1918

2019
func resourcePostgreSQLSchema() *schema.Resource {
@@ -33,12 +32,6 @@ func resourcePostgreSQLSchema() *schema.Resource {
3332
Required: true,
3433
Description: "The name of the schema",
3534
},
36-
schemaAuthorizationAttr: {
37-
Type: schema.TypeString,
38-
Optional: true,
39-
Computed: true,
40-
Description: "The role name of the owner of the schema",
41-
},
4235
},
4336
}
4437
}
@@ -55,10 +48,6 @@ func resourcePostgreSQLSchemaCreate(d *schema.ResourceData, meta interface{}) er
5548
b := bytes.NewBufferString("CREATE SCHEMA ")
5649
fmt.Fprintf(b, pq.QuoteIdentifier(schemaName))
5750

58-
if v, ok := d.GetOk(schemaAuthorizationAttr); ok {
59-
fmt.Fprint(b, " AUTHORIZATION ", pq.QuoteIdentifier(v.(string)))
60-
}
61-
6251
query := b.String()
6352
_, err = conn.Query(query)
6453
if err != nil {
@@ -99,8 +88,8 @@ func resourcePostgreSQLSchemaRead(d *schema.ResourceData, meta interface{}) erro
9988
defer conn.Close()
10089

10190
schemaId := d.Id()
102-
var schemaName, schemaAuthorization string
103-
err = conn.QueryRow("SELECT nspname, pg_catalog.pg_get_userbyid(nspowner) FROM pg_catalog.pg_namespace WHERE nspname=$1", schemaId).Scan(&schemaName, &schemaAuthorization)
91+
var schemaName string
92+
err = conn.QueryRow("SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname=$1", schemaId).Scan(&schemaName)
10493
switch {
10594
case err == sql.ErrNoRows:
10695
log.Printf("[WARN] PostgreSQL schema (%s) not found", schemaId)
@@ -110,7 +99,6 @@ func resourcePostgreSQLSchemaRead(d *schema.ResourceData, meta interface{}) erro
11099
return errwrap.Wrapf("Error reading schema: {{err}}", err)
111100
default:
112101
d.Set(schemaNameAttr, schemaName)
113-
d.Set(schemaAuthorizationAttr, schemaAuthorization)
114102
d.SetId(schemaName)
115103
return nil
116104
}
@@ -128,10 +116,6 @@ func resourcePostgreSQLSchemaUpdate(d *schema.ResourceData, meta interface{}) er
128116
return err
129117
}
130118

131-
if err := setSchemaAuthorization(conn, d); err != nil {
132-
return err
133-
}
134-
135119
return resourcePostgreSQLSchemaRead(d, meta)
136120
}
137121

@@ -155,23 +139,3 @@ func setSchemaName(conn *sql.DB, d *schema.ResourceData) error {
155139

156140
return nil
157141
}
158-
159-
func setSchemaAuthorization(conn *sql.DB, d *schema.ResourceData) error {
160-
if !d.HasChange(schemaAuthorizationAttr) {
161-
return nil
162-
}
163-
164-
schemaAuthorization := d.Get(schemaAuthorizationAttr).(string)
165-
if schemaAuthorization == "" {
166-
return nil
167-
}
168-
169-
schemaName := d.Get(schemaNameAttr).(string)
170-
query := fmt.Sprintf("ALTER SCHEMA %s OWNER TO %s", pq.QuoteIdentifier(schemaName), pq.QuoteIdentifier(schemaAuthorization))
171-
172-
if _, err := conn.Query(query); err != nil {
173-
return errwrap.Wrapf("Error updating schema AUTHORIZATION: {{err}}", err)
174-
}
175-
176-
return nil
177-
}

builtin/providers/postgresql/resource_postgresql_schema_test.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,6 @@ func TestAccPostgresqlSchema_Basic(t *testing.T) {
2626

2727
resource.TestCheckResourceAttr(
2828
"postgresql_schema.test1", "name", "foo"),
29-
// `postgres` is a calculated value
30-
// based on the username used in the
31-
// provider
32-
resource.TestCheckResourceAttr(
33-
"postgresql_schema.test1", "authorization", "postgres"),
34-
),
35-
},
36-
},
37-
})
38-
39-
resource.Test(t, resource.TestCase{
40-
PreCheck: func() { testAccPreCheck(t) },
41-
Providers: testAccProviders,
42-
CheckDestroy: testAccCheckPostgresqlSchemaDestroy,
43-
Steps: []resource.TestStep{
44-
{
45-
Config: testAccPostgresqlSchemaAuthConfig,
46-
Check: resource.ComposeTestCheckFunc(
47-
testAccCheckPostgresqlSchemaExists("postgresql_schema.test2", "foo2"),
48-
resource.TestCheckResourceAttr(
49-
"postgresql_role.myrole4", "name", "myrole4"),
50-
resource.TestCheckResourceAttr(
51-
"postgresql_role.myrole4", "login", "true"),
52-
53-
resource.TestCheckResourceAttr(
54-
"postgresql_schema.test2", "name", "foo2"),
55-
resource.TestCheckResourceAttr(
56-
"postgresql_schema.test2", "authorization", "myrole4"),
5729
),
5830
},
5931
},
@@ -141,15 +113,3 @@ resource "postgresql_schema" "test1" {
141113
name = "foo"
142114
}
143115
`
144-
145-
var testAccPostgresqlSchemaAuthConfig = `
146-
resource "postgresql_role" "myrole4" {
147-
name = "myrole4"
148-
login = true
149-
}
150-
151-
resource "postgresql_schema" "test2" {
152-
name = "foo2"
153-
authorization = "${postgresql_role.myrole4.name}"
154-
}
155-
`

website/source/docs/providers/postgresql/r/postgresql_schema.html.markdown

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ PostgreSQL database.
1717
```
1818
resource "postgresql_schema" "my_schema" {
1919
name = "my_schema"
20-
authorization = "my_role"
2120
}
2221
```
2322

@@ -26,9 +25,6 @@ resource "postgresql_schema" "my_schema" {
2625
* `name` - (Required) The name of the schema. Must be unique in the PostgreSQL
2726
database instance where it is configured.
2827

29-
* `authorization` - (Optional) The owner of the schema. Defaults to the
30-
username configured in the schema's provider.
31-
3228
## Import Example
3329

3430
`postgresql_schema` supports importing resources. Supposing the following

0 commit comments

Comments
 (0)