commit
42d6d28143
|
@ -426,6 +426,7 @@ func TestTerraformStateReader_Azure_Resources(t *testing.T) {
|
|||
wantErr bool
|
||||
}{
|
||||
{name: "network security group", dirName: "azurerm_network_security_group", wantErr: false},
|
||||
{name: "load balancers", dirName: "azurerm_lb", wantErr: false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
[
|
||||
{
|
||||
"Id": "/subscriptions/7bfb2c5c-7308-46ed-8ae4-fffa356eb406/resourceGroups/LoadBalancerRG/providers/Microsoft.Network/loadBalancers/TestLoadBalancer",
|
||||
"Type": "azurerm_lb",
|
||||
"Attrs": {
|
||||
"frontend_ip_configuration": [
|
||||
{
|
||||
"availability_zone": "No-Zone",
|
||||
"id": "/subscriptions/7bfb2c5c-7308-46ed-8ae4-fffa356eb406/resourceGroups/LoadBalancerRG/providers/Microsoft.Network/loadBalancers/TestLoadBalancer/frontendIPConfigurations/PublicIPAddress",
|
||||
"name": "PublicIPAddress",
|
||||
"private_ip_address": "",
|
||||
"private_ip_address_allocation": "Dynamic",
|
||||
"private_ip_address_version": "",
|
||||
"public_ip_address_id": "/subscriptions/7bfb2c5c-7308-46ed-8ae4-fffa356eb406/resourceGroups/LoadBalancerRG/providers/Microsoft.Network/publicIPAddresses/PublicIPForLB",
|
||||
"public_ip_prefix_id": "",
|
||||
"subnet_id": ""
|
||||
}
|
||||
],
|
||||
"id": "/subscriptions/7bfb2c5c-7308-46ed-8ae4-fffa356eb406/resourceGroups/LoadBalancerRG/providers/Microsoft.Network/loadBalancers/TestLoadBalancer",
|
||||
"location": "westus",
|
||||
"name": "TestLoadBalancer",
|
||||
"private_ip_address": "",
|
||||
"resource_group_name": "LoadBalancerRG",
|
||||
"sku": "Basic"
|
||||
}
|
||||
}
|
||||
]
|
|
@ -0,0 +1,54 @@
|
|||
{
|
||||
"version": 4,
|
||||
"terraform_version": "0.15.5",
|
||||
"serial": 433,
|
||||
"lineage": "9566e18d-6080-4aa8-e9a6-4c38905cf68f",
|
||||
"outputs": {},
|
||||
"resources": [
|
||||
{
|
||||
"mode": "managed",
|
||||
"type": "azurerm_lb",
|
||||
"name": "example",
|
||||
"provider": "provider[\"registry.terraform.io/hashicorp/azurerm\"]",
|
||||
"instances": [
|
||||
{
|
||||
"schema_version": 0,
|
||||
"attributes": {
|
||||
"frontend_ip_configuration": [
|
||||
{
|
||||
"availability_zone": "No-Zone",
|
||||
"id": "/subscriptions/7bfb2c5c-7308-46ed-8ae4-fffa356eb406/resourceGroups/LoadBalancerRG/providers/Microsoft.Network/loadBalancers/TestLoadBalancer/frontendIPConfigurations/PublicIPAddress",
|
||||
"inbound_nat_rules": [],
|
||||
"load_balancer_rules": [],
|
||||
"name": "PublicIPAddress",
|
||||
"outbound_rules": [],
|
||||
"private_ip_address": "",
|
||||
"private_ip_address_allocation": "Dynamic",
|
||||
"private_ip_address_version": "",
|
||||
"public_ip_address_id": "/subscriptions/7bfb2c5c-7308-46ed-8ae4-fffa356eb406/resourceGroups/LoadBalancerRG/providers/Microsoft.Network/publicIPAddresses/PublicIPForLB",
|
||||
"public_ip_prefix_id": "",
|
||||
"subnet_id": "",
|
||||
"zones": []
|
||||
}
|
||||
],
|
||||
"id": "/subscriptions/7bfb2c5c-7308-46ed-8ae4-fffa356eb406/resourceGroups/LoadBalancerRG/providers/Microsoft.Network/loadBalancers/TestLoadBalancer",
|
||||
"location": "westus",
|
||||
"name": "TestLoadBalancer",
|
||||
"private_ip_address": "",
|
||||
"private_ip_addresses": [],
|
||||
"resource_group_name": "LoadBalancerRG",
|
||||
"sku": "Basic",
|
||||
"tags": null,
|
||||
"timeouts": null
|
||||
},
|
||||
"sensitive_attributes": [],
|
||||
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInJlYWQiOjMwMDAwMDAwMDAwMCwidXBkYXRlIjoxODAwMDAwMDAwMDAwfX0=",
|
||||
"dependencies": [
|
||||
"azurerm_public_ip.example",
|
||||
"azurerm_resource_group.example"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
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 AzurermLoadBalancerEnumerator struct {
|
||||
repository repository.NetworkRepository
|
||||
factory resource.ResourceFactory
|
||||
}
|
||||
|
||||
func NewAzurermLoadBalancerEnumerator(repo repository.NetworkRepository, factory resource.ResourceFactory) *AzurermLoadBalancerEnumerator {
|
||||
return &AzurermLoadBalancerEnumerator{
|
||||
repository: repo,
|
||||
factory: factory,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *AzurermLoadBalancerEnumerator) SupportedType() resource.ResourceType {
|
||||
return azurerm.AzureLoadBalancerResourceType
|
||||
}
|
||||
|
||||
func (e *AzurermLoadBalancerEnumerator) Enumerate() ([]*resource.Resource, error) {
|
||||
loadBalancers, err := e.repository.ListAllLoadBalancers()
|
||||
if err != nil {
|
||||
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
|
||||
}
|
||||
|
||||
results := make([]*resource.Resource, 0, len(loadBalancers))
|
||||
|
||||
for _, res := range loadBalancers {
|
||||
results = append(
|
||||
results,
|
||||
e.factory.CreateAbstractResource(
|
||||
string(e.SupportedType()),
|
||||
*res.ID,
|
||||
map[string]interface{}{
|
||||
"name": *res.Name,
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
return results, err
|
||||
}
|
|
@ -64,6 +64,7 @@ func Init(
|
|||
remoteLibrary.AddEnumerator(NewAzurermPostgresqlDatabaseEnumerator(postgresqlRepo, factory))
|
||||
remoteLibrary.AddEnumerator(NewAzurermNetworkSecurityGroupEnumerator(networkRepo, factory))
|
||||
remoteLibrary.AddDetailsFetcher(azurerm.AzureNetworkSecurityGroupResourceType, common.NewGenericDetailsFetcher(azurerm.AzureNetworkSecurityGroupResourceType, provider, deserializer))
|
||||
remoteLibrary.AddEnumerator(NewAzurermLoadBalancerEnumerator(networkRepo, factory))
|
||||
|
||||
err = resourceSchemaRepository.Init(terraform.AZURE, provider.Version(), provider.Schema())
|
||||
if err != nil {
|
||||
|
|
|
@ -35,6 +35,29 @@ func (_m *MockNetworkRepository) ListAllFirewalls() ([]*armnetwork.AzureFirewall
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// ListAllLoadBalancers provides a mock function with given fields:
|
||||
func (_m *MockNetworkRepository) ListAllLoadBalancers() ([]*armnetwork.LoadBalancer, error) {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 []*armnetwork.LoadBalancer
|
||||
if rf, ok := ret.Get(0).(func() []*armnetwork.LoadBalancer); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*armnetwork.LoadBalancer)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func() error); ok {
|
||||
r1 = rf()
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// ListAllPublicIPAddresses provides a mock function with given fields:
|
||||
func (_m *MockNetworkRepository) ListAllPublicIPAddresses() ([]*armnetwork.PublicIPAddress, error) {
|
||||
ret := _m.Called()
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
// Code generated by mockery v0.0.0-dev. DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
armnetwork "github.com/Azure/azure-sdk-for-go/sdk/network/armnetwork"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// mockLoadBalancersClient is an autogenerated mock type for the loadBalancersClient type
|
||||
type mockLoadBalancersClient struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// ListAll provides a mock function with given fields: options
|
||||
func (_m *mockLoadBalancersClient) ListAll(options *armnetwork.LoadBalancersListAllOptions) loadBalancersListAllPager {
|
||||
ret := _m.Called(options)
|
||||
|
||||
var r0 loadBalancersListAllPager
|
||||
if rf, ok := ret.Get(0).(func(*armnetwork.LoadBalancersListAllOptions) loadBalancersListAllPager); ok {
|
||||
r0 = rf(options)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(loadBalancersListAllPager)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
// Code generated by mockery v0.0.0-dev. DO NOT EDIT.
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
armnetwork "github.com/Azure/azure-sdk-for-go/sdk/network/armnetwork"
|
||||
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// mockLoadBalancersListAllPager is an autogenerated mock type for the loadBalancersListAllPager type
|
||||
type mockLoadBalancersListAllPager struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
// Err provides a mock function with given fields:
|
||||
func (_m *mockLoadBalancersListAllPager) Err() error {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func() error); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// NextPage provides a mock function with given fields: ctx
|
||||
func (_m *mockLoadBalancersListAllPager) NextPage(ctx context.Context) bool {
|
||||
ret := _m.Called(ctx)
|
||||
|
||||
var r0 bool
|
||||
if rf, ok := ret.Get(0).(func(context.Context) bool); ok {
|
||||
r0 = rf(ctx)
|
||||
} else {
|
||||
r0 = ret.Get(0).(bool)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// PageResponse provides a mock function with given fields:
|
||||
func (_m *mockLoadBalancersListAllPager) PageResponse() armnetwork.LoadBalancersListAllResponse {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 armnetwork.LoadBalancersListAllResponse
|
||||
if rf, ok := ret.Get(0).(func() armnetwork.LoadBalancersListAllResponse); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Get(0).(armnetwork.LoadBalancersListAllResponse)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
|
@ -18,6 +18,7 @@ type NetworkRepository interface {
|
|||
ListAllFirewalls() ([]*armnetwork.AzureFirewall, error)
|
||||
ListAllPublicIPAddresses() ([]*armnetwork.PublicIPAddress, error)
|
||||
ListAllSecurityGroups() ([]*armnetwork.NetworkSecurityGroup, error)
|
||||
ListAllLoadBalancers() ([]*armnetwork.LoadBalancer, error)
|
||||
}
|
||||
|
||||
type publicIPAddressesClient interface {
|
||||
|
@ -122,6 +123,23 @@ func (s networkSecurityGroupsClientImpl) ListAll(options *armnetwork.NetworkSecu
|
|||
return s.client.ListAll(options)
|
||||
}
|
||||
|
||||
type loadBalancersListAllPager interface {
|
||||
pager
|
||||
PageResponse() armnetwork.LoadBalancersListAllResponse
|
||||
}
|
||||
|
||||
type loadBalancersClient interface {
|
||||
ListAll(options *armnetwork.LoadBalancersListAllOptions) loadBalancersListAllPager
|
||||
}
|
||||
|
||||
type loadBalancersClientImpl struct {
|
||||
client *armnetwork.LoadBalancersClient
|
||||
}
|
||||
|
||||
func (s loadBalancersClientImpl) ListAll(options *armnetwork.LoadBalancersListAllOptions) loadBalancersListAllPager {
|
||||
return s.client.ListAll(options)
|
||||
}
|
||||
|
||||
type networkRepository struct {
|
||||
virtualNetworksClient virtualNetworksClient
|
||||
routeTableClient routeTablesClient
|
||||
|
@ -129,6 +147,7 @@ type networkRepository struct {
|
|||
firewallsClient firewallsClient
|
||||
publicIPAddressesClient publicIPAddressesClient
|
||||
networkSecurityGroupsClient networkSecurityGroupsClient
|
||||
loadbalancersClient loadBalancersClient
|
||||
cache cache.Cache
|
||||
}
|
||||
|
||||
|
@ -140,6 +159,7 @@ func NewNetworkRepository(con *arm.Connection, config common.AzureProviderConfig
|
|||
&firewallsClientImpl{client: armnetwork.NewAzureFirewallsClient(con, config.SubscriptionID)},
|
||||
&publicIPAddressesClientImpl{client: armnetwork.NewPublicIPAddressesClient(con, config.SubscriptionID)},
|
||||
&networkSecurityGroupsClientImpl{client: armnetwork.NewNetworkSecurityGroupsClient(con, config.SubscriptionID)},
|
||||
&loadBalancersClientImpl{client: armnetwork.NewLoadBalancersClient(con, config.SubscriptionID)},
|
||||
cache,
|
||||
}
|
||||
}
|
||||
|
@ -308,3 +328,27 @@ func (s *networkRepository) ListAllSecurityGroups() ([]*armnetwork.NetworkSecuri
|
|||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (s *networkRepository) ListAllLoadBalancers() ([]*armnetwork.LoadBalancer, error) {
|
||||
cacheKey := "networkListAllLoadBalancers"
|
||||
if v := s.cache.Get(cacheKey); v != nil {
|
||||
return v.([]*armnetwork.LoadBalancer), nil
|
||||
}
|
||||
|
||||
pager := s.loadbalancersClient.ListAll(nil)
|
||||
results := make([]*armnetwork.LoadBalancer, 0)
|
||||
for pager.NextPage(context.Background()) {
|
||||
resp := pager.PageResponse()
|
||||
if err := pager.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
results = append(results, resp.Value...)
|
||||
}
|
||||
|
||||
if err := pager.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.cache.Put(cacheKey, results)
|
||||
return results, nil
|
||||
}
|
||||
|
|
|
@ -969,3 +969,96 @@ func Test_Network_ListAllSecurityGroups(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Network_ListAllLoadBalancers(t *testing.T) {
|
||||
expectedResults := []*armnetwork.LoadBalancer{
|
||||
{
|
||||
Resource: armnetwork.Resource{
|
||||
ID: to.StringPtr("lb-1"),
|
||||
Name: to.StringPtr("lb-1"),
|
||||
},
|
||||
},
|
||||
{
|
||||
Resource: armnetwork.Resource{
|
||||
ID: to.StringPtr("lb-2"),
|
||||
Name: to.StringPtr("lb-2"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
testcases := []struct {
|
||||
name string
|
||||
mocks func(*mockLoadBalancersListAllPager, *cache.MockCache)
|
||||
expected []*armnetwork.LoadBalancer
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
name: "should return load balancers",
|
||||
mocks: func(pager *mockLoadBalancersListAllPager, mockCache *cache.MockCache) {
|
||||
pager.On("NextPage", context.Background()).Return(true).Times(1)
|
||||
pager.On("NextPage", context.Background()).Return(false).Times(1)
|
||||
pager.On("PageResponse").Return(armnetwork.LoadBalancersListAllResponse{
|
||||
LoadBalancersListAllResult: armnetwork.LoadBalancersListAllResult{
|
||||
LoadBalancerListResult: armnetwork.LoadBalancerListResult{
|
||||
Value: expectedResults,
|
||||
},
|
||||
},
|
||||
}).Times(1)
|
||||
pager.On("Err").Return(nil).Times(2)
|
||||
|
||||
mockCache.On("Get", "networkListAllLoadBalancers").Return(nil).Times(1)
|
||||
mockCache.On("Put", "networkListAllLoadBalancers", expectedResults).Return(false).Times(1)
|
||||
},
|
||||
expected: expectedResults,
|
||||
},
|
||||
{
|
||||
name: "should hit cache and return load balancers",
|
||||
mocks: func(pager *mockLoadBalancersListAllPager, mockCache *cache.MockCache) {
|
||||
mockCache.On("Get", "networkListAllLoadBalancers").Return(expectedResults).Times(1)
|
||||
},
|
||||
expected: expectedResults,
|
||||
},
|
||||
{
|
||||
name: "should return remote error",
|
||||
mocks: func(pager *mockLoadBalancersListAllPager, mockCache *cache.MockCache) {
|
||||
pager.On("NextPage", context.Background()).Return(true).Times(1)
|
||||
pager.On("NextPage", context.Background()).Return(false).Times(1)
|
||||
pager.On("PageResponse").Return(armnetwork.LoadBalancersListAllResponse{}).Times(1)
|
||||
pager.On("Err").Return(errors.New("remote error")).Times(1)
|
||||
|
||||
mockCache.On("Get", "networkListAllLoadBalancers").Return(nil).Times(1)
|
||||
},
|
||||
wantErr: "remote error",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range testcases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
fakePager := &mockLoadBalancersListAllPager{}
|
||||
fakeClient := &mockLoadBalancersClient{}
|
||||
mockCache := &cache.MockCache{}
|
||||
|
||||
fakeClient.On("ListAll", (*armnetwork.LoadBalancersListAllOptions)(nil)).Return(fakePager).Maybe()
|
||||
|
||||
tt.mocks(fakePager, mockCache)
|
||||
|
||||
s := &networkRepository{
|
||||
loadbalancersClient: fakeClient,
|
||||
cache: mockCache,
|
||||
}
|
||||
got, err := s.ListAllLoadBalancers()
|
||||
if tt.wantErr != "" {
|
||||
assert.EqualError(t, err, tt.wantErr)
|
||||
} else {
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
fakeClient.AssertExpectations(t)
|
||||
mockCache.AssertExpectations(t)
|
||||
|
||||
if !reflect.DeepEqual(got, tt.expected) {
|
||||
t.Errorf("ListAllLoadBalancers() got = %v, want %v", got, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -789,3 +789,96 @@ func TestAzurermSecurityGroups(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAzurermLoadBalancers(t *testing.T) {
|
||||
|
||||
dummyError := errors.New("this is an error")
|
||||
|
||||
tests := []struct {
|
||||
test string
|
||||
mocks func(*repository.MockNetworkRepository, *mocks.AlerterInterface)
|
||||
assertExpected func(t *testing.T, got []*resource.Resource)
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
test: "no load balancer",
|
||||
mocks: func(repository *repository.MockNetworkRepository, alerter *mocks.AlerterInterface) {
|
||||
repository.On("ListAllLoadBalancers").Return([]*armnetwork.LoadBalancer{}, nil)
|
||||
},
|
||||
assertExpected: func(t *testing.T, got []*resource.Resource) {
|
||||
assert.Len(t, got, 0)
|
||||
},
|
||||
},
|
||||
{
|
||||
test: "error listing load balancers",
|
||||
mocks: func(repository *repository.MockNetworkRepository, alerter *mocks.AlerterInterface) {
|
||||
repository.On("ListAllLoadBalancers").Return(nil, dummyError)
|
||||
},
|
||||
wantErr: error2.NewResourceListingError(dummyError, resourceazure.AzureLoadBalancerResourceType),
|
||||
},
|
||||
{
|
||||
test: "multiple load balancers",
|
||||
mocks: func(repository *repository.MockNetworkRepository, alerter *mocks.AlerterInterface) {
|
||||
repository.On("ListAllLoadBalancers").Return([]*armnetwork.LoadBalancer{
|
||||
{
|
||||
Resource: armnetwork.Resource{
|
||||
ID: to.StringPtr("lb-1"), // Here we don't care to have a valid ID, it is for testing purpose only
|
||||
Name: to.StringPtr("lb-1"),
|
||||
},
|
||||
},
|
||||
{
|
||||
Resource: armnetwork.Resource{
|
||||
ID: to.StringPtr("lb-2"),
|
||||
Name: to.StringPtr("lb-2"),
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
},
|
||||
assertExpected: func(t *testing.T, got []*resource.Resource) {
|
||||
assert.Len(t, got, 2)
|
||||
|
||||
assert.Equal(t, got[0].ResourceId(), "lb-1")
|
||||
assert.Equal(t, got[0].ResourceType(), resourceazure.AzureLoadBalancerResourceType)
|
||||
|
||||
assert.Equal(t, got[1].ResourceId(), "lb-2")
|
||||
assert.Equal(t, got[1].ResourceType(), resourceazure.AzureLoadBalancerResourceType)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
providerVersion := "2.71.0"
|
||||
schemaRepository := testresource.InitFakeSchemaRepository("azurerm", providerVersion)
|
||||
resourceazure.InitResourcesMetadata(schemaRepository)
|
||||
factory := terraform.NewTerraformResourceFactory(schemaRepository)
|
||||
|
||||
for _, c := range tests {
|
||||
t.Run(c.test, func(tt *testing.T) {
|
||||
|
||||
scanOptions := ScannerOptions{}
|
||||
remoteLibrary := common.NewRemoteLibrary()
|
||||
|
||||
// Initialize mocks
|
||||
alerter := &mocks.AlerterInterface{}
|
||||
fakeRepo := &repository.MockNetworkRepository{}
|
||||
c.mocks(fakeRepo, alerter)
|
||||
|
||||
var repo repository.NetworkRepository = fakeRepo
|
||||
|
||||
remoteLibrary.AddEnumerator(azurerm.NewAzurermLoadBalancerEnumerator(repo, factory))
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
c.assertExpected(tt, got)
|
||||
alerter.AssertExpectations(tt)
|
||||
fakeRepo.AssertExpectations(tt)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package azurerm
|
||||
|
||||
import "github.com/cloudskiff/driftctl/pkg/resource"
|
||||
|
||||
const AzureLoadBalancerResourceType = "azurerm_lb"
|
||||
|
||||
func initAzureLoadBalancerMetadata(resourceSchemaRepository resource.SchemaRepositoryInterface) {
|
||||
resourceSchemaRepository.SetHumanReadableAttributesFunc(AzureLoadBalancerResourceType, 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
|
||||
}
|
||||
return attrs
|
||||
})
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package azurerm_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cloudskiff/driftctl/test"
|
||||
"github.com/cloudskiff/driftctl/test/acceptance"
|
||||
)
|
||||
|
||||
func TestAcc_Azure_LoadBalancers(t *testing.T) {
|
||||
acceptance.Run(t, acceptance.AccTestCase{
|
||||
TerraformVersion: "0.15.5",
|
||||
Paths: []string{"./testdata/acc/azurerm_lb"},
|
||||
Args: []string{
|
||||
"scan",
|
||||
"--to", "azure+tf",
|
||||
},
|
||||
Checks: []acceptance.AccCheck{
|
||||
{
|
||||
Check: func(result *test.ScanResult, stdout string, err error) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result.AssertInfrastructureIsInSync()
|
||||
result.AssertManagedCount(1)
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -13,4 +13,5 @@ func InitResourcesMetadata(resourceSchemaRepository resource.SchemaRepositoryInt
|
|||
initAzurePublicIPMetadata(resourceSchemaRepository)
|
||||
initAzurePostgresqlDatabaseMetadata(resourceSchemaRepository)
|
||||
initAzureNetworkSecurityGroupMetadata(resourceSchemaRepository)
|
||||
initAzureLoadBalancerMetadata(resourceSchemaRepository)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!azurerm_lb
|
|
@ -0,0 +1,39 @@
|
|||
# This file is maintained automatically by "terraform init".
|
||||
# Manual edits may be lost in future updates.
|
||||
|
||||
provider "registry.terraform.io/hashicorp/azurerm" {
|
||||
version = "2.71.0"
|
||||
constraints = "~> 2.71.0"
|
||||
hashes = [
|
||||
"h1:RiFIxNI4Yr9CqleqEdgg1ydLAZ5JiYiz6l5iTD3WcuU=",
|
||||
"zh:2b9d8a703a0222f72cbceb8d2bdb580066afdcd7f28b6ad65d5ed935319b5433",
|
||||
"zh:332988f4c1747bcc8ebd32734bf8de2bea4c13a6fbd08d7eb97d0c43d335b15e",
|
||||
"zh:3a902470276ba48e23ad4dd6baff16a9ce3b60b29c0b07064dbe96ce4640a31c",
|
||||
"zh:5eaa0d0c2c6554913421be10fbf4bb6a9ef98fbbd750d3d1f02c99798aae2c22",
|
||||
"zh:67859f40ed2f770f33ace9d3911e8b9c9be505947b38a0578e6d097f5db1d4bf",
|
||||
"zh:7cd9bf4899fe383fc7eeede03cad138d637244878cd295a7a1044ca20ca0652c",
|
||||
"zh:afcb82c1382a1a9d63a41137321e077144aad768e4e46057a7ea604d067b4181",
|
||||
"zh:c6e358759ed00a628dcfe7adb0906b2c98576ac3056fdd70930786d404e1da66",
|
||||
"zh:cb3390c34f6790ad656929d0268ab3bc082678e8cbe2add0a177cf7896068844",
|
||||
"zh:cc213dbf59cf41506e86b83492ccfef6ef5f34d4d00d9e49fc8a01fee253f4ee",
|
||||
"zh:d1e8c9b507e2d187ea2447ae156028ba3f76db2164674761987c14217d04fee5",
|
||||
]
|
||||
}
|
||||
|
||||
provider "registry.terraform.io/hashicorp/random" {
|
||||
version = "3.1.0"
|
||||
hashes = [
|
||||
"h1:BZMEPucF+pbu9gsPk0G0BHx7YP04+tKdq2MrRDF1EDM=",
|
||||
"zh:2bbb3339f0643b5daa07480ef4397bd23a79963cc364cdfbb4e86354cb7725bc",
|
||||
"zh:3cd456047805bf639fbf2c761b1848880ea703a054f76db51852008b11008626",
|
||||
"zh:4f251b0eda5bb5e3dc26ea4400dba200018213654b69b4a5f96abee815b4f5ff",
|
||||
"zh:7011332745ea061e517fe1319bd6c75054a314155cb2c1199a5b01fe1889a7e2",
|
||||
"zh:738ed82858317ccc246691c8b85995bc125ac3b4143043219bd0437adc56c992",
|
||||
"zh:7dbe52fac7bb21227acd7529b487511c91f4107db9cc4414f50d04ffc3cab427",
|
||||
"zh:a3a9251fb15f93e4cfc1789800fc2d7414bbc18944ad4c5c98f466e6477c42bc",
|
||||
"zh:a543ec1a3a8c20635cf374110bd2f87c07374cf2c50617eee2c669b3ceeeaa9f",
|
||||
"zh:d9ab41d556a48bd7059f0810cf020500635bfc696c9fc3adab5ea8915c1d886b",
|
||||
"zh:d9e13427a7d011dbd654e591b0337e6074eef8c3b9bb11b2e39eaaf257044fd7",
|
||||
"zh:f7605bd1437752114baf601bdf6931debe6dc6bfe3006eb7e9bb9080931dca8a",
|
||||
]
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
azurerm = {
|
||||
source = "hashicorp/azurerm"
|
||||
version = "~> 2.71.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "azurerm" {
|
||||
features {}
|
||||
}
|
||||
|
||||
data "azurerm_resource_group" "qa1" {
|
||||
name = "driftctl-qa-1"
|
||||
}
|
||||
|
||||
resource "random_uuid" "rgId" {}
|
||||
|
||||
resource "azurerm_resource_group" "default" {
|
||||
name = "AccLoadBalancerRG-${random_uuid.rgId.result}"
|
||||
location = "West Europe"
|
||||
}
|
||||
|
||||
resource "azurerm_public_ip" "default" {
|
||||
name = "AccPublicIPForLB"
|
||||
location = "West US"
|
||||
resource_group_name = azurerm_resource_group.default.name
|
||||
allocation_method = "Static"
|
||||
}
|
||||
|
||||
resource "azurerm_lb" "default" {
|
||||
name = "AccTestLoadBalancer-7128046527"
|
||||
location = "West US"
|
||||
resource_group_name = azurerm_resource_group.default.name
|
||||
|
||||
frontend_ip_configuration {
|
||||
name = "PublicIPAddress"
|
||||
public_ip_address_id = azurerm_public_ip.default.id
|
||||
}
|
||||
}
|
|
@ -178,6 +178,7 @@ var supportedTypes = map[string]ResourceTypeMeta{
|
|||
"azurerm_postgresql_database": {},
|
||||
"azurerm_public_ip": {},
|
||||
"azurerm_network_security_group": {},
|
||||
"azurerm_lb": {},
|
||||
}
|
||||
|
||||
func IsResourceTypeSupported(ty string) bool {
|
||||
|
|
Loading…
Reference in New Issue