-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from Mongey/cm-run-testacc-in-ci
Run testacc in CI, fix broken tests.
- Loading branch information
Showing
14 changed files
with
233 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
dist: trusty | ||
sudo: required | ||
services: | ||
- docker | ||
- docker | ||
go_import_path: github.com/terraform-providers/terraform-provider-vault | ||
language: go | ||
go: | ||
- 1.11 | ||
- 1.11 | ||
|
||
install: | ||
# This script is used by the Travis build to install a cookie for | ||
# go.googlesource.com so rate limits are higher when using `go get` to fetch | ||
# packages that live there. | ||
# See: https://github.com/golang/go/issues/12933 | ||
- bash scripts/gogetcookie.sh | ||
- go get github.com/kardianos/govendor | ||
# This script is used by the Travis build to install a cookie for | ||
# go.googlesource.com so rate limits are higher when using `go get` to fetch | ||
# packages that live there. | ||
# See: https://github.com/golang/go/issues/12933 | ||
- bash scripts/gogetcookie.sh | ||
- go get github.com/kardianos/govendor | ||
|
||
script: | ||
- make test | ||
- make vendor-status | ||
- make vet | ||
- make website-test | ||
- docker run -d -e VAULT_DEV_ROOT_TOKEN_ID=TEST -p 8200:8200 --name vault vault:0.11.1 | ||
- sleep 10 | ||
- docker exec -e VAULT_TOKEN=TEST -e VAULT_ADDR="http://localhost:8200" vault vault secrets enable --version=1 -path=secretsv1 kv | ||
- make test | ||
- VAULT_ADDR=http://localhost:8200 VAULT_TOKEN=TEST make testacc | ||
- make vendor-status | ||
- make vet | ||
- make website-test | ||
|
||
branches: | ||
only: | ||
- master | ||
matrix: | ||
fast_finish: true | ||
allow_failures: | ||
- go: tip | ||
- master | ||
matrix: | ||
fast_finish: true | ||
allow_failures: | ||
- go: tip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package vault | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func awsAuthBackendRoleResourceMigrateState(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { | ||
switch v { | ||
case 0: | ||
log.Println("[INFO] Found AWS Auth Backend Role State v0; migrating to v1") | ||
return migrateawsAuthBackendRoleResourceStateV0toV1(is) | ||
default: | ||
return is, fmt.Errorf("Unexpected schema version: %d", v) | ||
} | ||
} | ||
|
||
func migrateawsAuthBackendRoleResourceStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) { | ||
if is.Empty() { | ||
log.Println("[DEBUG] Empty InstanceState; nothing to migrate.") | ||
return is, nil | ||
} | ||
log.Printf("[DEBUG] AWS Auth Backend Role Attributes before migration: %#v", is.Attributes) | ||
|
||
convertSingleAttributeToList(is, "bound_account_id") | ||
convertSingleAttributeToList(is, "bound_ami_id") | ||
convertSingleAttributeToList(is, "bound_iam_instance_profile_arn") | ||
convertSingleAttributeToList(is, "bound_iam_principal_arn") | ||
convertSingleAttributeToList(is, "bound_iam_role_arn") | ||
convertSingleAttributeToList(is, "bound_region") | ||
convertSingleAttributeToList(is, "bound_subnet_id") | ||
convertSingleAttributeToList(is, "bound_vpc_id") | ||
|
||
return is, nil | ||
} | ||
|
||
func convertSingleAttributeToList(is *terraform.InstanceState, attr string) { | ||
if v, ok := is.Attributes[attr]; ok { | ||
is.Attributes[attr+".#"] = "1" | ||
is.Attributes[attr+".0"] = v | ||
delete(is.Attributes, attr) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package vault | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestMigrateawsAuthBackendRoleResourceStateV0toV1(t *testing.T) { | ||
oldAttributes := map[string]string{ | ||
"bound_ami_id": "ami-1234", | ||
"bound_account_id": "account-123", | ||
"bound_iam_instance_profile_arn": "arn::123", | ||
"bound_iam_principal_arn": "arn::234", | ||
"bound_iam_role_arn": "arn::456", | ||
"bound_region": "us-west-1", | ||
"bound_subnet_id": "sub-abc", | ||
"bound_vpc_id": "vpc-1234", | ||
} | ||
|
||
newState, err := migrateawsAuthBackendRoleResourceStateV0toV1(&terraform.InstanceState{ | ||
ID: "nonempty", | ||
Attributes: oldAttributes, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
expectedAttributes := map[string]string{ | ||
"bound_ami_id.#": "1", | ||
"bound_ami_id.0": "ami-1234", | ||
"bound_account_id.#": "1", | ||
"bound_account_id.0": "account-123", | ||
"bound_iam_instance_profile_arn.#": "1", | ||
"bound_iam_instance_profile_arn.0": "arn::123", | ||
"bound_iam_principal_arn.#": "1", | ||
"bound_iam_principal_arn.0": "arn::234", | ||
"bound_iam_role_arn.#": "1", | ||
"bound_iam_role_arn.0": "arn::456", | ||
"bound_region.#": "1", | ||
"bound_region.0": "us-west-1", | ||
"bound_subnet_id.#": "1", | ||
"bound_subnet_id.0": "sub-abc", | ||
"bound_vpc_id.#": "1", | ||
"bound_vpc_id.0": "vpc-1234", | ||
} | ||
|
||
if !reflect.DeepEqual(newState.Attributes, expectedAttributes) { | ||
t.Fatalf("Expected attributes:%#v Given:%#v", expectedAttributes, newState.Attributes) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.