Skip to content

Commit

Permalink
Updated terraform discovery code for pingdom (#9)
Browse files Browse the repository at this point in the history
* Updated terraform discovery code for pingdom

* Updated for pingdom

* Working version with no pingdom.tf check

* Added check to verify pingdom resource exists in namespace or not

* Updated to comment json import and print statements

* Update terraform_discovery.py

Addressed  Matt's comment

* Update terraform_discovery.py

Corrected SC ID variable for elasticache and pingdom

* Updated lambda variables for elasticache and pingdom

* Update terraform_discovery.py

Corrected variable name for elasticache
  • Loading branch information
Sandhya1874 authored Aug 22, 2024
1 parent e21d16d commit 55f6b89
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions terraform_discovery.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,43 @@ def process_repo(**component):
# If there are any rds instances in the existing SC data
if sc_data[0]["attributes"]["elasticache_cluster"]:
# Find the elasticache cluster SC ID that matches
rds_id = list(filter(lambda rds: rds['tf_path'] == elasticache_cluster['__tfmeta']['path'], sc_data[0]["attributes"]["elasticache_cluster"]))[0]['id']
elasticache_cluster.update({'id': rds_id})
elasticache_id = list(filter(lambda elasticache: elasticache['tf_path'] == elasticache_cluster['__tfmeta']['path'], sc_data[0]["attributes"]["elasticache_cluster"]))[0]['id']
elasticache_cluster.update({'id': elasticache_id})
except (IndexError,KeyError):
pass

# Clean up field not used in post to SC
del elasticache_cluster['__tfmeta']
data.update({"elasticache_cluster": [elasticache_cluster]})

if 'pingdom_check' in parsed.keys() :
for r in parsed['pingdom_check']:
# Look for RDS instances.
if "http" in r['type']:
pingdom_check = r
# Delete ID that is generated by tfparse
del pingdom_check['id']
# Process fields
pingdom_check.update({'tf_label': pingdom_check['__tfmeta']['label']})
pingdom_check.update({'tf_filename': pingdom_check['__tfmeta']['filename']})
pingdom_check.update({'tf_path': pingdom_check['__tfmeta']['path']})
pingdom_check.update({'tf_line_end': pingdom_check['__tfmeta']['line_end']})
pingdom_check.update({'tf_line_start': pingdom_check['__tfmeta']['line_start']})
# pingdom_check.update({'tf_mod_version': tf_mod_version})
# Check for existing instance in SC and update same ID if so.
try:
# If there are any rds instances in the existing SC data
if sc_data[0]["attributes"]["pingdom_check"]:
# Find the Pingdom check SC ID that matches
pingdom_id = list(filter(lambda pingdom: pingdom['tf_path'] == pingdom_check['__tfmeta']['path'], sc_data[0]["attributes"]["pingdom_check"]))[0]['id']
pingdom_check.update({'id': pingdom_id})
except IndexError:
pass

# Clean up field not used in post to SC
del pingdom_check['__tfmeta']
data.update({"pingdom_check": [pingdom_check]})

print(data)
update_sc_namespace(namespace_id, data)

Expand Down

0 comments on commit 55f6b89

Please sign in to comment.