Skip to main content

abstractATerraformResource <S, T>

Base class for resources whose lifecycle is managed by Terraform.

Subclasses implement toHCL() to contribute terraform resource blocks and outputs. Octo invokes toHCL() automatically while generating terraform files. The received scope is bound to the module folder this resource belongs to.

Terraform resources cannot have resource actions; registering one throws.

@example
override async toHCL(terraform: TerraformModuleScope): Promise<void> {
const scope = terraform.addOctoTerraformResource(this, {
provider: { accountId: this.properties.awsAccountId, regionId: this.properties.awsRegionId },
});
const bucket = scope.addTerraformResource('aws_s3_bucket', this.resourceId, {
bucket: this.properties.bucketName,
});
scope.output({ arn: terraform.raw(`${bucket.address}.arn`) });
}
@group

Resources

@see

Hierarchy

Index

Properties

readonlyinheritedlocalResourceId

localResourceId: S[localResourceId]

The ID of the resource, unique within its scope.

readonlyinheritedparents

parents: (UnknownResource | MatchingResource<BaseResourceSchema>)[] = []

The resources this one is built on top of. A parent is always created before its children, and destroyed after them.

readonlyinheritedproperties

properties: S[properties]

The desired configuration of the resource.

readonlyinheritedresponse

response: S[response] = {}

What the cloud provider reported back about this resource, e.g. an ARN or a generated ID. It is empty until the resource has actually been created, and is what other resources read when they need to reference this one.

readonlyinheritedscope

scope: string[] = ...

The contexts of the models this resource is placed under, sorted. Octo derives it from the node whose action created the resource; a resource created outside a model action has an empty scope.

readonlyinheritedtags

tags: S[tags] = {}

The tags applied to this resource. See Octo.registerTags to set them in bulk.

staticreadonlyinheritedNODE_NAME

NODE_NAME: string

The name of the node. All nodes with same name are of the same category.

staticreadonlyinheritedNODE_PACKAGE

NODE_PACKAGE: string

The package of the node.

staticreadonlyinheritedNODE_SCHEMA

NODE_SCHEMA: unknown

The schema of the node.

staticreadonlyinheritedNODE_TYPE

NODE_TYPE: NodeType

The type of the node.

Accessors

inheritedresourceId

  • get resourceId(): S[resourceId]
  • The ID of the resource, unique across the infrastructure: its localResourceId, followed by a hash of its scope when it has one.


    Returns S[resourceId]

Methods

inheritedaddFieldDependency

  • addFieldDependency(): void
  • @deprecated

    Field dependencies are not supported in resources!


    Returns void

inheritedaddRelationship

  • @deprecated

    Relationships are not supported in resources!


    Returns { thatToThisDependency: Dependency; thisToThatDependency: Dependency }

inheriteddiffUnpack

  • diffUnpack(diff: Diff): Diff<UnknownNode, unknown>[]
  • Splits one diff into the diffs a resource action will actually receive.

    Override it when a single change on this resource has to be applied as several ordered steps. The default returns the diff unchanged.


    Parameters

    Returns Diff<UnknownNode, unknown>[]

inheritedfindParentsByProperty

  • findParentsByProperty(filters: { key: string; value: unknown }[]): UnknownResource[]
  • To find this resource's parents whose properties match every given filter.


    Parameters

    • filters: { key: string; value: unknown }[]

      Each filter is a property key the parent must carry with the given value.

    Returns UnknownResource[]

inheritedfindParentsByTag

  • findParentsByTag(filters: { key: string; value: string }[]): UnknownResource[]
  • To find this resource's parents whose tags match every given filter.


    Parameters

    • filters: { key: string; value: string }[]

      Each filter is a tag key the parent must carry with the given value.

    Returns UnknownResource[]

inheritedgetBoundaryMembers

  • getBoundaryMembers(): UnknownResource[]
  • @deprecated

    Boundary is not supported in resources!


    Returns UnknownResource[]

inheritedgetExternalTriggerProperties

  • getExternalTriggerProperties(): Partial<S[properties]>
  • The properties whose change means an external resource has to be run again. Terraform hashes them into the trigger of the null_resource that stands in for the resource, which is how it decides to call back.

    A resource that overrides diffProperties to ignore a property must exclude that property here too. The two answer the same question, and terraform plans a replacement for any property only this one covers, which octo then reports no change for.


    Returns Partial<S[properties]>

inheritedgetSiblings

  • getSiblings(): {}
  • @deprecated

    Siblings are not supported in resources!


    Returns {}

inheritedisMarkedDeleted

  • isMarkedDeleted(): boolean
  • Whether this resource is marked for deletion, and will leave the graph at the end of the transaction.


    Returns boolean

inheritedremove

  • remove(force?: boolean): void
  • To mark this resource for deletion. It leaves the graph at the end of the transaction.

    @throws

    RemoveResourceError If the resource still has children, and force is not set.


    Parameters

    • force: boolean = false

      Removes the resource even if other resources still depend on it.

    Returns void

inheritedsetResponse

  • setResponse(response: S[response]): void
  • To record what the cloud provider reported back about this resource. Keys absent from response are left as they were.


    Parameters

    • response: S[response]

    Returns void

abstracttoHCL

  • Emits this resource as terraform.


    Parameters

    • terraform: TerraformModuleScope

      The module folder to write into, already scoped to this resource's module.

    Returns void | Promise<void>