driftctl/pkg/remote/azurerm/azurerm_resource_group_enum...

48 lines
1.2 KiB
Go
Raw Normal View History

2021-10-04 10:40:55 +00:00
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 AzurermResourceGroupEnumerator struct {
repository repository.ResourcesRepository
factory resource.ResourceFactory
}
func NewAzurermResourceGroupEnumerator(repo repository.ResourcesRepository, factory resource.ResourceFactory) *AzurermResourceGroupEnumerator {
return &AzurermResourceGroupEnumerator{
repository: repo,
factory: factory,
}
}
func (e *AzurermResourceGroupEnumerator) SupportedType() resource.ResourceType {
return azurerm.AzureResourceGroupResourceType
}
func (e *AzurermResourceGroupEnumerator) Enumerate() ([]*resource.Resource, error) {
groups, err := e.repository.ListAllResourceGroups()
if err != nil {
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
}
results := make([]*resource.Resource, 0)
for _, group := range groups {
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
*group.ID,
map[string]interface{}{
"name": *group.Name,
},
),
)
}
return results, err
}