Connect AWS to Spotto with Terraform
The terraform-aws-spotto module deploys the same CloudFormation stacks as Launch Stack in AWS, as aws_cloudformation_stack resources. CloudFormation owns the role, its policies and the export. Terraform owns the stacks. There's no file to send back: the portal detects the connection once the stack completes.
Requirements
- Terraform 1.12.0 or later, with the
hashicorp/awsprovider 6.x. - An AWS provider for the management or standalone account. Module inputs select regional access/storage and the separate us-east-1 definition stack using provider v6 region arguments.
- Permission to create CloudFormation stacks and IAM roles. For a new export, also S3 buckets and Data Exports.
- For member accounts, StackSets trusted access turned on in the management account.
- Your External ID and trusted principal ARN: in Spotto, select Create, then AWS, and under Script or Terraform select Use Terraform. The page shows a snippet for the cost data you choose.
Inputs
| Variable | Default | What it does |
|---|---|---|
deployment | Required | Deployment supplied by the owning Portal. |
registration_topic_arn | Required | Must match deployment exactly. |
external_id | Required | Your company's External ID, spotto-<uuid>. |
trusted_principal_arn | Required | The Spotto IAM principal the role trusts. |
cost_data | "CreateExport" | Creates the bucket and the export spotto-cur2. Billing is required, so cost_data = "None" is rejected. Set existing_export instead to use an export you have. |
existing_export | null | A supported export to read instead: export_name, bucket_name, and optionally base_prefix and kms_key_arn. The bucket must be in the same account. |
connect_member_accounts | false | Deploy the role to member accounts with a StackSet. |
organizational_unit_ids | [] | Root (r-…) or OU IDs for member accounts. Required when connect_member_accounts is true. |
role_name | SpottoReadOnlyRole | Keep the default; Spotto looks for this name. |
repair_token | "" | Change to a new number to reapply the role's policies. See repair. |
template_base_url | The module's pinned template version | Leave the default. A module upgrade moves it to the new version. |
Find the root ID with aws organizations list-roots --query 'Roots[0].Id' --output text. See find your AWS IDs.
Example
An organization with a new export and every member account:
provider "aws" {
region = "us-east-1"
}
module "spotto" {
source = "git::https://github.com/spottoai/terraform-aws-spotto.git"
deployment = "dev-au"
registration_topic_arn = "arn:aws:sns:ap-southeast-2:715809501612:spotto-aws-connect-dev-au"
external_id = "spotto-<uuid>"
trusted_principal_arn = "<ARN shown in the portal>"
connect_member_accounts = true
organizational_unit_ids = ["r-ab12"]
}
To use an existing export instead, add:
existing_export = {
export_name = "cid-cur2"
bucket_name = "example-billing"
base_prefix = "cur2"
}
For a standalone account, leave out the member account inputs.
Apply
- Run
terraform init,terraform planandterraform apply. - Leave the portal on Waiting for the connection…. It detects the connection when the stack completes, then shows the accounts.
- Choose the accounts and select Finish.
Applied earlier, or closed the portal? Open Connect AWS again: the portal offers the detected account. Select Continue. If it isn't offered, select Enter Account ID.
| Output | Value |
|---|---|
role_arn | The role in this account. |
billing_bucket_name | The created or existing export's bucket, or null. |
export_arn | The created spotto-cur2 export, or null. |
connect_stack_id, billing_access_stack_id, member_accounts_stack_id | The stack IDs. |
Change Or Remove Access
- Change an input: apply again. Terraform updates the stacks.
- Update: bump the module version and apply. Each module version pins its template version. See update and repair.
- Repair: change
repair_tokenand apply. - Remove: remove the accounts from Spotto first, then run
terraform destroy. It deletes the roles. The bucket and export are kept, so cost data isn't lost. See delete the stacks. - Don't change the role or its policies outside the stacks. The next apply reverts it.
The External ID is in your Terraform state. AWS doesn't treat it as a secret, but it ties the role to your Spotto company, so use a remote backend with encryption and access controls.
Regional Storage And Global Billing Definition
AU uses Sydney (ap-southeast-2), US N. Virginia (us-east-1), EU Stockholm
(eu-north-1). Dev and production are separate. The regional connect stack creates
the role and private billing bucket/policy. A separate billing-export stack in
us-east-1 creates only the definition, deriving destination bucket and owner from
its account/deployment and delivering files to the mapped region. Existing-export
mode creates no new definition. Billing data is retained when stacks are removed.