Skip to content

Commit

Permalink
dependencies: updating github.com/hashicorp/terraform-plugin-sdk to…
Browse files Browse the repository at this point in the history
… `v1.13.1`
  • Loading branch information
tombuildsstuff committed Jul 6, 2020
1 parent aa59c73 commit 68a2f63
Show file tree
Hide file tree
Showing 412 changed files with 29,638 additions and 86,387 deletions.
24 changes: 9 additions & 15 deletions azurerm/internal/acceptance/data.go
Expand Up @@ -5,20 +5,22 @@ import (
"math"
"os"
"strconv"
"sync"
"testing"

"github.com/Azure/go-autorest/autorest/azure"
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-azuread/azuread"
"github.com/terraform-providers/terraform-provider-azuread/azuread/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/provider"
)

var once sync.Once
func init() {
// unit testing
if os.Getenv("TF_ACC") == "" {
return
}

EnsureProvidersAreInitialised()
}

type TestData struct {
// Locations is a set of Azure Regions which should be used for this Test
Expand Down Expand Up @@ -51,15 +53,7 @@ type TestData struct {

// BuildTestData generates some test data for the given resource
func BuildTestData(t *testing.T, resourceType string, resourceLabel string) TestData {
once.Do(func() {
azureProvider := provider.TestAzureProvider().(*schema.Provider)

AzureProvider = azureProvider
SupportedProviders = map[string]terraform.ResourceProvider{
"azurerm": azureProvider,
"azuread": azuread.Provider().(*schema.Provider),
}
})
EnsureProvidersAreInitialised()

env, err := Environment()
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions azurerm/internal/acceptance/providers.go
@@ -0,0 +1,33 @@
package acceptance

import (
"os"
"sync"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-azuread/azuread"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/provider"
)

var once sync.Once

func EnsureProvidersAreInitialised() {
// NOTE: (@tombuildsstuff) - opting-out of Binary Testing for the moment
os.Setenv("TF_DISABLE_BINARY_TESTING", "true")

once.Do(func() {
azureProvider := provider.TestAzureProvider().(*schema.Provider)

AzureProvider = azureProvider
SupportedProviders = map[string]terraform.ResourceProvider{
"azurerm": azureProvider,
"azuread": azuread.Provider().(*schema.Provider),
}

// NOTE: (@tombuildsstuff) - intentionally not calling these as Binary Testing
// is Disabled
//binarytestfuntime.UseBinaryDriver("azurerm", provider.TestAzureProvider)
//binarytestfuntime.UseBinaryDriver("azuread", azuread.Provider)
})
}
4 changes: 2 additions & 2 deletions azurerm/internal/common/client_options.go
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/hashicorp/go-azure-helpers/sender"
"github.com/hashicorp/terraform-plugin-sdk/httpclient"
"github.com/hashicorp/terraform-plugin-sdk/meta"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/version"
)
Expand Down Expand Up @@ -47,7 +47,7 @@ func (o ClientOptions) ConfigureClient(c *autorest.Client, authorizer autorest.A
}

func setUserAgent(client *autorest.Client, tfVersion, partnerID string, disableTerraformPartnerID bool) {
tfUserAgent := httpclient.TerraformUserAgent(tfVersion)
tfUserAgent := fmt.Sprintf("HashiCorp Terraform/%s (+https://www.terraform.io) Terraform Plugin SDK/%s", tfVersion, meta.SDKVersionString())

providerUserAgent := fmt.Sprintf("%s terraform-provider-azurerm/%s", tfUserAgent, version.ProviderVersion)
client.UserAgent = strings.TrimSpace(fmt.Sprintf("%s %s", client.UserAgent, providerUserAgent))
Expand Down
3 changes: 1 addition & 2 deletions azurerm/internal/locks/lock.go
@@ -1,12 +1,11 @@
package locks

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/mutexkv"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/common"
)

// armMutexKV is the instance of MutexKV for ARM resources
var armMutexKV = mutexkv.NewMutexKV()
var armMutexKV = NewMutexKV()

func ByID(id string) {
armMutexKV.Lock(id)
Expand Down
48 changes: 48 additions & 0 deletions azurerm/internal/locks/mutexkv.go
@@ -0,0 +1,48 @@
package locks

import (
"log"
"sync"
)

// mutexKV is a simple key/value store for arbitrary mutexes. It can be used to
// serialize changes across arbitrary collaborators that share knowledge of the
// keys they must serialize on.
type mutexKV struct {
lock sync.Mutex
store map[string]*sync.Mutex
}

// Locks the mutex for the given key. Caller is responsible for calling Unlock
// for the same key
func (m *mutexKV) Lock(key string) {
log.Printf("[DEBUG] Locking %q", key)
m.get(key).Lock()
log.Printf("[DEBUG] Locked %q", key)
}

// Unlock the mutex for the given key. Caller must have called Lock for the same key first
func (m *mutexKV) Unlock(key string) {
log.Printf("[DEBUG] Unlocking %q", key)
m.get(key).Unlock()
log.Printf("[DEBUG] Unlocked %q", key)
}

// Returns a mutex for the given key, no guarantee of its lock status
func (m *mutexKV) get(key string) *sync.Mutex {
m.lock.Lock()
defer m.lock.Unlock()
mutex, ok := m.store[key]
if !ok {
mutex = &sync.Mutex{}
m.store[key] = mutex
}
return mutex
}

// Returns a properly initialized mutexKV
func NewMutexKV() *mutexKV {
return &mutexKV{
store: make(map[string]*sync.Mutex),
}
}
28 changes: 9 additions & 19 deletions azurerm/internal/services/apimanagement/api_management_resource.go
Expand Up @@ -281,21 +281,21 @@ func resourceArmApiManagementService() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: apiManagementResourceHostnameSchema("management"),
Schema: apiManagementResourceHostnameSchema(),
},
},
"portal": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: apiManagementResourceHostnameSchema("portal"),
Schema: apiManagementResourceHostnameSchema(),
},
},
"developer_portal": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: apiManagementResourceHostnameSchema("developer_portal"),
Schema: apiManagementResourceHostnameSchema(),
},
},
"proxy": {
Expand All @@ -309,7 +309,7 @@ func resourceArmApiManagementService() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: apiManagementResourceHostnameSchema("scm"),
Schema: apiManagementResourceHostnameSchema(),
},
},
},
Expand Down Expand Up @@ -1076,9 +1076,9 @@ func expandApiManagementCustomProperties(d *schema.ResourceData) map[string]*str
}

