Quickstart Guide
Welcome to the Nuvibit Terraform Collection (NTC) Quickstart Guide!
This guide will help you deploy your first NTC building block: NTC Organizations. This building block is designed to create and manage your AWS Organization, define the Organizational Unit (OU) structure, and apply guardrails such as Service Control Policies (SCPs).
Why NTC Organizations?โ
The NTC Organizations building block manages AWS Organizations which is the first thing you need to configure when setting up an AWS multi-account environment.
Key goals include:
-
Creating an AWS Organization
Set up a central management layer for governing multiple AWS accounts. -
Defining OU Structures
Organize accounts by workloads, environments, or business units. -
Applying Guardrails
Enforce policies and ensure compliance using SCPs.
Prerequisitesโ
Before deploying the NTC Organizations building block, ensure the following requirements are met:
-
Valid NTC Subscription
Ensure you have a valid NTC subscription and access to the NTC library. Otherwise, contact us. -
AWS Management Account
A central AWS account to manage your AWS Organization. See Step 1. -
Terraform / OpenTofu Installed
Install the latest version of Terraform or OpenTofu.
We recommend using a version manager such as tenv to easily switch between versions. -
CI/CD Pipeline
Set up a CI/CD pipeline with tools like Spacelift, GitHub Actions, or GitLab. See Step 2 for guidance.
While a CI/CD pipeline is not strictly required for deployment, it is strongly recommended. Using a CI/CD pipeline ensures quality, reliability, and consistency throughout your infrastructure provisioning and updates.
Step-by-Step Deploymentโ
Step 1: Create AWS Management Accountโ
-
Access the AWS Management Console
Open the AWS Management Console at https://console.aws.amazon.com/. -
Create a New AWS Account
- Click Create a new AWS account and follow the instructions.
- Provide account details, including a valid email address, payment information, and phone verification.
- For detailed instructions, refer to the AWS Account Creation Guide.
-
Enable Multi-Factor Authentication (MFA)
- Configure MFA for the root user to enhance account security.
- For detailed instructions, refer to the AWS MFA Setup Guide.
Define a consistent naming convention for AWS accounts and email addresses that reflect their purpose.
For example:
- Account Name:
aws-org-management
- Email Address:
aws-org-management@company.com
- Use a non-personal email address for the AWS Management Account to prevent losing access to the mailbox.
- Regularly review and track who has access to the account and mailbox.
- Maintain a valid and active phone number for recovery purposes, capable of receiving text messages or calls.
For additional best practices, refer to the AWS Organizations Guide.
Step 2: Set up a CI/CD Pipelineโ
Check out our CI/CD Pipelines for Infrastructure-as-Code Delivery whitepaper for detailed guidance and best practices.
-
Choose a CI/CD Tool
Use a CI/CD pipeline tool like Spacelift, GitHub Actions, or GitLab CI/CD to automate and streamline deployments. -
Set Up a Terraform / OpenTofu State Backend
- Some CI/CD tools natively support Terraform / OpenTofu state management (e.g. Spacelift).
- Otherwise, you can use Amazon S3 as state backend and DynamoDB for state locking.
-
Create a Code Repository
- Set up a Git repository to store your Terraform / OpenTofu configuration.
- Keep consistent naming between AWS accounts, Git repositories and CI/CD pipelines for easier maintenance.
- We recommend enabling branch protection on the
main
branch and push updates via pull request.
-
Create a CI/CD Pipeline
- Associate the code repository with the pipeline and define pipeline triggers (e.g. pull request triggers a
plan
run) - Define pipeline stages for
checks
,plan
,apply
, andtesting
operations. - Define pipeline triggers (when to trigger a
plan
run and when to trigger anapply
run). - Define environment variables or integrate a secrets manager for sensitive data such as credentials or secrets.
- Associate the code repository with the pipeline and define pipeline triggers (e.g. pull request triggers a
-
Set Up OpenID Connect (OIDC)
- Configure OIDC for secure, short-lived authentication to AWS.
- Follow the AWS OIDC Setup Documentation to integrate your chosen CI/CD tool.
-
Grant Necessary Permissions
- Assign pipeline permissions via the IAM role in the AWS Management Account.
- Start with
AdministratorAccess
for simplicity and move towards least-privilege permissions as your setup matures. - Limit access to the pipeline to trusted users and maintain strict controls.
-
Configure NTC Access
- Your pipeline requires access to NTC. There are various options:
- Spacelift
- Github Token
- SSH Key
For a Spacelift pipeline, no credentials are required. Reference NTC directly from the Spacelift registry:
module "ntc_organizations" {
source = "spacelift.io/nuvibit/ntc-organizations/aws"
version = "1.3.1"
# additional parameters
}To access NTC via HTTPS you need to add a Github Token to the Git config inside your pipeline:
git config --global url."https://$GITHUB_TOKEN_NTC@github.com/nuvibit-terraform-collection".insteadOf "https://github.com/nuvibit-terraform-collection"
Reference NTC via HTTPS:
module "ntc_organizations" {
source = "github.com/nuvibit-terraform-collection/terraform-aws-ntc-organizations?ref=1.3.1"
# additional parameters
}To access NTC via SSH you need to import your SSH Key into your pipeline:
# copy SSH Key to '~/.ssh/id_rsa'
chmod 400 ~/.ssh/id_rsaReference NTC via SSH:
module "ntc_organizations" {
source = "git@github.com:nuvibit-terraform-collection/terraform-aws-ntc-organizations.git?ref=1.3.1"
# additional parameters
}
We strongly recommend using OpenID Connect (OIDC) for pipeline authentication to AWS.
Limit access to the CI/CD pipeline and audit its usage to prevent unauthorized changes.
If OIDC is not feasible, an IAM user with an access key and secret access key can also be used.
Make sure to regularly rotate access keys to minimize security risks.
Step 3: Deploy NTC Organizationsโ
-
Initialize Terraform / OpenTofu Configuration
Configure requirements, backend and providers:- main.tf
- backend.tf
- outputs.tf
# -----------------------------------------------------------------------------------------------
# REQUIREMENTS
# -----------------------------------------------------------------------------------------------
terraform {
# pin versions to only increment the patch to minimize the chance of breaking changes
required_version = "~> 1.8.5"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.80"
configuration_aliases = []
}
}
}
# -----------------------------------------------------------------------------------------------
# PROVIDERS
# -----------------------------------------------------------------------------------------------
/*
use environment variables for authentication via OpenID Connect:
AWS_ROLE_ARN, AWS_WEB_IDENTITY_TOKEN_FILE, AWS_ROLE_SESSION_NAME
use environment variables for authentication via IAM user:
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
*/
provider "aws" {
region = "eu-central-1"
# add default tags to all resources that the provider creates
default_tags {
tags = local.default_tags
}
}
# add additional providers for other regions in use
provider "aws" {
alias = "use1"
region = "us-east-1"
default_tags {
tags = local.default_tags
}
}
# -----------------------------------------------------------------------------------------------
# DATA
# -----------------------------------------------------------------------------------------------
data "aws_region" "default" {}
data "aws_caller_identity" "current" {}
# -----------------------------------------------------------------------------------------------
# LOCALS
# -----------------------------------------------------------------------------------------------
locals {
default_tags = {
ManagedBy = "opentofu"
ProvisionedBy = "ntc-organizations"
}
}# -----------------------------------------------------------------------------------------------
# BACKEND
# -----------------------------------------------------------------------------------------------
# If you're using Spacelift, do not specify any Terraform backend whatsoever
terraform {
backend "s3" {
bucket = "example-bucket"
key = "path/to/state"
region = "eu-central-1"
dynamodb_table = "example-table" # state locking via dynamodb
}
}# -----------------------------------------------------------------------------------------------
# OUTPUTS
# -----------------------------------------------------------------------------------------------
output "default_region" {
description = "The default region name"
value = data.aws_region.default.name
}
output "account_id" {
description = "The current account id"
value = data.aws_caller_identity.current.account_id
} -
Test Pipeline Access to AWS
If you configured OpenID Connect correctly, you should now be able to test your pipeline. You can either create a pull request or run a localplan
with Terraform / OpenTofu (requires local credentials).- Terraform
- Opentofu
# download and initialize providers and modules
terraform init --upgrade
# preview the changes that Terraform plans to make
terraform plan# download and initialize providers and modules
tofu init --upgrade
# preview the changes that OpenTofu plans to make
tofu planIf Terraform / OpenTofu outputs the โaccount_idโ and โdefault_regionโ, you have successfully connected your pipeline to AWS.
data.aws_caller_identity.current: Reading...
data.aws_region.default: Reading...
data.aws_region.default: Read complete after 0s [id=eu-central-1]
data.aws_caller_identity.current: Read complete after 0s [id=012345678901]
Changes to Outputs:
+ account_id = "012345678901"
+ default_region = "eu-central-1"
You can apply this plan to save these new output values to the OpenTofu state, without changing any real
infrastructure. -
Explore Configuration Options
Check the NTC Organizations documentation page to explore the full range of configuration options. The page includes:- A comprehensive list of parameters to tailor your setup.
- A practical usage example for implementation guidance.
- A detailed implementation blueprint to ensure alignment with best practices.
-
Define your Organization Structure
An organizational unit (OU) provides a means to group accounts. OUs are not meant to mirror your own organizationโs reporting structure. Instead, OUs are intended to group accounts that have common overarching security policies and operational needs. The primary question to ask yourself is: How likely will the group need a set of similar policies?Use the following organizational structure as a blueprint and adapt it as needed:
-
Apply Configuration
Open a pull request with your customized configuration:- ntc-organizations.tf
- ntc_organizations_guardrails.tf
# -----------------------------------------------------------------------------------------------
# NTC ORGANIZATIONS
# -----------------------------------------------------------------------------------------------
module "ntc_organizations" {
source = "github.com/nuvibit-terraform-collection/terraform-aws-ntc-organizations?ref=1.3.1"
# list of services which should be enabled in Organizations
service_access_principals = [
"account.amazonaws.com",
"cloudtrail.amazonaws.com",
"securityhub.amazonaws.com",
"config.amazonaws.com",
"config-multiaccountsetup.amazonaws.com",
"guardduty.amazonaws.com",
"inspector2.amazonaws.com",
"malware-protection.guardduty.amazonaws.com",
"sso.amazonaws.com",
"ipam.amazonaws.com",
"servicequotas.amazonaws.com",
]
# list of nested (up to 5 levels) organizational units
organizational_unit_paths = [
"/root/core",
"/root/sandbox",
"/root/exceptions",
"/root/suspended",
"/root/workloads",
"/root/workloads/prod",
"/root/workloads/dev",
]
# guardrails which should be attached to multiple organizational units and/or accounts
# NTC offers guardrail templates which can be directly referenced here
service_control_policies = [
# {
# policy_name = "scp_deny_all_outside_eu_regions",
# target_ou_paths = ["/root/workloads"]
# target_account_ids = []
# policy_json = "INSERT_SCP_JSON"
# }
module.ntc_guardrail_templates.service_control_policies["scp_root_ou"],
module.ntc_guardrail_templates.service_control_policies["scp_suspended_ou"],
module.ntc_guardrail_templates.service_control_policies["scp_workloads_ou"],
]
}# -----------------------------------------------------------------------------------------------
# NTC ORGANIZATIONS - GUARDRAIL TEMPLATES
# -----------------------------------------------------------------------------------------------
module "ntc_guardrail_templates" {
source = "github.com/nuvibit-terraform-collection/terraform-aws-ntc-guardrail-templates?ref=1.0.3"
# service control policies (SCPs) can apply permission guardrails at the organization, organizational unit, or account level
# https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html
service_control_policy_templates = [
{
policy_name = "scp_root_ou"
target_ou_paths = ["/root"]
template_names = ["deny_leaving_organizations", "deny_actions_as_root"]
},
{
policy_name = "scp_suspended_ou"
target_ou_paths = ["/root/suspended"]
template_names = ["deny_all"]
exclude_principal_arns = ["arn:aws:iam::*:role/OrganizationAccountAccessRole"]
},
{
policy_name = "scp_workloads_ou"
target_ou_paths = ["/root/workloads"]
template_names = ["deny_outside_allowed_regions"]
allowed_regions = ["eu-central-1", "eu-central-2"]
exclude_principal_arns = ["arn:aws:iam::*:role/OrganizationAccountAccessRole"]
}
]
}Wait for pull request checks to complete and merge to start deployment
-
Verify Deployment
-
Check the AWS Management Console to ensure the organization, OUs, and SCPs have been created.
-
Conclusionโ
Congratulations ๐ You have successfully deployed the NTC Organizations building block. This essential step sets up a structured AWS Organization with initial guardrails, providing a solid starting point to scale your AWS environment.
Next Stepsโ
The Nuvibit Terraform Collection (NTC) is designed with a modular approach, offering flexibility to adapt to your specific needs and requirements. Explore NTC building blocks by topic or the NTC library page for detailed information about NTC building blocks.
Use the Nuvibit AWS Reference Architecture as a starting point and customize it to your specific requirements.
Implementing the Nuvibit AWS Reference Architectureโ
-
NTC Account Factory (documentation) (implementation blueprint)
- Serves as the cornerstone of your AWS foundation and Landing Zone.
- Create the Log Archive, Security, and Connectivity core accounts.
-
NTC Parameters (documentation) (implementation blueprint)
- Simplifies multi-account orchestration by providing a streamlined way to share parameters across AWS accounts and pipelines.
-
NTC Identity Center (documentation) (implementation blueprint)
- Enables single sign-on (SSO) access to your AWS environment with fine-grained controls for users and groups.
- When combined with the NTC Account Factory, SSO access management can be fully automated and orchestrated.
-
NTC Log Archive (documentation) (implementation blueprint)
- Provisions centralized S3 buckets to archive audit logs for regulatory compliance (e.g., CloudTrail, VPC FLow Logs).
- After creating the CloudTrail S3 Log Archive, enable CloudTrail in NTC Organizations.
-
NTC Security Tooling (documentation) (implementation blueprint)
- Configure necessary admin delegations via NTC Organizations for the security account.
- Configure the central Security Hub and additional security services of your choice (e.g., GuardDuty, Inspector, Macie).
-
NTC Connectivity Building Blocks (implementation blueprint)
- Implement your custom AWS network architecture with a combination of connectivity building blocks.
Check the latest NTC releases for new features and updates.