Skip to content

Commit

Permalink
Provisioner args
Browse files Browse the repository at this point in the history
  • Loading branch information
Chang Zhe Jiet authored and Chang Zhe Jiet committed Jan 15, 2024
1 parent 3223b91 commit 07055f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
39 changes: 31 additions & 8 deletions src/blocks/Provisioner.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
import { Argument, Attribute } from '../arguments';
import { Argument, Attribute, Map } from '../arguments';
import { Util } from '../utils';
import { Block } from '.';

interface ProvisionerArgs {
when?: Argument<'create' | 'destroy'>;
on_failure?: Argument<'continue' | 'fail'>;
}

/**
* @category Block
*/
export type ProvisionerType = 'local-exec' | 'remote-exec';
export interface FileProvisionerArgs extends ProvisionerArgs {
source?: string;
content?: string;
destination?: string;
}

/**
* @category Block
*/
export interface ProvisionerArgs {
export interface LocalExecProvisionerArgs extends ProvisionerArgs {
command: string;
when?: Argument<'destroy'>;
on_failure?: Argument<'continue' | 'fail'>;
working_dir?: string;
interpreter?: string[];
environment?: Map;
quiet?: boolean;
}

/**
* @category Block
*/
export interface RemoteExecProvisionerArgs extends ProvisionerArgs {
inline?: string[];
script?: string;
scripts?: string[];
}

/**
* @category Block
*/
export class Provisioner extends Block<ProvisionerArgs> {
export class Provisioner extends Block<FileProvisionerArgs | LocalExecProvisionerArgs | RemoteExecProvisionerArgs> {

readonly type: ProvisionerType;
readonly type: 'file' | 'local-exec' | 'remote-exec';

/**
* Construct provisioner.
Expand All @@ -31,7 +51,10 @@ export class Provisioner extends Block<ProvisionerArgs> {
* @param type type
* @param args arguments
*/
constructor(type: ProvisionerType, args: ProvisionerArgs) {
constructor(type: 'file', args: FileProvisionerArgs);
constructor(type: 'local-exec', args: LocalExecProvisionerArgs);
constructor(type: 'remote-exec', args: RemoteExecProvisionerArgs);
constructor(type: 'file' | 'local-exec' | 'remote-exec', args: FileProvisionerArgs | LocalExecProvisionerArgs | RemoteExecProvisionerArgs) {
super('provisioner', [type], args);

this.type = type;
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export {
Module, ModuleArgs,
Output, OutputArgs,
Provider,
Provisioner, ProvisionerArgs, ProvisionerType,
Provisioner, FileProvisionerArgs, LocalExecProvisionerArgs, RemoteExecProvisionerArgs,
Resource, ResourceToDataOptions,
Variable, VariableArgs
} from './blocks';
Expand Down
2 changes: 1 addition & 1 deletion test/blocks/Block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('Block arguments', () => {
command: 'cmd1'
}),
new Provisioner('remote-exec', {
command: 'cmd2',
script: 'cmd2',
when: new Argument('destroy'),
on_failure: new Argument('fail')
})
Expand Down

0 comments on commit 07055f9

Please sign in to comment.