<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Practical AWS - Medium]]></title>
        <description><![CDATA[You can envision perfect architectures on AWS, but when implementing and operating… this is where things start to scatter. Practical AWS aims to share real life experience and lesson learned from working on numerous AWS projects for AWS customers. - Medium]]></description>
        <link>https://medium.com/practical-aws?source=rss----df4ad87dd53a---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Practical AWS - Medium</title>
            <link>https://medium.com/practical-aws?source=rss----df4ad87dd53a---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 14:30:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/practical-aws" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Avoid the chaos: AWS tagging in practice]]></title>
            <link>https://medium.com/practical-aws/tag-enforcement-in-aws-ac3cd970daf1?source=rss----df4ad87dd53a---4</link>
            <guid isPermaLink="false">https://medium.com/p/ac3cd970daf1</guid>
            <category><![CDATA[tagging]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[policy-as-code]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[governance]]></category>
            <dc:creator><![CDATA[Ronen Dancziger]]></dc:creator>
            <pubDate>Fri, 14 Feb 2025 22:51:35 GMT</pubDate>
            <atom:updated>2025-05-08T21:24:28.300Z</atom:updated>
            <content:encoded><![CDATA[<p>Making sure your AWS resources are tagged correctly is one of those things that seems simple but can get surprisingly tricky. There is not a single simple and straightforwards mechanism to enforce your organization tagging strategy across your AWS environment consists of multiple AWS accounts and operated between operations team and application teams.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ykGW3u0qk66OpKh3zaLWqA.jpeg" /></figure><p>Tags are metadata that provides context for your AWS resources, which can serve different purposes like: automated operations and maintenance, Attribute-based Access Control (ABAC), ownership tracking, cloud-to-code mapping, cost allocation, and many more.</p><h3>The Mess</h3><p>Let’s face reality — while the teams deploying resources (whether through code or clicking buttons) are responsible for proper tagging, it’s rarely at the top of their priority list. They’re usually focused on getting their applications up and running, and tagging often becomes an afterthought. This is how you end up with a mess of inconsistent tags across your AWS resources. Without proper enforcement mechanisms, even the best-designed tagging strategy can fall apart in practice.</p><p>This is where AWS controls come to the rescue! Think of controls as your tagging strategy’s safety net — they help you prevent mistakes before they happen, catch misalignments that slip through, and fix them automatically.</p><p>Let’s explore the different controls available in the AWS echo system to keep your tagging strategy on track.</p><h3>Infrastructure as Code proactive check</h3><p>Infrastructure as Code (IaC) gives us a perfect opportunity to check tags before deployment. While traditional IaC linters (like <a href="https://pypi.org/project/cfn-lint/">cfn-lint</a> or <a href="https://github.com/terraform-linters/tflint">tflint</a>) can help, they’re mostly limited to syntax and best practices checks. For tag validation, you’ll want to use Policy as Code (PaC) tools like <a href="https://www.openpolicyagent.org/">Open Policy Agent (OPA)</a>, <a href="https://docs.aws.amazon.com/cfn-guard/latest/ug/what-is-guard.html">CloudFormation Guard</a> or <a href="https://developer.hashicorp.com/sentinel">Terraform Sentinel</a>. These tools are specifically designed for custom policy validation and can be integrated at any stage of your development pipeline — from your IDE all the way to last step before deployment time. Generally speaking, OPA is the tool agnostic standard for Policy as Code and is supported by most vendors (Terraform, CloudFromation, Pulumi, CDK, etc.).</p><p>Here is an example of CloudFormation Guard policy to validate tags existence and some values patterns on EC2 instance resource type.</p><pre>let aws_resources = Resources.*[ Type == &#39;AWS::EC2::Instance&#39; ]<br><br>let required_tags = [&quot;iac:source-repository&quot;, &quot;application:name&quot;, &quot;application:owner-email&quot;]<br><br>rule check_required_tags {<br>    %aws_resources.Properties {<br>        Tags exists<br>        Tags is_list <br>        %required_tags[*] in Tags[*].Key<br>    }<br>}<br>        <br>rule check_application_name {<br>    %aws_resources.Properties.Tags[Key == &#39;application:name&#39;] {<br>        Value != &quot;&quot;<br>    }<br>}<br><br>rule check_iac_source_repository {<br>    %aws_resources.Properties.Tags[Key == &#39;iac:source-repository&#39;] {<br>        Value == /^https:\/\/gitlab\.com\/.+/<br>    }<br>}<br><br>rule check_application_owner_email_tag {<br>    %aws_resources.Properties.Tags[Key == &#39;application:owner-email&#39;] {<br>        Value == /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/<br>    }<br>}</pre><p>Speaking about Infrastructure as Code and tagging, it is worth mentioning <a href="https://yor.io/">YOR</a> . YOR is an open source tool that applies custom required tags as well as dynamic versioning and tracing tags. YOR’s superpower is making the <strong><em>code to cloud</em></strong> mapping and versioning tagging a no brainer for the developer. You can embed YOR cli in your CI/CD or even as a git commit hook in your IDE to transparently apply tags as part of the development process.</p><h3>Service Control Policy as preventive control</h3><p>With <a href="https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html">Service Control Policies</a> you can prevent creation of resources which are not aligned with the tagging requirements. In the following example, an EC2 instance provisioning will fail if application:name tag is not specified in the API call ec2:RunInstances. And creating EBS volume will fail with ec2:CreateVolume if the tag is not specified, unless the call is done by CloudFormation service.</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;DenyRunInstances&quot;,<br>      &quot;Effect&quot;: &quot;Deny&quot;,<br>      &quot;Action&quot;: [<br>        &quot;ec2:RunInstances&quot;<br>      ],<br>      &quot;Resource&quot;: &quot;arn:aws:ec2:*:*:instance/*&quot;,<br>      &quot;Condition&quot;: {<br>        &quot;Null&quot;: {<br>          &quot;aws:RequestTag/application:name&quot;: &quot;true&quot;<br>        }<br>      }<br>    },<br>    {<br>      &quot;Sid&quot;: &quot;DenyCreateVolume&quot;,<br>      &quot;Effect&quot;: &quot;Deny&quot;,<br>      &quot;Action&quot;: [<br>        &quot;ec2:CreateVolume&quot;<br>      ],<br>      &quot;Resource&quot;: &quot;arn:aws:ec2:*:*:volume/*&quot;,<br>      &quot;Condition&quot;: {<br>        &quot;Null&quot;: {<br>          &quot;aws:RequestTag/application:name&quot;: &quot;true&quot;<br>        },<br>        &quot;StringNotEquals&quot;: {<br>          &quot;aws:CalledVia&quot;: &quot;cloudformation.amazonaws.com&quot;<br>        }<br>      }<br>    }<br>  ]<br>}</pre><p>SCPs are powerful tools for enforcing tags, but watch out — they come with some gotchas! One significant risk is unintended prevention of other AWS services or 3rd party tools. For example, when CloudFormation creates EBS volume it first calls ec2:CreateVolume and only then calls tag:TagResources to tag the volume. The SCP will deny that first call, even though CloudFormation aimed to add the tag later. For this specific case you can use &quot;aws:CalledVia&quot;: &quot;cloudformation.amazonaws.com&quot; to exclude from CloudFormation. This can be true for different AWS services like EKS, AWS Batch, etc., but also to tools like Terraform, Wiz, or other 3rd party integrations.</p><p>SCPs also come with some hard limits: you only get 5 policies per account/OU, and each policy can’t exceed 5.1KB. Given these constraints, here’s my advice: use SCPs selectively for your most critical resources and tags. Make sure to thoroughly test your operational use cases against the SCP. Hit the SCPs limit? Consider using <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html">IAM permission boundaries</a> instead for wide used roles.</p><h3>Organizations Tag policies to enforce tagging values</h3><p><a href="https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html">Tag policies</a> are AWS Organizations’ way of enforcing tagging rules — they make sure your tag values follow the rules you set. But here’s the catch: they only care about tag values, not whether tags exist in the first place. In other words, if someone creates a resource with the wrong value for a tag (like using “prod” instead of “prd”), the tag policy will block it. But if they completely forget to add the tag? The tag policy won’t say a word. This behavior applies to both resource creation and any later tag modifications.</p><p>Let’s look at an example of what tag policies can enforce.</p><pre>{<br>  &quot;tags&quot;: {<br>    &quot;ops:application-name&quot;: {<br>      &quot;tag_key&quot;: {<br>        &quot;@@assign&quot;: &quot;ops:application-name&quot;<br>      }<br>    },<br>    &quot;ops:lifecycle&quot;: {<br>      &quot;tag_key&quot;: {<br>        &quot;@@assign&quot;: &quot;ops:lifecycle&quot;<br>      },<br>      &quot;tag_value&quot;: {<br>        &quot;@@assign&quot;: [<br>          &quot;prd&quot;,<br>          &quot;dev&quot;,<br>          &quot;uat&quot;<br>        ]<br>      }<br>    },<br>    &quot;ops:owner&quot;: {<br>      &quot;tag_key&quot;: {<br>        &quot;@@assign&quot;: &quot;ops:owner&quot;<br>      },<br>      &quot;tag_value&quot;: {<br>        &quot;@@assign&quot;: [<br>          &quot;*@mycorpdomain.com&quot;<br>        ]<br>      }<br>    }<br>  }<br>}</pre><p>Line 3: ops:application-name tag: creation of tag keys like Ops:Application-Name or oPs:application-name will be prevented.<br>Line 8: ops:lifecycle tag: allow to assign only one of prd, dev, or uat to the key ops:lifecycle.<br>Line 20: ops:owner tag: must be assigned an email address of the form *@mycorpdomain.com.</p><h3>Config rules to detect non-compliant resources</h3><p>AWS Config tracks resources configuration changes, and runs a configuration check rule when a change occur. One of the possible checks managed by AWS is <a href="https://docs.aws.amazon.com/config/latest/developerguide/required-tags.html">required-tags</a>, which checks that the resource in scope has up to 6 required tag keys and values defined by you. Whenever a resource is created or modified the rule runs against it and checks if the required tags are there and if their values aligned with the definition.</p><p>If you need more than 6 tags, or if your evaluation login is more complex you can create a custom config rule and implement your own verification logic in a lambda function.</p><h3>Event bridge to detect and response to tagging changes</h3><p><a href="https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html">Event bridge</a> is a stream of events from all the different AWS services. Each service has its own particular events that it will push to the stream. To identify tagging changes we can <a href="https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule.html">create a rule</a> that will capture events from the aws.tag service:</p><pre>{<br>  &quot;detail-type&quot;: [&quot;Tag Change on Resource&quot;],<br>  &quot;source&quot;: [&quot;aws.tag&quot;],<br>  &quot;detail&quot;: {<br>    &quot;tags&quot;: {<br>      &quot;ops:application-name&quot;: [{<br>        &quot;exists&quot;: true<br>      }]<br>    }<br>  }<br>}</pre><p>This event will be matched to aws.tag service events for “tag change” for any resource tag is tagged with ops:application-name. We can use the event rule to invoke a lambda function that will evaluate the compliance of the change with the tagging strategy. This method is much more flexible as compare with the managed AWS Config rule, as it allows more complex evaluation business logic.</p><h3>Automatically correct resource tagging</h3><p>When detective controls identify tag misalignments, corrective procedures automatically fix the resource tags. However, determining the correct tag values presents a challenge. While some values can be derived through business logic and resource context (like AWS account tags, AWS Region, names, etc.), others require explicit values stored in a dedicated datastore (such as application owners or project codes) which requires maintenance. These corrective procedures are typically implemented using AWS Lambda functions or Systems Manager Automation documents, with more complex cases requiring orchestrated workflows across multiple services. For example, a Lambda function might derive an environment tag from the resource’s VPC, but need to look up the correct owner tag from a DynamoDB table. The key is designing a robust system that can both determine and apply the right tags automatically while handling edge cases gracefully.</p><h3>Note about Resource Explorer, resource groups, and tag editor</h3><p>Although these services are very useful to explore, trace, and modify resources with context, the right tools to continuously maintain your tagging strategy compliance are controls and automation, which can leverage those services APIs.</p><h3>To Summarize</h3><p>Maintaining a consistent tagging strategy across your AWS environment requires a multi-layered approach combining proactive and reactive controls. From Infrastructure as Code validation with tools like OPA and CloudFormation Guard, to preventive controls with Service Control Policies, to detective mechanisms using AWS Config and EventBridge, each layer serves a specific purpose in your tagging governance. While tools like Resource Explorer and Tag Editor can help with manual oversight, the key to sustainable tagging compliance lies in automation and systematic enforcement. By implementing these controls thoughtfully and understanding their limitations, you can ensure your organization’s tagging strategy remains effective and your AWS resources stay properly organized, traceable, and manageable across your entire cloud environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac3cd970daf1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/practical-aws/tag-enforcement-in-aws-ac3cd970daf1">Avoid the chaos: AWS tagging in practice</a> was originally published in <a href="https://medium.com/practical-aws">Practical AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Account Factory for Terraform: Lessons from the Trenches]]></title>
            <link>https://medium.com/practical-aws/account-factory-for-terraform-lessons-from-the-trenches-7e86a5c4d3ee?source=rss----df4ad87dd53a---4</link>
            <guid isPermaLink="false">https://medium.com/p/7e86a5c4d3ee</guid>
            <category><![CDATA[aws-control-tower]]></category>
            <category><![CDATA[aws-account-factory]]></category>
            <category><![CDATA[aws-landing-zone]]></category>
            <category><![CDATA[aft]]></category>
            <category><![CDATA[aws-account]]></category>
            <dc:creator><![CDATA[Ronen Dancziger]]></dc:creator>
            <pubDate>Fri, 14 Feb 2025 22:51:07 GMT</pubDate>
            <atom:updated>2025-05-26T19:00:49.736Z</atom:updated>
            <content:encoded><![CDATA[<p>During the last couple of years I have managed the AWS environment for one of my customers using <a href="https://docs.aws.amazon.com/controltower/latest/userguide/taf-account-provisioning.html">AFT</a>, and now its time to share my experience.</p><h4>TL;DR</h4><ul><li>Fork AFT if you deploy it with custom providers, need multi-region support, or want to implement enhanced security controls</li><li>Watch out for the privileged access in management account — the default AWSAFTExecution and AWSAFTService roles need tightening</li><li>AFT’s account request feature is great for GitOps-style account provisioning</li><li>Keep AFT focused on account bootstrapping — it’s not ideal for frequently changing infrastructure</li><li>Consider the propagation time (couple of hours for 100 accounts) when planning changes</li><li>Global customizations work best with a modular approach and clear component separation</li><li>Staging of changes is possible through OU-based exclusions in global customizations — test in one OU before rolling out widely</li><li>Monitor pipeline status separately — step function success doesn’t guarantee pipeline completion</li></ul><p>Going back about two years ago, as a Terraform workshop and consumers of AWS Control Tower, AFT was our goto for AWS accounts bootstrapping and platform infrastructure distribution. As we don’t use Terraform Cloud or Enterprise we used the publicly free option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dbY88IOJE94tCs9oueU9xw.jpeg" /></figure><h3>The Deployment</h3><h4>Custom Providers</h4><p>The <a href="https://github.com/aws-ia/terraform-aws-control_tower_account_factory">AFT Terraform module</a> specifies <a href="https://github.com/aws-ia/terraform-aws-control_tower_account_factory/blob/main/providers.tf">providers.tf</a> file which prevents you from calling the module with your own providers, because of <a href="https://developer.hashicorp.com/terraform/language/meta-arguments/module-providers">how terraform module and providers work</a>:</p><pre>Error: Cannot override provider configuration<br>│<br>│ on main.tf line 4, in module &quot;aft&quot;:<br>│ 4: aws.ct_management = aws.management<br>│<br>│ The configuration of module.aft has its own local configuration for aws.ct_management, and so it cannot accept an overridden configuration provided by the root module.</pre><p>The reason to use our own providers is twofold. First, applying our own tagging strategy on the AFT deployed resources leveraging the provider’s default_tags attribute. And second, our secure terraform deployment pipeline blueprint, requires us to provision anything Terraform with it’s own IAM target roles. And thus we have to define the provider for each target account. This is why, as mentioned in <a href="https://discuss.hashicorp.com/t/terraform-reusable-modules-and-provider-declarations-best-practices/39808/2">this HashiCorp discussion</a>:</p><blockquote>Shared modules should not have provider blocks</blockquote><p>However, since AFT module does, we had to fork it.</p><h4>Required VPC and GitLab support</h4><p>Back then, deploying Lambda function within a VPC was mandatory (AFT team fixed that last February 2024), and GitLab was not supported as VCS (although CodeStar connection introduced GitLab support on August 2023, AFT added it just about year later on October 2024). With those two limitations it was a no-brainer → fork was a must.</p><h4>Security Scanning (PaC)</h4><p>Another reason you might end up forking AFT is modifications to the global/account customizations CodeBuild projects’ buildspec. This was required for us in order to embed some verification and security scanning mechanism in the accounts pipelines.</p><h4>A privileged access concern</h4><p>I’m ok with cross account roles that has privileged access for such extensive automation frameworks like AFT. However, the management account is definitely an exception to that approach.</p><p>Now, if I have access to aft-management account and capable to assume the AWSAFTAdmin role (trusts any local principal) I have now got Admin on the organizations management account, by simply assuming the AWSAFTExecution or AWSAFTService role, which is an Administrator!!! WHAT??? <a href="https://github.com/aws-ia/terraform-aws-control_tower_account_factory/blob/main/modules/aft-iam-roles/iam.tf">see in the repo</a>.</p><pre>module &quot;ct_management_exec_role&quot; {<br>  source = &quot;./admin-role&quot;<br>  providers = {<br>    aws = aws.ct_management<br>  }<br>  trusted_entity        = aws_iam_role.aft_admin_role.arn<br>  aft_admin_session_arn = local.aft_admin_assumed_role_arn<br>}<br><br>module &quot;ct_management_service_role&quot; {<br>  source = &quot;./service-role&quot;<br>  providers = {<br>    aws = aws.ct_management<br>  }<br>  trusted_entity        = aws_iam_role.aft_admin_role.arn<br>  aft_admin_session_arn = local.aft_admin_assumed_role_arn<br>}</pre><p>This is where you want to fork and set this role to be <strong><em>LEAST PRIVILEGED</em></strong>. In our case we reduced the AWSAFTExecution and AWSAFTService role permission in the management account, and on the side of AWSAFTAdmin we limited the trust policy to the different principals that should use it (CodeBuild projects, StepFunction, etc.). I guess that the AFT team requirement to have a dedicated aft-management account eases the severity here, but then you have to treat this account as very sensitive one, where usually Platform Eng. team will have a wide open access.</p><p>The following policies works for me:</p><blockquote><strong>(!) WARNING</strong>: Please test those policies thoroughly, as AFT is updated from time to time, and your environment might have different settings.</blockquote><p><em>AWSAFTService</em> permissions for management account:</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;AFTServicePermissions&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: [<br>        &quot;cloudformation:GetTemplateSummary&quot;,<br>        &quot;iam:GetRole&quot;,<br>        &quot;organizations:DescribeAccount&quot;,<br>        &quot;organizations:ListAccounts&quot;,<br>        &quot;organizations:ListParents&quot;,<br>        &quot;organizations:TagResource&quot;,<br>        &quot;servicecatalog:AssociatePrincipalWithPortfolio&quot;,<br>        &quot;servicecatalog:DescribeProductAsAdmin&quot;,<br>        &quot;servicecatalog:DescribeProvisioningArtifact&quot;,<br>        &quot;servicecatalog:GetProvisionedProductOutputs&quot;,<br>        &quot;servicecatalog:ListPortfolios&quot;,<br>        &quot;servicecatalog:ProvisionProduct&quot;,<br>        &quot;servicecatalog:ScanProvisionedProducts&quot;,<br>        &quot;servicecatalog:SearchProvisionedProducts&quot;,<br>        &quot;servicecatalog:UpdateProvisionedProduct&quot;,<br>        &quot;sts:AssumeRole&quot;,<br>        &quot;sts:GetCallerIdentity&quot;<br>      ],<br>      &quot;Resource&quot;: &quot;*&quot;<br>    }<br>  ]<br>}</pre><p><em>AWSAFTExecution</em> permissions for management account:</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;SupportedServiceSid0&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: [<br>        &quot;organizations:DescribeAccount&quot;,<br>        &quot;organizations:ListAccounts&quot;,<br>        &quot;organizations:ListParents&quot;<br>      ],<br>      &quot;Resource&quot;: &quot;*&quot;<br>    }<br>  ]<br>}</pre><h3>Account Request is powerful!</h3><p>AFT account request allows account creation as part of our git process, which allows us to leverage our native, controlled change process through git. Security wise, there is no need for Admin console access on the Control Tower (management) account when creating new accounts. And AFT handles queueing to prevent throttling of Control Tower Account Factory.</p><p>Another great option is the custom_fields which allows us to implant general metadata in form of SSM parameters in the created accounts. We are mainly use those for organization information which is not availble on the account level and might be needed by local business logic. An example is our local tagging corrective control which need to know if this is dev, uat, or prod account. Since it doesn’t have access to read the account tagging from organizations it can simply read the SSM parameter /aft/account-request/custom-fields/stage.</p><pre>module &quot;account_corp1-app-myapp-dev-01&quot; {<br>  source = &quot;./modules/aft-account-request&quot;<br><br>  control_tower_parameters = {<br>    AccountEmail              = &quot;aws-corp1+app-myapp-dev-01@corp.com&quot;<br>    AccountName               = &quot;corp1-app-myapp-dev-01&quot;<br>    ManagedOrganizationalUnit = &quot;Develop (ou-t3d6-34fi53)&quot;<br>    SSOUserEmail              = &quot;johndoe@corp.com&quot;<br>    SSOUserFirstName          = &quot;John&quot;<br>    SSOUserLastName           = &quot;Doe&quot;<br>  }<br><br>  account_tags = {<br>    &quot;corp:account:owner&quot;    = &quot;myappteam@corp.com&quot;<br>    &quot;corp:account:type&quot;     = &quot;app&quot;<br>    &quot;corp:account:stage&quot;    = &quot;dev&quot;<br>    &quot;corp:account:function&quot; = &quot;MyApp development account&quot;<br>  }<br><br>  change_management_parameters = {<br>    change_requested_by = &quot;John Doe&quot;<br>    change_reason       = &quot;Account creation&quot;<br>  }<br><br>  custom_fields = {<br>    stage = &quot;dev&quot;<br>    ou    = &quot;Root/Workloads/Dev&quot;<br>  }<br><br>  account_customizations_name = &quot;corp1-app-myapp-dev-01&quot;<br>}</pre><p>Note about control_tower_parameters: For our case I chose <strong>to disable </strong>the IAM Identity Center integration. Thus, SSOUser details are not required. However, the Service Catalog product “AWS Control Tower Account Factory” requires those parameters to be none empty strings. The workaround in this case is to provide either placeholders or the details of the person that actually pushes the request.</p><h4>Thanks for these options</h4><p>We found AFT options, straight-forward, simple and useful. We leverage both aft_feature_cloudtrail_data_events and aft_feature_delete_default_vpcs_enabled. It would be nice to have more granularity in terms of the CloudTrail configuration, like S3 buckets prefix name and additional data event types.</p><h3>Constructing Global Customizations</h3><p>The general structure of our terraform/ folder includes a modules/ folder and a configuration file per applied component.</p><pre>.<br>├── aft-providers.jinja<br>├── backend.jinja<br>...    <br>---------------------------COMPONENTS<br>├── notifications.tf<br>├── alerts.tf<br>├── contacts.tf<br>├── iam-password-policy.tf<br>├── ebs-default-encryption.tf<br>├── imds-default-settings.tf<br>├── prevent-public-ami.tf<br>├── prevent-snapshot-sharing.tf<br>├── service-catalog-role.tf<br>├── custom-control-vpc.tf<br>├── custom-control-sg.tf<br>├── custom-control-instance.tf<br>...<br>---------------------------MODULES<br>├── modules<br>│   ├── thirdparty-instance-control ...<br>│   ├── thirdparty-vpc-control ...<br>│   ├── datatrail ...<br>│   ├── solution1-role ...<br>│   ├── notifications ...<br>│   └── service-catalog-role ...<br>├── data.tf<br>├── locals.tf<br>└── variables.tf</pre><p>The modules and the dedicated terraform file per component make it easy to navigate the repository and incorporate changes. Each component includes calls to one or more modules/resources, and a local exclude_&lt;component-name&gt;boolean. The exclude_ determines whether the component is deployed or not to the account, based on list of excluded accounts and/or OUs.</p><h4>Staging changes</h4><p>Other than allowing exceptions to the global configuration, excluding OUs also supports staging of changes. New component can be applied on single OU, and after validation takes place, it can be promoted to higher environments. <br>For example imds-default-settings.tf configuration:</p><pre># data.tf<br><br>data &quot;aws_ssm_parameter&quot; &quot;ou_path&quot; {<br>  name = &quot;/aft/account-request/custom-fields/ou&quot;<br>}<br><br>locals {<br>  current_ou = data.aws_ssm_parameter.ou_path.value<br>  current_id = data.aws_caller_identity.current.account_id<br>}</pre><pre># imds-default-settings.tf<br><br>locals {<br>  exclude_ec2_imds_default_settings = contains(var.exclude_imds_default_settings.ous, local.current_ou) || contains(var.exclude_imds_default_settings.accounts, local.current_id)<br>}<br><br>resource &quot;aws_ec2_instance_metadata_defaults&quot; &quot;this&quot; {<br>  count                       = local.exclude_ec2_imds_default_settings ? 0 : 1<br>  http_endpoint               = &quot;no-preference&quot;<br>  http_tokens                 = &quot;required&quot;<br>  http_put_response_hop_limit = 2<br>  instance_metadata_tags      = &quot;no-preference&quot;<br>}</pre><p>The configuration in this example aws_ec2_instance_metadata_defaults will be deployed only if the current account is not part of excluded OUs/Accounts.</p><p><em>Note: Considering the AWS declarative policies </em><a href="https://aws.amazon.com/about-aws/whats-new/2024/12/aws-declarative-policies/"><em>announcement</em></a><em> configuring IMDS default settings from AFT doesn’t necessary make sense anymore, but that besides the point.</em></p><h3>Account Customizations Configurations</h3><p>Each account request includes an account_customizations_name field. This name corresponds to a folder in your customizations repository, and AFT will apply any Terraform configurations found in that folder to the account. In our case we were able to group the customizations according to our SDLC lifecycle OUs. A dedicated folder per: Production, UAT, Dev, and Sandbox. If there is an exception configuration which need to be deployed to a subset of accounts, a red indication will turned on and we will rethink if the right place for this configuration is AFT. If an account should be excluded from these customization we remove the account_customizations_name field from the account request.</p><h3>A Quick Look at API Helpers</h3><p>Think of API helpers as your Swiss Army knife in AFT — they let you run Python or Bash scripts before and after your Terraform deployments. While this capability gives you tons of flexibility, we’ve found that keeping things simple and declarative with regular Terraform configurations usually works best. Too many options isn’t always helpful.</p><h3>Use Case for Account Provisioning Customizations</h3><p>This very open ended mechanism embedded to AFT is yet to address any need for our platform. We did considered it few times, but ended up find an easier, simple and more consistent solution with either global or account customizations.</p><h3>Rolling out</h3><h4>Source code versus Actual state</h4><p>When rolling out changes, after testing, you want to make sure it is applied to all accounts. This prevents gaps between the source code and the applied configuration. You don’t want to discover that a pipeline for specific account fails when the last time it run successfully was 20 commits ago, which leads us to the next point.</p><h4>AFT rushing no where</h4><p>Propagating a change in AFT to the whole fleet of accounts, in our case ~100 AWS accounts, takes couple of hours. This is mainly because it invokes a batch of 5 pipelines for 5 accounts, and only when those complete it invokes the next batch. This is actually configurable, however, when we tried to increase the batch size we exhausted other quotas, for instance our SVC clone requests. Thus, I would consider the turn around of AFT changes to be a day or half day. My recommendation is to stay away from AFT for configurations that tend to change frequently. Also, when testing your change make sure to target a single account, and rather than starting the step function execution, just release the account pipeline directly.</p><h4>Monitoring</h4><p>After waiting for AFT couple of hours to complete, the step function execution seems to be GREEN, however, if you check the accounts’ pipelines themselves you might discover a failed RED pipeline for one or more accounts. The step function doesn’t wait for the pipeline to complete successfully, but rather reporting success on invocation of the pipeline. And when you have more than ~100 account to will have to put a complementary mechanism out there to indicate failed change propagation.</p><h3>AWSCC provider</h3><p>For some cases, especially in legacy environments, your terraform need to query previously created infrastructure in order to decide on how to deploy a resource or if to deploy it at all. <a href="https://registry.terraform.io/providers/hashicorp/awscc/latest/docs">awscc</a> provider is very useful for quarrying the environment, and so, I added it to aft-providers.jinja:</p><pre>provider &quot;awscc&quot; {<br>  region = &quot;{{ provider_region }}&quot;<br>  assume_role = {<br>    role_arn    = &quot;{{ target_admin_role_arn }}&quot;<br>  }<br>}</pre><h3>Avoid making AFT a jack-of-all-trades tool</h3><p>Due to the many options AFT provides and due to the fact that it is an open source, there might be a tendency to abuse it and make it our go to for any infrastructure deployment. This approach undermine the primary aim of AFT to manage account bootstrapping. AFT propagates changes to all environment stages and the risk of deploying unverified change is there. In addition, due to the slow and vast scope of propagating changes, frequent changing infrastructure is not a good fit for AFT.</p><h3>Multi Region support</h3><p>AFT was not designed for multi region support! However, in reality multi-region will mostly be there, especially for high regulated environments where resiliency is a strict requirement. To support additional regions to the primary one (CT and AFT region) AFT suggests custom AWS “regional” providers, one per additional region. A good implementation example can be seen in <a href="https://medium.com/@joshpattison23/a-better-way-of-using-aft-in-a-multi-region-ct-landing-zone-e8482ef72ea">this post</a> by <a href="https://medium.com/@joshpattison23?source=post_page---byline--e8482ef72ea---------------------------------------">Josh Pattison</a>.</p><h3>In conclusion</h3><p>After two years of using AWS Account Factory for Terraform (AFT) for AWS account bootstrapping, I’ve found it to be a powerful tool that shines when used for its primary purpose — account provisioning and baseline configuration. However, like any tool, it comes with its quirks and limitations that require careful consideration, especially around security, scalability, and change management.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e86a5c4d3ee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/practical-aws/account-factory-for-terraform-lessons-from-the-trenches-7e86a5c4d3ee">Account Factory for Terraform: Lessons from the Trenches</a> was originally published in <a href="https://medium.com/practical-aws">Practical AWS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>