2021-03-01 15:04:43 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/aws/aws-sdk-go/service/lambda"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
|
|
|
|
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
|
|
|
resourceaws "github.com/cloudskiff/driftctl/pkg/resource/aws"
|
2021-05-21 14:09:45 +00:00
|
|
|
|
2021-03-01 15:04:43 +00:00
|
|
|
"github.com/cloudskiff/driftctl/pkg/terraform"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LambdaEventSourceMappingSupplier struct {
|
|
|
|
reader terraform.ResourceReader
|
2021-05-21 14:09:45 +00:00
|
|
|
deserializer *resource.Deserializer
|
2021-03-01 15:04:43 +00:00
|
|
|
client repository.LambdaRepository
|
|
|
|
runner *terraform.ParallelResourceReader
|
|
|
|
}
|
|
|
|
|
2021-05-31 15:39:16 +00:00
|
|
|
func NewLambdaEventSourceMappingSupplier(provider *AWSTerraformProvider, deserializer *resource.Deserializer, repo repository.LambdaRepository) *LambdaEventSourceMappingSupplier {
|
2021-03-01 15:04:43 +00:00
|
|
|
return &LambdaEventSourceMappingSupplier{
|
|
|
|
provider,
|
2021-05-21 14:09:45 +00:00
|
|
|
deserializer,
|
2021-05-31 15:39:16 +00:00
|
|
|
repo,
|
2021-03-01 15:04:43 +00:00
|
|
|
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-17 15:54:53 +00:00
|
|
|
func (s *LambdaEventSourceMappingSupplier) Resources() ([]resource.Resource, error) {
|
2021-03-01 15:04:43 +00:00
|
|
|
functions, err := s.client.ListAllLambdaEventSourceMappings()
|
|
|
|
if err != nil {
|
|
|
|
return nil, remoteerror.NewResourceEnumerationError(err, resourceaws.AwsLambdaEventSourceMappingResourceType)
|
|
|
|
}
|
|
|
|
var results []cty.Value
|
|
|
|
for _, function := range functions {
|
|
|
|
fun := *function
|
|
|
|
s.runner.Run(func() (cty.Value, error) {
|
|
|
|
return s.readLambdaEventSourceMapping(fun)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
results, err = s.runner.Wait()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-21 14:09:45 +00:00
|
|
|
return s.deserializer.Deserialize(resourceaws.AwsLambdaEventSourceMappingResourceType, results)
|
2021-03-01 15:04:43 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 15:54:53 +00:00
|
|
|
func (s *LambdaEventSourceMappingSupplier) readLambdaEventSourceMapping(sourceMappingConfig lambda.EventSourceMappingConfiguration) (cty.Value, error) {
|
2021-03-01 15:04:43 +00:00
|
|
|
resFunction, err := s.reader.ReadResource(
|
|
|
|
terraform.ReadResourceArgs{
|
|
|
|
Ty: resourceaws.AwsLambdaEventSourceMappingResourceType,
|
|
|
|
ID: *sourceMappingConfig.UUID,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Warnf("Error reading %s: %+v", resourceaws.AwsLambdaEventSourceMappingResourceType, err)
|
|
|
|
return cty.NilVal, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return *resFunction, nil
|
|
|
|
}
|