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

issue with referencing ipv6 cidr block in subnet #3603

Open
anilkaliya123 opened this issue Apr 23, 2024 · 1 comment
Open

issue with referencing ipv6 cidr block in subnet #3603

anilkaliya123 opened this issue Apr 23, 2024 · 1 comment
Labels
bug Something isn't working new Un-triaged issue pre-built providers Issues around pre-built providers managed at https://github.com/hashicorp/cdktf-repository-manager

Comments

@anilkaliya123
Copy link

anilkaliya123 commented Apr 23, 2024

Expected Behavior

  • I am trying to create a vpc and subnet and assign amazon-provided ipv6 to vpc.

  • The second resource is subnet which uses the ipv6 cidr_block of vpc but has smaller subnet ("/64").

  • I assumed this should have worked, since subnet is dependent on vpc,

  • it should be able to read the ipv6 cidr block of vpc and truncate to /64.

    test_vpc = Vpc(
               self,
               "cmc-vpc",
               cidr_block="10.10.0.0/16",
               enable_dns_hostnames=True,
               tags={**DEFAULT_TAGS, "Name": f"{stack_id}-test"},
               assign_generated_ipv6_cidr_block=true
           )
                 test_subnet = Subnet(
               self,
               "test-subnet-external",
               tags={**DEFAULT_TAGS_CMC, "Name": f"{stack_id}-test-external"},
               cidr_block="10.10.0.0/16",
               availability_zone=REGION_AZ_MAPPING[region][0],
               vpc_id=test_vpc.id,
               map_public_ip_on_launch=False,
               depends_on =[cmc_vpc],
               ipv6_cidr_block = test_vpc.ipv6_cidr_block.split("/")[0] + "/64"
           )
    


### Actual Behavior

> The ipv6_cidr_block of vpc is /56 (amazon provided ipv6), 
> Subnet is not able to get the /64 cidr_block and it throws an error like 
> invalid cidr block  2600:1f18:7fb:9600::/56/64
> seems like  ipv6 of subnet is getting appended with /64 , and truncation is not happening . 
> Any suggestion here, how can i achieve the same

### Steps to Reproduce

1. create stack 

class DbVpcStack(TerraformStack):
def init(
self,
scope: Construct,
stack_id: str,
region: str,
dbvpc_cidr_block: str,
):
super().init(scope, stack_id)
test_vpc = Vpc(
self,
"cmc-vpc",
cidr_block="10.10.0.0/16",
enable_dns_hostnames=True,
tags={**DEFAULT_TAGS, "Name": f"{stack_id}-test"},
assign_generated_ipv6_cidr_block=true
)
test_subnet = Subnet(
self,
"test-subnet-external",
tags={**DEFAULT_TAGS_CMC, "Name": f"{stack_id}-test-external"},
cidr_block="10.10.0.0/16",
availability_zone=REGION_AZ_MAPPING[region][0],
vpc_id=test_vpc.id,
map_public_ip_on_launch=False,
depends_on =[cmc_vpc],
ipv6_cidr_block = test_vpc.ipv6_cidr_block.split("/")[0] + "/64"
)


2. run terrform init and terraform apply

### Versions

0.16.3

### Providers

_No response_

### Gist

_No response_

### Possible Solutions

_No response_

### Workarounds

_No response_

### Anything Else?

_No response_

### References

_No response_

### Help Wanted

- [ ] I'm interested in contributing a fix myself

### Community Note

- Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or other comments that do not add relevant new information or questions, 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
@anilkaliya123 anilkaliya123 added bug Something isn't working new Un-triaged issue pre-built providers Issues around pre-built providers managed at https://github.com/hashicorp/cdktf-repository-manager labels Apr 23, 2024
@anilkaliya123 anilkaliya123 changed the title PROVIDER_NAME: short issue description issue with referencing ipv6 cidr block in subnet Apr 24, 2024
@nbaju1
Copy link

nbaju1 commented May 27, 2024

Pythonic string manipulation only happens when you synthesize the stack. The ipv6 block is resolved on deploy. You need to use the objects that corresponds with hcl string manipulation, which is resolved on deploy:

from cdktf import StringConcat, FnGenerated

str_concat = StringConcat()
test_vpc = Vpc(self, "cmc-vpc", cidr_block="10.10.0.0/16", enable_dns_hostnames=True, assign_generated_ipv6_cidr_block=True)
test_subnet = Subnet(
    self,
    "test-subnet-external",
    cidr_block="10.10.0.0/16",
    vpc_id=test_vpc.id,
    map_public_ip_on_launch=False,
    ipv6_cidr_block=str_concat.join(FnGenerated.element(FnGenerated.split("/", test_vpc.ipv6_cidr_block), 0), "/64"),
)

Converted into JSON:

  "resource": {
    "aws_subnet": {
      "test-subnet-external": {
        "//": {
          "metadata": {
            "path": "example/test-subnet-external",
            "uniqueId": "test-subnet-external"
          }
        },
        "cidr_block": "10.10.0.0/16",
        "ipv6_cidr_block": "${element(split(\"/\", aws_vpc.cmc-vpc.ipv6_cidr_block), 0)}/64",
        "map_public_ip_on_launch": false,
        "vpc_id": "${aws_vpc.cmc-vpc.id}"
      }
    },
    "aws_vpc": {
      "cmc-vpc": {
        "//": {
          "metadata": {
            "path": "example/cmc-vpc",
            "uniqueId": "cmc-vpc"
          }
        },
        "assign_generated_ipv6_cidr_block": true,
        "cidr_block": "10.10.0.0/16",
        "enable_dns_hostnames": true
      }
    }
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new Un-triaged issue pre-built providers Issues around pre-built providers managed at https://github.com/hashicorp/cdktf-repository-manager
Projects
None yet
Development

No branches or pull requests

2 participants