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

azurerm_cosmosdb_account ip_range_filter doesn't actually allow CIDR #2146

Closed
test-in-prod opened this issue Oct 23, 2018 · 2 comments
Closed

Comments

@test-in-prod
Copy link

test-in-prod commented Oct 23, 2018

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.11.8

  • provider.azurerm v1.16.0
  • provider.external v1.0.0
  • provider.random v2.0.0

Affected Resource(s)

  • azurerm_cosmosdb_account

Terraform Configuration Files

variable "our_ip_whitelist" {
  default = ["0.0.0.0/24" ... ] # Example list of our public IPs
}

locals {
  
  # IP Range Filter here is to allow azure portal access
  cosmosdb_ip_range_azure = [
    "104.42.195.92/32",
    "40.76.54.131/32",
    "52.176.6.30/32",
    "52.169.50.45/32",
    "52.187.184.26/32"
  ]
}

resource "azurerm_cosmosdb_account" "nameredacted" {
  name                  = "${var.name}"
  resource_group_name   = "${var.resource_group_name}"
  location              = "${var.location}"
  tags                  = "${var.tags}"

  offer_type            = "${var.offer_type}"
  kind                  = "${var.kind}"

  # IPs https://docs.microsoft.com/en-us/azure/cosmos-db/firewall-support#connections-from-the-azure-portal
  ip_range_filter       = "${join(",",concat(local.cosmosdb_ip_range_azure,var.our_ip_whitelist)}"
  is_virtual_network_filter_enabled = "true"
  virtual_network_rule {
      id                = "${var.vnet_subnet_id}"
  }

  consistency_policy {
      consistency_level = "Session"
  }

  geo_location {
      location          = "${var.location}"
      failover_priority = 0
  } 
}

Expected Behavior

IPs with CIDR notations added to CosmosDB firewall.

For sake of sanity:

output "test" {
  value = "${join(",",concat(local.cosmosdb_ip_range_azure,var.our_ip_whitelist))}"
}

produces

test = 104.42.195.92/32,40.76.54.131/32,52.176.6.30/32,52.169.50.45/32,52.187.184.26/32,0.0.0.0/24

Actual Behavior

terraform plan

Error: module.cosmosdb.azurerm_cosmosdb_account.sirenplatform: invalid value for ip_range_filter (Cosmos DB ip_range_filter must be a set of CIDR IP addresses separated by commas with no spaces: '10.0.0.1,10.0.0.2,10.20.0.0/16')

Steps to Reproduce

See configuration example above, then run terraform plan

Important Factoids

Actually adding IPs manually in Azure Portal, then trying to terraform plan to check sanity if the string is correct gives me this plan:

 ~ cosmosdb.azurerm_cosmosdb_account.<redacted>
      ip_range_filter: "0.0.0.0/24,1.1.1.1/24,104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45,52.187.184.26" => ""

In short, it seems that validation for ip_range_filter is erroneous. All IPs provided are in CIDR have no spaces and are separated by commas.

@test-in-prod
Copy link
Author

test-in-prod commented Oct 23, 2018

Hm.. it seems that upon closer inspection of regex for this field, it's not allowing a /32 (single IP) even if Azure allows it. In fact neither /31, /30 work, but /29 does.

Looks like a possible workaround might be to use replace() to strip out /32:

${replace(join(",",var.ip_range_filter),"/32","")}

@ghost
Copy link

ghost commented Mar 6, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants