Cidr_block IP value invalid from local_file data although IP is correctly retrieved

Hi, the cidr IP value is correctly read from local_file where the IP address is stored. But, cidr_block of master_authorized_networks_config is throwing invalid IP although it is retrieving the correct IP. Weird thing is that, when I hardcoded the cidr IP value into cidr_block, it works but not when I pass the IP from local_file.

Any idea why the cidr ip value that’s being passed from local_file data isn’t working? I tried most of the things already but still not shining a light.

This is how I have the code at the moment which retrieves the cidr IP successfully and assigns to cidr_block:
master_authorized_networks_config {
cidr_blocks {
display_name = “local-client”
cidr_block = data.local_file.local_client_external_ip.content

This is what I got as an invalid error although IP is picked up correctly:
Error: expected master_authorized_networks_config.0.cidr_blocks.0.cidr_block to contain a valid Value, got: 78.150.x.x/32
│ with err: invalid CIDR address: 78.150.x.x/32

│ with google_container_cluster.private-gke-cluster,
│ on line 86, in resource “google_container_cluster” “private-gke-cluster”:
│ 86: cidr_blocks {

My guess would be the value from the file has a trailing newline character, which you’ll need to strip off.

1 Like

Hey @maxb, thank you so much for shinning a light. I looked around stripping off any trailing newline characters and used chomp() function and worked perfectly.
Appreciated it!

Solution code:

cidr_block = chomp(data.local_file.local_client_external_ip.content)