Skip to content

Commit

Permalink
Fix the doc for database and add extra field (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrojnm committed Jul 11, 2023
1 parent 90ca864 commit ebf0ba6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
19 changes: 19 additions & 0 deletions civo/datasource_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package civo

import (
"context"
"fmt"
"log"
"strings"

Expand Down Expand Up @@ -77,6 +78,21 @@ func dataSourceDatabase() *schema.Resource {
Computed: true,
Description: "The password of the database",
},
"endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "The endpoint of the database",
},
"dns_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "The DNS endpoint of the database",
},
"port": {
Type: schema.TypeInt,
Computed: true,
Description: "The port of the database",
},
"status": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -128,6 +144,9 @@ func dataSourceDatabaseRead(_ context.Context, d *schema.ResourceData, m interfa
d.Set("firewall_id", foundDatabase.FirewallID)
d.Set("username", foundDatabase.Username)
d.Set("password", foundDatabase.Password)
d.Set("endpoint", foundDatabase.PublicIPv4)
d.Set("dns_endpoint", fmt.Sprintf("%s.db.civo.com", foundDatabase.ID))
d.Set("port", foundDatabase.Port)
d.Set("status", foundDatabase.Status)

return nil
Expand Down
20 changes: 20 additions & 0 deletions civo/resource_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package civo

import (
"context"
"fmt"
"log"
"time"

Expand Down Expand Up @@ -47,6 +48,7 @@ func resourceDatabase() *schema.Resource {
Optional: true,
Computed: true,
Description: "The id of the associated network",
ForceNew: true,
},
"nodes": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -76,6 +78,21 @@ func resourceDatabase() *schema.Resource {
Computed: true,
Description: "The password of the database",
},
"endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "The endpoint of the database",
},
"dns_endpoint": {
Type: schema.TypeString,
Computed: true,
Description: "The DNS endpoint of the database",
},
"port": {
Type: schema.TypeInt,
Computed: true,
Description: "The port of the database",
},
"status": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -249,6 +266,9 @@ func resourceDatabaseRead(ctx context.Context, d *schema.ResourceData, m interfa
d.Set("region", apiClient.Region)
d.Set("username", resp.Username)
d.Set("password", resp.Password)
d.Set("endpoint", resp.PublicIPv4)
d.Set("dns_endpoint", fmt.Sprintf("%s.db.civo.com", resp.ID))
d.Set("port", resp.Port)
d.Set("status", resp.Status)

return nil
Expand Down
12 changes: 12 additions & 0 deletions examples/data-sources/civo_database_version/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ data civo_database_version "postgresql" {
}
}

data "civo_size" "small" {
filter {
key = "name"
values = ["db.small"]
match_by = "re"
}
filter {
key = "type"
values = ["database"]
}
}

# To use this data source, make sure you have a database cluster created.
resource "civo_database" "custom_database" {
name = "custom_database"
Expand Down
7 changes: 7 additions & 0 deletions examples/resources/civo_database/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ data "civo_size" "small" {
}
}

data civo_database_version "mysql" {
filter {
key = "engine"
values = ["mysql"]
}
}

resource "civo_database" "custom_database" {
name = "custom_database"
size = element(data.civo_size.small.sizes, 0).name
Expand Down

0 comments on commit ebf0ba6

Please sign in to comment.