if vp := d.Get("protocols").([]interface{}); len(vp) > 0 {
if p, ok := d.GetOkExists("protocols.0.enable_http2"); ok {
customProperties[apimHttp2Protocol] = utils.String(strconv.FormatBool(p.(bool)))
}
vpr := vp[0].(map[string]interface{})
enableHttp2 := vpr["enable_http2"].(bool)
customProperties[apimHttp2Protocol] = utils.String(strconv.FormatBool(enableHttp2))
}

return customProperties
Expand Down Expand Up @@ -1134,7 +1134,7 @@ func flattenApiManagementVirtualNetworkConfiguration(input *apimanagement.Virtua
return []interface{}{virtualNetworkConfiguration}
}

func apiManagementResourceHostnameSchema(schemaName string) map[string]*schema.Schema {
func apiManagementResourceHostnameSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"host_name": {
Type: schema.TypeString,
Expand All @@ -1146,30 +1146,20 @@ func apiManagementResourceHostnameSchema(schemaName string) map[string]*schema.S
Type: schema.TypeString,
Optional: true,
ValidateFunc: azure.ValidateKeyVaultChildIdVersionOptional,
ConflictsWith: []string{
fmt.Sprintf("hostname_configuration.0.%s.0.certificate", schemaName),
fmt.Sprintf("hostname_configuration.0.%s.0.certificate_password", schemaName),
},
},

"certificate": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validation.StringIsNotEmpty,
ConflictsWith: []string{
fmt.Sprintf("hostname_configuration.0.%s.0.key_vault_id", schemaName),
},
},

"certificate_password": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validation.StringIsNotEmpty,
ConflictsWith: []string{
fmt.Sprintf("hostname_configuration.0.%s.0.key_vault_id", schemaName),
},
},

"negotiate_client_certificate": {
Expand All @@ -1181,7 +1171,7 @@ func apiManagementResourceHostnameSchema(schemaName string) map[string]*schema.S
}

