Skip to content

Commit

Permalink
Merge pull request #137 from ulucinar/fix-867
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanduplessis authored Nov 11, 2022
2 parents d9f4624 + df1b435 commit 6de200a
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pkg/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ type Provider struct {
// can add "aws_waf.*" to the list.
SkipList []string

// skippedResourceNames is a list of Terraform resource names
// available in the Terraform provider schema, but
// not in the include list or in the skip list, meaning that
// the corresponding managed resources are not generated.
skippedResourceNames []string

// IncludeList is a list of regex for the Terraform resources to be
// included. For example, to include "aws_shield_protection_group" into
// the generated resources, one can add "aws_shield_protection_group$".
Expand Down Expand Up @@ -207,19 +213,16 @@ func NewProvider(schema []byte, prefix string, modulePath string, metadata []byt
o(p)
}

p.skippedResourceNames = make([]string, 0, len(resourceMap))
for name, terraformResource := range resourceMap {
if len(terraformResource.Schema) == 0 {
// There are resources with no schema, that we will address later.
fmt.Printf("Skipping resource %s because it has no schema\n", name)
continue
}
if matches(name, p.SkipList) {
continue
}
if !matches(name, p.IncludeList) {
if len(terraformResource.Schema) == 0 || matches(name, p.SkipList) || !matches(name, p.IncludeList) {
p.skippedResourceNames = append(p.skippedResourceNames, name)
continue
}

p.Resources[name] = DefaultResource(name, terraformResource, providerMetadata.Resources[name], p.DefaultResourceOptions...)
}
for i, refInjector := range p.refInjectors {
Expand Down Expand Up @@ -255,6 +258,14 @@ func (p *Provider) ConfigureResources() {
}
}

// GetSkippedResourceNames returns a list of Terraform resource names
// available in the Terraform provider schema, but
// not in the include list or in the skip list, meaning that
// the corresponding managed resources are not generated.
func (p *Provider) GetSkippedResourceNames() []string {
return p.skippedResourceNames
}

func matches(name string, regexList []string) bool {
for _, r := range regexList {
ok, err := regexp.MatchString(r, name)
Expand Down

0 comments on commit 6de200a

Please sign in to comment.