driftctl/pkg/remote/github/github_team_supplier.go

60 lines
1.6 KiB
Go
Raw Normal View History

2021-02-24 12:55:26 +00:00
package github
import (
"fmt"
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 GithubTeamSupplier struct {
reader terraform.ResourceReader
2021-05-21 14:09:45 +00:00
deserializer *resource.Deserializer
2021-02-24 12:55:26 +00:00
repository GithubRepository
runner *terraform.ParallelResourceReader
}
2021-05-21 14:09:45 +00:00
func NewGithubTeamSupplier(provider *GithubTerraformProvider, repository GithubRepository, deserializer *resource.Deserializer) *GithubTeamSupplier {
2021-02-24 12:55:26 +00:00
return &GithubTeamSupplier{
provider,
2021-05-21 14:09:45 +00:00
deserializer,
2021-02-24 12:55:26 +00:00
repository,
terraform.NewParallelResourceReader(provider.Runner().SubRunner()),
}
}
func (s GithubTeamSupplier) Resources() ([]resource.Resource, error) {
resourceList, err := s.repository.ListTeams()
if err != nil {
return nil, remoteerror.NewResourceEnumerationError(err, resourcegithub.GithubTeamResourceType)
}
2021-03-01 12:39:00 +00:00
for _, team := range resourceList {
team := team
2021-02-24 12:55:26 +00:00
s.runner.Run(func() (cty.Value, error) {
completeResource, err := s.reader.ReadResource(terraform.ReadResourceArgs{
Ty: resourcegithub.GithubTeamResourceType,
2021-03-01 12:39:00 +00:00
ID: fmt.Sprintf("%d", team.DatabaseId),
2021-02-24 12:55:26 +00:00
})
if err != nil {
2021-03-01 12:39:00 +00:00
logrus.Warnf("Error reading %d[%s]: %+v", team.DatabaseId, resourcegithub.GithubTeamResourceType, err)
2021-02-24 12:55:26 +00:00
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.GithubTeamResourceType, results)
2021-02-24 12:55:26 +00:00
}