Skip to content

Commit ff5fc1e

Browse files
committed
reuse generate_subnet_read_payload method
1 parent 3aaa760 commit ff5fc1e

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

localstack-core/localstack/services/ec2/resource_providers/aws_ec2_subnet.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,33 +186,15 @@ def read(
186186
- ec2:DescribeSubnets
187187
- ec2:DescribeNetworkAcls
188188
"""
189-
ec2 = request.aws_client_factory.ec2
190-
subnet_id = request.desired_state["SubnetId"]
191-
subnet = ec2.describe_subnets(SubnetIds=[subnet_id])["Subnets"][0]
192-
193-
model = EC2SubnetProperties(**util.select_attributes(subnet, self.SCHEMA["properties"]))
194-
195-
if "Tags" not in model:
196-
model["Tags"] = []
197-
198-
if "EnableDns64" not in model:
199-
model["EnableDns64"] = False
200-
201-
optional_bool_attrs = ["EnableResourceNameDnsAAAARecord", "EnableResourceNameDnsARecord"]
202-
for attr in optional_bool_attrs:
203-
if attr not in model["PrivateDnsNameOptionsOnLaunch"]:
204-
model["PrivateDnsNameOptionsOnLaunch"][attr] = False
205-
206-
network_acl_associations = ec2.describe_network_acls(
207-
Filters=[{"Name": "association.subnet-id", "Values": [subnet_id]}]
189+
models = generate_subnet_read_payload(
190+
ec2_client=request.aws_client_factory.ec2,
191+
schema=self.SCHEMA["properties"],
192+
subnet_ids=[request.desired_state["SubnetId"]],
208193
)
209-
model["NetworkAclAssociationId"] = network_acl_associations["NetworkAcls"][0][
210-
"NetworkAclId"
211-
]
212194

213195
return ProgressEvent(
214196
status=OperationStatus.SUCCESS,
215-
resource_model=model,
197+
resource_model=models[0],
216198
custom_context=request.custom_context,
217199
)
218200

0 commit comments

Comments
 (0)