Skip to content

chore: track terraform module source type in telemetry #15590

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

Merged
merged 3 commits into from
Nov 20, 2024

Conversation

hugodutka
Copy link
Contributor

@hugodutka hugodutka marked this pull request as ready for review November 19, 2024 11:38
@hugodutka hugodutka requested a review from johnstcn November 19, 2024 11:38
ModuleSourceTypeUnknown ModuleSourceType = "unknown"
)

func GetModuleSourceType(source string) ModuleSourceType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good for future readers to add a doc comment to this function along with a link to https://developer.hashicorp.com/terraform/language/modules/sources, as they may have some similar questions to me before reading:

  • Wait, these aren't just URLS?! Nope.
  • There's difference between how relative and absolute local paths are handled? yup
  • Wait, you can have "localterraform.com" as a generic "local" hostname? yup
  • Wait, you can just use an un-prefixed GitHub registry as a module source? yup
  • etc...

Comment on lines 742 to 744
if !strings.Contains(source, "://") && !strings.Contains(source, ".") && strings.Contains(source, "/") {
return ModuleSourceTypePublicRegistry
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we tighten this condition up a bit and assert that it follows the form namespace/name/provider? And maybe move it up slightly?

@hugodutka
Copy link
Contributor Author

@johnstcn I made changes according to your feedback. Thanks!

Comment on lines +757 to +765
if strings.Contains(source, "registry.terraform.io") {
return ModuleSourceTypePublicRegistry
}
if strings.Contains(source, "app.terraform.io") || strings.Contains(source, "localterraform.com") {
return ModuleSourceTypePrivateRegistry
}
if strings.Contains(source, "registry.coder.com") {
return ModuleSourceTypeCoderRegistry
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about registry.coder.com.mydomain.foo.bar? Should we instead use strings.HasPrefix here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnstcn I wasn't aware that people could access the coder registry that way. How does this work? Can people self-host our registry?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I write this, I realise that prefix-checking won't even help here unless we attempt to parse the module as an URL and extract only the hostname.

In any case, I don't see any reason that someone sufficiently motiviated couldn't do this if they controlled the domain mydomain.foo.bar and used something like outsiders/citizen to self-host a registry.

It's more of a contrived hypothetical though and I'm not going to block on this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's acceptable to misclassify a small percentage of modules. With telemetry, we’re more focused on aggregates, and cases like this are unlikely to affect the overall picture.

require.Equal(t, modules[1].Source, "registry.coder.com/terraform/aws")
require.Equal(t, modules[1].Version, "1.0.0")
require.Equal(t, modules[1].SourceType, telemetry.ModuleSourceTypeCoderRegistry)
})
t.Run("ModuleSourceType", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: nice test coverage!

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last comment but I don't need to re-review.

@hugodutka hugodutka merged commit 97ce44a into main Nov 20, 2024
26 checks passed
@hugodutka hugodutka deleted the hugodutka/module-source-type branch November 20, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants