mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-10 09:10:27 -04:00
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
// Copyright IBM Corp. 2013, 2025
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
//go:generate packer-sdc mapstructure-to-hcl2 -type Config,DatasourceOutput
|
|
package parrot
|
|
|
|
import (
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
|
"github.com/hashicorp/packer-plugin-sdk/hcl2helper"
|
|
"github.com/hashicorp/packer-plugin-sdk/template/config"
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
type Config struct {
|
|
Input []string `mapstructure:"input" required:"true"`
|
|
}
|
|
|
|
type Datasource struct {
|
|
config Config
|
|
}
|
|
|
|
type DatasourceOutput struct {
|
|
Output []string `mapstructure:"out"`
|
|
}
|
|
|
|
func (d *Datasource) ConfigSpec() hcldec.ObjectSpec {
|
|
return d.config.FlatMapstructure().HCL2Spec()
|
|
}
|
|
|
|
func (d *Datasource) Configure(raws ...interface{}) error {
|
|
err := config.Decode(&d.config, nil, raws...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (d *Datasource) OutputSpec() hcldec.ObjectSpec {
|
|
return (&DatasourceOutput{}).FlatMapstructure().HCL2Spec()
|
|
}
|
|
|
|
func (d *Datasource) Execute() (cty.Value, error) {
|
|
out := []string{}
|
|
for _, d := range d.config.Input {
|
|
out = append(out, d)
|
|
}
|
|
|
|
output := DatasourceOutput{
|
|
Output: out,
|
|
}
|
|
return hcl2helper.HCL2ValueFromConfig(output, d.OutputSpec()), nil
|
|
}
|