builder#

AMI Builder automation.

packer_ami_workflow.builder.filter_packer_files(path: Path) bool[source]#

Identify whether it is a .pkr.hcl or .pkrvars.hcl file.

class packer_ami_workflow.builder.AmiBuilder(workflow_param: WorkflowParam, step_param: StepParam, workspace: Workspace, table_class: Type[T_AMI_DATA])[source]#

This class provide automation for building an AMI for a single step.

Parameters:
  • workflow_param – The WorkflowParam object.

  • step_param – The StepParam object.

property source_ami_id: str#

Get the source AMI id. If the step doesn’t have previous step id, then this is the first step. So that the source AMI is the root base AMI. Otherwise, use DynamoDB to pull previous step AMI information.

Returns:

the source ami id for this step.

property source_ami_name: str#

Get the source AMI name. If the step doesn’t have previous step id, then this is the first step. So that the source AMI is the root base AMI. Otherwise, use DynamoDB to pull previous step AMI information.

Returns:

the source ami name for this step.

property output_ami_name: str#

The output AMI name follows this naming convention {root_ami_name}/{workflow_id}/{step_id}

Returns:

the output ami name.

classmethod make(dir_step: ~pathlib_mate.pathlib2.Path, table_class: ~typing.Type[~packer_ami_workflow.dynamodb.T_AMI_DATA], workflow_param_class: ~typing.Type[~packer_ami_workflow.param.WorkflowParam] = <class 'packer_ami_workflow.param.WorkflowParam'>, step_param_class: ~typing.Type[~packer_ami_workflow.param.StepParam] = <class 'packer_ami_workflow.param.StepParam'>)[source]#

Factory method.

Parameters:

table_classAmiData or user defined subclass.

clean_up()[source]#

Delete existing .pkc.hcl and .pkrvars.hcl files in the workspace directory.

render(clean_up: bool = True)[source]#

Generate all the packer template files in the workspace directory, by rendering the jinja2 template with the parameter object.

Parameters:

clean_up – Whether to clean up the existing .pkr.hcl and .pkrvars.hcl files.

packer_validate(render: bool = True, clean_up: bool = True)[source]#

Run packer validate.

Parameters:
  • render – Whether to render the jinja2 template before running the command.

  • clean_up – Whether to clean up the existing .pkr.hcl and .pkrvars.hcl files.

Reference:

packer_build(render: bool = True, clean_up: bool = True, dry_run: bool = True)[source]#

Run packer build.

Parameters:
  • render – Whether to render the jinja2 template before running the command.

  • clean_up – Whether to clean up the existing .pkr.hcl and .pkrvars.hcl files.

run_packer_build_workflow(render: bool = True, clean_up: bool = True, validate: bool = True, dry_run: bool = True)[source]#

Run packer validate. :param render: Whether to render the jinja2 template before running the command. :param clean_up: Whether to clean up the existing .pkr.hcl and .pkrvars.hcl files. :param validate: Whether to run the packer validate command before running the packer build command. :param dry_run: Whether to run the command in dry-run mode.