DEV Community

Discussion on: Configuring an isolated network in Google Cloud

Collapse
chabane profile image
Chabane R. Author

Thanks for your feedback :+1

AUTHORIZED_NETWORK could be your local ip (curl -s checkip.amazonaws.com/)
or the public IP of your private network

Collapse
nikhilakki profile image
Nikhil Akki

Thanks for the quick response, this helped and I was able to run the scripts, however, with some modifications.

  1. sed -i "s,,$AUTHORIZED_NETWORK,g" terraform.tfvars gave an error - sed: 1: "terraform.tfvars": undefined label 'erraform.tfvars'. I modified it to sed "s//$AUTHORIZED_NETWORK/g" terraform.tfvars I haven't really used sed tool before (followed steps from this link). Eventually I gave up and replaced the value for AUTHORIZED_NETWORK to the IP I got from the checkip.amazonaws.com url.
  2. All other definitions in *.tf files error-ed out due to missing definition/property - project. I created a variable project in variable.tf with default value as "" and referenced it in each definition as project = var.project.
  3. Created an apply.sh file for running these set of commands -
cd infra/plan

export AUTHORIZED_NETWORK=$(curl -s checkip.amazonaws.com/)
export TF_VAR_project=$PROJECT_ID

echo 'AUTHORIZED_NETWORK =' $AUTHORIZED_NETWORK
echo 'TF_VAR_project =' $PROJECT_ID

sed "s/<AUTHORIZED_NETWORK>/$AUTHORIZED_NETWORK/g" terraform.tfvars
# sed -i "s,<AUTHORIZED_NETWORK>,$AUTHORIZED_NETWORK,g" terraform.tfvars

terraform init \
    -backend-config="bucket=${TERRAFORM_BUCKET_NAME}" \
    -backend-config="prefix=state"

terraform apply
Enter fullscreen mode Exit fullscreen mode

It all worked at the end, but my approach seems a hacky one, let me know your thoughts.

Looking forward to reading the next posts in the series. 😃

Thread Thread
nikhilakki profile image
Nikhil Akki

Great series... thanks again for sharing it :-) I was able to setup and customise the scripts as per my requirements.