Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(cloudformation): resolve Fn::Select in conditions (#1962)
mishukdutta-cz8e75f87d71b1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 486bbd32..9982c108 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -52,6 +52,10 @@ Versioning follows [Semantic Versioning](https://semver.org/).- **CloudFormation — `AWS::SQS::Queue` with `FifoQueue` gets a generated `.fifo` name** — `FifoQueue: true` without a `QueueName` creates a FIFO queue with a generated `.fifo` name instead of a standard queue, and a `QueueName` whose `.fifo` suffix disagrees with `FifoQueue` fails the resource. Contributed by @iot-rocket.- **CloudFormation — nested stack with a `Transform`** — under `AUTH=true`, a nested stack whose template declares a `Transform` or calls `Fn::Transform` fails with `Requires capabilities : [CAPABILITY_AUTO_EXPAND]` unless the parent acknowledged `CAPABILITY_AUTO_EXPAND`, as on AWS. Contributed by @iot-rocket.+### Fixed++- **CloudFormation — `Fn::Select` in a condition** — a condition that checks one member of a `CommaDelimitedList`, such as `!Not [!Equals [!Select [2, !Ref KeySpec], ""]]`, was always true, whatever the parameter value. Templates use this check for an optional member: `"id,S,,"` gives `["id", "S", "", ""]`, and an empty member means "no value". Conditions did not resolve `Fn::Select`, so `Fn::Equals` compared the unresolved function with `""`. Thus the stack made resources whose condition is false, and `Fn::If` took the wrong branch. Conditions now resolve `Fn::Select`, with the same comma split as resource properties. Contributed by @mishukdutta-cz.+## [1.5.20] — 2026-10-01### Addeddiff --git a/ministack/services/cloudformation/engine.py b/ministack/services/cloudformation/engine.pyindex 34855d8d..d143b967 100644--- a/ministack/services/cloudformation/engine.py+++ b/ministack/services/cloudformation/engine.py@@ -633,6 +633,16 @@ def _evaluate_conditions(template: dict, params: dict) -> dict:return _eval(val)if "Condition" in val:return _eval(val)+ if "Fn::Select" in val:+ index, items = val["Fn::Select"]+ index = int(_resolve_cond_value(index))+ items = _resolve_cond_value(items)+ if isinstance(items, str):+ # A CommaDelimitedList parameter is one string here: "id,S,," becomes ["id", "S", "", ""]+ items = [s.strip() for s in items.split(",")]+ if 0 <= index < len(items):+ return items[index]+ return ""return valfor name, defn in cond_defs.items():diff --git a/tests/test_cfn.py b/tests/test_cfn.pyindex 5cb1050c..cfbdda55 100644--- a/tests/test_cfn.py+++ b/tests/test_cfn.py@@ -2160,6 +2160,33 @@ def test_cfn_conditions(cfn, s3):with pytest.raises(ClientError):s3.head_bucket(Bucket="cfn-t04-cond")++def test_cfn_condition_selects_from_comma_delimited_list(cfn):+ """Fn::Select in a condition gives one member of a CommaDelimitedList. An empty member makes the condition false,+ so the stack does not make the resource."""+ name = f"cfn-cond-select-{_uuid_mod.uuid4().hex[:8]}"++ def parameter(condition):+ return {"Type": "AWS::SSM::Parameter", "Condition": condition,+ "Properties": {"Name": f"/{name}/{condition}", "Type": "String", "Value": "x"}}++ template = {+ "Parameters": {"Spec": {"Type": "CommaDelimitedList", "Default": "gsi,,S"}},+ "Conditions": {+ "FirstSet": {"Fn::Not": [{"Fn::Equals": [{"Fn::Select": [0, {"Ref": "Spec"}]}, ""]}]},+ "SecondSet": {"Fn::Not": [{"Fn::Equals": [{"Fn::Select": [1, {"Ref": "Spec"}]}, ""]}]},+ },+ "Resources": {"First": parameter("FirstSet"), "Second": parameter("SecondSet")},+ }+ try:+ cfn.create_stack(StackName=name, TemplateBody=json.dumps(template))+ assert _wait_stack(cfn, name)["StackStatus"] == "CREATE_COMPLETE"+ resources = cfn.describe_stack_resources(StackName=name)["StackResources"]+ assert [r["LogicalResourceId"] for r in resources] == ["First"]+ finally:+ _delete_cfn_test_stack(cfn, name)++def test_cfn_outputs_exports(cfn):template = {"AWSTemplateFormatVersion": "2010-09-09",