diff --git a/runway/_cli/commands/_deploy.py b/runway/_cli/commands/_deploy.py index 397e6a99b..d3cc2188b 100644 --- a/runway/_cli/commands/_deploy.py +++ b/runway/_cli/commands/_deploy.py @@ -26,6 +26,8 @@ def deploy(ctx: click.Context, debug: bool, tags: Tuple[str, ...], **_: Any) -> """Deploy infrastructure as code. \b + Process + ------- 1. Determines the deploy environment. - "-e, --deploy-environment" option - "DEPLOY_ENVIRONMENT" environment variable diff --git a/runway/_cli/commands/_destroy.py b/runway/_cli/commands/_destroy.py index e2ddb23c7..7ba600e02 100644 --- a/runway/_cli/commands/_destroy.py +++ b/runway/_cli/commands/_destroy.py @@ -26,6 +26,8 @@ def destroy(ctx: click.Context, debug: bool, tags: Tuple[str, ...], **_: Any) -> """Destroy infrastructure as code. \b + Process + ------- 1. Determines the deploy environment. - "-e, --deploy-environment" option - "DEPLOY_ENVIRONMENT" environment variable diff --git a/runway/_cli/commands/_init.py b/runway/_cli/commands/_init.py index b77163e9d..fce4d95e0 100644 --- a/runway/_cli/commands/_init.py +++ b/runway/_cli/commands/_init.py @@ -26,6 +26,8 @@ def init(ctx: click.Context, debug: bool, tags: Tuple[str, ...], **_: Any) -> No """Run initialization/bootstrap steps. \b + Process + ------- 1. Determines the deploy environment. - "-e, --deploy-environment" option - "DEPLOY_ENVIRONMENT" environment variable @@ -40,6 +42,15 @@ def init(ctx: click.Context, debug: bool, tags: Tuple[str, ...], **_: Any) -> No 3. Initializes/bootstraps selected deployments/modules in the order defined. (e.g. "cdk bootstrap", "terraform init") + \b + Steps By Module Type + -------------------- + - AWS CDK: Runs "cdk bootstrap". + - CFNgin: Creates the "cfngin_bucket" if needed. + - Terraform: Runs "terraform init", changes the workspace if needed, runs + "terraform init" again if the workspace was changed, and finally + downloads/updates Terraform modules. + """ # noqa: D301 try: Runway(ctx.obj.runway_config, ctx.obj.get_runway_context()).init( diff --git a/runway/_cli/commands/_plan.py b/runway/_cli/commands/_plan.py index fbc48377e..cd92e23cd 100644 --- a/runway/_cli/commands/_plan.py +++ b/runway/_cli/commands/_plan.py @@ -26,6 +26,8 @@ def plan(ctx: click.Context, debug: bool, tags: Tuple[str, ...], **_: Any) -> No """Determine what infrastructure changes will occur during the next deploy. \b + Process + ------- 1. Determines the deploy environment. - "-e, --deploy-environment" option - "DEPLOY_ENVIRONMENT" environment variable diff --git a/runway/module/terraform.py b/runway/module/terraform.py index 5108f36a3..59ecad65d 100644 --- a/runway/module/terraform.py +++ b/runway/module/terraform.py @@ -239,6 +239,14 @@ def cleanup_dot_terraform(self) -> None: self.logger.debug("removing: %s", child) send2trash(str(child)) # does not support Path objects + def deploy(self) -> None: + """Run Terraform apply.""" + self.run("apply") + + def destroy(self) -> None: + """Run Terraform destroy.""" + self.run("destroy") + def gen_command( self, command: Union[List[str], str, Tuple[str, ...]], @@ -337,6 +345,14 @@ def handle_parameters(self) -> None: self.ctx.env.vars, self.parameters ) + def init(self) -> None: + """Run init.""" + self.run("init") + + def plan(self) -> None: + """Run Terraform plan.""" + self.run("plan") + def terraform_apply(self) -> None: """Execute ``terraform apply`` command. @@ -543,31 +559,16 @@ def run(self, action: TerraformActionTypeDef) -> None: self.terraform_workspace_new(self.required_workspace) self.logger.verbose("re-running init after workspace change...") self.terraform_init() - self.logger.info("init (complete)") self.terraform_get() - self.logger.info("%s (in progress)", action) - self["terraform_" + action]() - self.logger.info("%s (complete)", action) + self.logger.info("init (complete)") + if action != "init": + self.logger.info("%s (in progress)", action) + self["terraform_" + action]() + self.logger.info("%s (complete)", action) finally: if self.auto_tfvars.exists(): self.auto_tfvars.unlink() - def deploy(self) -> None: - """Run Terraform apply.""" - self.run("apply") - - def destroy(self) -> None: - """Run Terraform destroy.""" - self.run("destroy") - - def init(self) -> None: - """Run init.""" - LOGGER.warning("init not currently supported for %s", self.__class__.__name__) - - def plan(self) -> None: - """Run Terraform plan.""" - self.run("plan") - class TerraformOptions(ModuleOptions): """Module options for Terraform. diff --git a/tests/unit/module/test_terraform.py b/tests/unit/module/test_terraform.py index 8fd18e43a..e828193cc 100644 --- a/tests/unit/module/test_terraform.py +++ b/tests/unit/module/test_terraform.py @@ -214,7 +214,7 @@ def test_env_file( else: assert not obj.env_file - @pytest.mark.parametrize("action", ["deploy", "destroy", "plan"]) + @pytest.mark.parametrize("action", ["deploy", "destroy", "init", "plan"]) def test_execute( self, action: str, @@ -476,20 +476,6 @@ def test_handle_parameters( mock_update_envvars.assert_called_once_with(runway_context.env.vars, {}) assert obj.ctx.env.vars == {"result": "success"} - def test_init( - self, - caplog: LogCaptureFixture, - runway_context: MockRunwayContext, - tmp_path: Path, - ) -> None: - """Test init.""" - caplog.set_level(logging.WARNING, logger=MODULE) - obj = Terraform(runway_context, module_root=tmp_path) - assert not obj.init() - assert ( - f"init not currently supported for {Terraform.__name__}" in caplog.messages - ) - @pytest.mark.parametrize( "env, param, expected", [