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

r/cosmosdb: handling when the resource has been deleted #2702

Merged
merged 1 commit into from
Jan 17, 2019
Merged
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
19 changes: 19 additions & 0 deletions azurerm/resource_arm_cosmos_db_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,22 +601,41 @@ func resourceArmCosmosDBAccountRead(d *schema.ResourceData, meta interface{}) er
// implying that it also returns the read only keys, however this appears to not be the case
keys, err := client.ListKeys(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(keys.Response) {
log.Printf("[DEBUG] Keys were not found for CosmosDB Account %q (Resource Group %q) - removing from state!", name, resourceGroup)
d.SetId("")
return nil
}

return fmt.Errorf("[ERROR] Unable to List Write keys for CosmosDB Account %s: %s", name, err)
}
d.Set("primary_master_key", keys.PrimaryMasterKey)
d.Set("secondary_master_key", keys.SecondaryMasterKey)

readonlyKeys, err := client.ListReadOnlyKeys(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(keys.Response) {
log.Printf("[DEBUG] Read Only Keys were not found for CosmosDB Account %q (Resource Group %q) - removing from state!", name, resourceGroup)
d.SetId("")
return nil
}

return fmt.Errorf("[ERROR] Unable to List read-only keys for CosmosDB Account %s: %s", name, err)
}
d.Set("primary_readonly_master_key", readonlyKeys.PrimaryReadonlyMasterKey)
d.Set("secondary_readonly_master_key", readonlyKeys.SecondaryReadonlyMasterKey)

connStringResp, err := client.ListConnectionStrings(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(keys.Response) {
log.Printf("[DEBUG] Connection Strings were not found for CosmosDB Account %q (Resource Group %q) - removing from state!", name, resourceGroup)
d.SetId("")
return nil
}

return fmt.Errorf("[ERROR] Unable to List connection strings for CosmosDB Account %s: %s", name, err)
}

var connStrings []string
if connStringResp.ConnectionStrings != nil {
connStrings = make([]string, len(*connStringResp.ConnectionStrings))
Expand Down