diff --git a/azurerm/data_source_cosmos_db_account.go b/azurerm/data_source_cosmos_db_account.go index 0aee23ac951b..779c84ed86b8 100644 --- a/azurerm/data_source_cosmos_db_account.go +++ b/azurerm/data_source_cosmos_db_account.go @@ -238,18 +238,30 @@ func dataSourceArmCosmosDbAccountRead(d *schema.ResourceData, meta interface{}) readEndpoints := make([]string, 0) if locations := props.ReadLocations; locations != nil { for _, l := range *locations { + if l.DocumentEndpoint == nil { + continue + } + readEndpoints = append(readEndpoints, *l.DocumentEndpoint) } } - d.Set("read_endpoints", readEndpoints) + if err := d.Set("read_endpoints", readEndpoints); err != nil { + return fmt.Errorf("Error setting `read_endpoints`: %s", err) + } writeEndpoints := make([]string, 0) if locations := props.WriteLocations; locations != nil { for _, l := range *locations { + if l.DocumentEndpoint == nil { + continue + } + writeEndpoints = append(writeEndpoints, *l.DocumentEndpoint) } } - d.Set("write_endpoints", writeEndpoints) + if err := d.Set("write_endpoints", writeEndpoints); err != nil { + return fmt.Errorf("Error setting `write_endpoints`: %s", err) + } d.Set("enable_multiple_write_locations", resp.EnableMultipleWriteLocations) } diff --git a/azurerm/resource_arm_cosmosdb_account.go b/azurerm/resource_arm_cosmosdb_account.go index 26f6bf271d66..5bd18d1f1bbd 100644 --- a/azurerm/resource_arm_cosmosdb_account.go +++ b/azurerm/resource_arm_cosmosdb_account.go @@ -619,20 +619,32 @@ func resourceArmCosmosDbAccountRead(d *schema.ResourceData, meta interface{}) er return fmt.Errorf("Error setting `virtual_network_rule`: %+v", err) } + readEndpoints := make([]string, 0) if p := resp.ReadLocations; p != nil { - readEndpoints := make([]string, 0) for _, l := range *p { + if l.DocumentEndpoint == nil { + continue + } + readEndpoints = append(readEndpoints, *l.DocumentEndpoint) } - d.Set("read_endpoints", readEndpoints) + } + if err := d.Set("read_endpoints", readEndpoints); err != nil { + return fmt.Errorf("Error setting `read_endpoints`: %s", err) } + writeEndpoints := make([]string, 0) if p := resp.WriteLocations; p != nil { - writeEndpoints := make([]string, 0) for _, l := range *p { + if l.DocumentEndpoint == nil { + continue + } + writeEndpoints = append(writeEndpoints, *l.DocumentEndpoint) } - d.Set("write_endpoints", writeEndpoints) + } + if err := d.Set("write_endpoints", writeEndpoints); err != nil { + return fmt.Errorf("Error setting `write_endpoints`: %s", err) } // ListKeys returns a data structure containing a DatabaseAccountListReadOnlyKeysResult pointer