infrapuzzle/terraform/misc/get_domain.py

46 lines
2.1 KiB
Python

# -*- encoding: utf-8 -*-
'''
List all domain relevant information to add them to Terraform
'''
import json
import ovh
import sys
# Instanciate an OVH Client.
# You can generate new credentials with full access to your account on
# the token creation page
client = ovh.Client(
endpoint='ovh-eu', # Endpoint of API OVH Europe (List of available endpoints)
application_key='pSnvZrS8R4LPCLEh', # Application Key
application_secret='CKUHMo5ZXDm8JLA6ZWWUzAolglQmvylv', # Application Secret
consumer_key='EVBu0meA2OYvEvVWUbR0qwU2lD7uXKiM', # Consumer Key
)
all_domains = client.get('/domain')
# Pretty print
print("All domains: "+json.dumps(all_domains, indent=4))
for domain in all_domains :
print("Looking at domain: " +domain)
try:
if(domain in ["moritzgraf.de"]):
all_resources = client.get('/domain/zone/'+str(domain)+"/record")
print("All resources:"+json.dumps(all_resources,indent=4))
for resource in all_resources:
try:
record_details = client.get('/domain/zone/'+str(domain)+"/record/"+str(resource))
if(record_details["subDomain"] and record_details["subDomain"] in ["git","auth","prometheus","alertmanager",
"chat","mqtt", "cloud","monitoring","smtp","pop3","imap","jaeger","ldap","code","hub","grafana",
"tt-rss","phpmyadmin","phppgadmin","www","terraformtest","rstudio","code" ]):
#print("Domain"+str(record_details["zone"])+"Subdomain:"+str(record_details["subDomain"]))
print("terraform import 'ovh_domain_zone_record.moritzgraf_subdomains[\""+record_details["subDomain"]+"\"]' "+ str(record_details["id"])+"."+str(record_details["zone"]))
except Exception as e:
print("Somthing did not work for domain:"+str(record_details))
print(e)
# print("###details###"+str(record_details))
else:
print("Domain "+str(domain)+" not on whitelist, ignoring")
except Exception as e:
print("Somthing did not work for domain:"+domain)
print(e)