|
| 1 | +package postgresql |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 5 | + "strconv" |
| 6 | + "strings" |
| 7 | +) |
| 8 | + |
| 9 | +func dataSourcePostgreSQLDatabaseConnection() *schema.Resource { |
| 10 | + return &schema.Resource{ |
| 11 | + Read: PGResourceFunc(dataSourcePostgreSQLConnectionRead), |
| 12 | + Schema: map[string]*schema.Schema{ |
| 13 | + "host": { |
| 14 | + Type: schema.TypeString, |
| 15 | + Computed: true, |
| 16 | + Description: "The current connected PostgreSQL server hostname", |
| 17 | + }, |
| 18 | + "port": { |
| 19 | + Type: schema.TypeInt, |
| 20 | + Computed: true, |
| 21 | + Description: "The current connected PostgreSQL server port", |
| 22 | + }, |
| 23 | + "scheme": { |
| 24 | + Type: schema.TypeString, |
| 25 | + Computed: true, |
| 26 | + Description: "TThe current connected PostgreSQL server scheme", |
| 27 | + }, |
| 28 | + "username": { |
| 29 | + Type: schema.TypeString, |
| 30 | + Computed: true, |
| 31 | + Description: "The current connected username of the PostgreSQL server", |
| 32 | + }, |
| 33 | + "database_username": { |
| 34 | + Type: schema.TypeString, |
| 35 | + Computed: true, |
| 36 | + Description: "The current connected username of the PostgreSQL server", |
| 37 | + }, |
| 38 | + "version": { |
| 39 | + Type: schema.TypeString, |
| 40 | + Computed: true, |
| 41 | + Description: "The current connected PostgreSQL server version", |
| 42 | + }, |
| 43 | + "database": { |
| 44 | + Type: schema.TypeString, |
| 45 | + Computed: true, |
| 46 | + Description: "The current connected PostgreSQL server database", |
| 47 | + }, |
| 48 | + }, |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +func dataSourcePostgreSQLConnectionRead(db *DBConnection, d *schema.ResourceData) error { |
| 53 | + d.Set("host", db.client.config.Host) |
| 54 | + d.Set("port", db.client.config.Port) |
| 55 | + d.Set("scheme", db.client.config.Scheme) |
| 56 | + d.Set("username", db.client.config.Username) |
| 57 | + d.Set("database_username", db.client.config.DatabaseUsername) |
| 58 | + d.Set("version", db.version.String()) |
| 59 | + d.Set("database", db.client.databaseName) |
| 60 | + |
| 61 | + d.SetId(strings.Join([]string{ |
| 62 | + db.client.config.Host, |
| 63 | + strconv.Itoa(db.client.config.Port), |
| 64 | + db.client.config.Scheme, |
| 65 | + db.client.config.Username, |
| 66 | + db.client.config.DatabaseUsername, |
| 67 | + db.version.String(), |
| 68 | + db.client.databaseName, |
| 69 | + }, "_")) |
| 70 | + return nil |
| 71 | +} |
0 commit comments