I am trying to develop a Python Automation script that adds a DNS record-sets of "A" type into my existing GCP DNS Managed-Zone "my-sites"
import json
from google.oauth2 import service_account
from google.cloud import dns
from google.cloud.exceptions import NotFound
gcp_dns_credentials={
"type": "service_account",
"project_id": "mygcpprojectid-1122",
"private_key_id": "myprivkeyid",
"private_key": "-----BEGIN PRIVATE KEY-----\nmyprivatekey\n-----END PRIVATE KEY-----\n",
"client_email": "client-mail@mygcpprojectid-1122.iam.gserviceaccount.com",
"client_id": "myclientid",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/client-mail%40mygcpprojectid-1122.iam.gserviceaccount.com"
}
project_id="mygcpprojectid-1122"
zone_name="my-sites"
dns_credentials = service_account.Credentials.from_service_account_info(gcp_dns_credentials)
client = dns.Client(project=project_id,credentials=dns_credentials)
zone = client.zone(zone_name)
create_records=dns.resource_record_set.ResourceRecordSet(name="mydnsrecord2.mygcpproject.com",record_type="A",ttl=300,rrdatas=["13.66.xx.xx"],zone=zone)
This script execution neither throws the error nor creates DNS record-set. I referred this doc - https://cloud.google.com/python/docs/reference/dns/latest/resource-record-set
Can someone help me :)