Created
November 24, 2017 11:55
-
-
Save alces/e5510eb96855617a631f2d0dae57b883 to your computer and use it in GitHub Desktop.
return a list of google compute instances existing before a current run of terraform
This file contains hidden or 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 json | |
data = json.load(open('terraform.tfstate')) | |
all_res = [mod['resources'].values() for mod in data['modules']] | |
res_list = reduce(lambda x, y: x + y, all_res) | |
disk_attrs = [r['primary']['attributes'] for r in res_list if r['type'] == 'google_compute_disk'] | |
print [a['users.0'].split('/')[-1] for a in disk_attrs if 'users.0' in a] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment