Module module

The module resource allows a blueprint to reference other files or blueprints. Blueprints can be referenced from the local file system or from GitHub repositories.

All resources contained within a module are scoped to the name of the containing module. For example, if a module mine contains a kubernetes cluster called dev then the FQRN and the name within docker would be:

server.dev.mine.k8s-cluster.local.jmpd.in

Modules can also contain modules, to ensure that resouce references are unique resources always take on the name of their module including any parent modules.

For example, if a module mine contains a kubernetes cluster called dev was contained in module parent. Then the FQRN and the name within docker would be:

server.dev.parent.mine.k8s-cluster.local.jmpd.in

Properties

  • Name
    source
    Type
    (string: "")
    Required
    required
    Readonly
    Description

    The source of the module, can either be a local file or GitHub repositories or remote archive.

  • Name
    variables
    Type
    (map[string]interface: map[]{})
    Required
    Readonly
    Description

    Module can define variables making them dynamic, variables are scoped to each module meaning that any variable that is set globally will not be readable to modules or submodules. To set variables defined inside a module use the varaibles block

      variables = {
        network_id  = resource.network.cloud.meta.id
        consul_port = 18501
      }
    

Meta Properties

In addition to the main properties, all resources have meta properties, such as the id of the resource. To see the list of these properties please see the Meta Properties section in the documentation /docs/resources/meta.

Examples

Module Reuse

The following example shows how a module can be used multiple times.

resource "network" "cloud" {
  subnet = "10.5.0.0/16"
}

module "consul_dc1" {
  source = "./module_k3s"

  variables = {
    network_id  = resource.network.cloud.meta.id
    consul_port = 18500
  }
}

module "consul_dc2" {
  // CI has limited resources, add a manual dependency to ensure that only one module
  // is created at once
  depends_on = ["module.consul_dc1"]

  source = "./module_k3s"

  variables = {
    network_id  = resource.network.cloud.meta.id
    consul_port = 18501
  }
}

output "dc1_addr" {
  value = module.consul_dc1.output.consul_http_addr
}

output "dc2_addr" {
  value = module.consul_dc2.output.consul_http_addr
}