Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
katbyte committed May 15, 2020
2 parents 44fca85 + 5e53ba6 commit 924734f
Show file tree
Hide file tree
Showing 204 changed files with 21,387 additions and 5,589 deletions.
123 changes: 92 additions & 31 deletions CHANGELOG.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions GNUmakefile
Expand Up @@ -82,6 +82,7 @@ test-docker:
docker run --rm -v $$(pwd):/go/src/github.com/terraform-providers/terraform-provider-azurerm -w /go/src/github.com/terraform-providers/terraform-provider-azurerm golang:1.13 make test

test: fmtcheck
@TEST=$(TEST) ./scripts/run-gradually-deprecated.sh
@TEST=$(TEST) ./scripts/run-test.sh

test-compile:
Expand Down
53 changes: 53 additions & 0 deletions azurerm/helpers/azure/key_vault_child.go
Expand Up @@ -42,6 +42,38 @@ func ParseKeyVaultChildID(id string) (*KeyVaultChildID, error) {
return &childId, nil
}

func ParseKeyVaultChildIDVersionOptional(id string) (*KeyVaultChildID, error) {
// example: https://tharvey-keyvault.vault.azure.net/type/bird/fdf067c93bbb4b22bff4d8b7a9a56217
idURL, err := url.ParseRequestURI(id)
if err != nil {
return nil, fmt.Errorf("Cannot parse Azure KeyVault Child Id: %s", err)
}

path := idURL.Path

path = strings.TrimPrefix(path, "/")
path = strings.TrimSuffix(path, "/")

components := strings.Split(path, "/")

if len(components) != 2 && len(components) != 3 {
return nil, fmt.Errorf("Azure KeyVault Child Id should have 2 or 3 segments, got %d: '%s'", len(components), path)
}

version := ""
if len(components) == 3 {
version = components[2]
}

childId := KeyVaultChildID{
KeyVaultBaseUrl: fmt.Sprintf("%s://%s/", idURL.Scheme, idURL.Host),
Name: components[1],
Version: version,
}

return &childId, nil
}

func ValidateKeyVaultChildName(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)

Expand Down Expand Up @@ -72,3 +104,24 @@ func ValidateKeyVaultChildId(i interface{}, k string) (warnings []string, errors

return warnings, errors
}

// Unfortunately this can't (easily) go in the Validate package
// since there's a circular reference on this package
func ValidateKeyVaultChildIdVersionOptional(i interface{}, k string) (warnings []string, errors []error) {
if warnings, errors = validation.StringIsNotEmpty(i, k); len(errors) > 0 {
return warnings, errors
}

v, ok := i.(string)
if !ok {
errors = append(errors, fmt.Errorf("Expected %s to be a string!", k))
return warnings, errors
}

if _, err := ParseKeyVaultChildIDVersionOptional(v); err != nil {
errors = append(errors, fmt.Errorf("Error parsing Key Vault Child ID: %s", err))
return warnings, errors
}

return warnings, errors
}
137 changes: 137 additions & 0 deletions azurerm/helpers/azure/key_vault_child_test.go
Expand Up @@ -55,6 +55,59 @@ func TestAccAzureRMValidateKeyVaultChildID(t *testing.T) {
}
}

func TestAccAzureRMValidateKeyVaultChildIDVersionOptional(t *testing.T) {
cases := []struct {
Input string
ExpectError bool
}{
{
Input: "",
ExpectError: true,
},
{
Input: "https://my-keyvault.vault.azure.net/secrets",
ExpectError: true,
},
{
Input: "https://my-keyvault.vault.azure.net/secrets/bird",
ExpectError: false,
},
{
Input: "https://my-keyvault.vault.azure.net/secrets/bird/fdf067c93bbb4b22bff4d8b7a9a56217",
ExpectError: false,
},
{
Input: "https://my-keyvault.vault.azure.net/certificates/hello/world",
ExpectError: false,
},
{
Input: "https://my-keyvault.vault.azure.net/keys/castle/1492",
ExpectError: false,
},
{
Input: "https://my-keyvault.vault.azure.net/secrets/bird/fdf067c93bbb4b22bff4d8b7a9a56217/XXX",
ExpectError: true,
},
}

for _, tc := range cases {
warnings, err := ValidateKeyVaultChildIdVersionOptional(tc.Input, "example")
if err != nil {
if !tc.ExpectError {
t.Fatalf("Got error for input %q: %+v", tc.Input, err)
}

return
}

if tc.ExpectError && len(warnings) == 0 {
t.Fatalf("Got no errors for input %q but expected some", tc.Input)
} else if !tc.ExpectError && len(warnings) > 0 {
t.Fatalf("Got %d errors for input %q when didn't expect any", len(warnings), tc.Input)
}
}
}

