terraform/internal/command/workdir/doc.go

17 lines
941 B
Go
Raw Normal View History

workdir: Start of a new package for working directory state management Thus far our various interactions with the bits of state we keep associated with a working directory have all been implemented directly inside the "command" package -- often in the huge command.Meta type -- and not managed collectively via a single component. There's too many little codepaths reading and writing from the working directory and data directory to refactor it all in one step, but this is an attempt at a first step towards a future where everything that reads and writes from the current working directory would do so via an object that encapsulates the implementation details and offers a high-level API to read and write all of these session-persistent settings. The design here continues our gradual path towards using a dependency injection style where "package main" is solely responsible for directly interacting with the OS command line, the OS environment, the OS working directory, the stdio streams, and the CLI configuration, and then communicating the resulting information to the rest of Terraform by wiring together objects. It seems likely that eventually we'll have enough wiring code in package main to justify a more explicit organization of that code, but for this commit the new "workdir.Dir" object is just wired directly in place of its predecessors, without any significant change of code organization at that top layer. This first commit focuses on the main files and directories we use to find provider plugins, because a subsequent commit will lightly reorganize the separation of concerns for plugin launching with a similar goal of collecting all of the relevant logic together into one spot.
2021-09-02 02:01:44 +02:00
// Package workdir models the various local artifacts and state we keep inside
// a Terraform "working directory".
//
// The working directory artifacts and settings are typically initialized or
// modified by "terraform init", after which they persist for use by other
// commands in the same directory, but are not visible to commands run in
// other working directories or on other computers.
//
// Although "terraform init" is the main command which modifies a workdir,
// other commands do sometimes make more focused modifications for settings
// which can typically change multiple times during a session, such as the
// currently-selected workspace name. Any command which modifies the working
// directory settings must discard and reload any objects which derived from
// those settings, because otherwise the existing objects will often continue
// to follow the settings that were present when they were created.
package workdir