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 - adding support for connection_strings #1194

Merged
merged 2 commits into from
May 4, 2018
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
36 changes: 28 additions & 8 deletions azurerm/resource_arm_cosmos_db_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ func resourceArmCosmosDBAccount() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"connection_strings": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}
Expand Down Expand Up @@ -490,19 +498,31 @@ func resourceArmCosmosDBAccountRead(d *schema.ResourceData, meta interface{}) er

keys, err := client.ListKeys(ctx, resourceGroup, name)
if err != nil {
log.Printf("[ERROR] Unable to List Write keys for CosmosDB Account %s: %s", name, err)
} else {
d.Set("primary_master_key", keys.PrimaryMasterKey)
d.Set("secondary_master_key", keys.SecondaryMasterKey)
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 {
log.Printf("[ERROR] Unable to List read-only keys for CosmosDB Account %s: %s", name, err)
} else {
d.Set("primary_readonly_master_key", readonlyKeys.PrimaryReadonlyMasterKey)
d.Set("secondary_readonly_master_key", readonlyKeys.SecondaryReadonlyMasterKey)
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 {
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))
for i, v := range *connStringResp.ConnectionStrings {
connStrings[i] = *v.ConnectionString
}

}
d.Set("connection_strings", connStrings)

return nil
}
Expand Down
1 change: 1 addition & 0 deletions azurerm/resource_arm_cosmos_db_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func TestAccAzureRMCosmosDBAccount_mongoDB(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
checkAccAzureRMCosmosDBAccount_basic(resourceName, testLocation(), string(documentdb.BoundedStaleness), 1),
resource.TestCheckResourceAttr(resourceName, "kind", "MongoDB"),
resource.TestCheckResourceAttr(resourceName, "connection_strings.#", "1"),
),
},
},
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cosmosdb_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ The following attributes are exported:

* `secondary_readonly_master_key` - The Secondary read-only master key for the CosmosDB Account.

* `connection_strings` - A list of connection strings available for this CosmosDB account. If the kind is `GlobalDocumentDB`, this will be empty.


## Import

Expand Down