Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sc-12773 use a more rigid regex for tfvars templating #27

Merged
merged 3 commits into from
May 30, 2024
Merged
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
4 changes: 2 additions & 2 deletions src/dynamic_importer/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def create_value(
environment_id = self.create_environment(environment_name)["id"]
parameter_id = self.create_parameter(project_name, parameter_name)["id"]

value = str(value) if isinstance(value, bool) else value
value = str(value).lower() if isinstance(value, bool) else value
resp = self._make_request(
f"projects/{project_id}/parameters/{parameter_id}/values",
"POST",
Expand All @@ -329,7 +329,7 @@ def update_value(
environment_id = self.get_environment_id(environment_name)
parameter_id = self.get_parameter_id(project_name, parameter_name)

value = str(value) if isinstance(value, bool) else value
value = str(value).lower() if isinstance(value, bool) else value
return self._make_request(
f"projects/{project_id}/parameters/{parameter_id}/values/{value_id}",
"PATCH",
Expand Down
3 changes: 2 additions & 1 deletion src/dynamic_importer/processors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ def _traverse_data(
if not hints:
obj_type = self.guess_type(obj)
param_name = self.path_to_param_name(path)
value = str(obj).lower() if obj_type == "boolean" else obj
return f"{{{{ cloudtruth.parameters.{param_name} }}}}", {
path: {
"values": {env: obj},
"values": {env: value},
"param_name": param_name,
"type": obj_type,
"secret": self.is_param_secret(param_name),
Expand Down
8 changes: 6 additions & 2 deletions src/dynamic_importer/processors/tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ def _traverse_data(
if set(obj.keys()) >= self.data_keys:
if not hints:
param_name = self.path_to_param_name(path)
value = (
str(obj["default"]).lower() if obj["type"] == "boolean" else obj
)
return f"{{{{ cloudtruth.parameters.{param_name} }}}}", {
path: {
"values": {env: obj["default"]},
"values": {env: value},
"param_name": param_name,
"description": obj.get("description", ""),
"type": obj["type"],
Expand All @@ -111,9 +114,10 @@ def _traverse_data(
if not hints:
obj_type = self.guess_type(obj)
param_name = self.path_to_param_name(path)
value = str(obj).lower() if obj_type == "boolean" else obj
return f"{{{{ cloudtruth.parameters.{param_name} }}}}", {
path: {
"values": {env: obj},
"values": {env: value},
"param_name": param_name,
"type": obj_type,
"secret": False,
Expand Down
9 changes: 7 additions & 2 deletions src/dynamic_importer/processors/tfvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ def encode_template_references(
environment = "default"
if config_data:
for _, data in config_data.items():
value = str(data["values"][environment])
reference = rf'{{{{ cloudtruth.parameters.{data["param_name"]} }}}}'
source_name = sub(r"_\d+", "", data["param_name"])
value = (
rf"({source_name})(\s*=\s*.*){str(data['values'][environment])}(.*)"
)
reference = (
rf'\1\2{{{{ cloudtruth.parameters.{data["param_name"]} }}}}\3'
)
template_body = sub(value, reference, template_body)

return template_body
Loading