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_sql_managed_instance_active_directory_administrator #14104

Merged
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
68 changes: 39 additions & 29 deletions internal/services/sql/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ import (
)

type Client struct {
DatabasesClient *sql.DatabasesClient
DatabaseThreatDetectionPoliciesClient *sql.DatabaseThreatDetectionPoliciesClient
ElasticPoolsClient *sql.ElasticPoolsClient
DatabaseExtendedBlobAuditingPoliciesClient *sql.ExtendedDatabaseBlobAuditingPoliciesClient
FirewallRulesClient *sql.FirewallRulesClient
FailoverGroupsClient *sql.FailoverGroupsClient
ManagedInstancesClient *sqlv5.ManagedInstancesClient
ManagedDatabasesClient *msi.ManagedDatabasesClient
ServersClient *sql.ServersClient
ServerExtendedBlobAuditingPoliciesClient *sql.ExtendedServerBlobAuditingPoliciesClient
ServerConnectionPoliciesClient *sql.ServerConnectionPoliciesClient
ServerAzureADAdministratorsClient *sqlv5.ServerAzureADAdministratorsClient
ServerAzureADOnlyAuthenticationsClient *sqlv5.ServerAzureADOnlyAuthenticationsClient
ServerSecurityAlertPoliciesClient *sql.ServerSecurityAlertPoliciesClient
VirtualNetworkRulesClient *sql.VirtualNetworkRulesClient
DatabasesClient *sql.DatabasesClient
DatabaseThreatDetectionPoliciesClient *sql.DatabaseThreatDetectionPoliciesClient
ElasticPoolsClient *sql.ElasticPoolsClient
DatabaseExtendedBlobAuditingPoliciesClient *sql.ExtendedDatabaseBlobAuditingPoliciesClient
FirewallRulesClient *sql.FirewallRulesClient
FailoverGroupsClient *sql.FailoverGroupsClient
ManagedInstancesClient *sqlv5.ManagedInstancesClient
ManagedInstanceAdministratorsClient *sqlv5.ManagedInstanceAdministratorsClient
ManagedInstanceAzureADOnlyAuthenticationsClient *sqlv5.ManagedInstanceAzureADOnlyAuthenticationsClient
ManagedDatabasesClient *msi.ManagedDatabasesClient
ServersClient *sql.ServersClient
ServerExtendedBlobAuditingPoliciesClient *sql.ExtendedServerBlobAuditingPoliciesClient
ServerConnectionPoliciesClient *sql.ServerConnectionPoliciesClient
ServerAzureADAdministratorsClient *sqlv5.ServerAzureADAdministratorsClient
ServerAzureADOnlyAuthenticationsClient *sqlv5.ServerAzureADOnlyAuthenticationsClient
ServerSecurityAlertPoliciesClient *sql.ServerSecurityAlertPoliciesClient
VirtualNetworkRulesClient *sql.VirtualNetworkRulesClient
}

func NewClient(o *common.ClientOptions) *Client {
Expand All @@ -48,6 +50,12 @@ func NewClient(o *common.ClientOptions) *Client {
managedInstancesClient := sqlv5.NewManagedInstancesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&managedInstancesClient.Client, o.ResourceManagerAuthorizer)

managedInstanceAdministratorsClient := sqlv5.NewManagedInstanceAdministratorsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&managedInstanceAdministratorsClient.Client, o.ResourceManagerAuthorizer)

managedInstanceAzureADOnlyAuthenticationsClient := sqlv5.NewManagedInstanceAzureADOnlyAuthenticationsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&managedInstanceAzureADOnlyAuthenticationsClient.Client, o.ResourceManagerAuthorizer)

managedDatabasesClient := msi.NewManagedDatabasesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&managedDatabasesClient.Client, o.ResourceManagerAuthorizer)

