Created
July 25, 2023 13:05
-
-
Save beranm14/6c79731a3f020b3bcde07e8ee59f61ea to your computer and use it in GitHub Desktop.
Get terraform resource based on its address
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
import sys | |
import json | |
state = json.loads(sys.stdin.read()) | |
address = sys.argv[1] | |
def get_by_address(state, address): | |
if type(state) is list: | |
for i in state: | |
found = get_by_address(i, address) | |
if found: | |
return found | |
elif type(state) is dict: | |
if state.get('address', '') == address: | |
return state | |
else: | |
for i in state: | |
found = get_by_address(state[i], address) | |
if found: | |
return found | |
print(json.dumps(get_by_address(state, address))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment