This repository has been archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from arkahna/features/addRetryWhenGettingResou…
…rceNamesFromState Add retry when getting resource names from terraform
- Loading branch information
Showing
14 changed files
with
112 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@arkahna/nx-terraform': minor | ||
--- | ||
|
||
Add retry when getting resource names from terraform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
libs/nx-terraform/src/common/getTfResourceNameWithRetry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import execa from 'execa' | ||
import { retryOnFirewallError } from './retryOnFirewallError' | ||
|
||
export async function getTfResourceNameWithRetry( | ||
terragruntConfigFile: string, | ||
resourceAddress: string, | ||
projectRoot: string, | ||
retryAttempts: number, | ||
/** Retry delay, in seconds */ | ||
retryDelay: number, | ||
) { | ||
try { | ||
const outputHcl = await retryOnFirewallError( | ||
async () => | ||
await execa( | ||
'terragrunt', | ||
[ | ||
'state', | ||
'show', | ||
'--terragrunt-config', | ||
terragruntConfigFile, | ||
resourceAddress, | ||
'-no-color', | ||
], | ||
{ | ||
stdio: [process.stdin, 'pipe', 'pipe'], | ||
cwd: projectRoot, | ||
}, | ||
), | ||
{ | ||
retryAttempts, | ||
retryDelay, | ||
}, | ||
) | ||
|
||
const match = outputHcl.stdout.match(/.{4}name\s+=\s"([a-z]+)"/) | ||
if (!match || !match[1]) { | ||
throw 'could not find match in returned hcl' | ||
} | ||
|
||
resourceAddress = match[1] | ||
return resourceAddress | ||
} catch (err) { | ||
console.log('Failed to look up resource name', err) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters