Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Resource: azurerm_cognitive_account #962

Merged
merged 2 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(),
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
"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