<?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[Stories by Anthony Angel on Medium]]></title>
        <description><![CDATA[Stories by Anthony Angel on Medium]]></description>
        <link>https://medium.com/@anthonyangel?source=rss-39fe6db8f04e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Tw2OaADElUga7x3d.</url>
            <title>Stories by Anthony Angel on Medium</title>
            <link>https://medium.com/@anthonyangel?source=rss-39fe6db8f04e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 03:49:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anthonyangel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[It’s easy when you know the answer — finding an S3 bucket when you don’t know the name]]></title>
            <link>https://medium.com/fundapps-tech/its-easy-when-you-know-the-answer-finding-an-s3-bucket-when-you-don-t-know-the-name-5a4fec27abc4?source=rss-39fe6db8f04e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a4fec27abc4</guid>
            <dc:creator><![CDATA[Anthony Angel]]></dc:creator>
            <pubDate>Wed, 03 Aug 2022 08:18:46 GMT</pubDate>
            <atom:updated>2022-08-03T08:18:46.764Z</atom:updated>
            <content:encoded><![CDATA[<h3>It’s easy when you know the answer — finding an S3 bucket when you don’t know the name</h3><p>Our clients at FundApps are some of the worlds largest financial institutions, who collectively manage in excess of $14 trillion. One of the guardrails which we have implemented is a shared-nothing approach, where each tenant has their own infrastructure residing in their own dedicated AWS account.</p><p>One of the notable limitations of Amazon S3 is globally unique bucket names. Although a bucket is created in a specific region, and specific to an AWS account (it can of course be shared cross-account), the name of the bucket has to be unique not only to the AWS account in question, but to all AWS accounts, i.e if I create a bucket called thisismybucket in 1 account, then no-one else can re-use that name in any other account.</p><p>Based on the above we needed to find a way to create a copy of the infrastructure in each AWS account, whilst keeping the required uniqueness for bucket names. The Terraform S3 resource does have an input value for bucket_prefix , which will create a unique bucket name by appending a random suffix, i.e. we can create a bucket named metadata20210625152621311800000002 from the following code</p><pre>resource &quot;aws_s3_bucket&quot; &quot;bucket&quot; {<br>  bucket_prefix = &quot;metadata&quot;<br>}</pre><h4>DevOps ❤ pets (not that kind!)</h4><p>This isn’t particularly pleasant to look at, so instead we use the Terraform random pet provider to give more human-readable names.</p><pre>resource “random_pet” “this” {<br>  length = 2<br>}</pre><pre>resource &quot;aws_s3_bucket&quot; &quot;bucket&quot; {<br>  bucket = &quot;metadata-${random_pet.this.id}&quot;<br>}</pre><p>The resulting names are far more readable, and memorable when developing or troubleshooting. Some examples include:</p><ul><li>metadata-social-basilisk</li><li>metadata-eminent-reptile</li><li>metadata-wired-lobster</li></ul><h4>What could possibly go wrong?</h4><p>One of our values at FundApps is #BeTransparent, there’s an assumption within our engineering team that at some point we will write the bucket name into an incident report, and then we will have to explain to a client that the names are randomly generated and not meant as a personal slight!</p><h4>Why is this a problem?</h4><p>If we only needed to reference these buckets in the same block of Terraform which created them, life would be simple, as we’d just reference the Terraform resource identifier aws_s3_bucket.bucket.arn , but we need to reference these buckets from other places within Terraform.</p><p>A common example is having our logging buckets set up in 1 Terraform workspace, and separate workspaces for each service. This keeps the Terraform nice and tidy, whilst allowing a separation of concerns between our product teams. In order to set up an S3 bucket to log to a different bucket we need to know the name of the log bucket.</p><pre># Pseudo-code, this block is meant to be within an aws_s3_bucket_logging resource</pre><pre>logging {<br>  target_bucket = aws_s3_bucket.logs.id # This is the bucket name<br>  target_prefix = &quot;log/&quot;<br>}</pre><p>We need to know the name of the bucket in order to reference it.</p><pre># This won&#39;t work unless you know the full name of what you are looking for</pre><pre>data &quot;aws_s3_bucket&quot; &quot;logs&quot; {<br>  bucket = &quot;logs&quot;<br>}</pre><h4>SSM to the rescue</h4><p>One approach would be to write the S3 bucket name to an SSM parameter, and have Terraform perform a data lookup on the SSM parameter. This does work, but requires an overhead on creating the SSM parameter next to the bucket.</p><pre>data &quot;aws_ssm_parameter&quot; &quot;logs_bucket&quot; {<br>  name = &quot;/s3_buckets/logs&quot;<br>} </pre><pre>logging {<br>  target_bucket = data.aws_ssm_parameter.logs_bucket.value<br>  target_prefix = &quot;log/&quot;<br>}</pre><h4>A nicer approach</h4><p>An alternative approach using the <a href="https://aws.amazon.com/cloudcontrolapi/">AWS Cloud Control API</a>, and more specifically the <a href="https://github.com/hashicorp/terraform-provider-awscc">Terraform provider</a> for it.</p><pre>terraform {<br>  required_providers {<br>    awscc = {<br>      source  = &quot;hashicorp/awscc&quot;<br>    }<br>  }<br>}</pre><pre>provider &quot;awscc&quot; { region = &quot;eu-west-1&quot; }</pre><pre>data &quot;awscc_s3_buckets&quot; &quot;this&quot; {}</pre><pre># This will output a list of all my S3 buckets<br>output &quot;buckets&quot; {<br>  value = data.awscc_s3_buckets.this<br>}</pre><pre>locals {<br>  bucket_list     = data.awscc_s3_buckets.this.ids<br>  matching_string = &quot;logs&quot;<br>  filtered_bucket = [for bucket in local.bucket_list : bucket if   substr(&quot;${bucket}&quot;, 0, length(&quot;${local.matching_string}&quot;)) == &quot;${local.matching_string}&quot;]<br>}</pre><pre>output &quot;filtered&quot; {<br>  value = local.filtered_bucket<br>}</pre><p>This allows us to not have to create any additional resources next to the S3 buckets, we have a single data lookup to return all bucket names back to us. We can keep our Terraform as DRY as possible, resulting in small &amp; atomic Terraform workspaces, whilst still keeping things unique.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a4fec27abc4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fundapps-tech/its-easy-when-you-know-the-answer-finding-an-s3-bucket-when-you-don-t-know-the-name-5a4fec27abc4">It’s easy when you know the answer — finding an S3 bucket when you don’t know the name</a> was originally published in <a href="https://medium.com/fundapps-tech">Engineering at FundApps</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>