github.com/opentofu/opentofu@v1.7.1/internal/legacy/tofu/ui_input_prefix.go (about)

     1  // Copyright (c) The OpenTofu Authors
     2  // SPDX-License-Identifier: MPL-2.0
     3  // Copyright (c) 2023 HashiCorp, Inc.
     4  // SPDX-License-Identifier: MPL-2.0
     5  
     6  package tofu
     7  
     8  import (
     9  	"context"
    10  	"fmt"
    11  )
    12  
    13  // PrefixUIInput is an implementation of UIInput that prefixes the ID
    14  // with a string, allowing queries to be namespaced.
    15  type PrefixUIInput struct {
    16  	IdPrefix    string
    17  	QueryPrefix string
    18  	UIInput     UIInput
    19  }
    20  
    21  func (i *PrefixUIInput) Input(ctx context.Context, opts *InputOpts) (string, error) {
    22  	opts.Id = fmt.Sprintf("%s.%s", i.IdPrefix, opts.Id)
    23  	opts.Query = fmt.Sprintf("%s%s", i.QueryPrefix, opts.Query)
    24  	return i.UIInput.Input(ctx, opts)
    25  }