Skip to content

Commit

Permalink
Merge pull request #175 from amplify-education/fix_add_support_for_re…
Browse files Browse the repository at this point in the history
…pushing_error_tfstate

Fix: Add Support For Pushing State if Error While Pushing State
  • Loading branch information
jconstance-amplify committed Jan 14, 2024
2 parents 58da07a + 33e3183 commit 4f9fc0a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions bin/tf
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def exec_tf_command(
elif "state data in S3 does not have the expected content" in error:
if update_digest(error, path, variables):
continue
elif "Error: Failed to persist state to backend" in error:
if repush_state(path):
continue

sys.exit(exit_code)

Expand Down Expand Up @@ -218,6 +221,24 @@ def update_digest(error: str, path: str, variables: Dict[str, str]) -> bool:
return False


def repush_state(path: str) -> bool:
"""
Repush terraform state if there was an error pushing it originally
:param path: Terraform path with errored state
:return: True if state is pushed successfully, false otherwise
"""
exit_code, output = execute_command(
["terraform", "state", "push", "errored.tfstate"],
print_command=True,
cwd=path,
retry=True,
)
if exit_code == 0:
return True

return False


def process_arguments(args: List[str]) -> Tuple[str, str, List[str], bool]:
try:
resolve_envvars = True
Expand Down
2 changes: 1 addition & 1 deletion terrawrap/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Place of record for the package version"""

__version__ = "0.9.31"
__version__ = "0.9.32"
__git_hash__ = "GIT_HASH"

0 comments on commit 4f9fc0a

Please sign in to comment.