Skip to content

Commit

Permalink
fix(azure): allow CosmosDB Accounts to be referenced by name
Browse files Browse the repository at this point in the history
This fixes some `account_name` not found issues for CosmosDB resources
  • Loading branch information
aliscott committed Feb 21, 2024
1 parent 3e8aa32 commit 352b9ca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
18 changes: 18 additions & 0 deletions internal/providers/terraform/azure/cosmosdb_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package azure

import (
"github.com/infracost/infracost/internal/schema"
)

// This is a free resource but needs it's own custom registry item to specify the custom ID lookup function.
func getCosmosDBAccountRegistryItem() *schema.RegistryItem {
return &schema.RegistryItem{
Name: "azurerm_cosmosdb_account",
NoPrice: true,
Notes: []string{"Free resource."},

CustomRefIDFunc: func(d *schema.ResourceData) []string {
return []string{d.Get("name").String()}
},
}
}
2 changes: 1 addition & 1 deletion internal/providers/terraform/azure/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var ResourceRegistry []*schema.RegistryItem = []*schema.RegistryItem{
GetAzureRMBastionHostRegistryItem(),
GetAzureRMCDNEndpointRegistryItem(),
getContainerRegistryRegistryItem(),
getCosmosDBAccountRegistryItem(),
GetAzureRMCosmosdbCassandraKeyspaceRegistryItem(),
GetAzureRMCosmosdbCassandraTableRegistryItem(),
GetAzureRMCosmosdbGremlinDatabaseRegistryItem(),
Expand Down Expand Up @@ -260,7 +261,6 @@ var FreeResources = []string{
"azurerm_consumption_budget_subscription",

// Azure CosmosDB
"azurerm_cosmosdb_account",
"azurerm_cosmosdb_notebook_workspace",
"azurerm_cosmosdb_sql_stored_procedure",
"azurerm_cosmosdb_sql_trigger",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,10 @@ resource "azurerm_cosmosdb_sql_database" "serverless" {
resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
account_name = azurerm_cosmosdb_account.example.name
}

resource "azurerm_cosmosdb_sql_database" "account_by_name" {
name = "tfex-cosmos-account-by-name"
resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
account_name = "tfex-cosmosdb-account"
throughput = 500
}

0 comments on commit 352b9ca

Please sign in to comment.