Skip to main content

TerraformModuleScope

The terraform module folder a resource writes itself into.

Octo hands one to ATerraformResource.toHCL, scoped to the folder that resource belongs to. It is a small HCL builder: register the octo resource, emit blocks on the scope it returns, and reference other resources through TerraformModuleScope.getRef rather than by writing addresses by hand - only getRef knows whether the producer lands in this folder or another one.

@group

Resources

@see

ATerraformResource for where this is used.

Index

Properties

readonlymoduleId

moduleId: string

The ID of the octo module this folder was generated for.

Methods

addOctoTerraformExternalResource

  • Wraps an octo resource whose lifecycle runs outside Terraform (e.g. a script or SDK call). Generates a null_resource + data "external" pair that calls octo run-action at apply time and exposes the result as outputs.


    Type parameters

    • T: UnknownResource

    Parameters

    • octoResource: T

    Returns OctoTerraformResourceScope<ResourceSchema<T>[response]>

addOctoTerraformResource

  • Registers an octo resource as a native Terraform resource. Returns an OctoTerraformResourceScope on which you call addTerraformResource() to emit HCL blocks and output() to declare what other resources can reference.

    • Pass options.explicitParents for dependencies that aren't captured by attribute references alone.
    • Pass options.provider to pin the resource to a specific account/region provider.

    Type parameters

    • T: UnknownResource

    Parameters

    Returns OctoTerraformResourceScope<ResourceSchema<T>[response]>

addTerraformData

  • addTerraformData(type: string, name: string, spec?: Record<string, unknown>): TerraformData
  • Emits a data "<type>" "<name>" block. Use for read-only data sources that look up existing infrastructure (e.g. aws_ami, aws_caller_identity).


    Parameters

    • type: string
    • name: string
    • optionalspec: Record<string, unknown>

    Returns TerraformData

getProviderAliasRef

  • getProviderAliasRef(accountId: string, regionId?: string): HclExpression
  • Returns the <providerType>.<alias> expression for a registered provider. Pass the result as the provider attribute when a resource must target a specific account/region different from the module's default.


    Parameters

    • accountId: string
    • optionalregionId: string

    Returns HclExpression

getRef

  • getRef<T>(resource: T, key: keyof ResourceSchema<T>[response] & string): HclExpression
  • getRef<S>(resource: MatchingResource<S>, key: keyof S[response] & string): HclExpression
  • Returns a reference to another resource's output that resolves correctly at render time: an inline TF expression when the producer is in the same module, or a var.* wired through terragrunt when it is in a different module.


    Type parameters

    • T: UnknownResource

    Parameters

    Returns HclExpression

interpolate

  • interpolate(...parts: (string | HclExpression)[]): HclExpression
  • Joins text and references into one quoted terraform string, for when a value is another resource's output with text of this resource's own around it. Each reference resolves as TerraformModuleScope.getRef does, so a producer in another folder is still wired in.

    @example
    // "https://${var.distribution_DomainName}/api/orders"
    terraform.interpolate('https://', terraform.getRef(distribution, 'DomainName'), '/api/orders');

    Parameters

    • rest...parts: (string | HclExpression)[]

    Returns HclExpression

jsonencode

  • jsonencode(subject: object | unknown[]): HclExpression
  • Wraps a value in a jsonencode(...) call.


    Parameters

    • subject: object | unknown[]

    Returns HclExpression

localPath

  • localPath(filePath: string): string
  • Returns the HCL for a file on the developer's disk, as a quoted string ready to pass to TerraformModuleScope.raw or to a terraform function such as filemd5.

    The path renders relative to the octo project root and is joined to var.OCTO_PROJECT_ROOT at plan time, so the generated folder holds the same text whichever machine wrote it. Terragrunt runs terraform from a copy of the folder, so a plain relative path would not resolve.


    Parameters

    • filePath: string

    Returns string

mapAttr

  • mapAttr(value: Record<string, unknown>): HclExpression
  • Use mapAttr() when the provider schema defines a map/object attribute (key = { }). Use a plain JS object in the resource spec when the schema expects a block (key { }). The distinction matters: blocks have no =. Check the provider docs for each argument.


    Parameters

    • value: Record<string, unknown>

    Returns HclExpression

raw

  • raw(value: unknown): HclExpression
  • Emits a value verbatim as a terraform expression (no quoting).


    Parameters

    • value: unknown

    Returns HclExpression

type

  • type(schema: unknown): HclExpression
  • Returns a terraform type(...) expression for use in variable declarations.


    Parameters

    • schema: unknown

    Returns HclExpression

variable

  • variable(name: string, typeExpression: unknown, options: { default: TerraformLiteralType; sensitive: boolean }): TerraformVariable
  • Declares a user-supplied input variable for this module. Use when a value must be provided at apply time rather than derived from another resource's output.


    Parameters

    • name: string
    • typeExpression: unknown
    • options: { default: TerraformLiteralType; sensitive: boolean }
      • default: TerraformLiteralType
      • sensitive: boolean

    Returns TerraformVariable