2020-12-09 15:31:34 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
2021-02-24 16:29:57 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
|
2020-12-09 15:31:34 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/remote/deserializer"
|
2021-01-20 13:01:57 +00:00
|
|
|
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
|
2020-12-09 15:31:34 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource/aws"
|
|
|
|
awsdeserializer "github.com/cloudskiff/driftctl/pkg/resource/aws/deserializer"
|
|
|
|
"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
|
|
|
|
deserializer deserializer.CTYDeserializer
|
2021-02-24 16:29:57 +00:00
|
|
|
client repository.RDSRepository
|
2020-12-09 15:31:34 +00:00
|
|
|
runner *terraform.ParallelResourceReader
|
|
|
|
}
|
|
|
|
|
2021-02-09 13:56:11 +00:00
|
|
|
func NewDBSubnetGroupSupplier(provider *AWSTerraformProvider) *DBSubnetGroupSupplier {
|
2020-12-09 15:31:34 +00:00
|
|
|
return &DBSubnetGroupSupplier{
|
2021-01-22 17:06:17 +00:00
|
|
|
provider,
|
2020-12-09 15:31:34 +00:00
|
|
|
awsdeserializer.NewDBSubnetGroupDeserializer(),
|
2021-02-24 16:29:57 +00:00
|
|
|
repository.NewRDSRepository(provider.session),
|
2021-01-22 17:06:17 +00:00
|
|
|
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
|
2020-12-09 15:31:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-17 15:54:53 +00:00
|
|
|
func (s *DBSubnetGroupSupplier) Resources() ([]resource.Resource, error) {
|
2020-12-09 15:31:34 +00:00
|
|
|
|
2021-02-24 16:29:57 +00:00
|
|
|
subnetGroups, err := s.client.ListAllDbSubnetGroups()
|
2020-12-09 15:31:34 +00:00
|
|
|
|
|
|
|
if err != nil {
|
2021-01-20 13:01:57 +00:00
|
|
|
return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsDbSubnetGroupResourceType)
|
2020-12-09 15:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
return s.deserializer.Deserialize(ctyValues)
|
|
|
|
}
|
|
|
|
|
2021-03-17 15:54:53 +00:00
|
|
|
func (s *DBSubnetGroupSupplier) readSubnetGroup(subnetGroup rds.DBSubnetGroup) (cty.Value, error) {
|
2020-12-09 15:31:34 +00:00
|
|
|
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
|
|
|
|
}
|