Skip to content

Commit 40c9dd3

Browse files
authored
Add datasource to retrieve pg password while using IAM (#4)
1 parent 4a759ac commit 40c9dd3

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package postgresql
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
5+
)
6+
7+
func dataSourcePostgrePassword() *schema.Resource {
8+
return &schema.Resource{
9+
Read: dataSourcePostgrePasswordRead,
10+
Schema: map[string]*schema.Schema{
11+
"password": {
12+
Type: schema.TypeString,
13+
Computed: true,
14+
},
15+
},
16+
}
17+
}
18+
19+
func dataSourcePostgrePasswordRead(d *schema.ResourceData, meta interface{}) error {
20+
client := meta.(*Client)
21+
d.SetId("password")
22+
d.Set("password", client.config.Password)
23+
return nil
24+
}

postgresql/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ func Provider() *schema.Provider {
175175
"postgresql_function": resourcePostgreSQLFunction(),
176176
},
177177

178+
DataSourcesMap: map[string]*schema.Resource{
179+
"postgresql_password": dataSourcePostgrePassword(),
180+
},
181+
178182
ConfigureFunc: providerConfigure,
179183
}
180184
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
layout: "postgresql"
3+
page_title: "PostgreSQL: postgresql_password"
4+
sidebar_current: "docs-postgresql-datasource-postgresql_password"
5+
description: |-
6+
Retrieve the postgres password generated by IAM Authentication
7+
---
8+
9+
# postgresql\_password
10+
11+
The ``postgresql_password`` data source can be used to retrieve the password
12+
generated by IAM Authentication for any other usage.
13+
14+
## Usage
15+
16+
```hcl
17+
data "postgresql_password" "my_password" {
18+
}
19+
```
20+
21+
## Attributes Reference
22+
23+
* `password` - The password generated by IAM Authentication (or the password provided by the user)

website/postgresql.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@
4545
</li>
4646
</ul>
4747
</li>
48+
49+
<li<%= sidebar_current("docs-postgresql-datasource") %>>
50+
<a href="#">Data Sources</a>
51+
<ul class="nav nav-visible">
52+
<li<%= sidebar_current("docs-postgresql-datasource-postgresql_password") %>>
53+
<a href="/docs/providers/postgresql/d/postgresql_password.html">postgresql_password</a>
54+
</li>
55+
</ul>
56+
</li>
4857
</ul>
4958
</div>
5059
<% end %>

0 commit comments

Comments
 (0)