Skip to content

Commit

Permalink
Allow terraform resource_schema attributes with nested_type
Browse files Browse the repository at this point in the history
Fixes ansible-collections#93

Signed-off-by: Justin Cinkelj <[email protected]>
  • Loading branch information
justinc1 committed Nov 16, 2023
1 parent 957b64b commit b979d68
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion plugins/module_utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def from_json(cls, json: TJsonObject) -> "TerraformShow":

@dataclass
class TerraformAttributeSpec:
type: Union[str, List[str]]
description_kind: str

# potentially undefined
Expand All @@ -157,6 +156,39 @@ class TerraformAttributeSpec:

@classmethod
def from_json(cls, json: TJsonObject) -> "TerraformAttributeSpec":
if "nested_type" in json:
return TerraformNestedAttributeSpec.from_json(json)
else:
return TerraformSimpleAttributeSpec.from_json(json)


@dataclass
class TerraformNestedAttributeSpec(TerraformAttributeSpec):
nested_attributes: Dict[str, TerraformAttributeSpec]

@classmethod
def from_json(cls, json: TJsonObject) -> "TerraformNestedAttributeSpec":
return cls(
nested_attributes={
sub_attribute_name: TerraformAttributeSpec.from_json(sub_attribute_item)
for sub_attribute_name, sub_attribute_item in json["nested_type"]["attributes"].items()
},
description_kind=json["description_kind"],
description=json.get("description"),
optional=json.get("optional", False),
required=json.get("required", False),
deprecated=json.get("deprecated", False),
sensitive=json.get("sensitive", False),
computed=json.get("computed", False),
)


@dataclass
class TerraformSimpleAttributeSpec(TerraformAttributeSpec):
type: Union[str, List[str]]

@classmethod
def from_json(cls, json: TJsonObject) -> "TerraformSimpleAttributeSpec":
return cls(
type=json["type"],
description_kind=json["description_kind"],
Expand Down

0 comments on commit b979d68

Please sign in to comment.