2024-02-08 03:48:59 -06:00
|
|
|
// Copyright (c) The OpenTofu Authors
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
2023-05-02 10:33:06 -05:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2023-09-20 07:16:53 -05:00
|
|
|
package tofu
|
2014-09-29 12:36:49 -05:00
|
|
|
|
|
|
|
import (
|
2019-03-07 14:07:13 -06:00
|
|
|
"context"
|
2014-09-29 12:36:49 -05:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PrefixUIInput is an implementation of UIInput that prefixes the ID
|
|
|
|
// with a string, allowing queries to be namespaced.
|
|
|
|
type PrefixUIInput struct {
|
2014-09-29 14:45:28 -05:00
|
|
|
IdPrefix string
|
|
|
|
QueryPrefix string
|
|
|
|
UIInput UIInput
|
2014-09-29 12:36:49 -05:00
|
|
|
}
|
|
|
|
|
2019-03-07 14:07:13 -06:00
|
|
|
func (i *PrefixUIInput) Input(ctx context.Context, opts *InputOpts) (string, error) {
|
2014-09-29 12:36:49 -05:00
|
|
|
opts.Id = fmt.Sprintf("%s.%s", i.IdPrefix, opts.Id)
|
2014-09-29 14:52:48 -05:00
|
|
|
opts.Query = fmt.Sprintf("%s%s", i.QueryPrefix, opts.Query)
|
2019-03-07 14:07:13 -06:00
|
|
|
return i.UIInput.Input(ctx, opts)
|
2014-09-29 12:36:49 -05:00
|
|
|
}
|