Skip to content

Commit

Permalink
New Resource: azurerm_cognitive_account (#962)
Browse files Browse the repository at this point in the history
* New Resource: `azurerm_cognitive_account`

* Updating to v21.1.0 of the Azure SDK
  • Loading branch information
Nepomuceno authored and tombuildsstuff committed Oct 1, 2018
1 parent ae174ca commit f7d0257
Show file tree
Hide file tree
Showing 16 changed files with 2,892 additions and 0 deletions.
11 changes: 11 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
appinsights "github.com/Azure/azure-sdk-for-go/services/appinsights/mgmt/2015-05-01/insights"
"github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation"
"github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2017-10-12/cdn"
"github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-06-01/compute"
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-04-01/containerinstance"
"github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2017-10-01/containerregistry"
Expand Down Expand Up @@ -123,6 +124,9 @@ type ArmClient struct {
cdnEndpointsClient cdn.EndpointsClient
cdnProfilesClient cdn.ProfilesClient

// Cognitive Services
cognitiveAccountsClient cognitiveservices.AccountsClient

// Compute
availSetClient compute.AvailabilitySetsClient
diskClient compute.DisksClient
Expand Down Expand Up @@ -452,6 +456,7 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) {
client.registerAutomationClients(endpoint, c.SubscriptionID, auth, sender)
client.registerAuthentication(endpoint, graphEndpoint, c.SubscriptionID, c.TenantID, auth, graphAuth, sender)
client.registerCDNClients(endpoint, c.SubscriptionID, auth, sender)
client.registerCognitiveServiceClients(endpoint, c.SubscriptionID, auth, sender)
client.registerComputeClients(endpoint, c.SubscriptionID, auth, sender)
client.registerContainerInstanceClients(endpoint, c.SubscriptionID, auth, sender)
client.registerContainerRegistryClients(endpoint, c.SubscriptionID, auth, sender)
Expand Down Expand Up @@ -547,6 +552,12 @@ func (c *ArmClient) registerCDNClients(endpoint, subscriptionId string, auth aut
c.cdnProfilesClient = profilesClient
}

func (c *ArmClient) registerCognitiveServiceClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
accountsClient := cognitiveservices.NewAccountsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&accountsClient.Client, auth)
c.cognitiveAccountsClient = accountsClient
}

func (c *ArmClient) registerCosmosDBClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
cdb := documentdb.NewDatabaseAccountsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&cdb.Client, auth)
Expand Down
15 changes: 15 additions & 0 deletions azurerm/helpers/validate/cognitiveservices.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package validate

import (
"regexp"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)

func CognitiveServicesAccountName() schema.SchemaValidateFunc {
return validation.StringMatch(
regexp.MustCompile("^([a-zA-Z0-9]{1}[a-zA-Z0-9_.-]{1,})$"),
"The Cognitive Services Account Name can only start with an alphanumeric character, and must only contain alphanumeric characters, periods, dashes or underscores.",
)
}
78 changes: 78 additions & 0 deletions azurerm/helpers/validate/cognitiveservices_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package validate

import (
"testing"
)

func TestValidateCognitiveServicesAccountName(t *testing.T) {
tests := []struct {
name string
input string
valid bool
}{
{
name: "empty name",
input: "",
valid: false,
},
{
name: "Valid short name",
input: "abc",
valid: true,
},
{
name: "Invalid short name",
input: "a",
valid: false,
},
{
name: "Valid short name",
input: "ab",
valid: true,
},
{
name: "Valid long name",
input: "abc_-.123",
valid: true,
},
{
name: "Valid with a digit at the end",
input: "hello1",
valid: true,
},
{
name: "Valid with a digit in the middle",
input: "hello1",
valid: true,
},
{
name: "Invalid with a digit at the start",
input: "1hello",
valid: true,
},
{
name: "Invalid with a period at the start",
input: ".heyo",
valid: false,
},
{
name: "Valid name with period in the middle",
input: "a.bc",
valid: true,
},
{
name: "Valid name with period at end",
input: "a.",
valid: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := CognitiveServicesAccountName()(tt.input, "")
valid := err == nil
if valid != tt.valid {
t.Errorf("Expected valid status %t but got %t for input %s", tt.valid, valid, tt.input)
}
})
}
}
2 changes: 2 additions & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_availability_set": resourceArmAvailabilitySet(),
"azurerm_cdn_endpoint": resourceArmCdnEndpoint(),
"azurerm_cdn_profile": resourceArmCdnProfile(),
"azurerm_cognitive_account": resourceArmCognitiveAccount(),
"azurerm_container_registry": resourceArmContainerRegistry(),
"azurerm_container_service": resourceArmContainerService(),
"azurerm_container_group": resourceArmContainerGroup(),
Expand Down Expand Up @@ -382,6 +383,7 @@ func determineAzureResourceProvidersToRegister(providerList []resources.Provider
"Microsoft.Automation": {},
"Microsoft.Cache": {},
"Microsoft.Cdn": {},
"Microsoft.CognitiveServices": {},
"Microsoft.Compute": {},
"Microsoft.ContainerInstance": {},
"Microsoft.ContainerRegistry": {},
Expand Down
Loading

0 comments on commit f7d0257

Please sign in to comment.