{"action":"opened","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/17724","repository_url":"https://api.github.com/repos/hashicorp/terraform","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/17724/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/17724/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/17724/events","html_url":"https://github.com/hashicorp/terraform/issues/17724","id":309654988,"number":17724,"title":"Supernetting using cidrsubnet - wrong results","user":{"login":"szczad","id":2914011,"avatar_url":"https://avatars0.githubusercontent.com/u/2914011?v=4","gravatar_id":"","url":"https://api.github.com/users/szczad","html_url":"https://github.com/szczad","followers_url":"https://api.github.com/users/szczad/followers","following_url":"https://api.github.com/users/szczad/following{/other_user}","gists_url":"https://api.github.com/users/szczad/gists{/gist_id}","starred_url":"https://api.github.com/users/szczad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szczad/subscriptions","organizations_url":"https://api.github.com/users/szczad/orgs","repos_url":"https://api.github.com/users/szczad/repos","events_url":"https://api.github.com/users/szczad/events{/privacy}","received_events_url":"https://api.github.com/users/szczad/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-29T07:57:00Z","updated_at":"2018-03-29T07:57:00Z","closed_at":null,"author_association":"NONE","body":"Hello,\r\n\r\nI'm aware that the **cidrsubnet** function's manual states that the function is used to **extend** the given range (and optionally transpose the result) for subnetting, but the same mechanics is used to **shrinking** the range for supernetting.\r\n\r\nFor the same reason version 1 should be working fine whereas version 2 is rather seeking for workaround (and just an example of broken logic under the hood).\r\n\r\n### Terraform Version\r\n```\r\nTerraform v0.11.5\r\n+ provider.null v1.0.0\r\n```\r\n\r\n### Terraform Configuration Files\r\nVersion 1:\r\n```hcl\r\nresource null_resource test {\r\n  provisioner local-exec {\r\n    command = \"echo ${cidrsubnet(\"10.2.0.0/16\", -8, 0)}\"\r\n  }\r\n}\r\n```\r\n\r\nVersion 2:\r\n```hcl\r\nresource null_resource test {\r\n  provisioner local-exec {\r\n    command = \"echo ${cidrsubnet(\"10.2.0.0/16\", -8, -2)}\"\r\n  }\r\n}\r\n```\r\n\r\n### Expected Behavior\r\n**Version 1**: \r\n```\r\nnull_resource.test: Creating...\r\nnull_resource.test: Provisioning with 'local-exec'...\r\nnull_resource.test (local-exec): Executing: [\"/bin/sh\" \"-c\" \"echo 10.0.0.0/8\"]\r\nnull_resource.test (local-exec): 10.0.0.0/8\r\nnull_resource.test: Creation complete after 0s \r\n```\r\n\r\n**Version 2**:\r\n```\r\nnull_resource.test: Creating...                                     \r\nnull_resource.test: Provisioning with 'local-exec'...               \r\nnull_resource.test (local-exec): Executing: [\"/bin/sh\" \"-c\" \"echo 8.0.0.0/8\"]                                                          \r\nnull_resource.test (local-exec): 8.0.0.0/8                        \r\nnull_resource.test: Creation complete after 0s (\r\n```\r\n\r\n### Actual Behavior\r\n**Version 1**: The function does not truncate trailing bits from address using given mask\r\n```\r\nnull_resource.test: Creating...\r\nnull_resource.test: Provisioning with 'local-exec'...\r\nnull_resource.test (local-exec): Executing: [\"/bin/sh\" \"-c\" \"echo 10.2.0.0/8\"]\r\nnull_resource.test (local-exec): 10.2.0.0/8\r\nnull_resource.test: Creation complete after 0s \r\n```\r\n\r\n**Version 2**: The function masks wrong address bits\r\n```\r\nnull_resource.test: Creating...                                     \r\nnull_resource.test: Provisioning with 'local-exec'...               \r\nnull_resource.test (local-exec): Executing: [\"/bin/sh\" \"-c\" \"echo 1.254.0.0/8\"]                                                          \r\nnull_resource.test (local-exec): 1.254.0.0/8                        \r\nnull_resource.test: Creation complete after 0s (\r\n```\r\n\r\n### Steps to Reproduce\r\n1. `terraform apply -target null_resource.test`\r\n"}}
{"actor":{"display_login":"szczad"}}