Skip to content

command: terraform providers mirror#25084

Merged
apparentlymart merged 3 commits intomasterfrom
f-cmd-providers-mirror
Jun 1, 2020
Merged

command: terraform providers mirror#25084
apparentlymart merged 3 commits intomasterfrom
f-cmd-providers-mirror

Conversation

@apparentlymart
Copy link
Copy Markdown
Contributor

This new command is intended to make it easy to create or update a mirror directory containing suitable providers for the current configuration, producing a layout that is appropriate both for a filesystem mirror or, if copied into the document root of an HTTP server, a network mirror. (Network mirrors are not yet supported by Terraform for installation, so that part is more aspirational but the directory structures are compatible in any case.)

This initial version is not customizable aside from being able to select multiple platforms to install packages for.

Future iterations of this could include commands to turn the JSON index generation on and off, or to instruct it to produce the unpacked directory layout instead of the packed directory layout as it currently does. Both of those options would make the generated directory unsuitable to be a network mirror, but it would still work as a filesystem mirror.

In the long run this will hopefully form part of a replacement workflow to terraform-bundle as a way to put copies of providers somewhere so we don't need to re-download them every time, but some other changes will be needed outside of just this command before that'd be true, such as adding support for network and/or filesystem mirrors in Terraform Enterprise.

(I originally wrote this as a way to make it easier for me to test filesystem and network mirrors during development, so I had originally intended it to land as part of adding support for network mirrors. However, in retrospect it seems useful in already as a helper for building filesystem mirrors, so I'm submitting it now to avoid it getting lost and forgotten in a random branch.)

@apparentlymart apparentlymart requested a review from a team May 29, 2020 22:38
@apparentlymart apparentlymart self-assigned this May 29, 2020
@codecov
Copy link
Copy Markdown

codecov bot commented May 29, 2020

Codecov Report

Merging #25084 into master will decrease coverage by 0.24%.
The diff coverage is 1.50%.

Impacted Files Coverage Δ
command/providers_mirror.go 0.00% <0.00%> (ø)
commands.go 1.02% <0.00%> (-0.02%) ⬇️
internal/getproviders/filesystem_search.go 62.18% <0.00%> (-3.31%) ⬇️
internal/getproviders/hash.go 0.00% <0.00%> (ø)
internal/getproviders/types.go 38.84% <0.00%> (-0.66%) ⬇️
internal/providercache/cached_provider.go 75.00% <80.00%> (+12.50%) ⬆️
dag/marshal.go 52.27% <0.00%> (-1.14%) ⬇️
states/statefile/version4.go 56.44% <0.00%> (+0.28%) ⬆️
... and 1 more

@apparentlymart apparentlymart force-pushed the f-cmd-providers-mirror branch from db3fe91 to a848c0d Compare May 29, 2020 23:04
// The tests in this file are for the "terraform providers schema" command,
// which is tested in an e2etest mode rather than a unit test mode because it
// interacts directly with Terraform Registry and the full details of that are
// tricky to mock. Such a mock is _possible_, but we're using e2etest as a
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not at all opposed to this e2e test, but just so you know we recently added a testRegistrySource helper function in the command package:

// testRegistrySource is a wrapper around testServices that uses the created

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This particular one is expecting to be talking always to upstream registries (so you don't have to unconfigure your mirrors just to populate them), so it wasn't very amenable to that sort of mocking. I did have an earlier version that created a mock registry on a fake domain and forced use of it via service discovery, but that required the fake providers to be properly signed and that was a little too complex to set up in a reasonable amount of time to get this done right now. Maybe in a later commit!

Copy link
Copy Markdown
Contributor

@alisdair alisdair left a comment

Choose a reason for hiding this comment

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

I think I spotted a couple of typos, otherwise looks great! Thanks as always for the excellent inline comments.

"github.com/hashicorp/terraform/e2e"
)

// The tests in this file are for the "terraform providers schema" command,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// The tests in this file are for the "terraform providers schema" command,
// The tests in this file are for the "terraform providers mirror" command,

Typo?

that will be used as a local filesystem mirror in the provider installation
configuration.

-> `terraform providers schema` is available only in Terraform v0.13 or later.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
-> `terraform providers schema` is available only in Terraform v0.13 or later.
-> `terraform providers mirror` is available only in Terraform v0.13 or later.

@apparentlymart
Copy link
Copy Markdown
Contributor Author

Heh... thanks for catching those typos @alisdair! I think by the end of the day on Friday I had lost the ability to distinguish those two command lines. I'll fix those before merging.

We previously had this functionality available for cached packages in the
providercache package. This moves the main implementation of this over
to the getproviders package and then implements it also for PackageMeta,
allowing us to compute hashes in a consistent way across both of our
representations of a provider package.

The new methods on PackageMeta will only be effective for packages in the
local filesystem because we need direct access to the contents in order
to produce the hash. Hopefully in future the registry protocol will be
able to also provide hashes using this content-based (rather than
archive-based) algorithm and then we'll be able to make this work for
PackageMeta referring to a package obtained from a registry too, but
hashes for local packages only are still useful for some cases right now,
such as generating mirror directories in the "terraform providers mirror"
command.
This is the equivalent of UnpackedDirectoryPathForPackage when working
with the packed directory layout. It returns a path to a .zip file with
a name that would be detected by SearchLocalDirectory as a
PackageLocalArchive package.
This new command is intended to make it easy to create or update a mirror
directory containing suitable providers for the current configuration,
producing a layout that is appropriate both for a filesystem mirror or,
if copied into the document root of an HTTP server, a network mirror.

This initial version is not customizable aside from being able to select
multiple platforms to install packages for.

Future iterations of this could include commands to turn the JSON index
generation on and off, or to instruct it to produce the unpacked directory
layout instead of the packed directory layout as it currently does. Both
of those options would make the generated directory unsuitable to be
a network mirror, but it would still work as a filesystem mirror.

In the long run this will hopefully form part of a replacement workflow to
terraform-bundle as a way to put copies of providers somewhere so we don't
need to re-download them every time, but some other changes will be needed
outside of just this command before that'd be true, such as adding support
for network and/or filesystem mirrors in Terraform Enterprise.
@apparentlymart apparentlymart force-pushed the f-cmd-providers-mirror branch from a848c0d to c9dc864 Compare June 1, 2020 21:44
@apparentlymart apparentlymart merged commit 49e2e00 into master Jun 1, 2020
@apparentlymart apparentlymart deleted the f-cmd-providers-mirror branch June 1, 2020 21:49
@ghost
Copy link
Copy Markdown

ghost commented Jul 2, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jul 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants