Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Commit

Permalink
Fixed for #6 #7 #8
Browse files Browse the repository at this point in the history
  • Loading branch information
iwarapter committed Sep 7, 2019
1 parent 97aa80e commit 3755066
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
vendor
func-tests/.terraform
func-tests/crash.log
func-tests/run.log
func-tests/terraform.*
terraform-provider-pingaccess
terraform-provider-pingaccess_v*
.scannerwork/
.vscode/
run.log
Expand Down
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ addons:
organization: "iwarapter-github"

script:
- go mod vendor
- go mod verify
- make test-and-report
- sonar-scanner
- go mod vendor || travis_terminate 1;
- go mod verify || travis_terminate 1;
- make test-and-report || travis_terminate 1;
- sonar-scanner || travis_terminate 1;
34 changes: 18 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Makefile
VERSION ?= local
NAME=terraform-provider-pingaccess_v${VERSION}

sweep:
@TF_ACC=1 go test ./... -v -sweep=true
Expand All @@ -8,33 +10,33 @@ pa-init:

test:
@rm -f pingaccess/terraform.log
@TF_LOG=TRACE TF_LOG_PATH=./terraform.log TF_ACC=1 go test ./... -v
@TF_LOG=TRACE TF_LOG_PATH=./terraform.log TF_ACC=1 go test -mod=vendor ./... -v

test-and-report:
@rm -f pingaccess/terraform.log coverage.out report.json
@TF_LOG=TRACE TF_LOG_PATH=./terraform.log TF_ACC=1 go test ./... -v -coverprofile=coverage.out -json > report.json && go tool cover -func=coverage.out
@TF_LOG=TRACE TF_LOG_PATH=./terraform.log TF_ACC=1 go test -mod=vendor ./... -v -coverprofile=coverage.out -json > report.json && go tool cover -func=coverage.out

build:
@go build -o terraform-provider-pingaccess .
@go build -mod=vendor -o ${NAME} -gcflags "all=-trimpath=$GOPATH" .

release:
@rm -rf build/*
GOOS=darwin GOARCH=amd64 go build -o build/darwin_amd64/terraform-provider-pingaccess . && zip -j build/darwin_amd64.zip build/darwin_amd64/terraform-provider-pingaccess
# GOOS=freebsd GOARCH=386 go build -o build/freebsd_386/terraform-provider-pingaccess .
# GOOS=freebsd GOARCH=amd64 go build -o build/freebsd_amd64/terraform-provider-pingaccess .
# GOOS=freebsd GOARCH=arm go build -o build/freebsd_arm/terraform-provider-pingaccess .
# GOOS=linux GOARCH=386 go build -o build/linux_386/terraform-provider-pingaccess .
GOOS=linux GOARCH=amd64 go build -o build/linux_amd64/terraform-provider-pingaccess . && zip -j build/linux_amd64.zip build/linux_amd64/terraform-provider-pingaccess
# GOOS=linux GOARCH=arm go build -o build/linux_arm/terraform-provider-pingaccess .
# GOOS=openbsd GOARCH=386 go build -o build/openbsd_386/terraform-provider-pingaccess .
# GOOS=openbsd GOARCH=amd64 go build -o build/openbsd_amd64/terraform-provider-pingaccess .
# GOOS=solaris GOARCH=amd64 go build -o build/solaris_amd64/terraform-provider-pingaccess .
# GOOS=windows GOARCH=386 go build -o build/windows_386/terraform-provider-pingaccess .
GOOS=windows GOARCH=amd64 go build -o build/windows_amd64/terraform-provider-pingaccess . && zip -j build/windows_amd64.zip build/windows_amd64/terraform-provider-pingaccess
GOOS=darwin GOARCH=amd64 go build -o -mod=vendor build/darwin_amd64/${NAME} -gcflags "all=-trimpath=$GOPATH" . && zip -j build/darwin_amd64.zip build/darwin_amd64/${NAME}
# GOOS=freebsd GOARCH=386 go build -o -mod=vendor build/freebsd_386/${NAME} -gcflags "all=-trimpath=$GOPATH" .
# GOOS=freebsd GOARCH=amd64 go build -o -mod=vendor build/freebsd_amd64/${NAME} -gcflags "all=-trimpath=$GOPATH" .
# GOOS=freebsd GOARCH=arm go build -o -mod=vendor build/freebsd_arm/${NAME} -gcflags "all=-trimpath=$GOPATH" .
# GOOS=linux GOARCH=386 go build -o -mod=vendor build/linux_386/${NAME} -gcflags "all=-trimpath=$GOPATH" .
GOOS=linux GOARCH=amd64 go build -o -mod=vendor build/linux_amd64/${NAME} -gcflags "all=-trimpath=$GOPATH" . && zip -j build/linux_amd64.zip build/linux_amd64/${NAME}
# GOOS=linux GOARCH=arm go build -o -mod=vendor build/linux_arm/${NAME} -gcflags "all=-trimpath=$GOPATH" .
# GOOS=openbsd GOARCH=386 go build -o -mod=vendor build/openbsd_386/${NAME} -gcflags "all=-trimpath=$GOPATH" .
# GOOS=openbsd GOARCH=amd64 go build -o -mod=vendor build/openbsd_amd64/${NAME} -gcflags "all=-trimpath=$GOPATH" .
# GOOS=solaris GOARCH=amd64 go build -o -mod=vendor build/solaris_amd64/${NAME} -gcflags "all=-trimpath=$GOPATH" .
# GOOS=windows GOARCH=386 go build -o -mod=vendor build/windows_386/${NAME} -gcflags "all=-trimpath=$GOPATH" .
GOOS=windows GOARCH=amd64 go build -o -mod=vendor build/windows_amd64/${NAME} -gcflags "all=-trimpath=$GOPATH" . && zip -j build/windows_amd64.zip build/windows_amd64/${NAME}

deploy-local:
@mkdir -p ~/.terraform.d/plugins
@cp terraform-provider-pingaccess ~/.terraform.d/plugins/
@cp ${NAME} ~/.terraform.d/plugins/

func-init:
@rm -rf func-tests/.terraform
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/iwarapter/terraform-provider-pingaccess

go 1.12

replace git.apache.org/thrift.git => github.com/apache/thrift v0.0.0-20180902110319-2566ecd5d999

require (
github.com/GeertJohan/go.rice v1.0.0 // indirect
github.com/Microsoft/go-winio v0.4.13 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkK
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/antchfx/xpath v0.0.0-20190129040759-c8489ed3251e/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk=
github.com/antchfx/xquery v0.0.0-20180515051857-ad5b8c7a47b0/go.mod h1:LzD22aAzDP8/dyiCKFp31He4m2GPjl0AFyzDtZzUu9M=
github.com/apache/thrift v0.0.0-20180902110319-2566ecd5d999/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apparentlymart/go-cidr v1.0.0 h1:lGDvXx8Lv9QHjrAVP7jyzleG4F9+FkRhJcEsDFxeb8w=
github.com/apparentlymart/go-cidr v1.0.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc=
github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
Expand Down
21 changes: 18 additions & 3 deletions pingaccess/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,24 @@ func TestMain(m *testing.M) {
log.Fatalf("Could not connect to docker: %s", err)
}

options := &dockertest.RunOptions{
Repository: "pingidentity/pingaccess",
Tag: "5.2.2-edge",
devOpsUser, devOpsUserExists := os.LookupEnv("PING_IDENTITY_DEVOPS_USER")
devOpsKey, devOpsKeyExists := os.LookupEnv("PING_IDENTITY_DEVOPS_KEY")

var options *dockertest.RunOptions

if devOpsUserExists && devOpsKeyExists {
options = &dockertest.RunOptions{
Repository: "pingidentity/pingaccess",
Env: []string{fmt.Sprintf("PING_IDENTITY_DEVOPS_USER=%s", devOpsUser), fmt.Sprintf("PING_IDENTITY_DEVOPS_KEY=%s", devOpsKey)},
Tag: "5.2.2-edge",
}
} else {
dir, _ := os.Getwd()
options = &dockertest.RunOptions{
Repository: "pingidentity/pingaccess",
Mounts: []string{dir + "/pingaccess.lic:/opt/in/instance/conf/pingaccess.lic"},
Tag: "5.2.2-edge",
}
}

// pulls an image, creates a container based on it and runs it
Expand Down
29 changes: 2 additions & 27 deletions pingaccess/resource_pingaccess_application.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pingaccess

import (
"encoding/json"
"fmt"
"log"
"strconv"
Expand Down Expand Up @@ -278,32 +277,8 @@ func resourcePingAccessApplicationReadData(d *schema.ResourceData) *pa.Applicati
}
}

if _, ok := d.GetOk(policy); ok {
policySet := d.Get(policy).([]interface{})

webPolicies := make([]*pa.PolicyItem, 0)
apiPolicies := make([]*pa.PolicyItem, 0)

policy := policySet[0].(map[string]interface{})
for _, pV := range policy["web"].(*schema.Set).List() {
p := pV.(map[string]interface{})
webPolicies = append(webPolicies, &pa.PolicyItem{
Id: json.Number(p["id"].(string)),
Type: String(p["type"].(string)),
})
}
for _, pV := range policy["api"].(*schema.Set).List() {
p := pV.(map[string]interface{})
apiPolicies = append(apiPolicies, &pa.PolicyItem{
Id: json.Number(p["id"].(string)),
Type: String(p["type"].(string)),
})
}
policies := map[string]*[]*pa.PolicyItem{
"Web": &webPolicies,
"API": &apiPolicies,
}
application.Policy = policies
if val, ok := d.GetOkExists("policy"); ok {
application.Policy = expandPolicy(val.([]interface{}))
}

return application
Expand Down
5 changes: 3 additions & 2 deletions pingaccess/resource_pingaccess_application_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func resourcePingAccessApplicationResourceSchema() map[string]*schema.Schema {
},
pathPrefixes: &schema.Schema{
Type: schema.TypeSet,
Required: true,
Deprecated: "DEPRECATED - to be removed in a future release; please use 'path_patterns' instead",
Optional: true,
Deprecated: "To be removed in a future release; please use 'path_patterns' instead",
Elem: &schema.Schema{
Type: schema.TypeString,
},
Expand Down Expand Up @@ -309,6 +309,7 @@ func resourcePingAccessApplicationResourceReadData(d *schema.ResourceData) *pa.R

if val, ok := d.GetOkExists("policy"); ok {
resource.Policy = expandPolicy(val.([]interface{}))

}

return resource
Expand Down
2 changes: 2 additions & 0 deletions pingaccess/resource_pingaccess_application_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ resource "pingaccess_application_resource" "app_res_test_root_resource" {
"/*"
]
policy {}
audit_level = "ON"
anonymous = false
enabled = true
Expand Down
1 change: 0 additions & 1 deletion pingaccess/resource_pingaccess_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func resourcePingAccessCertificateSchema() map[string]*schema.Schema {
"alias": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"file_data": &schema.Schema{
Type: schema.TypeString,
Expand Down
27 changes: 17 additions & 10 deletions pingaccess/resource_pingaccess_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ func TestAccPingAccessCertificate(t *testing.T) {
CheckDestroy: testAccCheckPingAccessCertificateDestroy,
Steps: []resource.TestStep{
{
Config: testAccPingAccessCertificateConfig("bar", "1"),
Config: testAccPingAccessCertificateConfig("bar"),
Check: resource.ComposeTestCheckFunc(
testAccCheckPingAccessCertificateExists("pingaccess_certificate.acc_test_idm_bar"),
testAccCheckPingAccessCertificateAttributes("pingaccess_certificate.acc_test_idm_bar"),
testAccCheckPingAccessCertificateExists("pingaccess_certificate.test"),
testAccCheckPingAccessCertificateAttributes("pingaccess_certificate.test"),
),
},
{
Config: testAccPingAccessCertificateConfig("bar", "2"),
Config: testAccPingAccessCertificateConfig("foo"),
Check: resource.ComposeTestCheckFunc(
testAccCheckPingAccessCertificateExists("pingaccess_certificate.acc_test_idm_bar"),
testAccCheckPingAccessCertificateAttributes("pingaccess_certificate.acc_test_idm_bar"),
testAccCheckPingAccessCertificateExists("pingaccess_certificate.test"),
testAccCheckPingAccessCertificateAttributes("pingaccess_certificate.test"),
),
},
},
Expand All @@ -37,12 +37,19 @@ func testAccCheckPingAccessCertificateDestroy(s *terraform.State) error {
return nil
}

func testAccPingAccessCertificateConfig(name, configUpdate string) string {
func testAccPingAccessCertificateConfig(name string) string {
return fmt.Sprintf(`
resource "pingaccess_certificate" "acc_test_idm_%s" {
resource "pingaccess_trusted_certificate_group" "test" {
name = "test_tcg"
cert_ids = [
pingaccess_certificate.test.id
]
}
resource "pingaccess_certificate" "test" {
alias = "%s"
file_data = "${base64encode(file("test_cases/amazon_root_ca%s.pem"))}"
}`, name, name, configUpdate)
file_data = "${base64encode(file("test_cases/amazon_root_ca1.pem"))}"
}`, name)
}

func testAccCheckPingAccessCertificateExists(n string) resource.TestCheckFunc {
Expand Down
1 change: 0 additions & 1 deletion pingaccess/resource_pingaccess_keypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func resourcePingAccessKeyPairSchema() map[string]*schema.Schema {
"alias": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"chain_certificates": &schema.Schema{
Type: schema.TypeSet,
Expand Down
15 changes: 8 additions & 7 deletions pingaccess/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,15 @@ func expandPolicy(in []interface{}) map[string]*[]*pa.PolicyItem {

webPolicies := make([]*pa.PolicyItem, 0)
apiPolicies := make([]*pa.PolicyItem, 0)

for _, raw := range in {
l := raw.(map[string]interface{})
if val, ok := l["web"]; ok && len(val.(*schema.Set).List()) > 0 {
webPolicies = expandPolicyItem(val.(*schema.Set).List())
}
if val, ok := l["api"]; ok && len(val.(*schema.Set).List()) > 0 {
apiPolicies = expandPolicyItem(val.(*schema.Set).List())
if raw != nil {
l := raw.(map[string]interface{})
if val, ok := l["web"]; ok && len(val.(*schema.Set).List()) > 0 {
webPolicies = expandPolicyItem(val.(*schema.Set).List())
}
if val, ok := l["api"]; ok && len(val.(*schema.Set).List()) > 0 {
apiPolicies = expandPolicyItem(val.(*schema.Set).List())
}
}
}

Expand Down

0 comments on commit 3755066

Please sign in to comment.