I need to delete a dns record in gcp. I got the dns record to delete from changes().list() method. As per the document I have appended the record I want to delete to the changes().deletions and called changes().create() method. But I am getting error Precondition not met for 'entity.change.deletions[0]'
mzone = client.managedZones().get(project=project_id,managedZone='abc-pods').execute()
changes = client.changes().list(project=project_id,managedZone='abc-pods').execute()
records_to_delete = []
for change in changes['changes']:
for record in change['additions']:
if dnsname in record['name']:
records_to_delete.append(change)
for record in records_to_delete:
record['deletions'].append(record['additions'][1])
record['additions'].remove(record['additions'][1])
for record in records_to_delete:
r = client.changes().create(project=project_id, managedZone='abd-pods', body=record).execute()
pprint.pprint(r)
Json I got from changes().list:
{u'additions': [{u'kind': u'dns#resourceRecordSet',
u'name': u'abc.com.',
u'rrdatas': [u'ns-cloud-c1.googledomains.com. cloud-dns-hostmaster.google.com. 2118 21600 3600 259200 300'],
u'signatureRrdatas': [],
u'ttl': 21600,
u'type': u'SOA'},
{u'kind': u'dns#resourceRecordSet',
u'name': u'xxx.abc.com.',
u'rrdatas': [u'34.76.78.35'],
u'signatureRrdatas': [],
u'ttl': 30,
u'type': u'A'}],
u'deletions': [{u'kind': u'dns#resourceRecordSet',
u'name': u'abc.com.',
u'rrdatas': [u'ns-cloud-c1.googledomains.com. cloud-dns-hostmaster.google.com. 2117 21600 3600 259200 300'],
u'signatureRrdatas': [],
u'ttl': 21600,
u'type': u'SOA'}],
u'id': u'2184',
u'kind': u'dns#change',
u'startTime': u'2020-07-13T18:04:34.896Z',
u'status': u'done'}
Modified Json given to changes().create() method:
{u'additions': [{u'kind': u'dns#resourceRecordSet',
u'name': u'abc.com.',
u'rrdatas': [u'ns-cloud-c1.googledomains.com. cloud-dns-hostmaster.google.com. 2118 21600 3600 259200 300'],
u'signatureRrdatas': [],
u'ttl': 21600,
u'type': u'SOA'}],
u'deletions': [{u'kind': u'dns#resourceRecordSet',
u'name': u'abc.com.',
u'rrdatas': [u'ns-cloud-c1.googledomains.com. cloud-dns-hostmaster.google.com. 2117 21600 3600 259200 300'],
u'signatureRrdatas': [],
u'ttl': 21600,
u'type': u'SOA'},
{u'kind': u'dns#resourceRecordSet',
u'name': u'xxx.abc.com.',
u'rrdatas': [u'34.76.78.35'],
u'signatureRrdatas': [],
u'ttl': 30,
u'type': u'A'}],
u'id': u'2184',
u'kind': u'dns#change',
u'startTime': u'2020-07-13T18:04:34.896Z',
u'status': u'done'}
As per the document, the body for create() method is same as the response from list() method. But still, I am not able to delete a record. Any idea what am I missing here?