Revert PRs that introduced propogating contexts (#835)

Co-authored-by: Dmitry Kisler <admin@dkisler.com>
This commit is contained in:
James Humphries
2023-11-08 21:09:14 +00:00
committed by GitHub
parent 2d6dd8eda8
commit 9c24b6183a
124 changed files with 1131 additions and 1535 deletions

View File

@@ -119,7 +119,7 @@ func New(services *disco.Disco) *Cloud {
}
// ConfigSchema implements backend.Enhanced.
func (b *Cloud) ConfigSchema(context.Context) *configschema.Block {
func (b *Cloud) ConfigSchema() *configschema.Block {
return &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"hostname": {
@@ -167,7 +167,7 @@ func (b *Cloud) ConfigSchema(context.Context) *configschema.Block {
}
// PrepareConfig implements backend.Backend.
func (b *Cloud) PrepareConfig(ctx context.Context, obj cty.Value) (cty.Value, tfdiags.Diagnostics) {
func (b *Cloud) PrepareConfig(obj cty.Value) (cty.Value, tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
if obj.IsNull() {
return obj, diags
@@ -233,7 +233,7 @@ func (b *Cloud) ServiceDiscoveryAliases() ([]backend.HostAlias, error) {
}
// Configure implements backend.Enhanced.
func (b *Cloud) Configure(ctx context.Context, obj cty.Value) tfdiags.Diagnostics {
func (b *Cloud) Configure(obj cty.Value) tfdiags.Diagnostics {
var diags tfdiags.Diagnostics
if obj.IsNull() {
return diags
@@ -327,7 +327,7 @@ func (b *Cloud) Configure(ctx context.Context, obj cty.Value) tfdiags.Diagnostic
}
// Check if the organization exists by reading its entitlements.
entitlements, err := b.client.Organizations.ReadEntitlements(ctx, b.organization)
entitlements, err := b.client.Organizations.ReadEntitlements(context.Background(), b.organization)
if err != nil {
if err == tfe.ErrResourceNotFound {
err = fmt.Errorf("organization %q at host %s not found.\n\n"+
@@ -347,7 +347,7 @@ func (b *Cloud) Configure(ctx context.Context, obj cty.Value) tfdiags.Diagnostic
if ws, ok := os.LookupEnv("TF_WORKSPACE"); ok {
if ws == b.WorkspaceMapping.Name || b.WorkspaceMapping.Strategy() == WorkspaceTagsStrategy {
diag := b.validWorkspaceEnvVar(ctx, b.organization, ws)
diag := b.validWorkspaceEnvVar(context.Background(), b.organization, ws)
if diag != nil {
diags = diags.Append(diag)
return diags
@@ -535,7 +535,7 @@ func (b *Cloud) retryLogHook(attemptNum int, resp *http.Response) {
// Workspaces implements backend.Enhanced, returning a filtered list of workspace names according to
// the workspace mapping strategy configured.
func (b *Cloud) Workspaces(ctx context.Context) ([]string, error) {
func (b *Cloud) Workspaces() ([]string, error) {
// Create a slice to contain all the names.
var names []string
@@ -558,7 +558,7 @@ func (b *Cloud) Workspaces(ctx context.Context) ([]string, error) {
listOpts := &tfe.ProjectListOptions{
Name: b.WorkspaceMapping.Project,
}
projects, err := b.client.Projects.List(ctx, b.organization, listOpts)
projects, err := b.client.Projects.List(context.Background(), b.organization, listOpts)
if err != nil && err != tfe.ErrResourceNotFound {
return nil, fmt.Errorf("failed to retrieve project %s: %w", listOpts.Name, err)
}
@@ -571,7 +571,7 @@ func (b *Cloud) Workspaces(ctx context.Context) ([]string, error) {
}
for {
wl, err := b.client.Workspaces.List(ctx, b.organization, options)
wl, err := b.client.Workspaces.List(context.Background(), b.organization, options)
if err != nil {
return nil, err
}
@@ -596,7 +596,7 @@ func (b *Cloud) Workspaces(ctx context.Context) ([]string, error) {
}
// DeleteWorkspace implements backend.Enhanced.
func (b *Cloud) DeleteWorkspace(ctx context.Context, name string, force bool) error {
func (b *Cloud) DeleteWorkspace(name string, force bool) error {
if name == backend.DefaultStateName {
return backend.ErrDefaultWorkspaceNotSupported
}
@@ -605,7 +605,7 @@ func (b *Cloud) DeleteWorkspace(ctx context.Context, name string, force bool) er
return backend.ErrWorkspacesNotSupported
}
workspace, err := b.client.Workspaces.Read(ctx, b.organization, name)
workspace, err := b.client.Workspaces.Read(context.Background(), b.organization, name)
if err == tfe.ErrResourceNotFound {
return nil // If the workspace does not exist, succeed
}
@@ -616,11 +616,11 @@ func (b *Cloud) DeleteWorkspace(ctx context.Context, name string, force bool) er
// Configure the remote workspace name.
State := &State{tfeClient: b.client, organization: b.organization, workspace: workspace, enableIntermediateSnapshots: false}
return State.Delete(ctx, force)
return State.Delete(force)
}
// StateMgr implements backend.Enhanced.
func (b *Cloud) StateMgr(ctx context.Context, name string) (statemgr.Full, error) {
func (b *Cloud) StateMgr(name string) (statemgr.Full, error) {
var remoteTFVersion string
if name == backend.DefaultStateName {
@@ -631,7 +631,7 @@ func (b *Cloud) StateMgr(ctx context.Context, name string) (statemgr.Full, error
return nil, backend.ErrWorkspacesNotSupported
}
workspace, err := b.client.Workspaces.Read(ctx, b.organization, name)
workspace, err := b.client.Workspaces.Read(context.Background(), b.organization, name)
if err != nil && err != tfe.ErrResourceNotFound {
return nil, fmt.Errorf("Failed to retrieve workspace %s: %w", name, err)
}
@@ -646,7 +646,7 @@ func (b *Cloud) StateMgr(ctx context.Context, name string) (statemgr.Full, error
listOpts := &tfe.ProjectListOptions{
Name: b.WorkspaceMapping.Project,
}
projects, err := b.client.Projects.List(ctx, b.organization, listOpts)
projects, err := b.client.Projects.List(context.Background(), b.organization, listOpts)
if err != nil && err != tfe.ErrResourceNotFound {
// This is a failure to make an API request, fail to initialize
return nil, fmt.Errorf("Attempted to find configured project %s but was unable to.", b.WorkspaceMapping.Project)
@@ -685,7 +685,7 @@ func (b *Cloud) StateMgr(ctx context.Context, name string) (statemgr.Full, error
}
// didn't find project, create it instead
log.Printf("[TRACE] cloud: Creating cloud backend project %s/%s", b.organization, b.WorkspaceMapping.Project)
project, err := b.client.Projects.Create(ctx, b.organization, createOpts)
project, err := b.client.Projects.Create(context.Background(), b.organization, createOpts)
if err != nil && err != tfe.ErrResourceNotFound {
return nil, fmt.Errorf("failed to create project %s: %w", b.WorkspaceMapping.Project, err)
}
@@ -696,7 +696,7 @@ func (b *Cloud) StateMgr(ctx context.Context, name string) (statemgr.Full, error
// Create a workspace
log.Printf("[TRACE] cloud: Creating cloud backend workspace %s/%s", b.organization, name)
workspace, err = b.client.Workspaces.Create(ctx, b.organization, workspaceCreateOptions)
workspace, err = b.client.Workspaces.Create(context.Background(), b.organization, workspaceCreateOptions)
if err != nil {
return nil, fmt.Errorf("error creating workspace %s: %w", name, err)
}
@@ -709,7 +709,7 @@ func (b *Cloud) StateMgr(ctx context.Context, name string) (statemgr.Full, error
versionOptions := tfe.WorkspaceUpdateOptions{
TerraformVersion: tfe.String(tfversion.String()),
}
_, err := b.client.Workspaces.UpdateByID(ctx, workspace.ID, versionOptions)
_, err := b.client.Workspaces.UpdateByID(context.Background(), workspace.ID, versionOptions)
if err == nil {
remoteTFVersion = tfversion.String()
} else {
@@ -731,7 +731,7 @@ func (b *Cloud) StateMgr(ctx context.Context, name string) (statemgr.Full, error
Tags: b.WorkspaceMapping.tfeTags(),
}
log.Printf("[TRACE] cloud: Adding tags for cloud backend workspace %s/%s", b.organization, name)
err = b.client.Workspaces.AddTags(ctx, workspace.ID, options)
err = b.client.Workspaces.AddTags(context.Background(), workspace.ID, options)
if err != nil {
return nil, fmt.Errorf("Error updating workspace %s: %w", name, err)
}