func TestAccAzureRMKeyVaultChild_parseID(t *testing.T) {
cases := []struct {
Input string
Expand Down Expand Up @@ -134,6 +187,90 @@ func TestAccAzureRMKeyVaultChild_parseID(t *testing.T) {
}
}

func TestAccAzureRMKeyVaultChild_parseIDVersionOptional(t *testing.T) {
cases := []struct {
Input string
Expected KeyVaultChildID
ExpectError bool
}{
{
Input: "",
ExpectError: true,
},
{
Input: "https://my-keyvault.vault.azure.net/secrets",
ExpectError: true,
},
{
Input: "https://my-keyvault.vault.azure.net/secrets/bird",
ExpectError: false,
Expected: KeyVaultChildID{
Name: "bird",
KeyVaultBaseUrl: "https://my-keyvault.vault.azure.net/",
Version: "",
},
},
{
Input: "https://my-keyvault.vault.azure.net/secrets/bird/fdf067c93bbb4b22bff4d8b7a9a56217",
ExpectError: false,
Expected: KeyVaultChildID{
Name: "bird",
KeyVaultBaseUrl: "https://my-keyvault.vault.azure.net/",
Version: "fdf067c93bbb4b22bff4d8b7a9a56217",
},
},
{
Input: "https://my-keyvault.vault.azure.net/certificates/hello/world",
ExpectError: false,
Expected: KeyVaultChildID{
Name: "hello",
KeyVaultBaseUrl: "https://my-keyvault.vault.azure.net/",
Version: "world",
},
},
{
Input: "https://my-keyvault.vault.azure.net/keys/castle/1492",
ExpectError: false,
Expected: KeyVaultChildID{
Name: "castle",
KeyVaultBaseUrl: "https://my-keyvault.vault.azure.net/",
Version: "1492",
},
},
{
Input: "https://my-keyvault.vault.azure.net/secrets/bird/fdf067c93bbb4b22bff4d8b7a9a56217/XXX",
ExpectError: true,
},
}

for _, tc := range cases {
secretId, err := ParseKeyVaultChildIDVersionOptional(tc.Input)
if err != nil {
if !tc.ExpectError {
t.Fatalf("Got error for ID '%s': %+v", tc.Input, err)
}

return
}

if secretId == nil {
t.Fatalf("Expected a SecretID to be parsed for ID '%s', got nil.", tc.Input)
}

if tc.Expected.KeyVaultBaseUrl != secretId.KeyVaultBaseUrl {
t.Fatalf("Expected 'KeyVaultBaseUrl' to be '%s', got '%s' for ID '%s'", tc.Expected.KeyVaultBaseUrl, secretId.KeyVaultBaseUrl, tc.Input)
}

if tc.Expected.Name != secretId.Name {
t.Fatalf("Expected 'Version' to be '%s', got '%s' for ID '%s'", tc.Expected.Name, secretId.Name, tc.Input)
}

if tc.Expected.Version != secretId.Version {
t.Fatalf("Expected 'Version' to be '%s', got '%s' for ID '%s'", tc.Expected.Version, secretId.Version, tc.Input)
}
}
}

func TestAccAzureRMKeyVaultChild_validateName(t *testing.T) {
cases := []struct {
Input string
Expand Down
15 changes: 0 additions & 15 deletions azurerm/helpers/azure/mysql.go

This file was deleted.

15 changes: 13 additions & 2 deletions azurerm/helpers/azure/resource_group.go
Expand Up @@ -30,8 +30,19 @@ func SchemaResourceGroupNameDiffSuppress() *schema.Schema {

func SchemaResourceGroupNameForDataSource() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateResourceGroupName,
}
}

func SchemaResourceGroupNameOptionalComputed() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Computed: true,
ValidateFunc: validateResourceGroupName,
}
}

Expand Down
23 changes: 0 additions & 23 deletions azurerm/helpers/validate/database.go

This file was deleted.

28 changes: 0 additions & 28 deletions azurerm/helpers/validate/mariadb.go

This file was deleted.

Expand Up @@ -52,6 +52,34 @@ func dataSourceApiManagementService() *schema.Resource {
Computed: true,
},

"identity": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Computed: true,
},
"principal_id": {
Type: schema.TypeString,
Computed: true,
},
"tenant_id": {
Type: schema.TypeString,
Computed: true,
},
"identity_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},

"notification_sender_email": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -124,6 +152,13 @@ func dataSourceApiManagementService() *schema.Resource {
Schema: apiManagementDataSourceHostnameSchema(),
},
},
"developer_portal": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: apiManagementDataSourceHostnameSchema(),
},
},
"proxy": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -207,6 +242,7 @@ func flattenDataSourceApiManagementHostnameConfigurations(input *[]apimanagement
managementResults := make([]interface{}, 0)
proxyResults := make([]interface{}, 0)
portalResults := make([]interface{}, 0)
developerPortalResults := make([]interface{}, 0)
scmResults := make([]interface{}, 0)

for _, config := range *input {
Expand Down Expand Up @@ -238,17 +274,21 @@ func flattenDataSourceApiManagementHostnameConfigurations(input *[]apimanagement
case strings.ToLower(string(apimanagement.HostnameTypePortal)):
portalResults = append(portalResults, output)

case strings.ToLower(string(apimanagement.HostnameTypeDeveloperPortal)):
developerPortalResults = append(developerPortalResults, output)

case strings.ToLower(string(apimanagement.HostnameTypeScm)):
scmResults = append(scmResults, output)
}
}

return []interface{}{
map[string]interface{}{
"management": managementResults,
"portal": portalResults,
"proxy": proxyResults,
"scm": scmResults,
"management": managementResults,
"portal": portalResults,
"developer_portal": developerPortalResults,
"proxy": proxyResults,
"scm": scmResults,
},
}
}
Expand Down

0 comments on commit 924734f

Please sign in to comment.