add support for azurerm_private_dns_ptr_record
parent
05bd1d1ef8
commit
8627b57329
|
@ -446,6 +446,7 @@ func TestTerraformStateReader_Azure_Resources(t *testing.T) {
|
|||
{name: "private dns a record", dirName: "azurerm_private_dns_a_record", wantErr: false},
|
||||
{name: "private dns aaaa record", dirName: "azurerm_private_dns_aaaa_record", wantErr: false},
|
||||
{name: "private dns cname record", dirName: "azurerm_private_dns_cname_record", wantErr: false},
|
||||
{name: "private dns ptr record", dirName: "azurerm_private_dns_ptr_record", wantErr: false},
|
||||
{name: "images", dirName: "azurerm_image", wantErr: false},
|
||||
{name: "ssh public key", dirName: "azurerm_ssh_public_key", wantErr: false},
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
[
|
||||
{
|
||||
"Id": "/subscriptions/8cb43347-a79f-4bb2-a8b4-c838b41fa5a5/resourceGroups/martin-dev/providers/Microsoft.Network/privateDnsZones/thisisatestusingtf.com/PTR/testptr",
|
||||
"Type": "azurerm_private_dns_ptr_record",
|
||||
"Attrs": {
|
||||
"fqdn": "testptr.thisisatestusingtf.com.",
|
||||
"id": "/subscriptions/8cb43347-a79f-4bb2-a8b4-c838b41fa5a5/resourceGroups/martin-dev/providers/Microsoft.Network/privateDnsZones/thisisatestusingtf.com/PTR/testptr",
|
||||
"name": "testptr",
|
||||
"records": [
|
||||
"ptr3.thisisatestusingtf.com"
|
||||
],
|
||||
"resource_group_name": "martin-dev",
|
||||
"ttl": 300,
|
||||
"zone_name": "thisisatestusingtf.com"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Id": "/subscriptions/8cb43347-a79f-4bb2-a8b4-c838b41fa5a5/resourceGroups/martin-dev/providers/Microsoft.Network/privateDnsZones/thisisatestusingtf.com/PTR/othertestptr",
|
||||
"Type": "azurerm_private_dns_ptr_record",
|
||||
"Attrs": {
|
||||
"fqdn": "othertestptr.thisisatestusingtf.com.",
|
||||
"id": "/subscriptions/8cb43347-a79f-4bb2-a8b4-c838b41fa5a5/resourceGroups/martin-dev/providers/Microsoft.Network/privateDnsZones/thisisatestusingtf.com/PTR/othertestptr",
|
||||
"name": "othertestptr",
|
||||
"records": [
|
||||
"ptr1.thisisatestusingtf.com",
|
||||
"ptr2.thisisatestusingtf.com"
|
||||
],
|
||||
"resource_group_name": "martin-dev",
|
||||
"ttl": 300,
|
||||
"zone_name": "thisisatestusingtf.com"
|
||||
}
|
||||
}
|
||||
]
|
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
"version": 4,
|
||||
"terraform_version": "0.14.5",
|
||||
"serial": 19,
|
||||
"lineage": "7f22faf7-4655-0f68-3b00-9099a46450a7",
|
||||
"outputs": {},
|
||||
"resources": [
|
||||
{
|
||||
"mode": "managed",
|
||||
"type": "azurerm_private_dns_ptr_record",
|
||||
"name": "othertestptr",
|
||||
"provider": "provider[\"registry.terraform.io/hashicorp/azurerm\"]",
|
||||
"instances": [
|
||||
{
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"fqdn": "othertestptr.thisisatestusingtf.com.",
|
||||
"id": "/subscriptions/8cb43347-a79f-4bb2-a8b4-c838b41fa5a5/resourceGroups/martin-dev/providers/Microsoft.Network/privateDnsZones/thisisatestusingtf.com/PTR/othertestptr",
|
||||
"name": "othertestptr",
|
||||
"records": [
|
||||
"ptr1.thisisatestusingtf.com",
|
||||
"ptr2.thisisatestusingtf.com"
|
||||
],
|
||||
"resource_group_name": "martin-dev",
|
||||
"tags": null,
|
||||
"timeouts": null,
|
||||
"ttl": 300,
|
||||
"zone_name": "thisisatestusingtf.com"
|
||||
},
|
||||
"sensitive_attributes": [],
|
||||
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInJlYWQiOjMwMDAwMDAwMDAwMCwidXBkYXRlIjoxODAwMDAwMDAwMDAwfX0=",
|
||||
"dependencies": [
|
||||
"azurerm_private_dns_zone.testzone",
|
||||
"data.azurerm_resource_group.martin"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"mode": "managed",
|
||||
"type": "azurerm_private_dns_ptr_record",
|
||||
"name": "testptr",
|
||||
"provider": "provider[\"registry.terraform.io/hashicorp/azurerm\"]",
|
||||
"instances": [
|
||||
{
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"fqdn": "testptr.thisisatestusingtf.com.",
|
||||
"id": "/subscriptions/8cb43347-a79f-4bb2-a8b4-c838b41fa5a5/resourceGroups/martin-dev/providers/Microsoft.Network/privateDnsZones/thisisatestusingtf.com/PTR/testptr",
|
||||
"name": "testptr",
|
||||
"records": [
|
||||
"ptr3.thisisatestusingtf.com"
|
||||
],
|
||||
"resource_group_name": "martin-dev",
|
||||
"tags": null,
|
||||
"timeouts": null,
|
||||
"ttl": 300,
|
||||
"zone_name": "thisisatestusingtf.com"
|
||||
},
|
||||
"sensitive_attributes": [],
|
||||
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInJlYWQiOjMwMDAwMDAwMDAwMCwidXBkYXRlIjoxODAwMDAwMDAwMDAwfX0=",
|
||||
"dependencies": [
|
||||
"azurerm_private_dns_zone.testzone",
|
||||
"data.azurerm_resource_group.martin"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package azurerm
|
||||
|
||||
import (
|
||||
"github.com/cloudskiff/driftctl/pkg/remote/azurerm/repository"
|
||||
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
|
||||
"github.com/cloudskiff/driftctl/pkg/resource"
|
||||
"github.com/cloudskiff/driftctl/pkg/resource/azurerm"
|
||||
)
|
||||
|
||||
type AzurermPrivateDNSPTRRecordEnumerator struct {
|
||||
repository repository.PrivateDNSRepository
|
||||
factory resource.ResourceFactory
|
||||
}
|
||||
|
||||
func NewAzurermPrivateDNSPTRRecordEnumerator(repo repository.PrivateDNSRepository, factory resource.ResourceFactory) *AzurermPrivateDNSPTRRecordEnumerator {
|
||||
return &AzurermPrivateDNSPTRRecordEnumerator{
|
||||
repository: repo,
|
||||
factory: factory,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *AzurermPrivateDNSPTRRecordEnumerator) SupportedType() resource.ResourceType {
|
||||
return azurerm.AzurePrivateDNSPTRRecordResourceType
|
||||
}
|
||||
|
||||
func (e *AzurermPrivateDNSPTRRecordEnumerator) Enumerate() ([]*resource.Resource, error) {
|
||||
|
||||
zones, err := e.repository.ListAllPrivateZones()
|
||||
if err != nil {
|
||||
return nil, remoteerror.NewResourceListingErrorWithType(err, string(e.SupportedType()), azurerm.AzurePrivateDNSZoneResourceType)
|
||||
}
|
||||
|
||||
results := make([]*resource.Resource, 0)
|
||||
|
||||
for _, zone := range zones {
|
||||
records, err := e.repository.ListAllPTRRecords(zone)
|
||||
if err != nil {
|
||||
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
|
||||
}
|
||||
for _, record := range records {
|
||||
results = append(
|
||||
results,
|
||||
e.factory.CreateAbstractResource(
|
||||
string(e.SupportedType()),
|
||||
*record.ID,
|
||||
map[string]interface{}{
|
||||
"name": record.Name,
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return results, err
|
||||
}
|
|
@ -67,17 +67,16 @@ func Init(
|
|||
remoteLibrary.AddEnumerator(NewAzurermNetworkSecurityGroupEnumerator(networkRepo, factory))
|
||||
remoteLibrary.AddDetailsFetcher(azurerm.AzureNetworkSecurityGroupResourceType, common.NewGenericDetailsFetcher(azurerm.AzureNetworkSecurityGroupResourceType, provider, deserializer))
|
||||
remoteLibrary.AddEnumerator(NewAzurermLoadBalancerEnumerator(networkRepo, factory))
|
||||
|
||||
remoteLibrary.AddEnumerator(NewAzurermPrivateDNSZoneEnumerator(privateDNSRepo, factory))
|
||||
remoteLibrary.AddDetailsFetcher(azurerm.AzurePrivateDNSZoneResourceType, common.NewGenericDetailsFetcher(azurerm.AzurePrivateDNSZoneResourceType, provider, deserializer))
|
||||
remoteLibrary.AddEnumerator(NewAzurermPrivateDNSARecordEnumerator(privateDNSRepo, factory))
|
||||
remoteLibrary.AddDetailsFetcher(azurerm.AzurePrivateDNSARecordResourceType, common.NewGenericDetailsFetcher(azurerm.AzurePrivateDNSARecordResourceType, provider, deserializer))
|
||||
remoteLibrary.AddEnumerator(NewAzurermPrivateDNSAAAARecordEnumerator(privateDNSRepo, factory))
|
||||
remoteLibrary.AddDetailsFetcher(azurerm.AzurePrivateDNSAAAARecordResourceType, common.NewGenericDetailsFetcher(azurerm.AzurePrivateDNSAAAARecordResourceType, provider, deserializer))
|
||||
|
||||
remoteLibrary.AddEnumerator(NewAzurermPrivateDNSCNameRecordEnumerator(privateDNSRepo, factory))
|
||||
remoteLibrary.AddDetailsFetcher(azurerm.AzurePrivateDNSCNameRecordResourceType, common.NewGenericDetailsFetcher(azurerm.AzurePrivateDNSCNameRecordResourceType, provider, deserializer))
|
||||
|
||||
remoteLibrary.AddEnumerator(NewAzurermPrivateDNSPTRRecordEnumerator(privateDNSRepo, factory))
|
||||
remoteLibrary.AddDetailsFetcher(azurerm.AzurePrivateDNSPTRRecordResourceType, common.NewGenericDetailsFetcher(azurerm.AzurePrivateDNSPTRRecordResourceType, provider, deserializer))
|
||||
remoteLibrary.AddEnumerator(NewAzurermImageEnumerator(computeRepo, factory))
|
||||
remoteLibrary.AddEnumerator(NewAzurermSSHPublicKeyEnumerator(computeRepo, factory))
|
||||
remoteLibrary.AddDetailsFetcher(azurerm.AzureSSHPublicKeyResourceType, common.NewGenericDetailsFetcher(azurerm.AzureSSHPublicKeyResourceType, provider, deserializer))
|
||||
|
|
|
@ -81,6 +81,29 @@ func (_m *MockPrivateDNSRepository) ListAllCNAMERecords(zone *armprivatedns.Priv
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// ListAllPTRRecords provides a mock function with given fields: zone
|
||||
func (_m *MockPrivateDNSRepository) ListAllPTRRecords(zone *armprivatedns.PrivateZone) ([]*armprivatedns.RecordSet, error) {
|
||||
ret := _m.Called(zone)
|
||||
|
||||
var r0 []*armprivatedns.RecordSet
|
||||
if rf, ok := ret.Get(0).(func(*armprivatedns.PrivateZone) []*armprivatedns.RecordSet); ok {
|
||||
r0 = rf(zone)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*armprivatedns.RecordSet)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*armprivatedns.PrivateZone) error); ok {
|
||||
r1 = rf(zone)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// ListAllPrivateZones provides a mock function with given fields:
|
||||
func (_m *MockPrivateDNSRepository) ListAllPrivateZones() ([]*armprivatedns.PrivateZone, error) {
|
||||
ret := _m.Called()
|
||||
|
|
|
@ -16,6 +16,7 @@ type PrivateDNSRepository interface {
|
|||
ListAllARecords(zone *armprivatedns.PrivateZone) ([]*armprivatedns.RecordSet, error)
|
||||
ListAllAAAARecords(zone *armprivatedns.PrivateZone) ([]*armprivatedns.RecordSet, error)
|
||||
ListAllCNAMERecords(zone *armprivatedns.PrivateZone) ([]*armprivatedns.RecordSet, error)
|
||||
ListAllPTRRecords(zone *armprivatedns.PrivateZone) ([]*armprivatedns.RecordSet, error)
|
||||
}
|
||||
|
||||
type privateDNSZoneListPager interface {
|
||||
|
@ -130,6 +131,22 @@ func (s *privateDNSRepository) ListAllAAAARecords(zone *armprivatedns.PrivateZon
|
|||
return results, nil
|
||||
}
|
||||
|
||||
func (s *privateDNSRepository) ListAllPTRRecords(zone *armprivatedns.PrivateZone) ([]*armprivatedns.RecordSet, error) {
|
||||
records, err := s.listAllRecords(zone)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
results := make([]*armprivatedns.RecordSet, 0)
|
||||
for _, record := range records {
|
||||
if record.Properties.PtrRecords == nil {
|
||||
continue
|
||||
}
|
||||
results = append(results, record)
|
||||
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (s *privateDNSRepository) ListAllCNAMERecords(zone *armprivatedns.PrivateZone) ([]*armprivatedns.RecordSet, error) {
|
||||
records, err := s.listAllRecords(zone)
|
||||
if err != nil {
|
||||
|
|
|
@ -808,3 +808,210 @@ func Test_ListAllCNAMERecords_Error(t *testing.T) {
|
|||
}
|
||||
|
||||
// endregion
|
||||
|
||||
// region PTRRecord
|
||||
func Test_ListAllPTRRecords_MultiplesResults(t *testing.T) {
|
||||
|
||||
expected := []*armprivatedns.RecordSet{
|
||||
{
|
||||
ProxyResource: armprivatedns.ProxyResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("record1"),
|
||||
},
|
||||
},
|
||||
Properties: &armprivatedns.RecordSetProperties{
|
||||
PtrRecords: []*armprivatedns.PtrRecord{
|
||||
{Ptrdname: to.StringPtr("ptrdname")},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ProxyResource: armprivatedns.ProxyResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("record3"),
|
||||
},
|
||||
},
|
||||
Properties: &armprivatedns.RecordSetProperties{
|
||||
PtrRecords: []*armprivatedns.PtrRecord{
|
||||
{Ptrdname: to.StringPtr("ptrdname")},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
fakeRecordSetClient := &mockPrivateRecordSetClient{}
|
||||
|
||||
mockPager := &mockPrivateDNSRecordSetListPager{}
|
||||
mockPager.On("Err").Return(nil).Times(3)
|
||||
mockPager.On("NextPage", mock.Anything).Return(true).Times(2)
|
||||
mockPager.On("NextPage", mock.Anything).Return(false).Times(1)
|
||||
mockPager.On("PageResponse").Return(armprivatedns.RecordSetsListResponse{
|
||||
RecordSetsListResult: armprivatedns.RecordSetsListResult{
|
||||
RecordSetListResult: armprivatedns.RecordSetListResult{
|
||||
Value: []*armprivatedns.RecordSet{
|
||||
{
|
||||
ProxyResource: armprivatedns.ProxyResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("record1"),
|
||||
},
|
||||
},
|
||||
Properties: &armprivatedns.RecordSetProperties{
|
||||
PtrRecords: []*armprivatedns.PtrRecord{
|
||||
{Ptrdname: to.StringPtr("ptrdname")},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ProxyResource: armprivatedns.ProxyResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("record2"),
|
||||
},
|
||||
},
|
||||
Properties: &armprivatedns.RecordSetProperties{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).Times(1)
|
||||
mockPager.On("PageResponse").Return(armprivatedns.RecordSetsListResponse{
|
||||
RecordSetsListResult: armprivatedns.RecordSetsListResult{
|
||||
RecordSetListResult: armprivatedns.RecordSetListResult{
|
||||
Value: []*armprivatedns.RecordSet{
|
||||
{
|
||||
ProxyResource: armprivatedns.ProxyResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("record3"),
|
||||
},
|
||||
},
|
||||
Properties: &armprivatedns.RecordSetProperties{
|
||||
PtrRecords: []*armprivatedns.PtrRecord{
|
||||
{Ptrdname: to.StringPtr("ptrdname")},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ProxyResource: armprivatedns.ProxyResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("record4"),
|
||||
},
|
||||
},
|
||||
Properties: &armprivatedns.RecordSetProperties{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).Times(1)
|
||||
|
||||
fakeRecordSetClient.On("List", "rgid", "zone", (*armprivatedns.RecordSetsListOptions)(nil)).Return(mockPager)
|
||||
|
||||
c := &cache.MockCache{}
|
||||
c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(nil).Times(1)
|
||||
c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return().Times(1)
|
||||
c.On("Put", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com", mock.Anything).Return(true).Times(1)
|
||||
s := &privateDNSRepository{
|
||||
recordClient: fakeRecordSetClient,
|
||||
cache: c,
|
||||
}
|
||||
got, err := s.ListAllPTRRecords(&armprivatedns.PrivateZone{
|
||||
TrackedResource: armprivatedns.TrackedResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com"),
|
||||
Name: to.StringPtr("zone"),
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("ListAllPTRRecords() error = %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
mockPager.AssertExpectations(t)
|
||||
fakeRecordSetClient.AssertExpectations(t)
|
||||
c.AssertExpectations(t)
|
||||
|
||||
if !reflect.DeepEqual(got, expected) {
|
||||
t.Errorf("ListAllPTRRecords() got = %v, want %v", got, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ListAllPTRRecords_MultiplesResults_WithCache(t *testing.T) {
|
||||
|
||||
expected := []*armprivatedns.RecordSet{
|
||||
{
|
||||
ProxyResource: armprivatedns.ProxyResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("record1"),
|
||||
},
|
||||
},
|
||||
Properties: &armprivatedns.RecordSetProperties{
|
||||
PtrRecords: []*armprivatedns.PtrRecord{
|
||||
{Ptrdname: to.StringPtr("ptrdname")},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
fakeRecordSetClient := &mockPrivateRecordSetClient{}
|
||||
|
||||
c := &cache.MockCache{}
|
||||
c.On("GetAndLock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Return(expected).Times(1)
|
||||
c.On("Unlock", "privateDNSlistAllRecords-/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com").Times(1)
|
||||
s := &privateDNSRepository{
|
||||
recordClient: fakeRecordSetClient,
|
||||
cache: c,
|
||||
}
|
||||
got, err := s.ListAllPTRRecords(&armprivatedns.PrivateZone{
|
||||
TrackedResource: armprivatedns.TrackedResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com"),
|
||||
Name: to.StringPtr("zone"),
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("ListAllPTRRecords() error = %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
fakeRecordSetClient.AssertExpectations(t)
|
||||
c.AssertExpectations(t)
|
||||
|
||||
if !reflect.DeepEqual(got, expected) {
|
||||
t.Errorf("ListAllPTRRecords() got = %v, want %v", got, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ListAllPTRRecords_Error(t *testing.T) {
|
||||
|
||||
fakeClient := &mockPrivateRecordSetClient{}
|
||||
|
||||
expectedErr := errors.New("unexpected error")
|
||||
|
||||
mockPager := &mockPrivateDNSRecordSetListPager{}
|
||||
mockPager.On("Err").Return(expectedErr).Times(1)
|
||||
mockPager.On("NextPage", mock.Anything).Return(true).Times(1)
|
||||
mockPager.On("PageResponse").Return(armprivatedns.RecordSetsListResponse{}).Times(1)
|
||||
|
||||
fakeClient.On("List", "rgid", "zone", (*armprivatedns.RecordSetsListOptions)(nil)).Return(mockPager)
|
||||
|
||||
s := &privateDNSRepository{
|
||||
recordClient: fakeClient,
|
||||
cache: cache.New(0),
|
||||
}
|
||||
got, err := s.ListAllPTRRecords(&armprivatedns.PrivateZone{
|
||||
TrackedResource: armprivatedns.TrackedResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("/subscriptions/subid/resourceGroups/rgid/providers/Microsoft.Network/privateDnsZones/zone.com"),
|
||||
Name: to.StringPtr("zone"),
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
mockPager.AssertExpectations(t)
|
||||
fakeClient.AssertExpectations(t)
|
||||
|
||||
assert.Equal(t, expectedErr, err)
|
||||
assert.Nil(t, got)
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
|
|
@ -599,3 +599,157 @@ func TestAzurermPrivateDNSCNAMERecord(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAzurermPrivateDNSPTRRecord(t *testing.T) {
|
||||
|
||||
dummyError := errors.New("this is an error")
|
||||
|
||||
tests := []struct {
|
||||
test string
|
||||
dirName string
|
||||
mocks func(*repository.MockPrivateDNSRepository, *mocks.AlerterInterface)
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
test: "no private ptr record",
|
||||
dirName: "azurerm_private_dns_ptr_record_empty",
|
||||
mocks: func(repository *repository.MockPrivateDNSRepository, alerter *mocks.AlerterInterface) {
|
||||
repository.On("ListAllPrivateZones").Return([]*armprivatedns.PrivateZone{}, nil)
|
||||
},
|
||||
},
|
||||
{
|
||||
test: "error listing private zone",
|
||||
dirName: "azurerm_private_dns_ptr_record_empty",
|
||||
mocks: func(repository *repository.MockPrivateDNSRepository, alerter *mocks.AlerterInterface) {
|
||||
repository.On("ListAllPrivateZones").Return(nil, dummyError)
|
||||
},
|
||||
wantErr: remoteerr.NewResourceListingErrorWithType(dummyError, resourceazure.AzurePrivateDNSPTRRecordResourceType, resourceazure.AzurePrivateDNSZoneResourceType),
|
||||
},
|
||||
{
|
||||
test: "error listing private ptr records",
|
||||
dirName: "azurerm_private_dns_ptr_record_empty",
|
||||
mocks: func(repository *repository.MockPrivateDNSRepository, alerter *mocks.AlerterInterface) {
|
||||
repository.On("ListAllPrivateZones").Return([]*armprivatedns.PrivateZone{
|
||||
{
|
||||
TrackedResource: armprivatedns.TrackedResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("/subscriptions/7bfb2c5c-7308-46ed-8ae4-fffa356eb406/resourceGroups/martin-dev/providers/Microsoft.Network/privateDnsZones/thisisatestusingtf.com"),
|
||||
Name: to.StringPtr("thisisatestusingtf.com"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
repository.On("ListAllPTRRecords", mock.Anything).Return(nil, dummyError)
|
||||
},
|
||||
wantErr: remoteerr.NewResourceListingError(dummyError, resourceazure.AzurePrivateDNSPTRRecordResourceType),
|
||||
},
|
||||
{
|
||||
test: "multiple private ptra records",
|
||||
dirName: "azurerm_private_dns_ptr_record_multiple",
|
||||
mocks: func(repository *repository.MockPrivateDNSRepository, alerter *mocks.AlerterInterface) {
|
||||
repository.On("ListAllPrivateZones").Return([]*armprivatedns.PrivateZone{
|
||||
{
|
||||
TrackedResource: armprivatedns.TrackedResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("/subscriptions/7bfb2c5c-7308-46ed-8ae4-fffa356eb406/resourceGroups/martin-dev/providers/Microsoft.Network/privateDnsZones/thisisatestusingtf.com"),
|
||||
Name: to.StringPtr("thisisatestusingtf.com"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
|
||||
repository.On("ListAllPTRRecords", mock.Anything).Return([]*armprivatedns.RecordSet{
|
||||
{
|
||||
ProxyResource: armprivatedns.ProxyResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("/subscriptions/8cb43347-a79f-4bb2-a8b4-c838b41fa5a5/resourceGroups/martin-dev/providers/Microsoft.Network/privateDnsZones/thisisatestusingtf.com/PTR/othertestptr"),
|
||||
Name: to.StringPtr("othertestptr"),
|
||||
},
|
||||
},
|
||||
Properties: &armprivatedns.RecordSetProperties{
|
||||
PtrRecords: []*armprivatedns.PtrRecord{
|
||||
{Ptrdname: to.StringPtr("ptr1.thisisatestusingtf.com")},
|
||||
{Ptrdname: to.StringPtr("ptr2.thisisatestusingtf.com")},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ProxyResource: armprivatedns.ProxyResource{
|
||||
Resource: armprivatedns.Resource{
|
||||
ID: to.StringPtr("/subscriptions/8cb43347-a79f-4bb2-a8b4-c838b41fa5a5/resourceGroups/martin-dev/providers/Microsoft.Network/privateDnsZones/thisisatestusingtf.com/PTR/testptr"),
|
||||
Name: to.StringPtr("testptr"),
|
||||
},
|
||||
},
|
||||
Properties: &armprivatedns.RecordSetProperties{
|
||||
PtrRecords: []*armprivatedns.PtrRecord{
|
||||
{Ptrdname: to.StringPtr("ptr3.thisisatestusingtf.com")},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil).Once()
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
providerVersion := "2.71.0"
|
||||
schemaRepository := testresource.InitFakeSchemaRepository("azurerm", providerVersion)
|
||||
resourceazure.InitResourcesMetadata(schemaRepository)
|
||||
factory := terraform.NewTerraformResourceFactory(schemaRepository)
|
||||
deserializer := resource.NewDeserializer(factory)
|
||||
|
||||
for _, c := range tests {
|
||||
t.Run(c.test, func(tt *testing.T) {
|
||||
shouldUpdate := c.dirName == *goldenfile.Update
|
||||
|
||||
scanOptions := ScannerOptions{Deep: true}
|
||||
providerLibrary := terraform.NewProviderLibrary()
|
||||
remoteLibrary := common.NewRemoteLibrary()
|
||||
|
||||
// Initialize mocks
|
||||
alerter := &mocks.AlerterInterface{}
|
||||
fakeRepo := &repository.MockPrivateDNSRepository{}
|
||||
c.mocks(fakeRepo, alerter)
|
||||
|
||||
var repo repository.PrivateDNSRepository = fakeRepo
|
||||
providerVersion := "2.71.0"
|
||||
realProvider, err := terraformtest.InitTestAzureProvider(providerLibrary, providerVersion)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
provider := terraformtest.NewFakeTerraformProvider(realProvider)
|
||||
provider.WithResponse(c.dirName)
|
||||
|
||||
// Replace mock by real resources if we are in update mode
|
||||
if shouldUpdate {
|
||||
err := realProvider.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
provider.ShouldUpdate()
|
||||
cred, err := azidentity.NewDefaultAzureCredential(&azidentity.DefaultAzureCredentialOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
con := arm.NewDefaultConnection(cred, nil)
|
||||
repo = repository.NewPrivateDNSRepository(con, realProvider.GetConfig(), cache.New(0))
|
||||
}
|
||||
|
||||
remoteLibrary.AddEnumerator(azurerm.NewAzurermPrivateDNSPTRRecordEnumerator(repo, factory))
|
||||
remoteLibrary.AddDetailsFetcher(resourceazure.AzurePrivateDNSPTRRecordResourceType, common.NewGenericDetailsFetcher(resourceazure.AzurePrivateDNSPTRRecordResourceType, provider, deserializer))
|
||||
|
||||
testFilter := &filter.MockFilter{}
|
||||
testFilter.On("IsTypeIgnored", mock.Anything).Return(false)
|
||||
|
||||
s := NewScanner(remoteLibrary, alerter, scanOptions, testFilter)
|
||||
got, err := s.Resources()
|
||||
assert.Equal(tt, c.wantErr, err)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
test.TestAgainstGoldenFile(got, resourceazure.AzurePrivateDNSPTRRecordResourceType, c.dirName, provider, deserializer, shouldUpdate, tt)
|
||||
alerter.AssertExpectations(tt)
|
||||
fakeRepo.AssertExpectations(tt)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"Typ": "WyJvYmplY3QiLHsiZnFkbiI6InN0cmluZyIsImlkIjoic3RyaW5nIiwibmFtZSI6InN0cmluZyIsInJlY29yZHMiOlsic2V0Iiwic3RyaW5nIl0sInJlc291cmNlX2dyb3VwX25hbWUiOiJzdHJpbmciLCJ0YWdzIjpbIm1hcCIsInN0cmluZyJdLCJ0aW1lb3V0cyI6WyJvYmplY3QiLHsiY3JlYXRlIjoic3RyaW5nIiwiZGVsZXRlIjoic3RyaW5nIiwicmVhZCI6InN0cmluZyIsInVwZGF0ZSI6InN0cmluZyJ9XSwidHRsIjoibnVtYmVyIiwiem9uZV9uYW1lIjoic3RyaW5nIn1d",
|
||||
"Val": "eyJmcWRuIjoib3RoZXJ0ZXN0cHRyLnRoaXNpc2F0ZXN0dXNpbmd0Zi5jb20uIiwiaWQiOiIvc3Vic2NyaXB0aW9ucy84Y2I0MzM0Ny1hNzlmLTRiYjItYThiNC1jODM4YjQxZmE1YTUvcmVzb3VyY2VHcm91cHMvbWFydGluLWRldi9wcm92aWRlcnMvTWljcm9zb2Z0Lk5ldHdvcmsvcHJpdmF0ZURuc1pvbmVzL3RoaXNpc2F0ZXN0dXNpbmd0Zi5jb20vUFRSL290aGVydGVzdHB0ciIsIm5hbWUiOiJvdGhlcnRlc3RwdHIiLCJyZWNvcmRzIjpbInB0cjEudGhpc2lzYXRlc3R1c2luZ3RmLmNvbSIsInB0cjIudGhpc2lzYXRlc3R1c2luZ3RmLmNvbSJdLCJyZXNvdXJjZV9ncm91cF9uYW1lIjoibWFydGluLWRldiIsInRhZ3MiOnt9LCJ0aW1lb3V0cyI6eyJjcmVhdGUiOm51bGwsImRlbGV0ZSI6bnVsbCwicmVhZCI6bnVsbCwidXBkYXRlIjpudWxsfSwidHRsIjozMDAsInpvbmVfbmFtZSI6InRoaXNpc2F0ZXN0dXNpbmd0Zi5jb20ifQ==",
|
||||
"Err": null
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"Typ": "WyJvYmplY3QiLHsiZnFkbiI6InN0cmluZyIsImlkIjoic3RyaW5nIiwibmFtZSI6InN0cmluZyIsInJlY29yZHMiOlsic2V0Iiwic3RyaW5nIl0sInJlc291cmNlX2dyb3VwX25hbWUiOiJzdHJpbmciLCJ0YWdzIjpbIm1hcCIsInN0cmluZyJdLCJ0aW1lb3V0cyI6WyJvYmplY3QiLHsiY3JlYXRlIjoic3RyaW5nIiwiZGVsZXRlIjoic3RyaW5nIiwicmVhZCI6InN0cmluZyIsInVwZGF0ZSI6InN0cmluZyJ9XSwidHRsIjoibnVtYmVyIiwiem9uZV9uYW1lIjoic3RyaW5nIn1d",
|
||||
"Val": "eyJmcWRuIjoidGVzdHB0ci50aGlzaXNhdGVzdHVzaW5ndGYuY29tLiIsImlkIjoiL3N1YnNjcmlwdGlvbnMvOGNiNDMzNDctYTc5Zi00YmIyLWE4YjQtYzgzOGI0MWZhNWE1L3Jlc291cmNlR3JvdXBzL21hcnRpbi1kZXYvcHJvdmlkZXJzL01pY3Jvc29mdC5OZXR3b3JrL3ByaXZhdGVEbnNab25lcy90aGlzaXNhdGVzdHVzaW5ndGYuY29tL1BUUi90ZXN0cHRyIiwibmFtZSI6InRlc3RwdHIiLCJyZWNvcmRzIjpbInB0cjMudGhpc2lzYXRlc3R1c2luZ3RmLmNvbSJdLCJyZXNvdXJjZV9ncm91cF9uYW1lIjoibWFydGluLWRldiIsInRhZ3MiOnt9LCJ0aW1lb3V0cyI6eyJjcmVhdGUiOm51bGwsImRlbGV0ZSI6bnVsbCwicmVhZCI6bnVsbCwidXBkYXRlIjpudWxsfSwidHRsIjozMDAsInpvbmVfbmFtZSI6InRoaXNpc2F0ZXN0dXNpbmd0Zi5jb20ifQ==",
|
||||
"Err": null
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
[
|
||||
{
|
||||
"fqdn": "testptr.thisisatestusingtf.com.",
|
||||
"id": "/subscriptions/8cb43347-a79f-4bb2-a8b4-c838b41fa5a5/resourceGroups/martin-dev/providers/Microsoft.Network/privateDnsZones/thisisatestusingtf.com/PTR/testptr",
|
||||
"name": "testptr",
|
||||
"records": [
|
||||
"ptr3.thisisatestusingtf.com"
|
||||
],
|
||||
"resource_group_name": "martin-dev",
|
||||
"tags": null,
|
||||
"timeouts": null,
|
||||
"ttl": 300,
|
||||
"zone_name": "thisisatestusingtf.com"
|
||||
},
|
||||
{
|
||||
"fqdn": "othertestptr.thisisatestusingtf.com.",
|
||||
"id": "/subscriptions/8cb43347-a79f-4bb2-a8b4-c838b41fa5a5/resourceGroups/martin-dev/providers/Microsoft.Network/privateDnsZones/thisisatestusingtf.com/PTR/othertestptr",
|
||||
"name": "othertestptr",
|
||||
"records": [
|
||||
"ptr1.thisisatestusingtf.com",
|
||||
"ptr2.thisisatestusingtf.com"
|
||||
],
|
||||
"resource_group_name": "martin-dev",
|
||||
"tags": null,
|
||||
"timeouts": null,
|
||||
"ttl": 300,
|
||||
"zone_name": "thisisatestusingtf.com"
|
||||
}
|
||||
]
|
|
@ -0,0 +1,25 @@
|
|||
package azurerm
|
||||
|
||||
import (
|
||||
"github.com/cloudskiff/driftctl/pkg/resource"
|
||||
)
|
||||
|
||||
const AzurePrivateDNSPTRRecordResourceType = "azurerm_private_dns_ptr_record"
|
||||
|
||||
func initAzurePrivateDNSPTRRecordMetaData(resourceSchemaRepository resource.SchemaRepositoryInterface) {
|
||||
resourceSchemaRepository.SetNormalizeFunc(AzurePrivateDNSPTRRecordResourceType, func(res *resource.Resource) {
|
||||
res.Attributes().SafeDelete([]string{"timeouts"})
|
||||
})
|
||||
resourceSchemaRepository.SetHumanReadableAttributesFunc(AzurePrivateDNSPTRRecordResourceType, func(res *resource.Resource) map[string]string {
|
||||
val := res.Attrs
|
||||
attrs := make(map[string]string)
|
||||
if name := val.GetString("name"); name != nil && *name != "" {
|
||||
attrs["Name"] = *name
|
||||
}
|
||||
if zone := val.GetString("zone_name"); zone != nil && *zone != "" {
|
||||
attrs["Zone"] = *zone
|
||||
}
|
||||
return attrs
|
||||
})
|
||||
resourceSchemaRepository.SetFlags(AzurePrivateDNSPTRRecordResourceType, resource.FlagDeepMode)
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package azurerm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cloudskiff/driftctl/test"
|
||||
"github.com/cloudskiff/driftctl/test/acceptance"
|
||||
)
|
||||
|
||||
func TestAcc_Azure_PrivateDNSPTRRecord(t *testing.T) {
|
||||
acceptance.Run(t, acceptance.AccTestCase{
|
||||
TerraformVersion: "0.15.5",
|
||||
Paths: []string{"./testdata/acc/azurerm_private_dns_ptr_record"},
|
||||
Args: []string{
|
||||
"scan",
|
||||
"--to", "azure+tf", "--deep",
|
||||
},
|
||||
Checks: []acceptance.AccCheck{
|
||||
{
|
||||
Check: func(result *test.ScanResult, stdout string, err error) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result.AssertInfrastructureIsInSync()
|
||||
result.AssertManagedCount(2)
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -17,6 +17,7 @@ func InitResourcesMetadata(resourceSchemaRepository resource.SchemaRepositoryInt
|
|||
initAzurePrivateDNSZoneMetaData(resourceSchemaRepository)
|
||||
initAzurePrivateDNSARecordMetaData(resourceSchemaRepository)
|
||||
initAzurePrivateDNSAAAARecordMetaData(resourceSchemaRepository)
|
||||
initAzurePrivateDNSPTRRecordMetaData(resourceSchemaRepository)
|
||||
initAzureImageMetaData(resourceSchemaRepository)
|
||||
initAzureSSHPublicKeyMetaData(resourceSchemaRepository)
|
||||
initAzurePrivateDNSCNameRecordMetaData(resourceSchemaRepository)
|
||||
|
|
|
@ -29,6 +29,7 @@ func TestAzureMetadata_Flags(t *testing.T) {
|
|||
AzurePrivateDNSARecordResourceType: {resource.FlagDeepMode},
|
||||
AzurePrivateDNSAAAARecordResourceType: {resource.FlagDeepMode},
|
||||
AzurePrivateDNSCNameRecordResourceType: {resource.FlagDeepMode},
|
||||
AzurePrivateDNSPTRRecordResourceType: {resource.FlagDeepMode},
|
||||
AzureImageResourceType: {},
|
||||
AzureSSHPublicKeyResourceType: {resource.FlagDeepMode},
|
||||
}
|
||||
|
|
2
pkg/resource/azurerm/testdata/acc/azurerm_private_dns_ptr_record/.driftignore
vendored
Normal file
2
pkg/resource/azurerm/testdata/acc/azurerm_private_dns_ptr_record/.driftignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!azurerm_private_dns_ptr_record
|
38
pkg/resource/azurerm/testdata/acc/azurerm_private_dns_ptr_record/terraform.tf
vendored
Normal file
38
pkg/resource/azurerm/testdata/acc/azurerm_private_dns_ptr_record/terraform.tf
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
azurerm = {
|
||||
source = "hashicorp/azurerm"
|
||||
version = "~> 2.71.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "azurerm" {
|
||||
features {}
|
||||
}
|
||||
|
||||
data "azurerm_resource_group" "example" {
|
||||
name = "driftctl-qa-1"
|
||||
}
|
||||
|
||||
resource "azurerm_private_dns_zone" "testzone" {
|
||||
name = "this-zone-is-a-test-for-driftctl.com"
|
||||
resource_group_name = data.azurerm_resource_group.example.name
|
||||
}
|
||||
|
||||
resource "azurerm_private_dns_ptr_record" "othertestptr" {
|
||||
name = "othertestptr"
|
||||
zone_name = azurerm_private_dns_zone.testzone.name
|
||||
resource_group_name = data.azurerm_resource_group.example.name
|
||||
ttl = 300
|
||||
records = ["ptr1.thisisatestusingtf.com", "ptr2.thisisatestusingtf.com"]
|
||||
}
|
||||
|
||||
resource "azurerm_private_dns_ptr_record" "testptr" {
|
||||
name = "testptr"
|
||||
zone_name = azurerm_private_dns_zone.testzone.name
|
||||
resource_group_name = data.azurerm_resource_group.example.name
|
||||
ttl = 300
|
||||
records = ["ptr3.thisisatestusingtf.com"]
|
||||
|
||||
}
|
|
@ -203,6 +203,7 @@ var supportedTypes = map[string]ResourceTypeMeta{
|
|||
"azurerm_private_dns_a_record": {},
|
||||
"azurerm_private_dns_aaaa_record": {},
|
||||
"azurerm_private_dns_cname_record": {},
|
||||
"azurerm_private_dns_ptr_record": {},
|
||||
"azurerm_image": {},
|
||||
"azurerm_ssh_public_key": {},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue