Skip to content

Commit

Permalink
d/cosmosdb_account: handling the document endpoint being nil (#3899)
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff authored and katbyte committed Jul 22, 2019
1 parent 73232ad commit af62f66
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
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

0 comments on commit af62f66

Please sign in to comment.