Skip to content

Commit

Permalink
Add datacenter ID to computed attributes of databases
Browse files Browse the repository at this point in the history
  • Loading branch information
emerkle826 committed Jun 21, 2022
1 parent f01fe33 commit 3b8e963
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ data "astra_database" "db" {
- `cloud_provider` (String) Cloud provider (AWS, GCP, AZURE)
- `cqlsh_url` (String) URL for cqlsh web
- `data_endpoint_url` (String) REST API URL
- `datacenters` (Map of String) Map of Datacenter IDs. The map key is "cloud_provider.region". Example: "GCP.us-east4".
- `grafana_url` (String) URL for the grafana dashboard for this database
- `graphql_url` (String) Graphql URL
- `keyspace` (String) Initial keyspace
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/private_link_endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ description: |-
```terraform
data "astra_private_link_endpoints" "dev" {
database_id = "8d356587-73b3-430a-9c0e-d780332e2afb"
datacenter_id = "8d356587-73b3-430a-9c0e-d780332e2afb"
datacenter_id = "8d356587-73b3-430a-9c0e-d780332e2afb-1"
endpoint_id = "com.amazonaws.vpce.us-east-1.vpce-svc-03ac5a4b18ee480df"
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/private_links.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ description: |-
```terraform
data "astra_private_links" "dev" {
database_id = "a6bc9c26-e7ce-424f-84c7-0a00afb12588"
datacenter_id = "a6bc9c26-e7ce-424f-84c7-0a00afb12588"
datacenter_id = "a6bc9c26-e7ce-424f-84c7-0a00afb12588-1"
}
```

Expand Down
3 changes: 2 additions & 1 deletion docs/resources/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ resource "astra_database" "example" {

### Read-Only

- `additional_keyspaces` (List of String) The total_storage
- `additional_keyspaces` (List of String) Additional keyspaces
- `cqlsh_url` (String) The cqlsh_url
- `data_endpoint_url` (String) The data_endpoint_url
- `datacenters` (Map of String) Map of Datacenter IDs. The map key is "cloud_provider.region". Example: "GCP.us-east4".
- `grafana_url` (String) The grafana_url
- `graphql_url` (String) The graphql_url
- `node_count` (Number) The node_count
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/private_link.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ description: |-
resource "astra_private_link" "example" {
allowed_principals = ["arn:aws:iam::111708290731:user/sebastian.estevez"]
database_id = "a6bc9c26-e7ce-424f-84c7-0a00afb12588"
datacenter_id = "a6bc9c26-e7ce-424f-84c7-0a00afb12588"
datacenter_id = "a6bc9c26-e7ce-424f-84c7-0a00afb12588-1"
}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
data "astra_private_link_endpoints" "dev" {
database_id = "8d356587-73b3-430a-9c0e-d780332e2afb"
datacenter_id = "8d356587-73b3-430a-9c0e-d780332e2afb"
datacenter_id = "8d356587-73b3-430a-9c0e-d780332e2afb-1"
endpoint_id = "com.amazonaws.vpce.us-east-1.vpce-svc-03ac5a4b18ee480df"
}
2 changes: 1 addition & 1 deletion examples/data-sources/astra_private_links/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
data "astra_private_links" "dev" {
database_id = "a6bc9c26-e7ce-424f-84c7-0a00afb12588"
datacenter_id = "a6bc9c26-e7ce-424f-84c7-0a00afb12588"
datacenter_id = "a6bc9c26-e7ce-424f-84c7-0a00afb12588-1"
}
2 changes: 1 addition & 1 deletion examples/resources/astra_private_link/resource.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "astra_private_link" "example" {
allowed_principals = ["arn:aws:iam::111708290731:user/sebastian.estevez"]
database_id = "a6bc9c26-e7ce-424f-84c7-0a00afb12588"
datacenter_id = "a6bc9c26-e7ce-424f-84c7-0a00afb12588"
datacenter_id = "a6bc9c26-e7ce-424f-84c7-0a00afb12588-1"
}
8 changes: 8 additions & 0 deletions internal/provider/data_source_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ func dataSourceDatabase() *schema.Resource {
Type: schema.TypeString,
},
},
"datacenters": {
Description: "Map of Datacenter IDs. The map key is \"cloud_provider.region\". Example: \"GCP.us-east4\".",
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}
Expand Down
18 changes: 16 additions & 2 deletions internal/provider/resource_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ func resourceDatabase() *schema.Resource {
Computed: true,
},
"additional_keyspaces": {
Description: "The total_storage",
Description: "Additional keyspaces",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"datacenters": {
Description: "Map of Datacenter IDs. The map key is \"cloud_provider.region\". Example: \"GCP.us-east4\".",
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}
Expand Down Expand Up @@ -511,19 +519,25 @@ func flattenDatabase(db *astra.Database) map[string]interface{} {
"node_count": db.Storage.NodeCount,
"replication_factor": db.Storage.ReplicationFactor,
"total_storage": db.Storage.TotalStorage,
"datacenters": map[string]interface{}{},
}

if db.Info.CloudProvider != nil {
cloudProvider := *db.Info.CloudProvider
flatDB["cloud_provider"] = string(cloudProvider)
}

if db.Info.Datacenters != nil && len(*db.Info.Datacenters) > 1 {
if db.Info.Datacenters != nil {
regions := make([]string, len(*db.Info.Datacenters))
datacenters := make(map[string]interface{}, len(*db.Info.Datacenters))
for index, dc := range *db.Info.Datacenters {
regions[index] = dc.Region
// make a datacenter key of cloud_provider.region
dcKey := strings.ToLower(flatDB["cloud_provider"].(string) + "." + dc.Region)
datacenters[dcKey] = *dc.Id
}
flatDB["regions"] = regions
flatDB["datacenters"] = datacenters
}
return flatDB
}
Expand Down

0 comments on commit 3b8e963

Please sign in to comment.