diff --git a/bin/build b/bin/build index 63d653a7..914a1122 100755 --- a/bin/build +++ b/bin/build @@ -4,14 +4,7 @@ set -e echo -e "\nGenerating Binary for ${GOOS} on arch ${GOARCH}..." -if [ $# -eq 0 ] - then - echo "Usage $0 " - exit 1 -fi - - CURRENTDIR=`pwd` -CGO_ENABLED=0 go build -o $CURRENTDIR/out/terraform-provider-credhub_$1 +CGO_ENABLED=0 go build -o $CURRENTDIR/out/terraform-provider-credhub echo -e "\nGenerating Binary finished." diff --git a/bin/build-all.sh b/bin/build-all.sh index 1b606b08..5b19be3e 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -5,8 +5,8 @@ set -e OUTDIR=$(dirname $0)/../out BINARYNAME="terraform-provider-credhub" -GOARCH=amd64 GOOS=windows $(dirname $0)/build $1 && cp $OUTDIR/$BINARYNAME "$OUTDIR/${BINARYNAME}_windows_amd64.exe" -GOARCH=386 GOOS=windows $(dirname $0)/build $1 && cp $OUTDIR/$BINARYNAME "$OUTDIR/${BINARYNAME}_windows_386.exe" -GOARCH=amd64 GOOS=linux $(dirname $0)/build $1 && cp $OUTDIR/$BINARYNAME "$OUTDIR/${BINARYNAME}_linux_amd64" -GOARCH=386 GOOS=linux $(dirname $0)/build $1 && cp $OUTDIR/$BINARYNAME "$OUTDIR/${BINARYNAME}_linux_386" -GOARCH=amd64 GOOS=darwin $(dirname $0)/build $1 && cp $OUTDIR/$BINARYNAME "$OUTDIR/${BINARYNAME}_darwin_amd64" \ No newline at end of file +GOARCH=amd64 GOOS=windows $(dirname $0)/build && cp $OUTDIR/$BINARYNAME "$OUTDIR/${BINARYNAME}_windows_amd64.exe" +GOARCH=386 GOOS=windows $(dirname $0)/build && cp $OUTDIR/$BINARYNAME "$OUTDIR/${BINARYNAME}_windows_386.exe" +GOARCH=amd64 GOOS=linux $(dirname $0)/build && cp $OUTDIR/$BINARYNAME "$OUTDIR/${BINARYNAME}_linux_amd64" +GOARCH=386 GOOS=linux $(dirname $0)/build && cp $OUTDIR/$BINARYNAME "$OUTDIR/${BINARYNAME}_linux_386" +GOARCH=amd64 GOOS=darwin $(dirname $0)/build && cp $OUTDIR/$BINARYNAME "$OUTDIR/${BINARYNAME}_darwin_amd64" diff --git a/credhub/data_sources.go b/credhub/data_sources.go index e2d8c565..f11125fc 100644 --- a/credhub/data_sources.go +++ b/credhub/data_sources.go @@ -13,9 +13,13 @@ type GenericDataSource struct { func (GenericDataSource) DataSourceRead(d *schema.ResourceData, meta interface{}) error { credMap := make(map[string]interface{}) - dataSourceReadGeneric(d, meta, &credMap, func(credValue interface{}) { + err := dataSourceReadGeneric(d, meta, &credMap, func(credValue interface{}) { credMap["value"] = fmt.Sprint(credValue) }) + if err != nil { + return err + } + for name, cred := range credMap { credKind := reflect.TypeOf(cred).Kind() if credKind == reflect.String { @@ -48,9 +52,12 @@ type ValueDataSource struct { func (ValueDataSource) DataSourceRead(d *schema.ResourceData, meta interface{}) error { data := "" - dataSourceReadGeneric(d, meta, &data, func(credValue interface{}) { + err := dataSourceReadGeneric(d, meta, &data, func(credValue interface{}) { data = fmt.Sprint(credValue) }) + if err != nil { + return err + } d.Set("value", data) return nil } @@ -70,9 +77,12 @@ type JsonDataSource struct { func (JsonDataSource) DataSourceRead(d *schema.ResourceData, meta interface{}) error { data := make(map[string]interface{}) - dataSourceReadGeneric(d, meta, &data, func(credValue interface{}) { + err := dataSourceReadGeneric(d, meta, &data, func(credValue interface{}) { data["value"] = fmt.Sprint(credValue) }) + if err != nil { + return err + } b, err := json.MarshalIndent(data, "", "\t") if err != nil { return err @@ -96,9 +106,12 @@ type PasswordDataSource struct { func (PasswordDataSource) DataSourceRead(d *schema.ResourceData, meta interface{}) error { password := "" - dataSourceReadGeneric(d, meta, &password, func(credValue interface{}) { + err := dataSourceReadGeneric(d, meta, &password, func(credValue interface{}) { password = fmt.Sprint(credValue) }) + if err != nil { + return err + } d.Set("password", password) return nil } @@ -119,7 +132,7 @@ type CertificateDataSource struct { func (CertificateDataSource) DataSourceRead(d *schema.ResourceData, meta interface{}) error { data := values.Certificate{} var err error - dataSourceReadGeneric(d, meta, &data, func(credValue interface{}) { + err = dataSourceReadGeneric(d, meta, &data, func(credValue interface{}) { err = fmt.Errorf("This is not a certificate credential") }) if err != nil { diff --git a/credhub/provider.go b/credhub/provider.go index 87a53394..b9a19c92 100644 --- a/credhub/provider.go +++ b/credhub/provider.go @@ -57,6 +57,12 @@ func Provider() terraform.ResourceProvider { Default: false, Description: "Set to true to skip verification of the API endpoint. Not recommended!", }, + "proxy": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("CREDHUB_PROXY", ""), + Description: "Create given proxy before connecting to connect credhub server", + }, }, ResourcesMap: map[string]*schema.Resource{ @@ -109,6 +115,12 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { if caCert != "" { options = append(options, credhub.CaCerts(caCert)) } + + proxy := d.Get("proxy").(string) + if proxy != "" { + os.Setenv("CREDHUB_PROXY", proxy) + } + client, err := credhub.New(apiEndpoint, options...) if err != nil { return nil, err