Skip to content

Commit

Permalink
Merge branch 'master' of github.com:orange-cloudfoundry/terraform-pro…
Browse files Browse the repository at this point in the history
…vider-credhub
  • Loading branch information
ArthurHlt committed Aug 16, 2018
2 parents db6b57a + d33975d commit e587c25
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
9 changes: 1 addition & 8 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ set -e

echo -e "\nGenerating Binary for ${GOOS} on arch ${GOARCH}..."

if [ $# -eq 0 ]
then
echo "Usage $0 <version_terraform>"
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."
10 changes: 5 additions & 5 deletions bin/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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"
23 changes: 18 additions & 5 deletions credhub/data_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions credhub/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e587c25

Please sign in to comment.