Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config.Provider.GetSkippedResourceNames #137

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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