Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d/cosmosdb_account: handling the document endpoint being nil #3899

Merged
merged 1 commit into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions azurerm/data_source_cosmos_db_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
20 changes: 16 additions & 4 deletions azurerm/resource_arm_cosmosdb_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down