in src/cli/utils/cicd.py [0:0]
def update_terraform_vars(self, project_dir: Path, is_dev: bool = False) -> None:
"""Update terraform variables with project configuration"""
if is_dev:
# Dev environment only needs one project ID
tf_vars_path = (
project_dir / "deployment" / "terraform" / "dev" / "vars" / "env.tfvars"
)
with open(tf_vars_path) as f:
content = f.read()
# Replace dev project ID
content = re.sub(
r'dev_project_id\s*=\s*"[^"]*"',
f'dev_project_id = "{self.config.dev_project_id}"',
content,
)
else:
# Path to production needs staging, prod, and CICD project IDs
tf_vars_path = (
project_dir / "deployment" / "terraform" / "vars" / "env.tfvars"
)
with open(tf_vars_path) as f:
content = f.read()
# Replace all project IDs
content = re.sub(
r'staging_project_id\s*=\s*"[^"]*"',
f'staging_project_id = "{self.config.staging_project_id}"',
content,
)
content = re.sub(
r'prod_project_id\s*=\s*"[^"]*"',
f'prod_project_id = "{self.config.prod_project_id}"',
content,
)
content = re.sub(
r'cicd_runner_project_id\s*=\s*"[^"]*"',
f'cicd_runner_project_id = "{self.config.cicd_project_id}"',
content,
)
# Add host connection and repository name
content = re.sub(
r'host_connection_name\s*=\s*"[^"]*"',
f'host_connection_name = "{self.config.host_connection_name}"',
content,
)
content = re.sub(
r'repository_name\s*=\s*"[^"]*"',
f'repository_name = "{self.config.repository_name}"',
content,
)
# Write updated content
with open(tf_vars_path, "w") as f:
f.write(content)