func apiManagementResourceHostnameProxySchema() map[string]*schema.Schema {
hostnameSchema := apiManagementResourceHostnameSchema("proxy")
hostnameSchema := apiManagementResourceHostnameSchema()

hostnameSchema["default_ssl_binding"] = &schema.Schema{
Type: schema.TypeBool,
Expand Down
Expand Up @@ -571,10 +571,9 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
},

"managed_disk_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ConflictsWith: []string{"storage_profile_os_disk.vhd_containers"},
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
string(compute.StorageAccountTypesPremiumLRS),
string(compute.StorageAccountTypesStandardLRS),
Expand Down
Expand Up @@ -152,8 +152,8 @@ func resourceArmCosmosDbMongoCollectionCreate(d *schema.ResourceData, meta inter
}

var ttl *int
if v, ok := d.GetOkExists("default_ttl_seconds"); ok {
ttl = utils.Int(v.(int))
if v := d.Get("default_ttl_seconds").(int); v > 0 {
ttl = utils.Int(v)
}

db := documentdb.MongoDBCollectionCreateUpdateParameters{
Expand All @@ -172,9 +172,9 @@ func resourceArmCosmosDbMongoCollectionCreate(d *schema.ResourceData, meta inter
}
}

if v, ok := d.GetOkExists("shard_key"); ok {
if shardKey := d.Get("shard_key").(string); shardKey != "" {
db.MongoDBCollectionCreateUpdateProperties.Resource.ShardKey = map[string]*string{
v.(string): utils.String("Hash"), // looks like only hash is supported for now
shardKey: utils.String("Hash"), // looks like only hash is supported for now
}
}

Expand Down Expand Up @@ -212,8 +212,8 @@ func resourceArmCosmosDbMongoCollectionUpdate(d *schema.ResourceData, meta inter
}

var ttl *int
if v, ok := d.GetOkExists("default_ttl_seconds"); ok {
ttl = utils.Int(v.(int))
if v := d.Get("default_ttl_seconds").(int); v > 0 {
ttl = utils.Int(v)
}

db := documentdb.MongoDBCollectionCreateUpdateParameters{
Expand All @@ -226,9 +226,9 @@ func resourceArmCosmosDbMongoCollectionUpdate(d *schema.ResourceData, meta inter
},
}

if v, ok := d.GetOkExists("shard_key"); ok {
if shardKey := d.Get("shard_key").(string); shardKey != "" {
db.MongoDBCollectionCreateUpdateProperties.Resource.ShardKey = map[string]*string{
v.(string): utils.String("Hash"), // looks like only hash is supported for now
shardKey: utils.String("Hash"), // looks like only hash is supported for now
}
}

Expand Down
Expand Up @@ -166,14 +166,17 @@ func resourceArmDatabricksWorkspaceCreateUpdate(d *schema.ResourceData, meta int
managedResourceGroupID = fmt.Sprintf("/subscriptions/%s/resourceGroups/%s", subscriptionID, managedResourceGroupName)
}

customParamsRaw := d.Get("custom_parameters").([]interface{})
customParams := expandWorkspaceCustomParameters(customParamsRaw)

workspace := databricks.Workspace{
Sku: &databricks.Sku{
Name: utils.String(skuName),
},
Location: utils.String(location),
WorkspaceProperties: &databricks.WorkspaceProperties{
ManagedResourceGroupID: &managedResourceGroupID,
Parameters: expandWorkspaceCustomParameters(d),
Parameters: customParams,
},
Tags: expandedTags,
}
Expand Down Expand Up @@ -240,7 +243,11 @@ func resourceArmDatabricksWorkspaceRead(d *schema.ResourceData, meta interface{}
}
d.Set("managed_resource_group_id", props.ManagedResourceGroupID)
d.Set("managed_resource_group_name", managedResourceGroupID.ResourceGroup)
d.Set("custom_parameters", flattenWorkspaceCustomParameters(props.Parameters))

if err := d.Set("custom_parameters", flattenWorkspaceCustomParameters(props.Parameters)); err != nil {
return fmt.Errorf("Error setting `custom_parameters`: %+v", err)
}

d.Set("workspace_url", props.WorkspaceURL)
d.Set("workspace_id", props.WorkspaceID)
}
Expand Down Expand Up @@ -306,12 +313,12 @@ func flattenWorkspaceCustomParameters(p *databricks.WorkspaceCustomParameters) [
return []interface{}{parameters}
}

func expandWorkspaceCustomParameters(d *schema.ResourceData) *databricks.WorkspaceCustomParameters {
configList, ok := d.GetOkExists("custom_parameters")
if !ok {
func expandWorkspaceCustomParameters(input []interface{}) *databricks.WorkspaceCustomParameters {
if len(input) == 0 || input[0] == nil {
return nil
}
config := configList.([]interface{})[0].(map[string]interface{})

config := input[0].(map[string]interface{})
parameters := databricks.WorkspaceCustomParameters{}

if v, ok := config["no_public_ip"].(bool); ok {
Expand Down
5 changes: 4 additions & 1 deletion azurerm/internal/services/hdinsight/common_hdinsight.go
Expand Up @@ -297,8 +297,11 @@ func deleteHDInsightEdgeNodes(ctx context.Context, client *hdinsight.Application
}

func expandHDInsightsMetastore(input []interface{}) map[string]interface{} {
v := input[0].(map[string]interface{})
if len(input) == 0 || input[0] == nil {
return map[string]interface{}{}
}

v := input[0].(map[string]interface{})
config := map[string]interface{}{}

if hiveRaw, ok := v["hive"]; ok {
Expand Down
Expand Up @@ -202,11 +202,10 @@ func resourceArmHDInsightHadoopClusterCreate(d *schema.ResourceData, meta interf
gatewayRaw := d.Get("gateway").([]interface{})
configurations := azure.ExpandHDInsightsConfigurations(gatewayRaw)

if metastoresRaw, ok := d.GetOkExists("metastores"); ok {
metastores := expandHDInsightsMetastore(metastoresRaw.([]interface{}))
for k, v := range metastores {
configurations[k] = v
}
metastoresRaw := d.Get("metastores").([]interface{})
metastores := expandHDInsightsMetastore(metastoresRaw)
for k, v := range metastores {
configurations[k] = v
}

storageAccountsRaw := d.Get("storage_account").([]interface{})
Expand Down

0 comments on commit 68a2f63

Please sign in to comment.