in rostran/providers/ros/template.py [0:0]
def _transform_resources(self) -> List[tf.Resource]:
tf_resources = []
for name, res in self.resources.items():
tf_name = camel_to_snake(name)
ros_res_type = res.get("Type")
resource_rule = self.get_resource_rule(ros_res_type)
if not resource_rule:
typer.secho(
f"Resource type {ros_res_type!r} is not supported and will be ignored.",
fg="yellow",
)
continue
tf_res_type = resource_rule.target_resource_type
properties = res.get("Properties")
resolved_props = self.resolve_values(properties, False) or {}
tf_argument = self._get_tf_argument(ros_res_type, resolved_props, resource_rule.properties)
if isinstance(tf_argument, tf.JsonType):
tf_argument = tf_argument.value
condition = res.get("Condition")
count = res.get("Count")
if count:
tf_argument["count"] = self.resolve_values(count)
if condition:
tf_count = tf_argument.get("count") if tf_argument.get("count") is not None else 1
tf_argument["count"] = tf.LiteralType(f"local.{condition} ? {tf_count} : 0")
depends_on = res.get("DependsOn")
if depends_on:
if isinstance(depends_on, str):
depends_on = [depends_on]
tf_depends_on = []
for depend in depends_on:
depend_res_type = self.resources[depend]['Type']
depend_resource_rule = self.get_resource_rule(depend_res_type)
if not depend_resource_rule:
typer.secho(
f"Resource type {depend_res_type!r} is not supported and will be ignored.",
fg="yellow",
)
continue
tf_depend = f"{depend_resource_rule.target_resource_type}.{camel_to_snake(depend)}"
tf_depends_on.append(tf.LiteralType(tf_depend))
tf_argument["depends_on"] = tf.JsonType(tf_depends_on)
resource = tf.Resource(tf_name, tf_res_type, tf_argument)
tf_resources.append(resource)
return tf_resources