builtin/providers/tf: pass real context.Context to backend methods (#2938)

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
This commit is contained in:
Martin Atkins
2025-06-19 02:46:39 -07:00
committed by GitHub
parent a1ba3e24aa
commit e6f0083ecc
3 changed files with 6 additions and 8 deletions

View File

@@ -106,7 +106,7 @@ func dataSourceRemoteStateValidate(cfg cty.Value) tfdiags.Diagnostics {
return diags
}
func dataSourceRemoteStateRead(d cty.Value, enc encryption.StateEncryption, path addrs.AbsResourceInstance) (cty.Value, tfdiags.Diagnostics) {
func dataSourceRemoteStateRead(ctx context.Context, d cty.Value, enc encryption.StateEncryption, path addrs.AbsResourceInstance) (cty.Value, tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
b, cfg, moreDiags := getBackend(d, enc)
@@ -115,9 +115,7 @@ func dataSourceRemoteStateRead(d cty.Value, enc encryption.StateEncryption, path
return cty.NilVal, diags
}
// TODO: Plumb a real context in here, once [providers.Interface] has
// been updated to allow one to pass through its API.
configureDiags := b.Configure(context.TODO(), cfg)
configureDiags := b.Configure(ctx, cfg)
if configureDiags.HasErrors() {
diags = diags.Append(configureDiags.Err())
return cty.NilVal, diags
@@ -137,7 +135,7 @@ func dataSourceRemoteStateRead(d cty.Value, enc encryption.StateEncryption, path
workspaceName = workspaceVal.AsString()
}
state, err := b.StateMgr(context.TODO(), workspaceName)
state, err := b.StateMgr(ctx, workspaceName)
if err != nil {
diags = diags.Append(tfdiags.AttributeValue(
tfdiags.Error,

View File

@@ -328,7 +328,7 @@ func TestState_basic(t *testing.T) {
var got cty.Value
if !diags.HasErrors() && config.IsWhollyKnown() {
var moreDiags tfdiags.Diagnostics
got, moreDiags = dataSourceRemoteStateRead(config, encryption.StateEncryptionDisabled(), addrs.AbsResourceInstance{
got, moreDiags = dataSourceRemoteStateRead(t.Context(), config, encryption.StateEncryptionDisabled(), addrs.AbsResourceInstance{
Resource: addrs.ResourceInstance{
Resource: addrs.Resource{
Mode: addrs.DataResourceMode,

View File

@@ -91,7 +91,7 @@ func (p *Provider) ReadDataSource(_ context.Context, req providers.ReadDataSourc
panic("Should not be called directly, special case for terraform_remote_state")
}
func (p *Provider) ReadDataSourceEncrypted(_ context.Context, req providers.ReadDataSourceRequest, path addrs.AbsResourceInstance, enc encryption.Encryption) providers.ReadDataSourceResponse {
func (p *Provider) ReadDataSourceEncrypted(ctx context.Context, req providers.ReadDataSourceRequest, path addrs.AbsResourceInstance, enc encryption.Encryption) providers.ReadDataSourceResponse {
// call function
var res providers.ReadDataSourceResponse
@@ -113,7 +113,7 @@ func (p *Provider) ReadDataSourceEncrypted(_ context.Context, req providers.Read
log.Printf("[DEBUG] accessing remote state at %s", key)
newState, diags := dataSourceRemoteStateRead(req.Config, enc.RemoteState(key), path)
newState, diags := dataSourceRemoteStateRead(ctx, req.Config, enc.RemoteState(key), path)
if diags.HasErrors() {
diags = diags.Append(fmt.Errorf("%s: Unable to read remote state", path.String()))