driftctl/pkg/remote/aws/db_subnet_group_supplier.go

66 lines
1.7 KiB
Go
Raw Normal View History

package aws
import (
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
"github.com/cloudskiff/driftctl/pkg/resource/aws"
2021-05-21 14:09:45 +00:00
"github.com/zclconf/go-cty/cty"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/cloudskiff/driftctl/pkg/resource"
"github.com/cloudskiff/driftctl/pkg/terraform"
"github.com/sirupsen/logrus"
)
type DBSubnetGroupSupplier struct {
reader terraform.ResourceReader
2021-05-21 14:09:45 +00:00
deserializer *resource.Deserializer
client repository.RDSRepository
runner *terraform.ParallelResourceReader
}
2021-05-31 15:39:16 +00:00
func NewDBSubnetGroupSupplier(provider *AWSTerraformProvider, deserializer *resource.Deserializer, repo repository.RDSRepository) *DBSubnetGroupSupplier {
return &DBSubnetGroupSupplier{
provider,
2021-05-21 14:09:45 +00:00
deserializer,
2021-05-31 15:39:16 +00:00
repo,
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
}
}
func (s *DBSubnetGroupSupplier) Resources() ([]resource.Resource, error) {
subnetGroups, err := s.client.ListAllDbSubnetGroups()
if err != nil {
return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsDbSubnetGroupResourceType)
}
for _, subnetGroup := range subnetGroups {
sub := *subnetGroup
s.runner.Run(func() (cty.Value, error) {
return s.readSubnetGroup(sub)
})
}
ctyValues, err := s.runner.Wait()
if err != nil {
return nil, err
}
2021-05-21 14:09:45 +00:00
return s.deserializer.Deserialize(aws.AwsDbSubnetGroupResourceType, ctyValues)
}
func (s *DBSubnetGroupSupplier) readSubnetGroup(subnetGroup rds.DBSubnetGroup) (cty.Value, error) {
val, err := s.reader.ReadResource(terraform.ReadResourceArgs{
ID: *subnetGroup.DBSubnetGroupName,
Ty: aws.AwsDbSubnetGroupResourceType,
})
if err != nil {
logrus.Error(err)
return cty.NilVal, err
}
return *val, nil
}