Expand All @@ -74,19 +82,21 @@ func NewClient(o *common.ClientOptions) *Client {

return &Client{
DatabasesClient: &databasesClient,
DatabaseExtendedBlobAuditingPoliciesClient: &databaseExtendedBlobAuditingPoliciesClient,
DatabaseThreatDetectionPoliciesClient: &databaseThreatDetectionPoliciesClient,
ElasticPoolsClient: &elasticPoolsClient,
FailoverGroupsClient: &failoverGroupsClient,
FirewallRulesClient: &firewallRulesClient,
ManagedInstancesClient: &managedInstancesClient,
ManagedDatabasesClient: &managedDatabasesClient,
ServersClient: &serversClient,
ServerAzureADAdministratorsClient: &serverAzureADAdministratorsClient,
ServerAzureADOnlyAuthenticationsClient: &serverAzureADOnlyAuthenticationsClient,
ServerConnectionPoliciesClient: &serverConnectionPoliciesClient,
ServerExtendedBlobAuditingPoliciesClient: &serverExtendedBlobAuditingPoliciesClient,
ServerSecurityAlertPoliciesClient: &serverSecurityAlertPoliciesClient,
VirtualNetworkRulesClient: &virtualNetworkRulesClient,
DatabaseExtendedBlobAuditingPoliciesClient: &databaseExtendedBlobAuditingPoliciesClient,
DatabaseThreatDetectionPoliciesClient: &databaseThreatDetectionPoliciesClient,
ElasticPoolsClient: &elasticPoolsClient,
FailoverGroupsClient: &failoverGroupsClient,
FirewallRulesClient: &firewallRulesClient,
ManagedInstancesClient: &managedInstancesClient,
ManagedInstanceAdministratorsClient: &managedInstanceAdministratorsClient,
ManagedInstanceAzureADOnlyAuthenticationsClient: &managedInstanceAzureADOnlyAuthenticationsClient,
ManagedDatabasesClient: &managedDatabasesClient,
ServersClient: &serversClient,
ServerAzureADAdministratorsClient: &serverAzureADAdministratorsClient,
ServerAzureADOnlyAuthenticationsClient: &serverAzureADOnlyAuthenticationsClient,
ServerConnectionPoliciesClient: &serverConnectionPoliciesClient,
ServerExtendedBlobAuditingPoliciesClient: &serverExtendedBlobAuditingPoliciesClient,
ServerSecurityAlertPoliciesClient: &serverSecurityAlertPoliciesClient,
VirtualNetworkRulesClient: &virtualNetworkRulesClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"
"strings"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

type ManagedInstanceAzureActiveDirectoryAdministratorId struct {
SubscriptionId string
ResourceGroup string
ManagedInstanceName string
AdministratorName string
}

func NewManagedInstanceAzureActiveDirectoryAdministratorID(subscriptionId, resourceGroup, managedInstanceName, administratorName string) ManagedInstanceAzureActiveDirectoryAdministratorId {
return ManagedInstanceAzureActiveDirectoryAdministratorId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
ManagedInstanceName: managedInstanceName,
AdministratorName: administratorName,
}
}

func (id ManagedInstanceAzureActiveDirectoryAdministratorId) String() string {
segments := []string{
fmt.Sprintf("Administrator Name %q", id.AdministratorName),
fmt.Sprintf("Managed Instance Name %q", id.ManagedInstanceName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Managed Instance Azure Active Directory Administrator", segmentsStr)
}

func (id ManagedInstanceAzureActiveDirectoryAdministratorId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/managedInstances/%s/administrators/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.ManagedInstanceName, id.AdministratorName)
}

// ManagedInstanceAzureActiveDirectoryAdministratorID parses a ManagedInstanceAzureActiveDirectoryAdministrator ID into an ManagedInstanceAzureActiveDirectoryAdministratorId struct
func ManagedInstanceAzureActiveDirectoryAdministratorID(input string) (*ManagedInstanceAzureActiveDirectoryAdministratorId, error) {
id, err := resourceids.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

resourceId := ManagedInstanceAzureActiveDirectoryAdministratorId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

if resourceId.ManagedInstanceName, err = id.PopSegment("managedInstances"); err != nil {
return nil, err
}
if resourceId.AdministratorName, err = id.PopSegment("administrators"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &resourceId, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/resourceid"
)

var _ resourceid.Formatter = ManagedInstanceAzureActiveDirectoryAdministratorId{}

func TestManagedInstanceAzureActiveDirectoryAdministratorIDFormatter(t *testing.T) {
actual := NewManagedInstanceAzureActiveDirectoryAdministratorID("12345678-1234-9876-4563-123456789012", "resGroup1", "instance1", "activeDirectory").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/managedInstances/instance1/administrators/activeDirectory"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

func TestManagedInstanceAzureActiveDirectoryAdministratorID(t *testing.T) {
testData := []struct {
Input string
Error bool
Expected *ManagedInstanceAzureActiveDirectoryAdministratorId
}{

{
// empty
Input: "",
Error: true,
},

{
// missing SubscriptionId
Input: "/",
Error: true,
},

{
// missing value for SubscriptionId
Input: "/subscriptions/",
Error: true,
},

{
// missing ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/",
Error: true,
},

{
// missing value for ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/",
Error: true,
},

{
// missing ManagedInstanceName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/",
Error: true,
},

{
// missing value for ManagedInstanceName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/managedInstances/",
Error: true,
},

{
// missing AdministratorName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/managedInstances/instance1/",
Error: true,
},

{
// missing value for AdministratorName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/managedInstances/instance1/administrators/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/managedInstances/instance1/administrators/activeDirectory",
Expected: &ManagedInstanceAzureActiveDirectoryAdministratorId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resGroup1",
ManagedInstanceName: "instance1",
AdministratorName: "activeDirectory",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.SQL/MANAGEDINSTANCES/INSTANCE1/ADMINISTRATORS/ACTIVEDIRECTORY",
Error: true,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Input)

actual, err := ManagedInstanceAzureActiveDirectoryAdministratorID(v.Input)
if err != nil {
if v.Error {
continue
}

t.Fatalf("Expect a value but got an error: %s", err)
}
if v.Error {
t.Fatal("Expect an error but didn't get one")
}

if actual.SubscriptionId != v.Expected.SubscriptionId {
t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId)
}
if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
if actual.ManagedInstanceName != v.Expected.ManagedInstanceName {
t.Fatalf("Expected %q but got %q for ManagedInstanceName", v.Expected.ManagedInstanceName, actual.ManagedInstanceName)
}
if actual.AdministratorName != v.Expected.AdministratorName {
t.Fatalf("Expected %q but got %q for AdministratorName", v.Expected.AdministratorName, actual.AdministratorName)
}
}
}
19 changes: 10 additions & 9 deletions internal/services/sql/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource {
// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*pluginsdk.Resource {
return map[string]*pluginsdk.Resource{
"azurerm_sql_active_directory_administrator": resourceSqlAdministrator(),
"azurerm_sql_database": resourceSqlDatabase(),
"azurerm_sql_elasticpool": resourceSqlElasticPool(),
"azurerm_sql_failover_group": resourceSqlFailoverGroup(),
"azurerm_sql_firewall_rule": resourceSqlFirewallRule(),
"azurerm_sql_managed_database": resourceArmSqlManagedDatabase(),
"azurerm_sql_managed_instance": resourceArmSqlMiServer(),
"azurerm_sql_server": resourceSqlServer(),
"azurerm_sql_virtual_network_rule": resourceSqlVirtualNetworkRule(),
"azurerm_sql_active_directory_administrator": resourceSqlAdministrator(),
"azurerm_sql_database": resourceSqlDatabase(),
"azurerm_sql_elasticpool": resourceSqlElasticPool(),
"azurerm_sql_failover_group": resourceSqlFailoverGroup(),
"azurerm_sql_firewall_rule": resourceSqlFirewallRule(),
"azurerm_sql_managed_database": resourceArmSqlManagedDatabase(),
"azurerm_sql_managed_instance": resourceArmSqlMiServer(),
"azurerm_sql_managed_instance_active_directory_administrator": resourceSqlManagedInstanceAdministrator(),
"azurerm_sql_server": resourceSqlServer(),
"azurerm_sql_virtual_network_rule": resourceSqlVirtualNetworkRule(),
}
}
1 change: 1 addition & 0 deletions internal/services/sql/resourceids.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ package sql
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=FirewallRule -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/servers/server1/firewallRules/rule1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=ManagedInstance -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/managedInstances/instance1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=ManagedDatabase -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/managedInstances/instance1/databases/database1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=ManagedInstanceAzureActiveDirectoryAdministrator -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/managedInstances/instance1/administrators/activeDirectory
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Server -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/servers/server1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VirtualNetworkRule -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Sql/servers/server1/virtualNetworkRules/virtualNetworkRule1
Loading