../_images/login_button.png ../_images/signup_button.png



How do I call a private module in Scalr IaCP?

If a Terraform configuraion 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).

../_images/how_to_mod_1.png

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

    ../_images/how_to_mod_2.png
  • Register the module

    ../_images/how_to_mod_3.png
  • Scalr generates an internal source reference for the module and provides the boiler plate code, including input variables so this can add the call to the Terraform configuration.

    ../_images/how_to_mod_4.png
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 it’s 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 : Modules in Scalr