Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 1.44 KB

File metadata and controls

48 lines (37 loc) · 1.44 KB

Terraform Data Sources

Terraform data sources allow data to be fetched to be used in Terraform configuration.

In TypeScript, a Terraform data source can fetches the AWS region can be expressed by DataAwsRegion.

.....
import { DataAwsRegion } from './gen/providers/aws'

export class HelloTerraform extends TerraformStack {
    constructor(scope: Construct, id: string) {
        super(scope, id);

        .....
        const region = new DataAwsRegion(this, 'region')
    }
}

Terraform Remote State

Terraform remote state retrieves state data from a Terraform backend. This allows you to use the root-level outputs of one or more Terraform configurations as input data for another configuration.

Typesciprt example usage:

.....
import { DataTerraformRemoteState } from 'cdktf';

export class HelloTerraform extends TerraformStack {
    constructor(scope: Construct, id: string) {
        super(scope, id);

        .....
        const remoteState = new DataTerraformRemoteState(this, {
            organization: 'hashicorp',
            workspaces: {
                name: 'vpc-prod'
            }
        });

        new AwsInstance(this, 'foo', {
            ....
            subnetId: remoteState.get('subnet_id')
        });
    }
}