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

Proposal for improving terraform taggable resources list #374

Closed
lonegunmanb opened this issue May 24, 2023 · 7 comments
Closed

Proposal for improving terraform taggable resources list #374

lonegunmanb opened this issue May 24, 2023 · 7 comments
Labels
wontfix This will not be worked on

Comments

@lonegunmanb
Copy link
Contributor

lonegunmanb commented May 24, 2023

I found that the azurerm resources from the taggable resource list are not update-to-date. It's very difficult to maintain this list manually every time a new provider version has been released. I assume that we also have the same problem with aws and gcp resources.

I have a personal repo named terraform-azurerm-schema, it runs terraform providers schema command and extracts resource schemas returned by Terraform provider plugin, convert the schemas into go code. With the help of this library, I can detect the missing resources by the following test (that's how I compose #373 and #371):

package structure

import (
	"strings"
	"testing"

	schema "github.com/lonegunmanb/terraform-azurerm-schema/v3/generated"
)

func TestMissingTaggableAzureResource(t *testing.T) {
	taggableAzureResource := make(map[string]struct{}, 0)
	for _, r := range TfTaggableResourceTypes {
		if strings.HasPrefix(r, "azurerm_") {
			taggableAzureResource[r] = struct{}{}
		}
	}
	for name, r := range schema.Resources {
		_, ok := r.Block.Attributes["tags"]
		if !ok {
			continue
		}
		_, ok = taggableAzureResource[name]
		if !ok {
			t.Errorf("%s should be taggable", name)
		}
	}
}

We can access any resources by calling the generated go code. I'd like to improve yor by two possible ways:

  1. Add unit tests to ensure that the current taggable resources list is correct.
  2. Replace the current static taggable resources list by calling the generated go code.

Now I have the schema repo for the following provider:

  • azurerm
  • time
  • local
  • random
  • azuread
  • null
  • tls

I can add aws and gcp schema repo. All schema repos have cronjob that checks whether there's new version every 6 hours. Once a new provider version has been released, a corresponding schema tag version would be generated and published.

I'd like to hear your thought @nimrodkor @gruebel

@nimrodkor
Copy link
Contributor

Very interesting @lonegunmanb !
I'd love this as a contribution, i.e. your 2nd suggestion. 1 would cause failure unrelated to code changes, which is less nice... :)
Of course you would need to add AWS, GCP support. And we will need to support the existing blocklisting mechanic, as some tags are not the regular tags / the documentation and provider are sometimes out of line.

@lonegunmanb
Copy link
Contributor Author

Glad to hear that you like this idea, I'll study the blocklisting mechanic. aws and gcp schema repos are easy to create, I'll create these two schema repos very soon.

@lonegunmanb
Copy link
Contributor Author

Another thought just jumped in @nimrodkor, every time a provider released a new major version, a lot of deprecated resources would be removed. If we depend on the latest schema only, yor could not generate tags for those old deprecated resources.

I would recommend we hardcode a static taggable resource list for previous major version when a new major version has been released, and we combine these list items together so yor can work for all major versions.

@stale
Copy link

stale bot commented Jun 24, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jun 24, 2023
@lonegunmanb
Copy link
Contributor Author

Please keep it open as we're waiting for go-git's upgrade.

@stale stale bot removed the wontfix This will not be worked on label Jun 25, 2023
@stale
Copy link

stale bot commented Jul 26, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jul 26, 2023
@lonegunmanb
Copy link
Contributor Author

Please keep it open, thanks.

@stale stale bot closed this as completed Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants