Setting Up a BYOC Provider Account via Terraform
Use the Instaclustr Terraform provider alongside the AWS provider to provision your entire BYOC setup as infrastructure as code — from registering the provider account to deploying AWS resources and validating the connection in a single terraform apply.
Step 1 – Configure the providers
Declare both the Instaclustr and AWS providers. The Instaclustr provider authenticates using a terraform_key in the format Instaclustr-Terraform <username>:<api_key>.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
terraform { required_providers { instaclustr = { source = "instaclustr/instaclustr" version = ">= 2.0.0, < 3.0.0" } aws = { source = "hashicorp/aws" version = "~> 6.0" } } } provider "instaclustr" { terraform_key = "Instaclustr-Terraform ${var.instaclustr_username}:${var.instaclustr_api_key}" } provider "aws" { region = "us-east-1" # a real AWS region string profile = "your-aws-profile" # local AWS credentials profile } |
Note: The AWS provider region must be a real AWS region string (e.g. us-east-1), which is different from the Instaclustr data center name used later (US_EAST_1). Don’t put the Instaclustr DC name in the AWS provider block.
Step 2 – Define your variables
Create a variables.tf file. Supply sensitive values — particularly instaclustr_api_key — via environment variables, a *.tfvars file excluded from version control, or your secrets manager. Never commit credentials to source control.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
variable "instaclustr_username" { description = "Instaclustr Provisioning API key username" type = string } variable "instaclustr_api_key" { description = "Instaclustr Provisioning API key" type = string sensitive = true } variable "cloudformation_stack_name" { description = "Name of the CloudFormation stack to create in your AWS account" type = string } variable "instaclustr_aws_account_id" { description = "Your 12-digit AWS Account ID" type = string } variable "provider_account_name" { description = "A unique Instaclustr BYOC provider account name" type = string } variable "s3_backup_bucket_name" { description = "S3 backup bucket name to create" type = string } variable "iam_role_name" { description = "IAM role name for the cross-account role" type = string } variable "key_pair_name" { description = "EC2 key pair name — must be your Instaclustr Account ID" type = string } variable "create_key_pair" { description = "Whether the CloudFormation stack should create the EC2 key pair. Set to false for a 2nd+ BYOC provider account targeting the SAME AWS account and region." type = bool default = true } |
About key_pair_name:
The CloudFormation template creates an EC2 key pair named with your Instaclustr Account ID. The data source substitutes this server-side (@@KEY_PAIR_NAME@@ → your Instaclustr Account ID), so you do not need a separate key_pair_name variable unless you reference it elsewhere.
-
First BYOC provider account in a given AWS account + region: leave
create_key_pair = true(default). -
Additional provider accounts in the same AWS account + region: set
create_key_pair = false. EC2 key pair names must be unique per AWS account/region, and the name is tied to your Instaclustr Account ID (not the provider account), so only the first stack should create it.
If you skip this on a second setup, AWS returns InvalidKeyPair.Duplicate and the stack fails.
You can find your Instaclustr Account ID in the Console under Account Settings.
Step 3 – Retrieve and customise the CloudFormation template
The Instaclustr provider exposes a data source that returns the CloudFormation template with Instaclustr-side values already substituted. You only need to replace the two customer-side placeholders: the backup bucket name and the IAM role name.
The following placeholders are substituted automatically by Instaclustr:
| Placeholder | Substituted with |
|---|---|
@@INSTACLUSTR_ACCOUNT_ID@@ |
Your Instaclustr account ID (used as the cross-account role ExternalId) |
@@INSTACLUSTR_AWS_ACCOUNT_ID@@ |
Instaclustr’s AWS account (used in the role trust policy) |
@@KEY_PAIR_NAME@@ |
Your Instaclustr account ID |
You substitute the remaining two placeholders in the locals block below:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
data "instaclustr_byoc_aws_cloudformation_template_v1" "byoc_template" {} locals { raw_template = ( length(data.instaclustr_byoc_aws_cloudformation_template_v1.byoc_template.templates[0]) > 0 ? data.instaclustr_byoc_aws_cloudformation_template_v1.byoc_template.templates[0].template : "" ) processed_template = replace( replace( local.raw_template, "@@S3_BACKUP_BUCKET_NAME@@", var.s3_backup_bucket_name ), "@@IAM_ROLE_NAME@@", var.iam_role_name ) } |
Important – values must match: The s3_backup_bucket_name and iam_role_name you substitute into the template must exactly match the backup_bucket_name and iam_role_name you provide to the instaclustr_byoc_aws_provider_account_setup_v1 resource in Step 5. If they differ, validation will fail because Instaclustr won’t find the expected bucket/role in your account.
Step 4 – Deploy the CloudFormation stack in AWS
Deploy the processed template into your AWS account. The stack creates the S3 backup bucket, EC2 key pair, cross-account IAM role, and the trust policy that allows Instaclustr’s InstaclustrProvisioning role to assume it — scoped by your Instaclustr account ID as the ExternalId.
The CAPABILITY_NAMED_IAM capability is required because the stack creates a named IAM role.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
resource "aws_cloudformation_stack" "instaclustr_byoc_stack" { name = var.cloudformation_stack_name template_body = local.processed_template capabilities = ["CAPABILITY_NAMED_IAM"] parameters = { CreateKeyPair = var.create_key_pair ? "true" : "false" } } output "cloudformation_outputs" { value = aws_cloudformation_stack.instaclustr_byoc_stack.outputs } |
When CreateKeyPair = "false": The stack skips creating AWS::EC2::KeyPair, but the KeyPairName output still returns your Instaclustr Account ID (the expected key pair name). Instaclustr validation assumes the key pair already exists from a prior BYOC setup in that AWS account/region.
Step 5 – Register and validate the provider account
Create the Instaclustr provider account resource. The depends_on ensures the CloudFormation stack is fully deployed before Instaclustr attempts validation.
Unlike the API flow, there is no separate “validate” step here — validation is triggered automatically when this resource is created. Instaclustr assumes the cross-account role, verifies the S3 bucket, EC2 key pair, and IAM role permissions, and transitions the account to RUNNING.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
resource "instaclustr_byoc_aws_provider_account_setup_v1" "byoc_setup" { depends_on = [aws_cloudformation_stack.instaclustr_byoc_stack] provider_account_name = var.provider_account_name cloud_provider_account_id = var.instaclustr_aws_account_id data_centre_backup_buckets = [{ data_centre = <span class="" data-testid="renderer-code-block-line-9" data-ds--code--row="">var.instaclustr_data_centre </span> backup_bucket_name = var.s3_backup_bucket_name}] iam_role_name = var.iam_role_name } output "provider_account_id" { value = instaclustr_byoc_aws_provider_account_setup_v1.byoc_setup.provider_account_id } |
Step 6 — Apply
|
1 2 3 |
terraform init terraform plan terraform apply |
On a successful apply, the provider account reaches RUNNING status and is ready to use. A default organisation is created for your account during validation if one does not already exist. You can confirm the result in the Console under Account Settings → BYOC Provider Accounts, where the status displays as Validated.
If apply fails:
The most common causes are: a bucket name or IAM role name mismatch between the template substitution (Step 3) and the provider account resource (Step 5), or create_key_pair = true on a second setup in the same AWS account/region. Review the Terraform error output and check the CloudFormation stack events in the AWS Console for details.