github.com/hashicorp/terraform-plugin-sdk@v1.17.2/terraform/ui_input_prefix.go (about)

     1  package terraform
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  )
     7  
     8  // PrefixUIInput is an implementation of UIInput that prefixes the ID
     9  // with a string, allowing queries to be namespaced.
    10  type PrefixUIInput struct {
    11  	IdPrefix    string
    12  	QueryPrefix string
    13  	UIInput     UIInput
    14  }
    15  
    16  func (i *PrefixUIInput) Input(ctx context.Context, opts *InputOpts) (string, error) {
    17  	opts.Id = fmt.Sprintf("%s.%s", i.IdPrefix, opts.Id)
    18  	opts.Query = fmt.Sprintf("%s%s", i.QueryPrefix, opts.Query)
    19  	return i.UIInput.Input(ctx, opts)
    20  }