Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/cloud-build/daily-tests/builds/h4d-vm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ steps:
REGION="$${ZONE%-*}"
BUILD_ID_SHORT=$${BUILD_ID:0:6}
BLUEPRINT="/workspace/examples/h4d-vm.yaml"
python3 tools/modify_vpc.py "$${BLUEPRINT}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The changes made by your new script tools/modify_vpc.py are being overwritten by a later sed command on line 87. Your script correctly assigns unique network names (e.g., $(vars.test_name)-0, $(vars.test_name)-1) to the VPC modules. However, the sed command on line 87 then resets the network_name for both VPC modules to the same value, $(vars.base_network_name), which will likely cause a resource name collision. You should probably remove the sed command on line 87 to allow your script's changes to persist.

sed -i -e '/deletion_protection:/{n;s/enabled: true/enabled: false/}' $${BLUEPRINT}
sed -i -e '/reason:/d' $${BLUEPRINT}
sed -i '/ - id: h4d-vms/,/ - id: wait-for-vms/ { / settings:/a \
Expand Down
1 change: 1 addition & 0 deletions tools/cloud-build/daily-tests/tests/h4d-vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ custom_vars:
h4d_onspot: true
enable_spot: true
cli_deployment_vars:
test_name: '{{ test_name }}'
base_network_name: '{{ test_name }}'
region: "{{ region }}"
zone: "{{ zone }}"
29 changes: 29 additions & 0 deletions tools/modify_vpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import yaml
import sys

def modify_vpcs(blueprint_path):
with open(blueprint_path, 'r') as f:
data = yaml.safe_load(f)

vpc_count = 0
# Iterate through all deployment groups and modules
if 'deployment_groups' in data:
for group in data['deployment_groups']:
for module in group.get('modules', []):
# Identify VPC modules by their source path
if 'modules/network/vpc' in module.get('source', ''):
if 'settings' not in module:
module['settings'] = {}
# Set the consecutive name using the $(vars.test_name) variable
module['settings']['network_name'] = f"$(vars.test_name)-{vpc_count}"
print(f"Updated module '{module.get('id')}' to: $(vars.test_name)-{vpc_count}")
vpc_count += 1

with open(blueprint_path, 'w') as f:
yaml.dump(data, f, sort_keys=False)

if __name__ == "__main__":
if len(sys.argv) < 2:
sys.exit(1)
modify_vpcs(sys.argv[1])

Loading