in tools/generator.py [0:0]
def generate(self):
rule = {
"Version": "2020-06-01",
"Type": "Resource",
"ResourceType": {
"From": self.from_resource.resource_type,
"To": self.to_resource.resource_type,
},
}
name = self.to_resource.resource_type.replace("alicloud_", "")
tf_rule_path = os.path.join(TF_ALI_RULES_DIR, f"{name}.yml")
path = self._get_rule_path()
if os.path.exists(path):
return
if os.path.exists(tf_rule_path):
with open(tf_rule_path, "r") as f:
tf_rule = yaml.safe_load(f)
for section in ["Properties", "Attributes"]:
ros_res_section = getattr(self.from_resource, section.lower())()
tf_rule_section = tf_rule.get(section, {}) or {}
rule[section] = self._get_rule_section(tf_rule_section, ros_res_section)
with open(path, "w") as f:
content = yaml.safe_dump(rule, sort_keys=False)
f.write(content)