Vendor Components
In the previous steps, we've configured the repository and decided to provision the vpc-flow-logs-bucket and vpc Terraform
components into three AWS accounts (dev, staging, prod) in the two AWS regions (us-east-2 and us-west-2).
We've also configured the Atmos CLI in the atmos.yaml CLI config file to search for the Terraform components in
the components/terraform directory.
Next step is to create the Terraform components vpc-flow-logs-bucket and vpc.
One way to create the Terraform components is to copy them into the corresponding folders in your repo:
-
Copy the
vpc-flow-logs-bucketcomponent from the open-source component repository vpc-flow-logs-bucket into thecomponents/terraform/vpc-flow-logs-bucketfolder -
Copy the
vpccomponent from the open-source component repository vpc into thecomponents/terraform/vpcfolder
The recommended way to vendor the components is to execute the atmos vendor pull CLI command.
For more information about Atmos Vendoring and the atmos vendor pull CLI command, refer to:
To vendor the components from the open-source component repository terraform-aws-components, perform the following steps:
Step 0: Create a vendor.yaml config file
Create a vendor.yaml Atmos vendor config file in the root of the repo with the following content:
vendor.yaml
Advanced Configuration
The glob library that Atmos uses to download remote artifacts does not treat the double-star ** as including sub-folders.
If the component's folder has sub-folders, and you need to vendor them, they have to be explicitly defined as in the following example.
vendor.yaml
Step 0: Vendor the dependencies
Execute the command atmos vendor pull from the root of the repo.
After the command is executed, the filesystem layout should look like this:
│ # Centralized stacks configuration
├── stacks
│
│ # Centralized components configuration. Components are broken down by tool
└── components
└── terraform # Terraform components (Terraform root modules)
├── vpc
│ ├── context.tf
│ ├── main.tf
│ ├── outputs.tf
│ ├── providers.tf
│ ├── remote-state.tf
│ ├── variables.tf
│ ├── versions.tf
│ └── vpc-flow-logs.tf
└── vpc-flow-logs-bucket
├── context.tf
├── main.tf
├── outputs.tf
├── providers.tf
├── variables.tf
└── versions.tf
Each component follows the Standard Module Structure that Terraform recommends. There are a few additions:
-
context.tf- this file contains all the common variables that Terraform modules and components consume (to make the component'svariables.tffile DRY). This is a standard file that is copied into each component. The file also defines the context variables (namespace,tenant,environment,stage) which are used by Atmos to search for Atmos stacks when executing the CLI commands -
remote-state.tfin thevpccomponent - this file configures the remote-state Terraform module to obtain the remote state for thevpc-flow-logs-bucketcomponent. ThevpcTerraform component needs the outputs from thevpc-flow-logs-bucketTerraform component to configure VPC Flow Logs and store them in the S3 bucket
components/terraform/vpc/remote-state.tf
Remote State Notes
The remote-state Terraform module uses the terraform-provider-utils Terraform provider to read Atmos configuration and obtain the remote state for Atmos components.
Both the atmos CLI and terraform-provider-utils Terraform provider use the same Go code,
which try to locate the CLI config atmos.yaml file before parsing and processing Atmos stacks.
This means that atmos.yaml file must be at a location in the file system where all processes can find it.
While placing atmos.yaml at the root of the repository will work for Atmos, it will not work for
the terraform-provider-utils Terraform provider because the provider gets executed from the
component's directory (e.g. components/terraform/vpc), and we don't want to replicate atmos.yaml into every component's folder.
atmos.yaml is loaded from the following locations (from lowest to highest priority):
- System dir (
/usr/local/etc/atmos/atmos.yamlon Linux,%LOCALAPPDATA%/atmos/atmos.yamlon Windows) - Home dir (
~/.atmos/atmos.yaml) - Current directory
- ENV variables
ATMOS_CLI_CONFIG_PATHandATMOS_BASE_PATH
For this to work for both the atmos CLI and the Terraform utils provider, we recommend doing one of the following:
-
Put
atmos.yamlat/usr/local/etc/atmos/atmos.yamlon local host and set the ENV varATMOS_BASE_PATHto point to the absolute path of the root of the repo -
Put
atmos.yamlinto the home directory (~/.atmos/atmos.yaml) and set the ENV varATMOS_BASE_PATHpointing to the absolute path of the root of the repo -
Put
atmos.yamlat a location in the file system and then set the ENV varATMOS_CLI_CONFIG_PATHto point to that location. The ENV var must point to a folder without theatmos.yamlfile name. For example, ifatmos.yamlis at/atmos/config/atmos.yaml, setATMOS_CLI_CONFIG_PATH=/atmos/config. Then set the ENV varATMOS_BASE_PATHpointing to the absolute path of the root of the repo -
When working in a Docker container, place
atmos.yamlin therootfsdirectory at /rootfs/usr/local/etc/atmos/atmos.yaml and then copy it into the container's file system in the Dockerfile by executing theCOPY rootfs/ /Docker command. Then in the Dockerfile, set the ENV varATMOS_BASE_PATHpointing to the absolute path of the root of the repo. Note that the Atmos example uses Geodesic as the base Docker image. Geodesic sets the ENV varATMOS_BASE_PATHautomatically to the absolute path of the root of the repo on local host
For a complete description of how Atmos components use remote state, refer to Component Remote State.