driftctl/pkg/remote/aws/route53_health_check_suppli...

64 lines
1.8 KiB
Go
Raw Normal View History

2021-02-15 20:00:16 +00:00
package aws
import (
"github.com/aws/aws-sdk-go/service/route53"
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
"github.com/sirupsen/logrus"
"github.com/zclconf/go-cty/cty"
"github.com/cloudskiff/driftctl/pkg/resource"
"github.com/cloudskiff/driftctl/pkg/resource/aws"
2021-05-21 14:09:45 +00:00
2021-02-15 20:00:16 +00:00
"github.com/cloudskiff/driftctl/pkg/terraform"
)
type Route53HealthCheckSupplier struct {
reader terraform.ResourceReader
2021-05-21 14:09:45 +00:00
deserializer *resource.Deserializer
2021-02-15 20:00:16 +00:00
client repository.Route53Repository
runner *terraform.ParallelResourceReader
}
2021-05-31 15:39:16 +00:00
func NewRoute53HealthCheckSupplier(provider *AWSTerraformProvider, deserializer *resource.Deserializer, repo repository.Route53Repository) *Route53HealthCheckSupplier {
2021-02-15 20:00:16 +00:00
return &Route53HealthCheckSupplier{
provider,
2021-05-21 14:09:45 +00:00
deserializer,
2021-05-31 15:39:16 +00:00
repo,
2021-02-15 20:00:16 +00:00
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
}
}
func (s *Route53HealthCheckSupplier) Resources() ([]resource.Resource, error) {
2021-02-15 20:00:16 +00:00
healthChecks, err := s.client.ListAllHealthChecks()
if err != nil {
return nil, remoteerror.NewResourceEnumerationError(err, aws.AwsRoute53HealthCheckResourceType)
}
for _, healthCheck := range healthChecks {
healthCheck := healthCheck
s.runner.Run(func() (cty.Value, error) {
return s.readHealthCheck(healthCheck)
})
}
retrieve, err := s.runner.Wait()
if err != nil {
return nil, err
}
2021-05-21 14:09:45 +00:00
return s.deserializer.Deserialize(aws.AwsRoute53HealthCheckResourceType, retrieve)
2021-02-15 20:00:16 +00:00
}
func (s *Route53HealthCheckSupplier) readHealthCheck(healthCheck *route53.HealthCheck) (cty.Value, error) {
2021-02-15 20:00:16 +00:00
val, err := s.reader.ReadResource(terraform.ReadResourceArgs{
ID: *healthCheck.Id,
Ty: aws.AwsRoute53HealthCheckResourceType,
})
if err != nil {
logrus.Error(err)
return cty.NilVal, err
}
return *val, nil
}