Skip to content

Commit

Permalink
Merge pull request #61 from mlinfra-io/add-targets-to-apply
Browse files Browse the repository at this point in the history
Add targets to apply
  • Loading branch information
aliabbasjaffri authored Feb 9, 2024
2 parents 14b6e4c + 2795e60 commit b2787d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def process_stack_modules(self):
def process_stack_inputs(self):
pass

# TODO: Outputs are not being populated completely
def process_stack_outputs(self):
self.output["output"].append({"state_storage": {"value": self.state_file_name}})
self.output["output"].append(
Expand Down
13 changes: 1 addition & 12 deletions src/mlinfra/terraform/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,4 @@ def plan(self):
self.check_region_has_three_azs(aws_region=aws_region)
self.check_terraform_state_storage(state_name=state_name, aws_region=aws_region)
modules_list = self.generate_modules_list()
return modules_list

def apply(self) -> str:
"""
This function is responsible for running terraform apply command
"""
modules_list = self.plan()
target_string = ""
for item in modules_list:
target_string += f" -target={item}"

return target_string
return "".join(f" -target={item}" for item in modules_list)
30 changes: 15 additions & 15 deletions src/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,33 @@ def terraform(
"""
Run terraform for the config file with the given action and args.
"""
Terraform(stack_config_path=stack_config_path).apply()
# targets_list = Terraform(stack_config_path=stack_config_path).apply()
# print(targets_list)
targets_list = Terraform(stack_config_path=stack_config_path).plan()
targets_list = ""

ctx.run(f"terraform -chdir={TF_PATH} init")

if action == "apply":
action += " -auto-approve"
if action == "plan":
args += f"{targets_list} -lock=false -input=false -compact-warnings"
amplitude_client.send_event(
amplitude_client.PLAN_EVENT,
event_properties={},
)
ctx.run(f"terraform -chdir={TF_PATH} plan {args} -out tfplan.binary")
elif action == "apply":
args += f"{targets_list} -lock=false -input=false -compact-warnings"
amplitude_client.send_event(
amplitude_client.APPLY_EVENT,
event_properties={},
)
ctx.run(f"terraform -chdir={TF_PATH} plan {args} -out tfplan.binary")
ctx.run(f"terraform -chdir={TF_PATH} apply -auto-approve tfplan.binary")
elif action == "destroy":
action += " -auto-approve"
args = "-auto-approve"
amplitude_client.send_event(
amplitude_client.DESTROY_EVENT,
event_properties={},
)
ctx.run(f"terraform -chdir={TF_PATH} destroy {args}")
# elif action == "force-unlock":
# file_processor.force_unlock()
# action = f"plan {args} -lock=false"
elif action == "plan":
action += " -lock=false -input=false -compact-warnings"
amplitude_client.send_event(
amplitude_client.PLAN_EVENT,
event_properties={},
)

# print(f"terraform -chdir={TF_PATH} {action} {args}")
ctx.run(f"terraform -chdir={TF_PATH} {action} {args}")

0 comments on commit b2787d6

Please sign in to comment.