import { Util } from '../Util' ; category export class Argument { readonly argument : string | Argument ; param arg constructor ( arg ) { if ( ! arg || ( typeof arg === 'string' && ! arg . trim ( ) ) ) { throw new Error ( 'Argument cannot be empty.' ) ; } this . argument = arg ; } param name attr ( name ) { name = name . trim ( ) ; if ( this . argument instanceof Argument ) { return this . argument . attr ( name ) ; } return new Argument ( `${ this . argument }.${ name }` ) ; } param idx element ( idx ) { if ( this . argument instanceof Argument ) { return this . argument . element ( idx ) ; } return new Argument ( `${ this . argument }[${ idx }]` ) ; } /**
     * To Terraform representation.
     *
     * Use this method when argument is used as an interpolation in another Terraform argument or code.
     */ toTerraform ( ) { let str = '' ; if ( this . argument instanceof Argument ) { str += this . argument . toTerraform ( ) ; } else { str += this . argument ; } return Util . escape ( str ) ; } /**
     * To string.
     *
     * Use this method when argument is used as an interpolation in a Terraform string or heredoc.
     *
     * It is automatically called when argument is used in template literal.
     */ toString ( ) { return `\${${ this . toTerraform ( ) }}` ; } } param arg category export const arg = ( arg ) : Argument => new Argument ( arg ) ;