Skip to content

Commit 244860d

Browse files
committed
v0.0.2: rename external-json to external
Fix the docs Improve error reporting a bit (include stderr in errors) Update packer-plugin-sdk to v0.4.0
1 parent 062438d commit 244860d

File tree

14 files changed

+460
-67
lines changed

14 files changed

+460
-67
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ A plugin for [Packer](https://www.packer.io/) which provides access to external
77
packer {
88
required_plugins {
99
external = {
10-
version = ">= 0.0.1"
10+
version = ">= 0.0.2"
1111
source = "github.com/joomcode/external"
1212
}
1313
}
1414
}
1515
16-
data "external-json" "example" {
16+
data "external" "example" {
1717
program = ["jq", "{ \"foo\": .key1 }"]
1818
query = {
1919
key1 = "val1"
@@ -26,8 +26,8 @@ data "external-raw" "example" {
2626
}
2727
2828
locals {
29-
json_result = data.external-json.example.result["foo"] # "val1"
30-
raw_result = data.external-raw.example.result # "olleh\n"
29+
external_result = data.external.example.result["foo"] # "val1"
30+
raw_result = data.external-raw.example.result # "olleh\n"
3131
}
3232
```
3333

datasource/json/data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (d *Datasource) Execute() (cty.Value, error) {
7878
stderr = string(eerr.Stderr)
7979
}
8080
log.Printf("command failed, err=%v, stdout='%q', stderr='%q'", err, string(resultJson), stderr)
81-
return cty.Value{}, fmt.Errorf("external program run failed: %v", err)
81+
return cty.Value{}, fmt.Errorf("external program run failed: %v, stderr='%q'", err, stderr)
8282
}
8383
log.Println("command result:", string(resultJson))
8484

datasource/json/data_acc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
//go:embed test-fixtures/template.pkr.hcl
1616
var testDatasourceHCL2Basic string
1717

18-
func TestAccExternalDatasource(t *testing.T) {
18+
func TestAccExternalJsonDatasource(t *testing.T) {
1919
testCase := &acctest.PluginTestCase{
2020
Name: "external_datasource_basic_test",
2121
Setup: func() error {
@@ -25,7 +25,7 @@ func TestAccExternalDatasource(t *testing.T) {
2525
return nil
2626
},
2727
Template: testDatasourceHCL2Basic,
28-
Type: "external-json",
28+
Type: "external",
2929
Check: func(buildCommand *exec.Cmd, logfile string) error {
3030
if buildCommand.ProcessState != nil {
3131
if buildCommand.ProcessState.ExitCode() != 0 {

datasource/json/test-fixtures/template.pkr.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
data "external-json" "test" {
1+
data "external" "test" {
22
program = ["jq", "-r", "{\"my_key1\": \"my_\\(.key1)\"}"]
33
query = {
44
key1 = "val1"
55
}
66
}
77

88
locals {
9-
result = data.external-json.test.result
9+
result = data.external.test.result
1010
}
1111

1212
source "null" "test" {

datasource/raw/data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (d *Datasource) Execute() (cty.Value, error) {
7272
stderr = string(eerr.Stderr)
7373
}
7474
log.Printf("command failed, err=%v, stdout='%q', stderr='%q'", err, string(resultRaw), stderr)
75-
return cty.Value{}, fmt.Errorf("external program run failed: %v", err)
75+
return cty.Value{}, fmt.Errorf("external program run failed: %v, stderr='%q'", err, stderr)
7676
}
7777
log.Println("command result:", string(resultRaw))
7878

datasource/raw/data_acc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
//go:embed test-fixtures/template.pkr.hcl
1616
var testDatasourceHCL2Basic string
1717

18-
func TestAccExternalDatasource(t *testing.T) {
18+
func TestAccExternalRawDatasource(t *testing.T) {
1919
testCase := &acctest.PluginTestCase{
2020
Name: "external_datasource_basic_test",
2121
Setup: func() error {

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ The External plugin allows to communicate with external programs
33

44
Contents:
55
- [index](/packer/plugins/datasources/index.mdx)
6-
- [data source json](/packer/plugins/datasources/json.mdx)
7-
- [data source raw](/packer/plugins/datasources/raw.mdx)
6+
- [data source external](/packer/plugins/datasources/external.mdx)
7+
- [data source external-raw](/packer/plugins/datasources/external-raw.mdx)
88

docs/datasources/json.mdx renamed to docs/datasources/external.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
description: >
33
The json data source is used to communicate with external commands
44
using JSON protocol.
5-
page_title: JSON - Data Sources
6-
nav_title: JSON
5+
page_title: External - Data Sources
6+
nav_title: External
77
---
88

9-
# External JSON
9+
# External
1010

11-
Type: `external-json`
11+
Type: `external`
1212

13-
The `json` data source allows an external program implementing a specific
13+
The `external` data source allows an external program implementing a specific
1414
protocol (defined below) to act as a data source, exposing arbitrary
1515
data for use elsewhere in the Packer configuration.
1616

@@ -24,15 +24,15 @@ be used differently) on different operating systems.
2424

2525
### Example Usage
2626
```hcl
27-
data "external-json" "example" {
27+
data "external" "example" {
2828
program = ["jq", "{ \"foo\": .key1 }"]
2929
query = {
3030
key1 = "val1"
3131
}
3232
}
3333
3434
locals {
35-
result = data.external-json.example.result
35+
result = data.external.example.result
3636
}
3737
3838
source "null" "example" {

docs/datasources/index.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ sidebar_title: Overview
1010
The External plugin is able to communicate with external commands.
1111
The following data sources are currently supported:
1212

13-
- [json](/packer/plugins/datasources/external/json) - Communicate with external commands
13+
- [external](/packer/plugins/datasources/external/external) - Communicate with external commands
1414
using JSON protocol.
15-
- [raw](/packer/plugins/datasources/external/raw) - Communicate with external commands
15+
- [external-raw](/packer/plugins/datasources/external/raw) - Communicate with external commands
1616
using plaintext protocol.
1717

1818
## Installation
@@ -32,7 +32,7 @@ Then, run [`packer init`](https://www.packer.io/docs/commands/init).
3232
packer {
3333
required_plugins {
3434
external = {
35-
version = ">= 0.0.1"
35+
version = ">= 0.0.2"
3636
source = "github.com/joomcode/external"
3737
}
3838
}

docs/datasources/raw.mdx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
description: >
33
The raw data source is used to communicate with external commands
44
using plaintext protocol.
5-
page_title: Raw - Data Sources
6-
nav_title: Raw
5+
page_title: External Raw - Data Sources
6+
nav_title: External Raw
77
---
88

99
# External Raw
1010

1111
Type: `external-raw`
1212

13-
The `raw` data source allows an external program to act as a data source,
13+
The `external-raw` data source allows an external program to act as a data source,
1414
exposing arbitrary data for use elsewhere in the Packer configuration.
1515

1616
~> **Warning** This mechanism is provided as an "escape hatch" for exceptional
@@ -49,12 +49,15 @@ build {
4949

5050
## External Program Protocol
5151

52-
The protocol is almost the same as the one used by the
53-
[json](/packer/plugins/datasources/external/json) data source.
54-
However, query and result are plaintext strings instead
55-
of JSON objects. Please refer to the [json](/packer/plugins/datasources/external/json)
52+
The protocol is similar to the one used by the
53+
[external](/packer/plugins/datasources/external/external) data source.
54+
However, query and result are plaintext strings instead of JSON objects.
55+
Refer to the [external](/packer/plugins/datasources/external/external) doc
5656
for more details.
5757

58+
`external-raw` should be used over `external` in cases where the external program
59+
does not support JSON input and/or output.
60+
5861
## Argument Reference
5962

6063
### Required

0 commit comments

Comments
 (0)