Skip to main content

Bucket module

The module that creates a private, versioned and encrypted bucket, with the three variables, the nested output, and what it decides for you.

Creates a bucket with what the house has already decided: private, versioned, encrypted with KMS, and with expiry of old versions. Three variables, and the first two are required.

Before you start

A session assumed in the target environment and the module version chosen. Pin the version: source without version resolves to the latest on every init.

The steps

  1. Declare

    module "relatorios" {
    source = "panlabs/bucket/aws"
    version = "3.1.0"

    nome = "relatorios"
    proposito = "output of the weekly reporting job"
    retencao = 90
    }
  2. Plan

    A new bucket creates between six and eight resources. A number far from that means the composition is picking up more than you asked for.

    terraform init -upgrade
    terraform plan -out plano.bin
  3. Apply

    In dev, directly; in the other two, through the pipeline.

    terraform apply plano.bin

Verification

panlabs infra conferir bucket relatorios
# name relatorios-dev
# access private (public access block: 4/4)
# versioning enabled

What it decides for you

DecisionValueWhy
Public accessblocked on all 4 keysthree out of four is the common way a "private" bucket is not
Versioningonrecovery from a bad write has no substitute
EncryptionKMSsse-s3 does not allow per-key policy
Environment suffixautomaticbucket names are immutable, and the mistake only shows after apply

The output is a nested object, and its anatomy is in A module's output.

nome gets the environment suffix on its own. Writing relatorios-dev produces relatorios-dev-dev, and since bucket names are immutable the fix is destroy and recreate.

retencao = 0 turns off expiry of old versions and needs a justification in the pull request. A versioned bucket with no expiry grows forever, and the cost shows up three quarters later.