Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

refactor terraform scripts and apply/destroy cli commands #126

Merged
merged 1 commit into from
Apr 22, 2022

Conversation

yubozhao
Copy link
Contributor

Description

Motivation and Context

How Has This Been Tested?

Checklist:

  • My code follows the bentoctl code style, both make format and
    make lint script have passed
  • My change reduces project test coverage and requires unit tests to be added
  • I have added unit tests covering my code change
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

@yubozhao yubozhao merged commit f34ed66 into main Apr 22, 2022
@yubozhao yubozhao deleted the refactor-terraform branch April 22, 2022 01:37
Comment on lines +13 to +21
if not return_output:
subprocess.run(["terraform", *cmd], check=False)
proc = subprocess.Popen(
["terraform", *cmd],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = proc.communicate()
return proc.returncode, stdout.decode("utf-8"), stderr.decode("utf-8")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we pipe out the outputs and stderr from terraform? we want the users to know exactly what terraform is doing write?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't user already see the changes in their console with subprocess?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh the issue was there were two subprocess calls happening if return_output if false.

Comment on lines +36 to +37
terraform_run(["apply", "-destroy", "-var-file", TERRAFORM_VALUES_FILE, '-auto-approve'])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having -auto-approve here would not give the users a change to see exactly what changes are being made to the infra right? They should probably have a plan phase before destroy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It won't let user to see what changed. I am not sure user can interact with subprocess. Also I think auto approve could be an Orion in our cli.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we don't pipe the stdin the user can interact with it as if we called it from the terminal, so it will be a low friction way to perform all the terraform commands and yeah, we should have the auto-approve command or a more general command like '--yes' or something.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants