null_data_source

The nullDataSource data source implements the standard data source lifecycle but does not interact with any external APIs.

Historically, the nullDataSource was typically used to construct intermediate values to re-use elsewhere in configuration. The same can now be achieved using locals or the terraform_data resource type in Terraform 1.4 and later.

Example Usage

// DO NOT EDIT. Code generated by 'cdktf convert' - Please report bugs at https://cdk.tf/bug
import { Construct } from "constructs";
import {
  Token,
  TerraformCount,
  Fn,
  TerraformOutput,
  TerraformStack,
} from "cdktf";
/*
 * Provider bindings are generated by running `cdktf get`.
 * See https://cdk.tf/provider-generation for more details.
 */
import { Elb } from "./.gen/providers/aws/elb";
import { Instance } from "./.gen/providers/aws/instance";
import { DataNullDataSource } from "./.gen/providers/null/data-null-data-source";
class MyConvertedCode extends TerraformStack {
  constructor(scope: Construct, name: string) {
    super(scope, name);
    /*In most cases loops should be handled in the programming language context and 
    not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
    you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
    you need to keep this like it is.*/
    const blueCount = TerraformCount.of(Token.asNumber("3"));
    const blue = new Instance(this, "blue", {
      ami: "ami-0dcc1e21636832c5d",
      instanceType: "m5.large",
      count: blueCount,
    });
    /*In most cases loops should be handled in the programming language context and 
    not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
    you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
    you need to keep this like it is.*/
    const greenCount = TerraformCount.of(Token.asNumber("3"));
    const green = new Instance(this, "green", {
      ami: "ami-0dcc1e21636832c5d",
      instanceType: "m5.large",
      count: greenCount,
    });
    const values = new DataNullDataSource(this, "values", {
      inputs: {
        all_server_ids: Token.asString(
          Fn.concat([
            Fn.lookupNested(green, ["*", "id"]),
            Fn.lookupNested(blue, ["*", "id"]),
          ])
        ),
        all_server_ips: Token.asString(
          Fn.concat([
            Fn.lookupNested(green, ["*", "private_ip"]),
            Fn.lookupNested(blue, ["*", "private_ip"]),
          ])
        ),
      },
    });
    new TerraformOutput(this, "all_server_ids", {
      value: Fn.lookupNested(values.outputs, ['"all_server_ids"']),
    });
    new TerraformOutput(this, "all_server_ips", {
      value: Fn.lookupNested(values.outputs, ['"all_server_ips"']),
    });
    new Elb(this, "main", {
      instances: Token.asList(
        Fn.lookupNested(values.outputs, ['"all_server_ids"'])
      ),
      listener: [
        {
          instancePort: 8000,
          instanceProtocol: "http",
          lbPort: 80,
          lbProtocol: "http",
        },
      ],
    });
  }
}

Schema

Optional

Read-Only