0

I deploy some VM's instances in my cloud infrastructure with bash script:

#!/bin/bash
instance_name="vm"
# create instance
yc compute instance create \
  --name $instance_name \
  --hostname reddit-app \
  --memory=2 \
  ...

I need to add timestamp to instance's name in format vm-DD-MM_YYYY-H-M-S.
For debug I tried to set value instance_name=$(date +%d-%m-%Y_%H-%M-%S) but got the error:

ERROR: rpc error: code = InvalidArgument desc = Request validation error: Name: invalid resource name

Any help would be appreciated.

ERemarque
  • 497
  • 3
  • 16
  • Presumably either underscore, hyphen or numbers are not allowed in the name. Try removing them or checking the YC docs. – l0b0 Jan 06 '21 at 22:36
  • @l0b0 Thanks for reply. I found that underscore may be relevant to this issue. I tried set `instance_name=$(date +%s)`. This should display only numbers without underscore, hyphen. But still looking the error. – ERemarque Jan 06 '21 at 23:44
  • 1
    Then I can only suggest looking at the docs. They may have any number of restrictions, like length or not including numbers. – l0b0 Jan 07 '21 at 00:01
  • 1
    Assuming the instance name should start with alphabet, please try: `instance_name="vm-$(date +%d-%m-%Y_%H-%M-%S)"`. – tshiono Jan 07 '21 at 07:12
  • @l0b0 The doc says: "The name may contain lowercase Latin letters, numbers, and hyphens. The first character must be a letter. The last character can't be a hyphen. The maximum length of the name is 63 characters". I modified my script with these recommendations and it works now. – ERemarque Jan 07 '21 at 11:26
  • @tshiono Thanks for reply. It's important notice. But It should not be used underscore in name of instance. Finally string is as follows: `instance_name="redditapp-$(date +%d-%m-%Y-%H-%M-%S)"`. I'm ready to confirm your answer. – ERemarque Jan 07 '21 at 11:45

1 Answers1

0

The Yandex Cloud documentation says:
"The name may contain lowercase Latin letters, numbers, and hyphens. The first character must be a letter. The last character can't be a hyphen. The maximum length of the name is 63 characters".

I changed my script following the recommendations and it works now:

#!/bin/bash
instance_name="vm-$(date +%d-%m-%Y-%H-%M-%S)"
# create instance
yc compute instance create \
  --name $instance_name \
  --hostname reddit-app \
  --memory=2 \
  ...
ERemarque
  • 497
  • 3
  • 16
  • 1
    Nice! In linux it is also useful to use ISO dates so that you can easily order files using their name: 20210121. – Pitto Jan 21 '21 at 08:35