Skip to content

Instantly share code, notes, and snippets.

@alces
Created November 24, 2017 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alces/e5510eb96855617a631f2d0dae57b883 to your computer and use it in GitHub Desktop.
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
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