import { IReferencableResource } from "./resource-object" ; import { snakeCase } from "./_util" ; /**
 * A Token that represents a CloudFormation reference to another resource
 *
 * If these references are used in a different stack from where they are
 * defined, appropriate CloudFormation `Export`s and `Fn::ImportValue`s will be
 * synthesized automatically instead of the regular CloudFormation references.
 *
 * Additionally, the dependency between the stacks will be recorded, and the toolkit
 * will make sure to deploy producing stack before the consuming stack.
 *
 * This magic happens in the prepare() phase, where consuming stacks will call
 * `consumeFromStack` on these Tokens and if they happen to be exported by a different
 * Stack, we'll register the dependency.
 */ export class TfReference { /**
     * Return the TfReference for the indicated target
     *
     * Will make sure that multiple invocations for the same target and intrinsic
     * return the same TfReference. Because TfReferences accumulate state in
     * the prepare() phase (for the purpose of cross-stack references), it's
     * important that the state isn't lost if it's lazily created, like so:
     *
     *     Lazy.stringValue({ produce: () => new TfReference(...) })
     */ public static for ( target , attribute , value ) { if ( value ) { return value ; } else { return `\$\{${ target . logicalId ( ) }.${ snakeCase ( attribute ) }\}` ; } } }