driftctl/pkg/remote/github/github_membership_supplier.go

58 lines
1.6 KiB
Go
Raw Normal View History

2021-02-26 15:12:27 +00:00
package github
import (
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
"github.com/cloudskiff/driftctl/pkg/resource"
resourcegithub "github.com/cloudskiff/driftctl/pkg/resource/github"
"github.com/cloudskiff/driftctl/pkg/terraform"
"github.com/sirupsen/logrus"
"github.com/zclconf/go-cty/cty"
)
type GithubMembershipSupplier struct {
reader terraform.ResourceReader
2021-05-21 14:09:45 +00:00
deserializer *resource.Deserializer
2021-02-26 15:12:27 +00:00
repository GithubRepository
runner *terraform.ParallelResourceReader
}
2021-05-21 14:09:45 +00:00
func NewGithubMembershipSupplier(provider *GithubTerraformProvider, repository GithubRepository, deserializer *resource.Deserializer) *GithubMembershipSupplier {
2021-02-26 15:12:27 +00:00
return &GithubMembershipSupplier{
provider,
2021-05-21 14:09:45 +00:00
deserializer,
2021-02-26 15:12:27 +00:00
repository,
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
}
}
func (s GithubMembershipSupplier) Resources() ([]resource.Resource, error) {
resourceList, err := s.repository.ListMembership()
if err != nil {
return nil, remoteerror.NewResourceEnumerationError(err, resourcegithub.GithubMembershipResourceType)
}
for _, id := range resourceList {
id := id
s.runner.Run(func() (cty.Value, error) {
completeResource, err := s.reader.ReadResource(terraform.ReadResourceArgs{
Ty: resourcegithub.GithubMembershipResourceType,
ID: id,
})
if err != nil {
logrus.Warnf("Error reading %s[%s]: %+v", id, resourcegithub.GithubMembershipResourceType, err)
return cty.NilVal, err
}
return *completeResource, nil
})
}
results, err := s.runner.Wait()
if err != nil {
return nil, err
}
2021-05-21 14:09:45 +00:00
return s.deserializer.Deserialize(resourcegithub.GithubMembershipResourceType, results)
2021-02-26 15:12:27 +00:00
}