0
votes

I'm using Google Cloud CLI to create a VM, and I needed to create firewall rules via the CLI also;

I have a bash script, with some predefined variables like the port, description, etc; that creates a VM, and then applies firewall rules for it;

To apply the rules I use

gcloud compute firewall-rules create

But the errors I get are arguments defined in the GCP documentation here

ERROR: (gcloud.compute.firewall-rules.create) unrecognized arguments:
./1541078390.sh: line 84: --allow: command not found
./1541078390.sh: line 86: --source-ranges: command not found
./1541078390.sh: line 87: --priority: command not found

I've tried different, but similar approaches and I keep getting them. Is there anything I'm missing?

An example of the script is

ports="udp:2555"
vm="client"
priority=100
description="Port 2555"

gcloud compute firewall-rules create "${ports%%:*} rule" \ 
    --allow "${ports}" \ (line 84)
    --source-tags "$vm" \ 
    --source-ranges "0.0.0.0/0" \ (line 86)
    --priority "$priority" \(line 87)
    --description "$description" \
    --direction INGRESS
2

2 Answers

1
votes

I think you might have white space after some backslash. make sure you remove all spaces after them and try again.

Based on your example, You should have a whitespace on line 83, 85 and 86

cheers,

0
votes

I found why this was happening.

After executing manually the command in the terminal, it output detailed errors where it was clear the parameters that are "unrecognised" were failing regex validation. So I adapted the parameters syntax according to the recommend one in the errors, and it worked;

TL;DR

The parameters that are "unrecognised" are badly formatted;