{
    "url": "https://delaparra-services.nl/knowledge-hub/for-expression",
    "locale": "en",
    "title": "for expression: Knowledge hub | DeLaParra Services",
    "description": "Transforms one collection into another. Square brackets build a list (tuple); braces build a map (object).",
    "alternates": {
        "en": "https://delaparra-services.nl/knowledge-hub/for-expression",
        "nl": "https://delaparra-services.nl/nl/kennisbank/for-expression"
    },
    "formats": {
        "csv": "https://delaparra-services.nl/knowledge-hub/for-expression.csv",
        "md": "https://delaparra-services.nl/knowledge-hub/for-expression.md",
        "json": "https://delaparra-services.nl/knowledge-hub/for-expression.json",
        "zip": "https://delaparra-services.nl/knowledge-hub/for-expression.zip",
        "pdf": "https://delaparra-services.nl/knowledge-hub/for-expression.pdf"
    },
    "downloads": [
        {
            "url": "https://delaparra-services.nl/knowledge-hub/for-expression.csv",
            "encodingFormat": "text/csv",
            "name": "for-expression.csv"
        },
        {
            "url": "https://delaparra-services.nl/knowledge-hub/for-expression.json",
            "encodingFormat": "application/json",
            "name": "for-expression.json"
        },
        {
            "url": "https://delaparra-services.nl/knowledge-hub/for-expression.md",
            "encodingFormat": "text/markdown",
            "name": "for-expression.md"
        },
        {
            "url": "https://delaparra-services.nl/knowledge-hub/for-expression.pdf",
            "encodingFormat": "application/pdf",
            "name": "for-expression.pdf"
        },
        {
            "url": "https://delaparra-services.nl/knowledge-hub/for-expression.zip",
            "encodingFormat": "application/zip",
            "name": "for-expression.zip"
        },
        {
            "url": "https://delaparra-services.nl/knowledge-hub/for-expression/skills.zip",
            "encodingFormat": "application/zip",
            "name": "for-expression-skills.zip"
        }
    ],
    "markdown": "1. [Home](<https://delaparra-services.nl/>) \n1. [Knowledge hub](<https://delaparra-services.nl/knowledge-hub>) \n1. [for expression](<https://delaparra-services.nl/knowledge-hub/for-expression>)\n\n  \n\nCategory: Terraform \n\n# for expression\n\n  Explained by [Reinier de la Parra](<https://delaparra-services.nl/about>)  Updated November 25, 2026    \n\n## What is for expression?\n\n \n\nfor expression: Transforms one collection into another. Square brackets build a list (tuple); braces build a map (object). A ` for ` expression in Terraform transforms one collection into another. ` [for name in var.names : upper(name)] ` builds a list of uppercase names. Curly braces build a map instead, such as ` {for u in var.users : u.id => u.email} `.\n\n \n\nDefinition source [Coders Lingo](<https://coderslingo.com/resources/open-dataset/>), [CC BY 4.0](<https://creativecommons.org/licenses/by/4.0/>)\n\n \n\n## Frequently asked questions about for expression\n\n  \n\n### How is for expression used in practice?\n\n \n\nYou can also filter with an ` if ` clause, as in ` [for s in var.servers : s.name if s.public] `.\n\n    \n\n### What should you keep in mind with for expression?\n\n \n\nThis is how you reshape input data into exactly what a resource or module needs, without repeating yourself. It is the Terraform equivalent of ` map ` and ` filter ` in other languages. Keep the expressions short, and put complex ones in a ` locals ` block with a descriptive name. That keeps resource blocks readable and lets you test the transformation in ` terraform console ` on its own.\n\n    \n\n### What does an example of for expression look like?\n\n \n\n```\nupper_names = [for n in var.names : upper(n)] by_id = {for u in var.users : u.id => u.name}\n```\n\n \n\n## At a glance\n\n   CategoryTerraform Explained by[Reinier de la Parra](<https://delaparra-services.nl/about>) UpdatedNovember 25, 2026\n\n \n\n## More Terraform terms\n\n \n\n- [drift](<https://delaparra-services.nl/knowledge-hub/drift>) \n- [expression](<https://delaparra-services.nl/knowledge-hub/expression>) \n- [fmt](<https://delaparra-services.nl/knowledge-hub/fmt>) \n- [for\\_each](<https://delaparra-services.nl/knowledge-hub/for-each>) \n- [heredoc](<https://delaparra-services.nl/knowledge-hub/heredoc>) \n- [import](<https://delaparra-services.nl/knowledge-hub/import>)\n\n \n\n[All terms starting with F](<https://delaparra-services.nl/knowledge-hub#letter-f>)\n\n \n\n## Skills\n\n \n\n- ### Terraform safe workflow\n\n \n\nUse when running or changing Terraform (or OpenTofu) - init, fmt, validate, plan, apply, destroy, import, state mv/rm, refresh, workspaces, remote backends, state locking, drift, taint/-replace. Enforces a plan-review-apply workflow and protects state.\n\n [View skill](<https://delaparra-services.nl/skills/terraform-safe-workflow>) [Download zip](<https://delaparra-services.nl/skills/terraform-safe-workflow/download>) \n- ### Terraform Module Library\n\n \n\nBuild reusable Terraform modules for AWS, Azure, GCP, and OCI infrastructure following infrastructure-as-code best practices. Use when creating infrastructure modules, standardizing cloud provisioning, or implementing reusable IaC components.\n\n [View skill](<https://delaparra-services.nl/skills/terraform-module-library>) [Download zip](<https://delaparra-services.nl/skills/terraform-module-library/download>) \n- ### Multi-Cloud Architecture\n\n \n\nDesign multi-cloud architectures using a decision framework to select and integrate services across AWS, Azure, GCP, and OCI. Use when building multi-cloud systems, avoiding vendor lock-in, or leveraging best-of-breed services from multiple providers.\n\n [View skill](<https://delaparra-services.nl/skills/multi-cloud-architecture>) [Download zip](<https://delaparra-services.nl/skills/multi-cloud-architecture/download>)\n\n [Download all skills (zip)](<https://delaparra-services.nl/knowledge-hub/for-expression/skills.zip>)\n\n \n\n## Manuals\n\n \n\n- [Kubernetes and Terraform: do you need them?](<https://delaparra-services.nl/manuals/kubernetes-en-terraform-heb-je-het-nodig>) \n- [Choosing cloud services for your app](<https://delaparra-services.nl/manuals/cloud-diensten-kiezen>)\n\n \n\n## Related services\n\n \n\n- [Custom software and web applications](<https://delaparra-services.nl/services#service-03>)\n\nPerhaps your customers need somewhere to download their invoices, or your staff are managing bookings in a spreadsheet.\n\n \n\n## Need any help?\n\n \n\nStuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.\n\n  [Get in touch](<https://delaparra-services.nl/availability>)\n\n[HTML version](https://delaparra-services.nl/knowledge-hub/for-expression)\n",
    "structured_data": {
        "@context": "https://schema.org",
        "@graph": [
            {
                "@type": "Organization",
                "@id": "https://delaparra-services.nl/#practice",
                "logo": "https://delaparra-services.nl/logo.png",
                "name": "DeLaParra Services",
                "legalName": "DeLaParra Services",
                "url": "https://delaparra-services.nl/",
                "description": "Bespoke software, web applications and mobile apps, developed in Laravel by a single developer in Groningen. Fixed price agreed in advance, full source code provided upon delivery.",
                "email": "info@delaparra-services.nl",
                "address": {
                    "@type": "PostalAddress",
                    "addressLocality": "Groningen",
                    "addressRegion": "Groningen",
                    "addressCountry": "NL"
                },
                "areaServed": "Groningen, the Netherlands",
                "knowsLanguage": [
                    "en",
                    "nl"
                ],
                "knowsAbout": [
                    "Web design and development",
                    "App development",
                    "Custom software and web applications",
                    "OpenSpec",
                    "AI code review",
                    "Your own coding agent"
                ],
                "founder": {
                    "@id": "https://delaparra-services.nl/#person"
                }
            },
            {
                "@type": "FAQPage",
                "@id": "https://delaparra-services.nl/knowledge-hub/for-expression#webpage",
                "url": "https://delaparra-services.nl/knowledge-hub/for-expression",
                "name": "for expression: Knowledge hub | DeLaParra Services",
                "description": "Transforms one collection into another. Square brackets build a list (tuple); braces build a map (object).",
                "isPartOf": {
                    "@id": "https://delaparra-services.nl/#website"
                },
                "about": {
                    "@type": "DefinedTerm",
                    "@id": "https://delaparra-services.nl/knowledge-hub/for-expression#term",
                    "name": "for expression",
                    "description": "Transforms one collection into another. Square brackets build a list (tuple); braces build a map (object).",
                    "termCode": "for-expression",
                    "url": "https://delaparra-services.nl/knowledge-hub/for-expression",
                    "inLanguage": "en",
                    "keywords": "Terraform",
                    "dateModified": "2026-11-25T17:46:26+00:00",
                    "inDefinedTermSet": {
                        "@id": "https://delaparra-services.nl/knowledge-hub#terms"
                    },
                    "isPartOf": {
                        "@id": "https://delaparra-services.nl/knowledge-hub#dataset"
                    },
                    "subjectOf": [
                        {
                            "@id": "https://delaparra-services.nl/knowledge-hub/for-expression#webpage"
                        },
                        {
                            "@id": "https://delaparra-services.nl/knowledge-hub/for-expression#dataset"
                        }
                    ]
                },
                "inLanguage": "en",
                "breadcrumb": {
                    "@id": "https://delaparra-services.nl/knowledge-hub/for-expression#breadcrumb"
                },
                "mainEntity": [
                    {
                        "@type": "Question",
                        "name": "What is for expression?",
                        "acceptedAnswer": {
                            "@type": "Answer",
                            "text": "Transforms one collection into another. Square brackets build a list (tuple); braces build a map (object). A for expression in Terraform transforms one collection into another. [for name in var.names : upper(name)] builds a list of uppercase names. Curly braces build a map instead, such as {for u in var.users : u.id => u.email}."
                        }
                    },
                    {
                        "@type": "Question",
                        "name": "How is for expression used in practice?",
                        "acceptedAnswer": {
                            "@type": "Answer",
                            "text": "You can also filter with an if clause, as in [for s in var.servers : s.name if s.public]."
                        }
                    },
                    {
                        "@type": "Question",
                        "name": "What should you keep in mind with for expression?",
                        "acceptedAnswer": {
                            "@type": "Answer",
                            "text": "This is how you reshape input data into exactly what a resource or module needs, without repeating yourself. It is the Terraform equivalent of map and filter in other languages. Keep the expressions short, and put complex ones in a locals block with a descriptive name. That keeps resource blocks readable and lets you test the transformation in terraform console on its own."
                        }
                    },
                    {
                        "@type": "Question",
                        "name": "What does an example of for expression look like?",
                        "acceptedAnswer": {
                            "@type": "Answer",
                            "text": "upper_names = [for n in var.names : upper(n)] by_id = {for u in var.users : u.id => u.name}"
                        }
                    }
                ],
                "author": {
                    "@id": "https://delaparra-services.nl/#person"
                },
                "mentions": [
                    {
                        "@id": "https://delaparra-services.nl/skills/terraform-safe-workflow#skill"
                    },
                    {
                        "@id": "https://delaparra-services.nl/skills/terraform-module-library#skill"
                    },
                    {
                        "@id": "https://delaparra-services.nl/skills/multi-cloud-architecture#skill"
                    },
                    {
                        "@id": "https://delaparra-services.nl/manuals/kubernetes-en-terraform-heb-je-het-nodig#article"
                    },
                    {
                        "@id": "https://delaparra-services.nl/manuals/cloud-diensten-kiezen#article"
                    }
                ]
            },
            {
                "@type": "BreadcrumbList",
                "@id": "https://delaparra-services.nl/knowledge-hub/for-expression#breadcrumb",
                "itemListElement": [
                    {
                        "@type": "ListItem",
                        "position": 1,
                        "name": "Home",
                        "item": "https://delaparra-services.nl/"
                    },
                    {
                        "@type": "ListItem",
                        "position": 2,
                        "name": "Knowledge hub",
                        "item": "https://delaparra-services.nl/knowledge-hub"
                    },
                    {
                        "@type": "ListItem",
                        "position": 3,
                        "name": "for expression"
                    }
                ]
            },
            {
                "@type": "Person",
                "@id": "https://delaparra-services.nl/#person",
                "name": "Reinier de la Parra",
                "url": "https://delaparra-services.nl/about"
            },
            {
                "@type": "Dataset",
                "@id": "https://delaparra-services.nl/knowledge-hub/for-expression#dataset",
                "name": "for expression",
                "description": "Transforms one collection into another. Square brackets build a list (tuple); braces build a map (object).",
                "url": "https://delaparra-services.nl/knowledge-hub/for-expression",
                "identifier": "https://delaparra-services.nl/knowledge-hub/for-expression#dataset",
                "about": {
                    "@id": "https://delaparra-services.nl/knowledge-hub/for-expression#term"
                },
                "creator": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "publisher": {
                    "@id": "https://delaparra-services.nl/#practice"
                },
                "license": "https://creativecommons.org/licenses/by/4.0/",
                "creditText": "Coders Lingo (https://coderslingo.com/resources/open-dataset/), CC BY 4.0",
                "isAccessibleForFree": true,
                "inLanguage": "en",
                "keywords": "Terraform",
                "version": "2026-11-25",
                "dateModified": "2026-11-25T17:46:26+00:00",
                "isPartOf": {
                    "@type": "Dataset",
                    "@id": "https://delaparra-services.nl/knowledge-hub#dataset",
                    "name": "IT terms from A to Z",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "includedInDataCatalog": {
                    "@type": "DataCatalog",
                    "@id": "https://delaparra-services.nl/knowledge-hub#catalog",
                    "name": "Knowledge hub data catalog",
                    "url": "https://delaparra-services.nl/knowledge-hub"
                },
                "distribution": [
                    {
                        "@type": "DataDownload",
                        "name": "for-expression.csv",
                        "encodingFormat": "text/csv",
                        "contentUrl": "https://delaparra-services.nl/knowledge-hub/for-expression.csv",
                        "inLanguage": "en",
                        "dateModified": "2026-11-25T17:46:26+00:00",
                        "license": "https://creativecommons.org/licenses/by/4.0/"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "for-expression.json",
                        "encodingFormat": "application/json",
                        "contentUrl": "https://delaparra-services.nl/knowledge-hub/for-expression.json",
                        "inLanguage": "en",
                        "dateModified": "2026-11-25T17:46:26+00:00",
                        "license": "https://creativecommons.org/licenses/by/4.0/"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "for-expression.md",
                        "encodingFormat": "text/markdown",
                        "contentUrl": "https://delaparra-services.nl/knowledge-hub/for-expression.md",
                        "inLanguage": "en",
                        "dateModified": "2026-11-25T17:46:26+00:00",
                        "license": "https://creativecommons.org/licenses/by/4.0/"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "for-expression.pdf",
                        "encodingFormat": "application/pdf",
                        "contentUrl": "https://delaparra-services.nl/knowledge-hub/for-expression.pdf",
                        "inLanguage": "en",
                        "dateModified": "2026-11-25T17:46:26+00:00",
                        "license": "https://creativecommons.org/licenses/by/4.0/"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "for-expression.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/knowledge-hub/for-expression.zip",
                        "inLanguage": "en",
                        "dateModified": "2026-11-25T17:46:26+00:00",
                        "license": "https://creativecommons.org/licenses/by/4.0/"
                    },
                    {
                        "@type": "DataDownload",
                        "name": "for-expression-skills.zip",
                        "encodingFormat": "application/zip",
                        "contentUrl": "https://delaparra-services.nl/knowledge-hub/for-expression/skills.zip",
                        "inLanguage": "en",
                        "dateModified": "2026-11-25T17:46:26+00:00",
                        "license": "https://creativecommons.org/licenses/by/4.0/"
                    }
                ]
            }
        ]
    }
}