driftctl/pkg/remote/github/github_team_membership_supp...

60 lines
1.8 KiB
Go
Raw Normal View History

2021-03-01 12:39:00 +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 GithubTeamMembershipSupplier struct {
reader terraform.ResourceReader
2021-05-21 14:09:45 +00:00
deserializer *resource.Deserializer
2021-03-01 12:39:00 +00:00
repository GithubRepository
runner *terraform.ParallelResourceReader
}
2021-05-21 14:09:45 +00:00
func NewGithubTeamMembershipSupplier(provider *GithubTerraformProvider, repository GithubRepository, deserializer *resource.Deserializer) *GithubTeamMembershipSupplier {
2021-03-01 12:39:00 +00:00
return &GithubTeamMembershipSupplier{
provider,
2021-05-21 14:09:45 +00:00
deserializer,
2021-03-01 12:39:00 +00:00
repository,
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
}
}
func (s GithubTeamMembershipSupplier) Resources() ([]resource.Resource, error) {
resourceList, err := s.repository.ListTeamMemberships()
if err != nil {
return nil, remoteerror.NewResourceEnumerationError(err, resourcegithub.GithubTeamMembershipResourceType)
}
for _, id := range resourceList {
id := id
s.runner.Run(func() (cty.Value, error) {
return s.readTeamMembership(id)
})
}
results, err := s.runner.Wait()
if err != nil {
return nil, err
}
2021-05-21 14:09:45 +00:00
return s.deserializer.Deserialize(resourcegithub.GithubTeamMembershipResourceType, results)
2021-03-01 12:39:00 +00:00
}
func (s GithubTeamMembershipSupplier) readTeamMembership(id string) (cty.Value, error) {
val, err := s.reader.ReadResource(terraform.ReadResourceArgs{
ID: id,
Ty: resourcegithub.GithubTeamMembershipResourceType,
})
if err != nil {
logrus.Warnf("Error reading %s[%s]: %+v", id, resourcegithub.GithubTeamMembershipResourceType, err)
return cty.NilVal, err
}
return *val, nil
}