How do I call a private module in Scalr?

If a Terraform configuration calls modules then the module source has to be accessible from Scalr so it can be pulled into the workspace at run time.

Example:

module "scalr_dynamic_vpc_dns" {
  source  = "github/scalr-eap/scalr_dynamic_vpc_dns"
...

There are 3 ways to make this work in Scalr.

Option 1: Modules and Terraform configuration in the same VCS system

In Scalr, VCS provider credentials can be set up to enable Scalr to pull Terraform configurations (VCS integrated workspaces, template registry).

633

If the module calls in the Terraform configuration are from the same VCS provider then Scalr will automatically pull the module using the same access token. No changes need to be made to the Terraform configuration.

Option 2 : Modules from other repositories

If the module source is not in the same VCS provider as the Terraform configuration then the Scalr Module Registry can be used to pull the module. This works for VCS and CLI.

📘

Note

The module registry and VCS providers can be configured in the account and the environments.

  • Create a VCS Provider for the module repo
631
  • Register the module
556
  • Scalr generates an internal source reference for the module and provides the boilerplate code, including input variables so this can add the call to the Terraform configuration.
512
module "scalr_dynamic_vpc_dns" {
  source  = "my-account.scalr.io/org-sgncvo4mr5l4na0/scalr_dynamic_vpc_dns/aws"
  version = "1.0.0"

  cidr              = var.cidr
  prefix            = var.prefix
  public            = var.public
  max_subnets       = var.max_subnets
}

Option 3 : Relative Paths

If a module exists as a sub-directory in the Terraform configuration directory it can be sourced using a relative path. This works for VCS integration and the CLI as the directory and all its sub-directories are always loaded into the Scalr workspace.

module "scalr_dynamic_vpc_dns" {
  source  = "./scalr_dynamic_vpc_dns"

  cidr              = var.cidr
  prefix            = var.prefix
  public            = var.public
  max_subnets       = var.max_subnets
}

Related documentation : Private Module Registry