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

cosmos db account - now checks to see if name is already in use #1464

Merged
merged 1 commit into from
Jun 29, 2018
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
15 changes: 10 additions & 5 deletions azurerm/resource_arm_cosmos_db_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,16 @@ func resourceArmCosmosDBAccountCreate(d *schema.ResourceData, meta interface{})
ipRangeFilter := d.Get("ip_range_filter").(string)
enableAutomaticFailover := d.Get("enable_automatic_failover").(bool)

r, err := client.CheckNameExists(ctx, name)
if err != nil {
return fmt.Errorf("Error checking if CosmosDB Account %q already exists (Resource Group %q): %+v", name, resourceGroup, err)
}
if !utils.ResponseWasNotFound(r) {
return fmt.Errorf("CosmosDB Account %s already exists, please import the resource via terraform import", name)
}

//hacky, todo fix up once deprecated field 'failover_policy' is removed
var geoLocations []documentdb.Location
var err error
if _, ok := d.GetOk("geo_location"); ok {
geoLocations, err = expandAzureRmCosmosDBAccountGeoLocations(name, d)
if err != nil {
Expand All @@ -277,7 +284,7 @@ func resourceArmCosmosDBAccountCreate(d *schema.ResourceData, meta interface{})
}
} else {
//could be a CustomizeDiff?, but this is temporary
return fmt.Errorf("Neither `geo_location` or `failover_policy` is set for CosmosDB Account '%s'", name)
return fmt.Errorf("Neither `geo_location` or `failover_policy` is set for CosmosDB Account %s", name)
}

account := documentdb.DatabaseAccountCreateUpdateParameters{
Expand All @@ -298,9 +305,7 @@ func resourceArmCosmosDBAccountCreate(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error creating CosmosDB Account %q (Resource Group %q): %+v", name, resourceGroup, err)
}

//todo is this still required?
r := *resp
id := r.ID
id := resp.ID
if id == nil {
return fmt.Errorf("Cannot read CosmosDB Account '%s' (resource group %s) ID", name, resourceGroup)
}
Expand Down