diff --git a/cmd/packer-plugin-check/main.go b/cmd/packer-plugin-check/main.go index ff2d15dd4..dcfd3bd52 100644 --- a/cmd/packer-plugin-check/main.go +++ b/cmd/packer-plugin-check/main.go @@ -12,6 +12,7 @@ import ( "strings" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer/plugin" ) @@ -141,7 +142,7 @@ func discoverAndLoad() error { // checkHCL2ConfigSpec checks if the hcl2spec config is present for the given plugins by validating that ConfigSpec() does not // return an empty map of specs. -func checkHCL2ConfigSpec(builders packersdk.MapOfBuilder, provisioners packersdk.MapOfProvisioner, postProcessors packersdk.MapOfPostProcessor) error { +func checkHCL2ConfigSpec(builders packer.BuilderStore, provisioners packer.ProvisionerStore, postProcessors packer.PostProcessorStore) error { var errs *packersdk.MultiError for _, b := range builders.List() { builder, err := builders.Start(b) diff --git a/command/build_parallel_test.go b/command/build_parallel_test.go index 5f5beaa4f..ceff83420 100644 --- a/command/build_parallel_test.go +++ b/command/build_parallel_test.go @@ -68,12 +68,12 @@ func testMetaParallel(t *testing.T, builder *ParallelTestBuilder, locked *Locked return Meta{ CoreConfig: &packer.CoreConfig{ Components: packer.ComponentFinder{ - BuilderStore: packersdk.MapOfBuilder{ + BuilderStore: packer.MapOfBuilder{ "parallel-test": func() (packersdk.Builder, error) { return builder, nil }, "file": func() (packersdk.Builder, error) { return &file.Builder{}, nil }, "lock": func() (packersdk.Builder, error) { return locked, nil }, }, - ProvisionerStore: packersdk.MapOfProvisioner{ + ProvisionerStore: packer.MapOfProvisioner{ "sleep": func() (packersdk.Provisioner, error) { return &sleep.Provisioner{}, nil }, }, }, diff --git a/command/build_test.go b/command/build_test.go index 250f1686a..b04fd0d86 100644 --- a/command/build_test.go +++ b/command/build_test.go @@ -836,16 +836,16 @@ func fileExists(filename string) bool { // available. This allows us to test a builder that writes files to disk. func testCoreConfigBuilder(t *testing.T) *packer.CoreConfig { components := packer.ComponentFinder{ - BuilderStore: packersdk.MapOfBuilder{ + BuilderStore: packer.MapOfBuilder{ "file": func() (packersdk.Builder, error) { return &file.Builder{}, nil }, "null": func() (packersdk.Builder, error) { return &null.Builder{}, nil }, }, - ProvisionerStore: packersdk.MapOfProvisioner{ + ProvisionerStore: packer.MapOfProvisioner{ "shell-local": func() (packersdk.Provisioner, error) { return &shell_local.Provisioner{}, nil }, "shell": func() (packersdk.Provisioner, error) { return &shell.Provisioner{}, nil }, "file": func() (packersdk.Provisioner, error) { return &filep.Provisioner{}, nil }, }, - PostProcessorStore: packersdk.MapOfPostProcessor{ + PostProcessorStore: packer.MapOfPostProcessor{ "shell-local": func() (packersdk.PostProcessor, error) { return &shell_local_pp.PostProcessor{}, nil }, "manifest": func() (packersdk.PostProcessor, error) { return &manifest.PostProcessor{}, nil }, }, diff --git a/command/build_timeout_test.go b/command/build_timeout_test.go index 504882330..b74adb8ee 100644 --- a/command/build_timeout_test.go +++ b/command/build_timeout_test.go @@ -16,10 +16,10 @@ import ( // available. This allows us to test a builder that writes files to disk. func testCoreConfigSleepBuilder(t *testing.T) *packer.CoreConfig { components := packer.ComponentFinder{ - BuilderStore: packersdk.MapOfBuilder{ + BuilderStore: packer.MapOfBuilder{ "file": func() (packersdk.Builder, error) { return &file.Builder{}, nil }, }, - ProvisionerStore: packersdk.MapOfProvisioner{ + ProvisionerStore: packer.MapOfProvisioner{ "sleep": func() (packersdk.Provisioner, error) { return &sleep.Provisioner{}, nil }, "shell-local": func() (packersdk.Provisioner, error) { return &shell_local.Provisioner{}, nil }, }, diff --git a/command/exec_test.go b/command/exec_test.go index a9453e2e2..3c18574d0 100644 --- a/command/exec_test.go +++ b/command/exec_test.go @@ -118,17 +118,17 @@ func commandMeta() Meta { func getBareComponentFinder() packer.ComponentFinder { return packer.ComponentFinder{ - BuilderStore: packersdk.MapOfBuilder{ + BuilderStore: packer.MapOfBuilder{ "file": func() (packersdk.Builder, error) { return &file.Builder{}, nil }, "null": func() (packersdk.Builder, error) { return &null.Builder{}, nil }, "amazon-ebs": func() (packersdk.Builder, error) { return &ebs.Builder{}, nil }, }, - ProvisionerStore: packersdk.MapOfProvisioner{ + ProvisionerStore: packer.MapOfProvisioner{ "shell-local": func() (packersdk.Provisioner, error) { return &shell_local.Provisioner{}, nil }, "shell": func() (packersdk.Provisioner, error) { return &shell.Provisioner{}, nil }, "file": func() (packersdk.Provisioner, error) { return &filep.Provisioner{}, nil }, }, - PostProcessorStore: packersdk.MapOfPostProcessor{ + PostProcessorStore: packer.MapOfPostProcessor{ "shell-local": func() (packersdk.PostProcessor, error) { return &shell_local_pp.PostProcessor{}, nil }, "manifest": func() (packersdk.PostProcessor, error) { return &manifest.PostProcessor{}, nil }, }, diff --git a/config.go b/config.go index d2be1686e..3b5e9ec65 100644 --- a/config.go +++ b/config.go @@ -13,6 +13,7 @@ import ( packersdk "github.com/hashicorp/packer-plugin-sdk/packer" "github.com/hashicorp/packer/command" + "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer/plugin" ) @@ -21,14 +22,14 @@ import ( const PACKERSPACE = "-PACKERSPACE-" type config struct { - DisableCheckpoint bool `json:"disable_checkpoint"` - DisableCheckpointSignature bool `json:"disable_checkpoint_signature"` - RawBuilders map[string]string `json:"builders"` - RawProvisioners map[string]string `json:"provisioners"` - RawPostProcessors map[string]string `json:"post-processors"` - Builders packersdk.MapOfBuilder `json:"-"` - Provisioners packersdk.MapOfProvisioner `json:"-"` - PostProcessors packersdk.MapOfPostProcessor `json:"-"` + DisableCheckpoint bool `json:"disable_checkpoint"` + DisableCheckpointSignature bool `json:"disable_checkpoint_signature"` + RawBuilders map[string]string `json:"builders"` + RawProvisioners map[string]string `json:"provisioners"` + RawPostProcessors map[string]string `json:"post-processors"` + Builders packer.MapOfBuilder `json:"-"` + Provisioners packer.MapOfProvisioner `json:"-"` + PostProcessors packer.MapOfPostProcessor `json:"-"` Plugins plugin.Config } diff --git a/config_test.go b/config_test.go index d0e2f18a4..cf28533cd 100644 --- a/config_test.go +++ b/config_test.go @@ -11,7 +11,7 @@ import ( "strings" "testing" - packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + "github.com/hashicorp/packer/packer" ) func TestDecodeConfig(t *testing.T) { @@ -49,9 +49,9 @@ func TestLoadExternalComponentsFromConfig(t *testing.T) { defer cleanUpFunc() var cfg config - cfg.Builders = packersdk.MapOfBuilder{} - cfg.PostProcessors = packersdk.MapOfPostProcessor{} - cfg.Provisioners = packersdk.MapOfProvisioner{} + cfg.Builders = packer.MapOfBuilder{} + cfg.PostProcessors = packer.MapOfPostProcessor{} + cfg.Provisioners = packer.MapOfProvisioner{} if err := decodeConfig(strings.NewReader(packerConfigData), &cfg); err != nil { t.Fatalf("error encountered decoding configuration: %v", err) @@ -81,7 +81,7 @@ func TestLoadExternalComponentsFromConfig_onlyProvisioner(t *testing.T) { defer cleanUpFunc() var cfg config - cfg.Provisioners = packersdk.MapOfProvisioner{} + cfg.Provisioners = packer.MapOfProvisioner{} if err := decodeConfig(strings.NewReader(packerConfigData), &cfg); err != nil { t.Fatalf("error encountered decoding configuration: %v", err) @@ -126,9 +126,9 @@ func TestLoadSingleComponent(t *testing.T) { } var cfg config - cfg.Builders = packersdk.MapOfBuilder{} - cfg.PostProcessors = packersdk.MapOfPostProcessor{} - cfg.Provisioners = packersdk.MapOfProvisioner{} + cfg.Builders = packer.MapOfBuilder{} + cfg.PostProcessors = packer.MapOfPostProcessor{} + cfg.Provisioners = packer.MapOfProvisioner{} for _, tc := range tt { tc := tc diff --git a/go.mod b/go.mod index 8286aa975..b7549fd54 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,7 @@ require ( github.com/hashicorp/go-uuid v1.0.2 github.com/hashicorp/go-version v1.2.0 github.com/hashicorp/hcl/v2 v2.8.0 - github.com/hashicorp/packer-plugin-sdk v0.0.6 + github.com/hashicorp/packer-plugin-sdk v0.0.7-0.20210111224258-fd30ebb797f0 github.com/hashicorp/vault/api v1.0.4 github.com/hetznercloud/hcloud-go v1.15.1 github.com/hyperonecom/h1-client-go v0.0.0-20191203060043-b46280e4c4a4 diff --git a/go.sum b/go.sum index 733b94c15..1d218fe86 100644 --- a/go.sum +++ b/go.sum @@ -102,12 +102,8 @@ github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20170113022742-e6dbea820a9f h1:jI4DIE github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20170113022742-e6dbea820a9f/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/antchfx/xpath v0.0.0-20170728053731-b5c552e1acbd h1:S3Fr6QnkpW9VRjiEY4psQHhhbbahASuNVj52YIce7lI= github.com/antchfx/xpath v0.0.0-20170728053731-b5c552e1acbd/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= -github.com/antchfx/xpath v0.0.0-20190129040759-c8489ed3251e h1:ptBAamGVd6CfRsUtyHD+goy2JGhv1QC32v3gqM8mYAM= -github.com/antchfx/xpath v0.0.0-20190129040759-c8489ed3251e/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= github.com/antchfx/xquery v0.0.0-20170730121040-eb8c3c172607 h1:BFFG6KP8ASFBg2ptWsJn8p8RDufBjBDKIxLU7BTYGOM= github.com/antchfx/xquery v0.0.0-20170730121040-eb8c3c172607/go.mod h1:LzD22aAzDP8/dyiCKFp31He4m2GPjl0AFyzDtZzUu9M= -github.com/antchfx/xquery v0.0.0-20180515051857-ad5b8c7a47b0 h1:JaCC8jz0zdMLk2m+qCCVLLLM/PL93p84w4pK3aJWj60= -github.com/antchfx/xquery v0.0.0-20180515051857-ad5b8c7a47b0/go.mod h1:LzD22aAzDP8/dyiCKFp31He4m2GPjl0AFyzDtZzUu9M= github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apparentlymart/go-cidr v1.0.1 h1:NmIwLZ/KdsjIUlhf+/Np40atNXm/+lZ5txfTJ/SpF+U= @@ -187,8 +183,6 @@ github.com/dylanmei/iso8601 v0.1.0 h1:812NGQDBcqquTfH5Yeo7lwR0nzx/cKdsmf3qMjPURU github.com/dylanmei/iso8601 v0.1.0/go.mod h1:w9KhXSgIyROl1DefbMYIE7UVSIvELTbMrCfx+QkYnoQ= github.com/dylanmei/winrmtest v0.0.0-20170819153634-c2fbb09e6c08 h1:0bp6/GrNOrTDtSXe9YYGCwf8jp5Fb/b+4a6MTRm4qzY= github.com/dylanmei/winrmtest v0.0.0-20170819153634-c2fbb09e6c08/go.mod h1:VBVDFSBXCIW8JaHQpI8lldSKfYaLMzP9oyq6IJ4fhzY= -github.com/dylanmei/winrmtest v0.0.0-20190225150635-99b7fe2fddf1 h1:r1oACdS2XYiAWcfF8BJXkoU8l1J71KehGR+d99yWEDA= -github.com/dylanmei/winrmtest v0.0.0-20190225150635-99b7fe2fddf1/go.mod h1:lcy9/2gH1jn/VCLouHA6tOEwLoNVd4GW6zhuKLmHC2Y= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4 h1:rEvIZUSZ3fx39WIi3JkQqQBitGwpELBIYWeBVh6wn+E= @@ -228,8 +222,6 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gofrs/flock v0.7.3 h1:I0EKY9l8HZCXTMYC4F80vwT6KNypV9uYKP3Alm/hjmQ= github.com/gofrs/flock v0.7.3/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= -github.com/gofrs/flock v0.8.0 h1:MSdYClljsF3PbENUUEx85nkWfJSGfzYI9yEBZOJz6CY= -github.com/gofrs/flock v0.8.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE= github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= @@ -306,8 +298,6 @@ github.com/google/pprof v0.0.0-20200905233945-acf8798be1f7/go.mod h1:ZgVRPoUq/hf github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/shlex v0.0.0-20150127133951-6f45313302b9 h1:JM174NTeGNJ2m/oLH3UOWOvWQQKd+BoL3hcSCUWFLt0= github.com/google/shlex v0.0.0-20150127133951-6f45313302b9/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE= -github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= -github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v0.0.0-20170306145142-6a5e28554805/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -331,12 +321,8 @@ github.com/hashicorp/aws-sdk-go-base v0.6.0 h1:qmUbzM36msbBF59YctwuO5w0M2oNXjlil github.com/hashicorp/aws-sdk-go-base v0.6.0/go.mod h1:2fRjWDv3jJBeN6mVWFHV6hFTNeFBx2gpDLQaZNxUVAY= github.com/hashicorp/consul/api v1.4.0 h1:jfESivXnO5uLdH650JU/6AnjRoHrLhULq0FnC3Kp9EY= github.com/hashicorp/consul/api v1.4.0/go.mod h1:xc8u05kyMa3Wjr9eEAsIAo3dg8+LywT5E/Cl7cNS5nU= -github.com/hashicorp/consul/api v1.8.0 h1:/djwFfq2mSyZeP6iqRpmYUzsJtzG5I9SlP3FJvSlbTE= -github.com/hashicorp/consul/api v1.8.0/go.mod h1:sDjTOq0yUyv5G4h+BqSea7Fn6BU+XbolEz1952UB+mk= github.com/hashicorp/consul/sdk v0.4.0 h1:zBtCfKJZcJDBvSCkQJch4ulp59m1rATFLKwNo/LYY30= github.com/hashicorp/consul/sdk v0.4.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM= -github.com/hashicorp/consul/sdk v0.7.0 h1:H6R9d008jDcHPQPAqPNuydAshJ4v5/8URdFnUvK/+sc= -github.com/hashicorp/consul/sdk v0.7.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-checkpoint v0.0.0-20171009173528-1545e56e46de h1:XDCSythtg8aWSRSO29uwhgh7b127fWr+m5SemqjSUL8= @@ -421,16 +407,15 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p github.com/hashicorp/memberlist v0.2.2 h1:5+RffWKwqJ71YPu9mWsF7ZOscZmwfasdA8kbdC7AO2g= github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= github.com/hashicorp/packer v1.6.6/go.mod h1:meJucaEeJro8UP1jw+KaOCpaiC4VE+itPLXY8lbIU2A= -github.com/hashicorp/packer-plugin-sdk v0.0.5 h1:ZaWvFY9b+YiDMmEBe5Z2UrEmmvmK7WsiZ3j6RDYVn+o= -github.com/hashicorp/packer-plugin-sdk v0.0.5/go.mod h1:xtyp/NeMzMrsESFAsUh1uFsLKgYI0kWbcMliDqvx3AM= +github.com/hashicorp/packer v1.6.7-0.20210107234516-6564ee76e807/go.mod h1:fBz288Z4of8zkpDWwL/ngG1txC36jGSXS7dnUmUaLUs= github.com/hashicorp/packer-plugin-sdk v0.0.6 h1:BN2G4APXSMvDURFdnk+6DspwsU83pZeMsbEur7NmGsA= github.com/hashicorp/packer-plugin-sdk v0.0.6/go.mod h1:Nvh28f+Jmpp2rcaN79bULTouNkGNDRfHckhHKTAXtyU= +github.com/hashicorp/packer-plugin-sdk v0.0.7-0.20210111224258-fd30ebb797f0 h1:2GsORpJjcMQN84ZA1IEyHzx0zPY6QH6tNGbZc7CP6QE= +github.com/hashicorp/packer-plugin-sdk v0.0.7-0.20210111224258-fd30ebb797f0/go.mod h1:YdWTt5w6cYfaQG7IOi5iorL+3SXnz8hI0gJCi8Db/LI= github.com/hashicorp/serf v0.8.2 h1:YZ7UKsJv+hKjqGVUUbtE3HNj79Eln2oQ75tniF6iPt0= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hashicorp/serf v0.9.2 h1:yJoyfZXo4Pk2p/M/viW+YLibBFiIbKoP79gu7kDAFP0= github.com/hashicorp/serf v0.9.2/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= -github.com/hashicorp/serf v0.9.5 h1:EBWvyu9tcRszt3Bxp3KNssBMP1KuHWyO51lz9+786iM= -github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= github.com/hashicorp/vault/api v1.0.4 h1:j08Or/wryXT4AcHj1oCbMd7IijXcKzYUGw59LGu9onU= github.com/hashicorp/vault/api v1.0.4/go.mod h1:gDcqh3WGcR1cpF5AJz/B1UFheUEneMoIospckxBxk6Q= github.com/hashicorp/vault/sdk v0.1.13 h1:mOEPeOhT7jl0J4AMl1E705+BcmeRs1VmKNb9F0sMLy8= @@ -438,8 +423,6 @@ github.com/hashicorp/vault/sdk v0.1.13/go.mod h1:B+hVj7TpuQY1Y/GPbCpffmgd+tSEwvh github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= -github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce h1:7UnVY3T/ZnHUrfviiAgIUjg2PXxsQfs5bphsG8F7Keo= -github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hetznercloud/hcloud-go v1.15.1 h1:G8Q+xyAqQ5IUY7yq4HKZgkabFa0S/VXJXq3TGCeT8JM= github.com/hetznercloud/hcloud-go v1.15.1/go.mod h1:8lR3yHBHZWy2uGcUi9Ibt4UOoop2wrVdERJgCtxsF3Q= github.com/hyperonecom/h1-client-go v0.0.0-20191203060043-b46280e4c4a4 h1:mSmyzhwBeQt2TlHbsXYLona9pwjWAvYGwQJ2Cq/k3VE= @@ -481,8 +464,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGi github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.0.0-20131111012553-2788f0dbd169 h1:YUrU1/jxRqnt0PSrKj1Uj/wEjk/fjnE80QFfi2Zlj7Q= github.com/kr/fs v0.0.0-20131111012553-2788f0dbd169/go.mod h1:glhvuHOU9Hy7/8PwwdtnarXqLagOX0b/TbZx2zLMqEg= -github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= -github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= @@ -532,8 +513,6 @@ github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMK github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/go-fs v0.0.0-20180402234041-7b48fa161ea7 h1:PXPMDtfqV+rZJshQHOiwUFqlqErXaAcuWy+/ZmyRfNc= github.com/mitchellh/go-fs v0.0.0-20180402234041-7b48fa161ea7/go.mod h1:g7SZj7ABpStq3tM4zqHiVEG5un/DZ1+qJJKO7qx1EvU= -github.com/mitchellh/go-fs v0.0.0-20180402235330-b7b9ca407fff h1:bFJ74ac7ZK/jyislqiWdzrnENesFt43sNEBRh1xk/+g= -github.com/mitchellh/go-fs v0.0.0-20180402235330-b7b9ca407fff/go.mod h1:g7SZj7ABpStq3tM4zqHiVEG5un/DZ1+qJJKO7qx1EvU= github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -582,8 +561,6 @@ github.com/outscale/osc-sdk-go/osc v0.0.0-20200722135656-d654809d0699 h1:SHe9i7h github.com/outscale/osc-sdk-go/osc v0.0.0-20200722135656-d654809d0699/go.mod h1:5AqqNH1X8zCHescKVlpSHRzrat1KCKDXqZoQPe8fY3A= github.com/packer-community/winrmcp v0.0.0-20180921204643-0fd363d6159a h1:A3QMuteviunoaY/8ex+RKFqwhcZJ/Cf3fCW3IwL2wx4= github.com/packer-community/winrmcp v0.0.0-20180921204643-0fd363d6159a/go.mod h1:f6Izs6JvFTdnRbziASagjZ2vmf55NSIkC/weStxCHqk= -github.com/packer-community/winrmcp v0.0.0-20180921211025-c76d91c1e7db h1:9uViuKtx1jrlXLBW/pMnhOfzn3iSEdLase/But/IZRU= -github.com/packer-community/winrmcp v0.0.0-20180921211025-c76d91c1e7db/go.mod h1:f6Izs6JvFTdnRbziASagjZ2vmf55NSIkC/weStxCHqk= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c h1:Lgl0gzECD8GnQ5QCWA8o6BtfL6mDH5rQgM4/fX3avOs= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= @@ -598,8 +575,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v0.0.0-20160118190721-e84cc8c755ca h1:k8gsErq3rkcbAyCnpOycQsbw88NjCHk7L3KfBZKhQDQ= github.com/pkg/sftp v0.0.0-20160118190721-e84cc8c755ca/go.mod h1:NxmoDg/QLVWluQDUYG7XBZTLUpKeFa8e3aMf1BfjyHk= -github.com/pkg/sftp v1.12.0 h1:/f3b24xrDhkhddlaobPe2JgBqfdt+gC/NYl0QY9IOuI= -github.com/pkg/sftp v1.12.0/go.mod h1:fUqqXB5vEgVCZ131L+9say31RAri6aF6KDViawhxKK8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w= @@ -727,7 +702,6 @@ golang.org/x/crypto v0.0.0-20200422194213-44a606286825 h1:dSChiwOTvzwbHFTMq2l6uR golang.org/x/crypto v0.0.0-20200422194213-44a606286825/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 h1:sYNJzB4J8toYPQTM6pAkcmBRgw9SnQKP9oXCHfgy604= golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= diff --git a/hcl2template/common_test.go b/hcl2template/common_test.go index ff0d36357..b93d33b6b 100644 --- a/hcl2template/common_test.go +++ b/hcl2template/common_test.go @@ -20,16 +20,16 @@ import ( func getBasicParser() *Parser { return &Parser{ Parser: hclparse.NewParser(), - BuilderSchemas: packersdk.MapOfBuilder{ + BuilderSchemas: packer.MapOfBuilder{ "amazon-ebs": func() (packersdk.Builder, error) { return &MockBuilder{}, nil }, "virtualbox-iso": func() (packersdk.Builder, error) { return &MockBuilder{}, nil }, "null": func() (packersdk.Builder, error) { return &null.Builder{}, nil }, }, - ProvisionersSchemas: packersdk.MapOfProvisioner{ + ProvisionersSchemas: packer.MapOfProvisioner{ "shell": func() (packersdk.Provisioner, error) { return &MockProvisioner{}, nil }, "file": func() (packersdk.Provisioner, error) { return &MockProvisioner{}, nil }, }, - PostProcessorsSchemas: packersdk.MapOfPostProcessor{ + PostProcessorsSchemas: packer.MapOfPostProcessor{ "amazon-import": func() (packersdk.PostProcessor, error) { return &MockPostProcessor{}, nil }, "manifest": func() (packersdk.PostProcessor, error) { return &MockPostProcessor{}, nil }, }, diff --git a/packer/core_test.go b/packer/core_test.go index 1dbdacfd3..e62825afb 100644 --- a/packer/core_test.go +++ b/packer/core_test.go @@ -800,7 +800,7 @@ func TestCoreBuild_provRetry(t *testing.T) { b := TestBuilder(t, config, "test") pString := new(packersdk.MockProvisioner) pInt := new(packersdk.MockProvisioner) - config.Components.ProvisionerStore = packersdk.MapOfProvisioner{ + config.Components.ProvisionerStore = MapOfProvisioner{ "test-string": func() (packersdk.Provisioner, error) { return pString, nil }, // backwards compatibility "test-integer": func() (packersdk.Provisioner, error) { return pInt, nil }, diff --git a/packer/maps.go b/packer/maps.go new file mode 100644 index 000000000..ddb19571b --- /dev/null +++ b/packer/maps.go @@ -0,0 +1,99 @@ +package packer + +import ( + "fmt" + + packersdk "github.com/hashicorp/packer-plugin-sdk/packer" +) + +type MapOfProvisioner map[string]func() (packersdk.Provisioner, error) + +func (mop MapOfProvisioner) Has(provisioner string) bool { + _, res := mop[provisioner] + return res +} + +func (mop MapOfProvisioner) Start(provisioner string) (packersdk.Provisioner, error) { + p, found := mop[provisioner] + if !found { + return nil, fmt.Errorf("Unknown provisioner %s", provisioner) + } + return p() +} + +func (mop MapOfProvisioner) List() []string { + res := []string{} + for k := range mop { + res = append(res, k) + } + return res +} + +type MapOfPostProcessor map[string]func() (packersdk.PostProcessor, error) + +func (mopp MapOfPostProcessor) Has(postProcessor string) bool { + _, res := mopp[postProcessor] + return res +} + +func (mopp MapOfPostProcessor) Start(postProcessor string) (packersdk.PostProcessor, error) { + p, found := mopp[postProcessor] + if !found { + return nil, fmt.Errorf("Unknown post-processor %s", postProcessor) + } + return p() +} + +func (mopp MapOfPostProcessor) List() []string { + res := []string{} + for k := range mopp { + res = append(res, k) + } + return res +} + +type MapOfBuilder map[string]func() (packersdk.Builder, error) + +func (mob MapOfBuilder) Has(builder string) bool { + _, res := mob[builder] + return res +} + +func (mob MapOfBuilder) Start(builder string) (packersdk.Builder, error) { + d, found := mob[builder] + if !found { + return nil, fmt.Errorf("Unknown builder %s", builder) + } + return d() +} + +func (mob MapOfBuilder) List() []string { + res := []string{} + for k := range mob { + res = append(res, k) + } + return res +} + +type MapOfDatasource map[string]func() (packersdk.Datasource, error) + +func (mod MapOfDatasource) Has(dataSource string) bool { + _, res := mod[dataSource] + return res +} + +func (mod MapOfDatasource) Start(dataSource string) (packersdk.Datasource, error) { + d, found := mod[dataSource] + if !found { + return nil, fmt.Errorf("Unknown data source %s", dataSource) + } + return d() +} + +func (mod MapOfDatasource) List() []string { + res := []string{} + for k := range mod { + res = append(res, k) + } + return res +} diff --git a/packer/plugin/discover.go b/packer/plugin/discover.go index 8b8c29fd7..f24018370 100644 --- a/packer/plugin/discover.go +++ b/packer/plugin/discover.go @@ -13,6 +13,7 @@ import ( packersdk "github.com/hashicorp/packer-plugin-sdk/packer" "github.com/hashicorp/packer-plugin-sdk/pathing" pluginsdk "github.com/hashicorp/packer-plugin-sdk/plugin" + "github.com/hashicorp/packer/packer" ) // PACKERSPACE is used to represent the spaces that separate args for a command @@ -22,12 +23,12 @@ const PACKERSPACE = "-PACKERSPACE-" type Config struct { PluginMinPort int PluginMaxPort int - builders packersdk.MapOfBuilder - provisioners packersdk.MapOfProvisioner - postProcessors packersdk.MapOfPostProcessor + builders packer.MapOfBuilder + provisioners packer.MapOfProvisioner + postProcessors packer.MapOfPostProcessor } -func (c *Config) GetPlugins() (packersdk.MapOfBuilder, packersdk.MapOfProvisioner, packersdk.MapOfPostProcessor) { +func (c *Config) GetPlugins() (packer.MapOfBuilder, packer.MapOfProvisioner, packer.MapOfPostProcessor) { return c.builders, c.provisioners, c.postProcessors } @@ -40,13 +41,13 @@ func (c *Config) GetPlugins() (packersdk.MapOfBuilder, packersdk.MapOfProvisione // CWD has the highest priority. func (c *Config) Discover() error { if c.builders == nil { - c.builders = packersdk.MapOfBuilder{} + c.builders = packer.MapOfBuilder{} } if c.provisioners == nil { - c.provisioners = packersdk.MapOfProvisioner{} + c.provisioners = packer.MapOfProvisioner{} } if c.postProcessors == nil { - c.postProcessors = packersdk.MapOfPostProcessor{} + c.postProcessors = packer.MapOfPostProcessor{} } // If we are already inside a plugin process we should not need to diff --git a/packer/plugin/discover_test.go b/packer/plugin/discover_test.go index 787ddd77b..d6b9ccdc5 100644 --- a/packer/plugin/discover_test.go +++ b/packer/plugin/discover_test.go @@ -11,7 +11,7 @@ import ( "strings" "testing" - "github.com/hashicorp/packer-plugin-sdk/packer" + packersdk "github.com/hashicorp/packer-plugin-sdk/packer" pluginsdk "github.com/hashicorp/packer-plugin-sdk/plugin" "github.com/hashicorp/packer-plugin-sdk/tmp" ) @@ -258,13 +258,13 @@ func createMockPlugins(t *testing.T, plugins map[string]pluginsdk.Set) { var ( mockPlugins = map[string]pluginsdk.Set{ "bird": pluginsdk.Set{ - Builders: map[string]packer.Builder{ + Builders: map[string]packersdk.Builder{ "feather": nil, "guacamole": nil, }, }, "chimney": pluginsdk.Set{ - PostProcessors: map[string]packer.PostProcessor{ + PostProcessors: map[string]packersdk.PostProcessor{ "smoke": nil, }, }, @@ -272,7 +272,7 @@ var ( defaultNameMock = map[string]pluginsdk.Set{ "foo": pluginsdk.Set{ - Builders: map[string]packer.Builder{ + Builders: map[string]packersdk.Builder{ "bar": nil, "baz": nil, pluginsdk.DEFAULT_NAME: nil, @@ -282,12 +282,12 @@ var ( doubleDefaultMock = map[string]pluginsdk.Set{ "yolo": pluginsdk.Set{ - Builders: map[string]packer.Builder{ + Builders: map[string]packersdk.Builder{ "bar": nil, "baz": nil, pluginsdk.DEFAULT_NAME: nil, }, - PostProcessors: map[string]packer.PostProcessor{ + PostProcessors: map[string]packersdk.PostProcessor{ pluginsdk.DEFAULT_NAME: nil, }, }, @@ -295,7 +295,7 @@ var ( badDefaultNameMock = map[string]pluginsdk.Set{ "foo": pluginsdk.Set{ - Builders: map[string]packer.Builder{ + Builders: map[string]packersdk.Builder{ "bar": nil, "baz": nil, pluginsdk.DEFAULT_NAME: nil, diff --git a/packer/testing.go b/packer/testing.go index fb54acc92..c07fb8e5c 100644 --- a/packer/testing.go +++ b/packer/testing.go @@ -11,7 +11,7 @@ import ( func TestCoreConfig(t *testing.T) *CoreConfig { // Create some test components components := ComponentFinder{ - BuilderStore: packersdk.MapOfBuilder{ + BuilderStore: MapOfBuilder{ "test": func() (packersdk.Builder, error) { return &packersdk.MockBuilder{}, nil }, }, } @@ -45,7 +45,7 @@ func TestUi(t *testing.T) packersdk.Ui { func TestBuilder(t *testing.T, c *CoreConfig, n string) *packersdk.MockBuilder { var b packersdk.MockBuilder - c.Components.BuilderStore = packersdk.MapOfBuilder{ + c.Components.BuilderStore = MapOfBuilder{ n: func() (packersdk.Builder, error) { return &b, nil }, } @@ -57,7 +57,7 @@ func TestBuilder(t *testing.T, c *CoreConfig, n string) *packersdk.MockBuilder { func TestProvisioner(t *testing.T, c *CoreConfig, n string) *packersdk.MockProvisioner { var b packersdk.MockProvisioner - c.Components.ProvisionerStore = packersdk.MapOfProvisioner{ + c.Components.ProvisionerStore = MapOfProvisioner{ n: func() (packersdk.Provisioner, error) { return &b, nil }, } @@ -69,7 +69,7 @@ func TestProvisioner(t *testing.T, c *CoreConfig, n string) *packersdk.MockProvi func TestPostProcessor(t *testing.T, c *CoreConfig, n string) *MockPostProcessor { var b MockPostProcessor - c.Components.PostProcessorStore = packersdk.MapOfPostProcessor{ + c.Components.PostProcessorStore = MapOfPostProcessor{ n: func() (packersdk.PostProcessor, error) { return &b, nil }, } diff --git a/post-processor/yandex-export/step-attach-disk.go b/post-processor/yandex-export/step-attach-disk.go index f0246aab5..53157b2ee 100644 --- a/post-processor/yandex-export/step-attach-disk.go +++ b/post-processor/yandex-export/step-attach-disk.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/hashicorp/packer-plugin-sdk/multistep" - "github.com/hashicorp/packer-plugin-sdk/packer" + packersdk "github.com/hashicorp/packer-plugin-sdk/packer" "github.com/hashicorp/packer/builder/yandex" "github.com/yandex-cloud/go-genproto/yandex/cloud/compute/v1" ) @@ -17,7 +17,7 @@ type StepAttachDisk struct { func (c *StepAttachDisk) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { driver := state.Get("driver").(yandex.Driver) - ui := state.Get("ui").(packer.Ui) + ui := state.Get("ui").(packersdk.Ui) instanceID := state.Get("instance_id").(string) ui.Say("Create secondary disk from image for export...") @@ -82,7 +82,7 @@ func (c *StepAttachDisk) Run(ctx context.Context, state multistep.StateBag) mult } func (s *StepAttachDisk) Cleanup(state multistep.StateBag) { - ui := state.Get("ui").(packer.Ui) + ui := state.Get("ui").(packersdk.Ui) driver := state.Get("driver").(yandex.Driver) if diskID, ok := state.GetOk("secondary_disk_id"); ok { ui.Say("Remove the secondary disk...") diff --git a/post-processor/yandex-export/step-create-s3-keys.go b/post-processor/yandex-export/step-create-s3-keys.go index 14e9e6daf..ddd4ba758 100644 --- a/post-processor/yandex-export/step-create-s3-keys.go +++ b/post-processor/yandex-export/step-create-s3-keys.go @@ -13,7 +13,7 @@ import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" "github.com/hashicorp/packer-plugin-sdk/multistep" - "github.com/hashicorp/packer-plugin-sdk/packer" + packersdk "github.com/hashicorp/packer-plugin-sdk/packer" "github.com/hashicorp/packer/builder/yandex" "github.com/yandex-cloud/go-genproto/yandex/cloud/iam/v1/awscompatibility" ) @@ -25,7 +25,7 @@ type StepCreateS3Keys struct { func (c *StepCreateS3Keys) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { driver := state.Get("driver").(yandex.Driver) - ui := state.Get("ui").(packer.Ui) + ui := state.Get("ui").(packersdk.Ui) ui.Say("Create temporary storage Access Key") // Create temporary storage Access Key @@ -48,7 +48,7 @@ func (c *StepCreateS3Keys) Run(ctx context.Context, state multistep.StateBag) mu func (s *StepCreateS3Keys) Cleanup(state multistep.StateBag) { driver := state.Get("driver").(yandex.Driver) - ui := state.Get("ui").(packer.Ui) + ui := state.Get("ui").(packersdk.Ui) if val, ok := state.GetOk("s3_secret"); ok { ui.Say("S3 secrets have been found") diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/packer/datasource.go b/vendor/github.com/hashicorp/packer-plugin-sdk/packer/datasource.go new file mode 100644 index 000000000..556aac22f --- /dev/null +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/packer/datasource.go @@ -0,0 +1,23 @@ +package packer + +import ( + "github.com/hashicorp/hcl/v2/hcldec" + "github.com/zclconf/go-cty/cty" +) + +// Datasources make data available for use in any source block of a Packer configuration. +type Datasource interface { + // HCL2Speccer is a type that can tell it's own hcl2 conf/layout. + HCL2Speccer + + // Configure takes values from HCL2 and applies them to the struct + Configure(...interface{}) error + + // OutputSpec is the HCL2 layout of the variable output, it will allow + // Packer to validate whether someone is using the output of the data + // source correctly without having to execute the data source call. + OutputSpec() hcldec.ObjectSpec + + // Execute the func call and return the values + Execute() (cty.Value, error) +} diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/packer/datasource_mock.go b/vendor/github.com/hashicorp/packer-plugin-sdk/packer/datasource_mock.go new file mode 100644 index 000000000..be788a288 --- /dev/null +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/packer/datasource_mock.go @@ -0,0 +1,47 @@ +//go:generate mapstructure-to-hcl2 -type MockDatasource,MockDatasourceResponse +package packer + +import ( + "github.com/hashicorp/hcl/v2/hcldec" + configHelper "github.com/hashicorp/packer-plugin-sdk/template/config" + "github.com/zclconf/go-cty/cty" +) + +type MockDatasource struct { + Foo string + + OutputSpecCalled bool `mapstructure-to-hcl2:",skip"` + ConfigureCalled bool `mapstructure-to-hcl2:",skip"` + ConfigureConfigs []interface{} `mapstructure-to-hcl2:",skip"` + ExecuteCalled bool `mapstructure-to-hcl2:",skip"` +} + +type MockDatasourceResponse struct { + Foo string +} + +func (d *MockDatasource) ConfigSpec() hcldec.ObjectSpec { + return d.FlatMapstructure().HCL2Spec() +} + +func (d *MockDatasource) OutputSpec() hcldec.ObjectSpec { + d.OutputSpecCalled = true + return (&MockDatasourceResponse{}).FlatMapstructure().HCL2Spec() +} + +func (d *MockDatasource) Configure(configs ...interface{}) error { + configHelper.Decode(d, nil, configs...) + d.ConfigureCalled = true + d.ConfigureConfigs = configs + return nil +} + +func (d *MockDatasource) Execute() (cty.Value, error) { + d.ExecuteCalled = true + if d.Foo == "" { + d.Foo = "bar" + } + return cty.ObjectVal(map[string]cty.Value{ + "foo": cty.StringVal(d.Foo), + }), nil +} diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/packer/datasource_mock.hcl2spec.go b/vendor/github.com/hashicorp/packer-plugin-sdk/packer/datasource_mock.hcl2spec.go new file mode 100644 index 000000000..2778b82a1 --- /dev/null +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/packer/datasource_mock.hcl2spec.go @@ -0,0 +1,54 @@ +// Code generated by "mapstructure-to-hcl2 -type MockDatasource,MockDatasourceResponse"; DO NOT EDIT. + +package packer + +import ( + "github.com/hashicorp/hcl/v2/hcldec" + "github.com/zclconf/go-cty/cty" +) + +// FlatMockDatasource is an auto-generated flat version of MockDatasource. +// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. +type FlatMockDatasource struct { + Foo *string `cty:"foo" hcl:"foo"` +} + +// FlatMapstructure returns a new FlatMockDatasource. +// FlatMockDatasource is an auto-generated flat version of MockDatasource. +// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up. +func (*MockDatasource) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } { + return new(FlatMockDatasource) +} + +// HCL2Spec returns the hcl spec of a MockDatasource. +// This spec is used by HCL to read the fields of MockDatasource. +// The decoded values from this spec will then be applied to a FlatMockDatasource. +func (*FlatMockDatasource) HCL2Spec() map[string]hcldec.Spec { + s := map[string]hcldec.Spec{ + "foo": &hcldec.AttrSpec{Name: "foo", Type: cty.String, Required: false}, + } + return s +} + +// FlatMockDatasourceResponse is an auto-generated flat version of MockDatasourceResponse. +// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. +type FlatMockDatasourceResponse struct { + Foo *string `cty:"foo" hcl:"foo"` +} + +// FlatMapstructure returns a new FlatMockDatasourceResponse. +// FlatMockDatasourceResponse is an auto-generated flat version of MockDatasourceResponse. +// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up. +func (*MockDatasourceResponse) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } { + return new(FlatMockDatasourceResponse) +} + +// HCL2Spec returns the hcl spec of a MockDatasourceResponse. +// This spec is used by HCL to read the fields of MockDatasourceResponse. +// The decoded values from this spec will then be applied to a FlatMockDatasourceResponse. +func (*FlatMockDatasourceResponse) HCL2Spec() map[string]hcldec.Spec { + s := map[string]hcldec.Spec{ + "foo": &hcldec.AttrSpec{Name: "foo", Type: cty.String, Required: false}, + } + return s +} diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/packer/maps.go b/vendor/github.com/hashicorp/packer-plugin-sdk/packer/maps.go index 7cad0a014..fbe5d80e2 100644 --- a/vendor/github.com/hashicorp/packer-plugin-sdk/packer/maps.go +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/packer/maps.go @@ -72,3 +72,26 @@ func (mob MapOfBuilder) List() []string { } return res } + +type MapOfDatasource map[string]func() (Datasource, error) + +func (mod MapOfDatasource) Has(dataSource string) bool { + _, res := mod[dataSource] + return res +} + +func (mod MapOfDatasource) Start(dataSource string) (Datasource, error) { + d, found := mod[dataSource] + if !found { + return nil, fmt.Errorf("Unknown data source %s", dataSource) + } + return d() +} + +func (mod MapOfDatasource) List() []string { + res := []string{} + for k := range mod { + res = append(res, k) + } + return res +} diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/plugin/set.go b/vendor/github.com/hashicorp/packer-plugin-sdk/plugin/set.go index 1d261499d..56d10c743 100644 --- a/vendor/github.com/hashicorp/packer-plugin-sdk/plugin/set.go +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/plugin/set.go @@ -10,7 +10,6 @@ import ( packersdk "github.com/hashicorp/packer-plugin-sdk/packer" pluginVersion "github.com/hashicorp/packer-plugin-sdk/version" - "github.com/hashicorp/packer/version" ) // Use this name to make the name of the plugin in the packer template match @@ -22,7 +21,6 @@ import ( // plugin per plugin type. const DEFAULT_NAME = "-packer-default-plugin-name-" - // Set is a plugin set. It's API is meant to be very close to what is returned // by plugin.Server // It can describe itself or run a single plugin using the CLI arguments. @@ -32,6 +30,7 @@ type Set struct { Builders map[string]packersdk.Builder PostProcessors map[string]packersdk.PostProcessor Provisioners map[string]packersdk.Provisioner + Datasources map[string]packersdk.Datasource } // SetDescription describes a Set. @@ -41,6 +40,7 @@ type SetDescription struct { Builders []string `json:"builders"` PostProcessors []string `json:"post_processors"` Provisioners []string `json:"provisioners"` + Datasources []string `json:"datasources"` } //// @@ -48,12 +48,13 @@ type SetDescription struct { //// func NewSet() *Set { + sdkVersion := pluginVersion.InitializePluginVersion(pluginVersion.Version, pluginVersion.VersionPrerelease) return &Set{ - version: version.String(), - sdkVersion: version.String(), // TODO: Set me after the split + sdkVersion: sdkVersion.String(), Builders: map[string]packersdk.Builder{}, PostProcessors: map[string]packersdk.PostProcessor{}, Provisioners: map[string]packersdk.Provisioner{}, + Datasources: map[string]packersdk.Datasource{}, } } @@ -82,6 +83,13 @@ func (i *Set) RegisterProvisioner(name string, provisioner packersdk.Provisioner i.Provisioners[name] = provisioner } +func (i *Set) RegisterDatasource(name string, datasource packersdk.Datasource) { + if _, found := i.Datasources[name]; found { + panic(fmt.Errorf("registering duplicate %s datasource", name)) + } + i.Datasources[name] = datasource +} + // Run takes the os Args and runs a packer plugin command from it. // * "describe" command makes the plugin set describe itself. // * "start builder builder-name" starts the builder "builder-name" @@ -125,6 +133,8 @@ func (i *Set) start(kind, name string) error { err = server.RegisterPostProcessor(i.PostProcessors[name]) case "provisioner": err = server.RegisterProvisioner(i.Provisioners[name]) + case "datasource": + err = server.RegisterDatasource(i.Datasources[name]) default: err = fmt.Errorf("Unknown plugin type: %s", kind) } @@ -146,6 +156,7 @@ func (i *Set) description() SetDescription { Builders: i.buildersDescription(), PostProcessors: i.postProcessorsDescription(), Provisioners: i.provisionersDescription(), + Datasources: i.datasourceDescription(), } } @@ -179,3 +190,12 @@ func (i *Set) provisionersDescription() []string { sort.Strings(out) return out } + +func (i *Set) datasourceDescription() []string { + out := []string{} + for key := range i.Datasources { + out = append(out, key) + } + sort.Strings(out) + return out +} diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/rpc/client.go b/vendor/github.com/hashicorp/packer-plugin-sdk/rpc/client.go index ff7d5bb91..8d33bb26d 100644 --- a/vendor/github.com/hashicorp/packer-plugin-sdk/rpc/client.go +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/rpc/client.go @@ -5,7 +5,7 @@ import ( "log" "net/rpc" - packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + "github.com/hashicorp/packer-plugin-sdk/packer" "github.com/ugorji/go/codec" ) @@ -69,7 +69,7 @@ func (c *Client) Close() error { return nil } -func (c *Client) Artifact() packersdk.Artifact { +func (c *Client) Artifact() packer.Artifact { return &artifact{ commonClient: commonClient{ endpoint: DefaultArtifactEndpoint, @@ -78,7 +78,7 @@ func (c *Client) Artifact() packersdk.Artifact { } } -func (c *Client) Build() packersdk.Build { +func (c *Client) Build() packer.Build { return &build{ commonClient: commonClient{ endpoint: DefaultBuildEndpoint, @@ -88,7 +88,7 @@ func (c *Client) Build() packersdk.Build { } } -func (c *Client) Builder() packersdk.Builder { +func (c *Client) Builder() packer.Builder { return &builder{ commonClient: commonClient{ endpoint: DefaultBuilderEndpoint, @@ -98,7 +98,7 @@ func (c *Client) Builder() packersdk.Builder { } } -func (c *Client) Communicator() packersdk.Communicator { +func (c *Client) Communicator() packer.Communicator { return &communicator{ commonClient: commonClient{ endpoint: DefaultCommunicatorEndpoint, @@ -108,7 +108,7 @@ func (c *Client) Communicator() packersdk.Communicator { } } -func (c *Client) Hook() packersdk.Hook { +func (c *Client) Hook() packer.Hook { return &hook{ commonClient: commonClient{ endpoint: DefaultHookEndpoint, @@ -118,7 +118,7 @@ func (c *Client) Hook() packersdk.Hook { } } -func (c *Client) PostProcessor() packersdk.PostProcessor { +func (c *Client) PostProcessor() packer.PostProcessor { return &postProcessor{ commonClient: commonClient{ endpoint: DefaultPostProcessorEndpoint, @@ -128,7 +128,7 @@ func (c *Client) PostProcessor() packersdk.PostProcessor { } } -func (c *Client) Provisioner() packersdk.Provisioner { +func (c *Client) Provisioner() packer.Provisioner { return &provisioner{ commonClient: commonClient{ endpoint: DefaultProvisionerEndpoint, @@ -138,7 +138,17 @@ func (c *Client) Provisioner() packersdk.Provisioner { } } -func (c *Client) Ui() packersdk.Ui { +func (c *Client) Datasource() packer.Datasource { + return &datasource{ + commonClient: commonClient{ + endpoint: DefaultDatasourceEndpoint, + client: c.client, + mux: c.mux, + }, + } +} + +func (c *Client) Ui() packer.Ui { return &Ui{ commonClient: commonClient{ endpoint: DefaultUiEndpoint, diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/rpc/datasource.go b/vendor/github.com/hashicorp/packer-plugin-sdk/rpc/datasource.go new file mode 100644 index 000000000..34a96a74c --- /dev/null +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/rpc/datasource.go @@ -0,0 +1,124 @@ +package rpc + +import ( + "bytes" + "encoding/gob" + "fmt" + + "github.com/hashicorp/hcl/v2/hcldec" + "github.com/hashicorp/packer-plugin-sdk/packer" + "github.com/zclconf/go-cty/cty" +) + +// An implementation of packer.Datasource where the data source is actually +// executed over an RPC connection. +type datasource struct { + commonClient +} + +type DatasourceConfigureArgs struct { + Configs []interface{} +} + +type DatasourceConfigureResponse struct { + Error *BasicError +} + +func (d *datasource) Configure(configs ...interface{}) error { + configs, err := encodeCTYValues(configs) + if err != nil { + return err + } + var resp DatasourceConfigureResponse + if err := d.client.Call(d.endpoint+".Configure", &DatasourceConfigureArgs{Configs: configs}, &resp); err != nil { + return err + } + if resp.Error != nil { + err = resp.Error + } + return err +} + +type OutputSpecResponse struct { + OutputSpec []byte +} + +func (d *datasource) OutputSpec() hcldec.ObjectSpec { + resp := new(OutputSpecResponse) + if err := d.client.Call(d.endpoint+".OutputSpec", new(interface{}), resp); err != nil { + err := fmt.Errorf("Datasource.OutputSpec failed: %v", err) + panic(err.Error()) + } + res := hcldec.ObjectSpec{} + err := gob.NewDecoder(bytes.NewReader(resp.OutputSpec)).Decode(&res) + if err != nil { + panic("ici:" + err.Error()) + } + return res +} + +type ExecuteResponse struct { + Value []byte + Error *BasicError +} + +func (d *datasource) Execute() (cty.Value, error) { + res := new(cty.Value) + resp := new(ExecuteResponse) + if err := d.client.Call(d.endpoint+".Execute", new(interface{}), resp); err != nil { + err := fmt.Errorf("Datasource.Execute failed: %v", err) + return *res, err + } + err := gob.NewDecoder(bytes.NewReader(resp.Value)).Decode(&res) + if err != nil { + return *res, err + } + return *res, nil +} + +// DatasourceServer wraps a packer.Datasource implementation and makes it +// exportable as part of a Golang RPC server. +type DatasourceServer struct { + contextCancel func() + + commonServer + d packer.Datasource +} + +func (d *DatasourceServer) Configure(args *DatasourceConfigureArgs, reply *DatasourceConfigureResponse) error { + config, err := decodeCTYValues(args.Configs) + if err != nil { + return err + } + err = d.d.Configure(config...) + reply.Error = NewBasicError(err) + return nil +} + +func (d *DatasourceServer) OutputSpec(args *DatasourceConfigureArgs, reply *OutputSpecResponse) error { + spec := d.d.OutputSpec() + b := bytes.NewBuffer(nil) + err := gob.NewEncoder(b).Encode(spec) + reply.OutputSpec = b.Bytes() + return err +} + +func (d *DatasourceServer) Execute(args *interface{}, reply *ExecuteResponse) error { + spec, err := d.d.Execute() + reply.Error = NewBasicError(err) + b := bytes.NewBuffer(nil) + err = gob.NewEncoder(b).Encode(spec) + reply.Value = b.Bytes() + return err +} + +func (d *DatasourceServer) Cancel(args *interface{}, reply *interface{}) error { + if d.contextCancel != nil { + d.contextCancel() + } + return nil +} + +func init() { + gob.Register(new(cty.Value)) +} diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/rpc/server.go b/vendor/github.com/hashicorp/packer-plugin-sdk/rpc/server.go index 3d0ef4f7f..3926cf4d3 100644 --- a/vendor/github.com/hashicorp/packer-plugin-sdk/rpc/server.go +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/rpc/server.go @@ -5,7 +5,7 @@ import ( "log" "net/rpc" - packersdk "github.com/hashicorp/packer-plugin-sdk/packer" + "github.com/hashicorp/packer-plugin-sdk/packer" "github.com/ugorji/go/codec" ) @@ -19,6 +19,7 @@ const ( DefaultHookEndpoint = "Hook" DefaultPostProcessorEndpoint = "PostProcessor" DefaultProvisionerEndpoint = "Provisioner" + DefaultDatasourceEndpoint = "Datasource" DefaultUiEndpoint = "Ui" ) @@ -63,20 +64,20 @@ func (s *Server) Close() error { return nil } -func (s *Server) RegisterArtifact(a packersdk.Artifact) error { +func (s *Server) RegisterArtifact(a packer.Artifact) error { return s.server.RegisterName(DefaultArtifactEndpoint, &ArtifactServer{ artifact: a, }) } -func (s *Server) RegisterBuild(b packersdk.Build) error { +func (s *Server) RegisterBuild(b packer.Build) error { return s.server.RegisterName(DefaultBuildEndpoint, &BuildServer{ build: b, mux: s.mux, }) } -func (s *Server) RegisterBuilder(b packersdk.Builder) error { +func (s *Server) RegisterBuilder(b packer.Builder) error { return s.server.RegisterName(DefaultBuilderEndpoint, &BuilderServer{ commonServer: commonServer{ selfConfigurable: b, @@ -86,7 +87,7 @@ func (s *Server) RegisterBuilder(b packersdk.Builder) error { }) } -func (s *Server) RegisterCommunicator(c packersdk.Communicator) error { +func (s *Server) RegisterCommunicator(c packer.Communicator) error { return s.server.RegisterName(DefaultCommunicatorEndpoint, &CommunicatorServer{ c: c, commonServer: commonServer{ @@ -95,14 +96,14 @@ func (s *Server) RegisterCommunicator(c packersdk.Communicator) error { }) } -func (s *Server) RegisterHook(h packersdk.Hook) error { +func (s *Server) RegisterHook(h packer.Hook) error { return s.server.RegisterName(DefaultHookEndpoint, &HookServer{ hook: h, mux: s.mux, }) } -func (s *Server) RegisterPostProcessor(p packersdk.PostProcessor) error { +func (s *Server) RegisterPostProcessor(p packer.PostProcessor) error { return s.server.RegisterName(DefaultPostProcessorEndpoint, &PostProcessorServer{ commonServer: commonServer{ selfConfigurable: p, @@ -112,7 +113,7 @@ func (s *Server) RegisterPostProcessor(p packersdk.PostProcessor) error { }) } -func (s *Server) RegisterProvisioner(p packersdk.Provisioner) error { +func (s *Server) RegisterProvisioner(p packer.Provisioner) error { return s.server.RegisterName(DefaultProvisionerEndpoint, &ProvisionerServer{ commonServer: commonServer{ selfConfigurable: p, @@ -122,7 +123,17 @@ func (s *Server) RegisterProvisioner(p packersdk.Provisioner) error { }) } -func (s *Server) RegisterUi(ui packersdk.Ui) error { +func (s *Server) RegisterDatasource(d packer.Datasource) error { + return s.server.RegisterName(DefaultDatasourceEndpoint, &DatasourceServer{ + commonServer: commonServer{ + selfConfigurable: d, + mux: s.mux, + }, + d: d, + }) +} + +func (s *Server) RegisterUi(ui packer.Ui) error { return s.server.RegisterName(DefaultUiEndpoint, &UiServer{ ui: ui, register: s.server.RegisterName, diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/version/version.go b/vendor/github.com/hashicorp/packer-plugin-sdk/version/version.go index 345530638..ebc14e02b 100644 --- a/vendor/github.com/hashicorp/packer-plugin-sdk/version/version.go +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/version/version.go @@ -12,6 +12,14 @@ import ( // The git commit that was compiled. This will be filled in by the compiler. var GitCommit string +// Package version helps plugin creators set and track the sdk version using +const Version = "0.0.6" + +// A pre-release marker for the version. If this is "" (empty string) +// then it means that it is a final release. Otherwise, this is a pre-release +// such as "dev" (in development), "beta", "rc1", etc. +const VersionPrerelease = "dev" + // InitializePluginVersion initializes the SemVer and returns a version var. // If the provided "version" string is not valid, the call to version.Must // will panic. Therefore, this function should always be called in a package diff --git a/vendor/modules.txt b/vendor/modules.txt index 54ffb937c..383300190 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -355,7 +355,7 @@ github.com/hashicorp/hcl/v2/hclparse github.com/hashicorp/hcl/v2/hclsyntax github.com/hashicorp/hcl/v2/hclwrite github.com/hashicorp/hcl/v2/json -# github.com/hashicorp/packer-plugin-sdk v0.0.6 +# github.com/hashicorp/packer-plugin-sdk v0.0.7-0.20210111224258-fd30ebb797f0 github.com/hashicorp/packer-plugin-sdk/acctest github.com/hashicorp/packer-plugin-sdk/acctest/provisioneracc github.com/hashicorp/packer-plugin-sdk/acctest/testutils