From ccc35cf2992a541ca59a67304e23ed6e2286f38a Mon Sep 17 00:00:00 2001 From: Yichun Ma Date: Tue, 6 Dec 2022 15:22:13 +0800 Subject: [PATCH] New resource `azurerm_digital_twins_time_series_database_connection` --- internal/provider/services.go | 1 + .../services/digitaltwins/client/client.go | 14 +- ...ime_series_database_connection_resource.go | 250 ++++++++++++++++++ ...eries_database_connection_resource_test.go | 195 ++++++++++++++ .../services/digitaltwins/registration.go | 10 + ...ns_time_series_database_connection_name.go | 31 +++ ...me_series_database_connection_name_test.go | 74 ++++++ .../timeseriesdatabaseconnections/README.md | 82 ++++++ .../timeseriesdatabaseconnections/client.go | 18 ++ .../constants.go | 117 ++++++++ .../id_digitaltwinsinstance.go | 124 +++++++++ .../id_timeseriesdatabaseconnection.go | 137 ++++++++++ .../method_createorupdate_autorest.go | 79 ++++++ .../method_delete_autorest.go | 78 ++++++ .../method_get_autorest.go | 68 +++++ .../method_list_autorest.go | 186 +++++++++++++ ...l_azuredataexplorerconnectionproperties.go | 50 ++++ .../model_managedidentityreference.go | 9 + .../model_timeseriesdatabaseconnection.go | 48 ++++ ..._timeseriesdatabaseconnectionproperties.go | 48 ++++ .../predicates.go | 24 ++ .../timeseriesdatabaseconnections/version.go | 12 + vendor/modules.txt | 1 + ...e_series_database_connection.html.markdown | 161 +++++++++++ 24 files changed, 1813 insertions(+), 4 deletions(-) create mode 100644 internal/services/digitaltwins/digital_twins_time_series_database_connection_resource.go create mode 100644 internal/services/digitaltwins/digital_twins_time_series_database_connection_resource_test.go create mode 100644 internal/services/digitaltwins/validate/digital_twins_time_series_database_connection_name.go create mode 100644 internal/services/digitaltwins/validate/digital_twins_time_series_database_connection_name_test.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/id_digitaltwinsinstance.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/id_timeseriesdatabaseconnection.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_createorupdate_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_delete_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_get_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_list_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_azuredataexplorerconnectionproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_managedidentityreference.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_timeseriesdatabaseconnection.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_timeseriesdatabaseconnectionproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/version.go create mode 100644 website/docs/r/digital_twins_time_series_database_connection.html.markdown diff --git a/internal/provider/services.go b/internal/provider/services.go index 40b1569b06e8..fa9d6648ea4c 100644 --- a/internal/provider/services.go +++ b/internal/provider/services.go @@ -130,6 +130,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration { costmanagement.Registration{}, dashboard.Registration{}, databricks.Registration{}, + digitaltwins.Registration{}, disks.Registration{}, domainservices.Registration{}, eventhub.Registration{}, diff --git a/internal/services/digitaltwins/client/client.go b/internal/services/digitaltwins/client/client.go index 86072925a754..1c1df4f9889e 100644 --- a/internal/services/digitaltwins/client/client.go +++ b/internal/services/digitaltwins/client/client.go @@ -2,12 +2,14 @@ package client import ( "github.com/Azure/azure-sdk-for-go/services/digitaltwins/mgmt/2020-12-01/digitaltwins" + "github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) type Client struct { - EndpointClient *digitaltwins.EndpointClient - InstanceClient *digitaltwins.Client + EndpointClient *digitaltwins.EndpointClient + InstanceClient *digitaltwins.Client + TimeSeriesDatabaseConnectionsClient *timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient } func NewClient(o *common.ClientOptions) *Client { @@ -17,8 +19,12 @@ func NewClient(o *common.ClientOptions) *Client { InstanceClient := digitaltwins.NewClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&InstanceClient.Client, o.ResourceManagerAuthorizer) + TimeSeriesDatabaseConnectionsClient := timeseriesdatabaseconnections.NewTimeSeriesDatabaseConnectionsClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&TimeSeriesDatabaseConnectionsClient.Client, o.ResourceManagerAuthorizer) + return &Client{ - EndpointClient: &endpointClient, - InstanceClient: &InstanceClient, + EndpointClient: &endpointClient, + InstanceClient: &InstanceClient, + TimeSeriesDatabaseConnectionsClient: &TimeSeriesDatabaseConnectionsClient, } } diff --git a/internal/services/digitaltwins/digital_twins_time_series_database_connection_resource.go b/internal/services/digitaltwins/digital_twins_time_series_database_connection_resource.go new file mode 100644 index 000000000000..ea4075e0285b --- /dev/null +++ b/internal/services/digitaltwins/digital_twins_time_series_database_connection_resource.go @@ -0,0 +1,250 @@ +package digitaltwins + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/eventhubs" + "github.com/hashicorp/go-azure-sdk/resource-manager/kusto/2022-07-07/clusters" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/digitaltwins/validate" + eventhubValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate" + kustoValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type TimeSeriesDatabaseConnectionModel struct { + Name string `tfschema:"name"` + DigitalTwinsId string `tfschema:"digital_twins_id"` + EventhubConsumerGroupName string `tfschema:"eventhub_consumer_group_name"` + EventhubName string `tfschema:"eventhub_name"` + EventhubNamespaceEndpointUri string `tfschema:"eventhub_namespace_endpoint_uri"` + EventhubNamespaceId string `tfschema:"eventhub_namespace_id"` + KustoClusterId string `tfschema:"kusto_cluster_id"` + KustoClusterUri string `tfschema:"kusto_cluster_uri"` + KustoDatabaseName string `tfschema:"kusto_database_name"` + KustoTableName string `tfschema:"kusto_table_name"` +} + +type TimeSeriesDatabaseConnectionResource struct{} + +func (m TimeSeriesDatabaseConnectionResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.DigitalTwinsTimeSeriesDatabaseConnectionName, + }, + + "digital_twins_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: timeseriesdatabaseconnections.ValidateDigitalTwinsInstanceID, + }, + + "eventhub_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: eventhubValidate.ValidateEventHubName(), + }, + + "eventhub_namespace_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: eventhubs.ValidateNamespaceID, + }, + + "eventhub_namespace_endpoint_uri": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "kusto_cluster_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: clusters.ValidateClusterID, + }, + + "kusto_cluster_uri": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "kusto_database_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: kustoValidate.DatabaseName, + }, + + "eventhub_consumer_group_name": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "$Default", + ForceNew: true, + ValidateFunc: eventhubValidate.ValidateEventHubConsumerName(), + }, + + "kusto_table_name": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: kustoValidate.EntityName, + }, + } +} + +func (m TimeSeriesDatabaseConnectionResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (m TimeSeriesDatabaseConnectionResource) ModelObject() interface{} { + return &TimeSeriesDatabaseConnectionModel{} +} + +func (m TimeSeriesDatabaseConnectionResource) ResourceType() string { + return "azurerm_digital_twins_time_series_database_connection" +} + +func (m TimeSeriesDatabaseConnectionResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return timeseriesdatabaseconnections.ValidateTimeSeriesDatabaseConnectionID +} + +func (m TimeSeriesDatabaseConnectionResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, meta sdk.ResourceMetaData) error { + client := meta.Client.DigitalTwins.TimeSeriesDatabaseConnectionsClient + + var model TimeSeriesDatabaseConnectionModel + if err := meta.Decode(&model); err != nil { + return err + } + + digitalTwinsId, err := timeseriesdatabaseconnections.ParseDigitalTwinsInstanceID(model.DigitalTwinsId) + if err != nil { + return err + } + + id := timeseriesdatabaseconnections.NewTimeSeriesDatabaseConnectionID(digitalTwinsId.SubscriptionId, digitalTwinsId.ResourceGroupName, digitalTwinsId.ResourceName, model.Name) + + existing, err := client.Get(ctx, id) + if !response.WasNotFound(existing.HttpResponse) { + if err != nil { + return fmt.Errorf("retrieving %s: %+v", id, err) + } + return meta.ResourceRequiresImport(m.ResourceType(), id) + } + + properties := timeseriesdatabaseconnections.AzureDataExplorerConnectionProperties{ + AdxDatabaseName: model.KustoDatabaseName, + AdxEndpointUri: model.KustoClusterUri, + AdxResourceId: model.KustoClusterId, + EventHubEndpointUri: model.EventhubNamespaceEndpointUri, + EventHubEntityPath: model.EventhubName, + EventHubNamespaceResourceId: model.EventhubNamespaceId, + } + + if model.KustoTableName != "" { + properties.AdxTableName = utils.String(model.KustoTableName) + } + + if model.EventhubConsumerGroupName != "" { + properties.EventHubConsumerGroup = utils.String(model.EventhubConsumerGroupName) + } + + req := timeseriesdatabaseconnections.TimeSeriesDatabaseConnection{ + Properties: properties, + } + + if err := client.CreateOrUpdateThenPoll(ctx, id, req); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + meta.SetID(id) + return nil + }, + } +} + +func (m TimeSeriesDatabaseConnectionResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, meta sdk.ResourceMetaData) error { + id, err := timeseriesdatabaseconnections.ParseTimeSeriesDatabaseConnectionID(meta.ResourceData.Id()) + if err != nil { + return err + } + + client := meta.Client.DigitalTwins.TimeSeriesDatabaseConnectionsClient + result, err := client.Get(ctx, *id) + if err != nil { + return err + } + + if result.Model == nil { + return fmt.Errorf("retrieving %s got nil model", id) + } + + var output TimeSeriesDatabaseConnectionModel + output.Name = id.TimeSeriesDatabaseConnectionName + output.DigitalTwinsId = timeseriesdatabaseconnections.NewDigitalTwinsInstanceID(id.SubscriptionId, id.ResourceGroupName, id.ResourceName).ID() + + if properties, ok := result.Model.Properties.(timeseriesdatabaseconnections.AzureDataExplorerConnectionProperties); ok { + output.EventhubName = properties.EventHubEntityPath + output.EventhubNamespaceEndpointUri = properties.EventHubEndpointUri + output.EventhubNamespaceId = properties.EventHubNamespaceResourceId + output.KustoClusterId = properties.AdxResourceId + output.KustoClusterUri = properties.AdxEndpointUri + output.KustoDatabaseName = properties.AdxDatabaseName + + eventhubConsumerGroupName := "$Default" + if properties.EventHubConsumerGroup != nil { + eventhubConsumerGroupName = *properties.EventHubConsumerGroup + } + output.EventhubConsumerGroupName = eventhubConsumerGroupName + + kustoTableName := "" + if properties.AdxTableName != nil { + kustoTableName = *properties.AdxTableName + } + output.KustoTableName = kustoTableName + } + + return meta.Encode(&output) + }, + } +} + +func (m TimeSeriesDatabaseConnectionResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, meta sdk.ResourceMetaData) error { + id, err := timeseriesdatabaseconnections.ParseTimeSeriesDatabaseConnectionID(meta.ResourceData.Id()) + if err != nil { + return err + } + + client := meta.Client.DigitalTwins.TimeSeriesDatabaseConnectionsClient + if err = client.DeleteThenPoll(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) + } + return nil + }, + } +} diff --git a/internal/services/digitaltwins/digital_twins_time_series_database_connection_resource_test.go b/internal/services/digitaltwins/digital_twins_time_series_database_connection_resource_test.go new file mode 100644 index 000000000000..081bfc7e71b5 --- /dev/null +++ b/internal/services/digitaltwins/digital_twins_time_series_database_connection_resource_test.go @@ -0,0 +1,195 @@ +package digitaltwins_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type TimeSeriesDatabaseConnectionResource struct{} + +func TestAccTimeSeriesDatabaseConnection_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_digital_twins_time_series_database_connection", "test") + r := TimeSeriesDatabaseConnectionResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("eventhub_consumer_group_name").HasValue("$Default"), + check.That(data.ResourceName).Key("kusto_table_name").IsSet(), + ), + }, + data.ImportStep(), + }) +} + +func TestAccTimeSeriesDatabaseConnection_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_digital_twins_time_series_database_connection", "test") + r := TimeSeriesDatabaseConnectionResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (r TimeSeriesDatabaseConnectionResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := timeseriesdatabaseconnections.ParseTimeSeriesDatabaseConnectionID(state.ID) + if err != nil { + return nil, err + } + resp, err := client.DigitalTwins.TimeSeriesDatabaseConnectionsClient.Get(ctx, *id) + if err != nil { + return nil, fmt.Errorf("retrieving TimeSeriesDatabaseConnection %s: %+v", id, err) + } + return utils.Bool(resp.Model != nil), nil +} + +func (r TimeSeriesDatabaseConnectionResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_digital_twins_time_series_database_connection" "test" { + name = "connection-%[2]d" + digital_twins_id = azurerm_digital_twins_instance.test.id + eventhub_name = azurerm_eventhub.test.name + eventhub_namespace_id = azurerm_eventhub_namespace.test.id + eventhub_namespace_endpoint_uri = "sb://${azurerm_eventhub_namespace.test.name}.servicebus.windows.net" + kusto_cluster_id = azurerm_kusto_cluster.test.id + kusto_cluster_uri = azurerm_kusto_cluster.test.uri + kusto_database_name = azurerm_kusto_database.test.name + + depends_on = [ + azurerm_role_assignment.database_contributor, + azurerm_role_assignment.eventhub_data_owner, + azurerm_kusto_database_principal_assignment.test + ] +} +`, r.template(data), data.RandomInteger) +} + +func (r TimeSeriesDatabaseConnectionResource) complete(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_eventhub_consumer_group" "test" { + name = "acctesteventhubcg-%[2]d" + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_digital_twins_time_series_database_connection" "test" { + name = "connection-%[2]d" + digital_twins_id = azurerm_digital_twins_instance.test.id + eventhub_name = azurerm_eventhub.test.name + eventhub_namespace_id = azurerm_eventhub_namespace.test.id + eventhub_namespace_endpoint_uri = "sb://${azurerm_eventhub_namespace.test.name}.servicebus.windows.net" + kusto_cluster_id = azurerm_kusto_cluster.test.id + kusto_cluster_uri = azurerm_kusto_cluster.test.uri + kusto_database_name = azurerm_kusto_database.test.name + + eventhub_consumer_group_name = azurerm_eventhub_consumer_group.test.name + kusto_table_name = "mytable" + + depends_on = [ + azurerm_role_assignment.database_contributor, + azurerm_role_assignment.eventhub_data_owner, + azurerm_kusto_database_principal_assignment.test + ] +} +`, r.template(data), data.RandomInteger) +} + +func (r TimeSeriesDatabaseConnectionResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-digitaltwin-%[2]d" + location = "%[1]s" +} + +resource "azurerm_digital_twins_instance" "test" { + name = "acctest-DT-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + identity { + type = "SystemAssigned" + } +} + +resource "azurerm_eventhub_namespace" "test" { + name = "acctesteventhubnamespace-%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "Standard" +} + +resource "azurerm_eventhub" "test" { + name = "acctesteventhub-%[2]d" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name + partition_count = 2 + message_retention = 7 +} + +resource "azurerm_kusto_cluster" "test" { + name = "acctestkc%[3]s" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + sku { + name = "Dev(No SLA)_Standard_D11_v2" + capacity = 1 + } +} + +resource "azurerm_kusto_database" "test" { + name = "acctestkd-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + cluster_name = azurerm_kusto_cluster.test.name +} + +resource "azurerm_role_assignment" "database_contributor" { + scope = azurerm_kusto_database.test.id + principal_id = azurerm_digital_twins_instance.test.identity.0.principal_id + role_definition_name = "Contributor" +} + +resource "azurerm_role_assignment" "eventhub_data_owner" { + scope = azurerm_eventhub.test.id + principal_id = azurerm_digital_twins_instance.test.identity.0.principal_id + role_definition_name = "Azure Event Hubs Data Owner" +} + +resource "azurerm_kusto_database_principal_assignment" "test" { + name = "acctestkdpa%[2]d" + resource_group_name = azurerm_resource_group.test.name + cluster_name = azurerm_kusto_cluster.test.name + database_name = azurerm_kusto_database.test.name + + tenant_id = azurerm_digital_twins_instance.test.identity.0.tenant_id + principal_id = azurerm_digital_twins_instance.test.identity.0.principal_id + principal_type = "App" + role = "Admin" +} + +`, data.Locations.Primary, data.RandomInteger, data.RandomString) +} diff --git a/internal/services/digitaltwins/registration.go b/internal/services/digitaltwins/registration.go index 76b67714baf4..85fb0b24966e 100644 --- a/internal/services/digitaltwins/registration.go +++ b/internal/services/digitaltwins/registration.go @@ -41,3 +41,13 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { "azurerm_digital_twins_endpoint_servicebus": resourceDigitalTwinsEndpointServiceBus(), } } + +func (r Registration) DataSources() []sdk.DataSource { + return []sdk.DataSource{} +} + +func (r Registration) Resources() []sdk.Resource { + return []sdk.Resource{ + TimeSeriesDatabaseConnectionResource{}, + } +} diff --git a/internal/services/digitaltwins/validate/digital_twins_time_series_database_connection_name.go b/internal/services/digitaltwins/validate/digital_twins_time_series_database_connection_name.go new file mode 100644 index 000000000000..db282fc491af --- /dev/null +++ b/internal/services/digitaltwins/validate/digital_twins_time_series_database_connection_name.go @@ -0,0 +1,31 @@ +package validate + +import ( + "fmt" + "regexp" +) + +func DigitalTwinsTimeSeriesDatabaseConnectionName(v interface{}, k string) (warnings []string, errors []error) { + name := v.(string) + + if len(name) < 3 { + errors = append(errors, fmt.Errorf("length should equal to or greater than %d, got %q", 3, v)) + return + } + + if len(name) > 50 { + errors = append(errors, fmt.Errorf("length should be equal to or less than %d, got %q", 50, v)) + return + } + + if regexp.MustCompile(`^[0-9]+$`).MatchString(name) { + errors = append(errors, fmt.Errorf("%q should not contain only numbers, got %v", k, v)) + return + } + + if !regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9-]+[A-Za-z0-9]$`).MatchString(name) { + errors = append(errors, fmt.Errorf("%q must begin with a letter or number, end with a letter or number and contain only letters, numbers, and hyphens, got %v", k, v)) + return + } + return +} diff --git a/internal/services/digitaltwins/validate/digital_twins_time_series_database_connection_name_test.go b/internal/services/digitaltwins/validate/digital_twins_time_series_database_connection_name_test.go new file mode 100644 index 000000000000..4636b27f40ea --- /dev/null +++ b/internal/services/digitaltwins/validate/digital_twins_time_series_database_connection_name_test.go @@ -0,0 +1,74 @@ +package validate + +import ( + "testing" +) + +func TestDigitalTwinsTimeSeriesDatabaseConnectionName(t *testing.T) { + tests := []struct { + Name string + Input string + Valid bool + }{ + { + Name: "Valid Name", + Input: "Digital-12-Twins", + Valid: true, + }, + { + Name: "Min characters", + Input: "aaa", + Valid: true, + }, + { + Name: "Max characters", + Input: "A1234567890123456789012345678901234567890123456789", + Valid: true, + }, + { + Name: "Empty", + Input: "", + Valid: false, + }, + { + Name: "Invalid character", + Input: "digital_twins", + Valid: false, + }, + { + Name: "Numbers only", + Input: "1234", + Valid: false, + }, + { + Name: "End with `-`", + Input: "Digital-", + Valid: false, + }, + { + Name: "Start with `-`", + Input: "-Digital", + Valid: false, + }, + { + Name: "Too short", + Input: "aa", + Valid: false, + }, + { + Name: "Too long", + Input: "A12345678901234567890123456789012345678901234567890", + Valid: false, + }, + } + + for _, tt := range tests { + t.Run(tt.Name, func(t *testing.T) { + _, err := DigitalTwinsTimeSeriesDatabaseConnectionName(tt.Input, "Name") + valid := err == nil + if valid != tt.Valid { + t.Errorf("Expected valid status %t but got %t for input %s", tt.Valid, valid, tt.Input) + } + }) + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/README.md new file mode 100644 index 000000000000..68d6fc87ba7e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections` Documentation + +The `timeseriesdatabaseconnections` SDK allows for interaction with the Azure Resource Manager Service `digitaltwins` (API Version `2022-10-31`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections" +``` + + +### Client Initialization + +```go +client := timeseriesdatabaseconnections.NewTimeSeriesDatabaseConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TimeSeriesDatabaseConnectionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := timeseriesdatabaseconnections.NewTimeSeriesDatabaseConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "timeSeriesDatabaseConnectionValue") + +payload := timeseriesdatabaseconnections.TimeSeriesDatabaseConnection{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TimeSeriesDatabaseConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := timeseriesdatabaseconnections.NewTimeSeriesDatabaseConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "timeSeriesDatabaseConnectionValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `TimeSeriesDatabaseConnectionsClient.Get` + +```go +ctx := context.TODO() +id := timeseriesdatabaseconnections.NewTimeSeriesDatabaseConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "timeSeriesDatabaseConnectionValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TimeSeriesDatabaseConnectionsClient.List` + +```go +ctx := context.TODO() +id := timeseriesdatabaseconnections.NewDigitalTwinsInstanceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/client.go new file mode 100644 index 000000000000..6f7cb51c3248 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/client.go @@ -0,0 +1,18 @@ +package timeseriesdatabaseconnections + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TimeSeriesDatabaseConnectionsClient struct { + Client autorest.Client + baseUri string +} + +func NewTimeSeriesDatabaseConnectionsClientWithBaseURI(endpoint string) TimeSeriesDatabaseConnectionsClient { + return TimeSeriesDatabaseConnectionsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/constants.go new file mode 100644 index 000000000000..fd56613e08c3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/constants.go @@ -0,0 +1,117 @@ +package timeseriesdatabaseconnections + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectionType string + +const ( + ConnectionTypeAzureDataExplorer ConnectionType = "AzureDataExplorer" +) + +func PossibleValuesForConnectionType() []string { + return []string{ + string(ConnectionTypeAzureDataExplorer), + } +} + +func parseConnectionType(input string) (*ConnectionType, error) { + vals := map[string]ConnectionType{ + "azuredataexplorer": ConnectionTypeAzureDataExplorer, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectionType(input) + return &out, nil +} + +type IdentityType string + +const ( + IdentityTypeSystemAssigned IdentityType = "SystemAssigned" + IdentityTypeUserAssigned IdentityType = "UserAssigned" +) + +func PossibleValuesForIdentityType() []string { + return []string{ + string(IdentityTypeSystemAssigned), + string(IdentityTypeUserAssigned), + } +} + +func parseIdentityType(input string) (*IdentityType, error) { + vals := map[string]IdentityType{ + "systemassigned": IdentityTypeSystemAssigned, + "userassigned": IdentityTypeUserAssigned, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IdentityType(input) + return &out, nil +} + +type TimeSeriesDatabaseConnectionState string + +const ( + TimeSeriesDatabaseConnectionStateCanceled TimeSeriesDatabaseConnectionState = "Canceled" + TimeSeriesDatabaseConnectionStateDeleted TimeSeriesDatabaseConnectionState = "Deleted" + TimeSeriesDatabaseConnectionStateDeleting TimeSeriesDatabaseConnectionState = "Deleting" + TimeSeriesDatabaseConnectionStateDisabled TimeSeriesDatabaseConnectionState = "Disabled" + TimeSeriesDatabaseConnectionStateFailed TimeSeriesDatabaseConnectionState = "Failed" + TimeSeriesDatabaseConnectionStateMoving TimeSeriesDatabaseConnectionState = "Moving" + TimeSeriesDatabaseConnectionStateProvisioning TimeSeriesDatabaseConnectionState = "Provisioning" + TimeSeriesDatabaseConnectionStateRestoring TimeSeriesDatabaseConnectionState = "Restoring" + TimeSeriesDatabaseConnectionStateSucceeded TimeSeriesDatabaseConnectionState = "Succeeded" + TimeSeriesDatabaseConnectionStateSuspending TimeSeriesDatabaseConnectionState = "Suspending" + TimeSeriesDatabaseConnectionStateUpdating TimeSeriesDatabaseConnectionState = "Updating" + TimeSeriesDatabaseConnectionStateWarning TimeSeriesDatabaseConnectionState = "Warning" +) + +func PossibleValuesForTimeSeriesDatabaseConnectionState() []string { + return []string{ + string(TimeSeriesDatabaseConnectionStateCanceled), + string(TimeSeriesDatabaseConnectionStateDeleted), + string(TimeSeriesDatabaseConnectionStateDeleting), + string(TimeSeriesDatabaseConnectionStateDisabled), + string(TimeSeriesDatabaseConnectionStateFailed), + string(TimeSeriesDatabaseConnectionStateMoving), + string(TimeSeriesDatabaseConnectionStateProvisioning), + string(TimeSeriesDatabaseConnectionStateRestoring), + string(TimeSeriesDatabaseConnectionStateSucceeded), + string(TimeSeriesDatabaseConnectionStateSuspending), + string(TimeSeriesDatabaseConnectionStateUpdating), + string(TimeSeriesDatabaseConnectionStateWarning), + } +} + +func parseTimeSeriesDatabaseConnectionState(input string) (*TimeSeriesDatabaseConnectionState, error) { + vals := map[string]TimeSeriesDatabaseConnectionState{ + "canceled": TimeSeriesDatabaseConnectionStateCanceled, + "deleted": TimeSeriesDatabaseConnectionStateDeleted, + "deleting": TimeSeriesDatabaseConnectionStateDeleting, + "disabled": TimeSeriesDatabaseConnectionStateDisabled, + "failed": TimeSeriesDatabaseConnectionStateFailed, + "moving": TimeSeriesDatabaseConnectionStateMoving, + "provisioning": TimeSeriesDatabaseConnectionStateProvisioning, + "restoring": TimeSeriesDatabaseConnectionStateRestoring, + "succeeded": TimeSeriesDatabaseConnectionStateSucceeded, + "suspending": TimeSeriesDatabaseConnectionStateSuspending, + "updating": TimeSeriesDatabaseConnectionStateUpdating, + "warning": TimeSeriesDatabaseConnectionStateWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TimeSeriesDatabaseConnectionState(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/id_digitaltwinsinstance.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/id_digitaltwinsinstance.go new file mode 100644 index 000000000000..63c1810a19ec --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/id_digitaltwinsinstance.go @@ -0,0 +1,124 @@ +package timeseriesdatabaseconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = DigitalTwinsInstanceId{} + +// DigitalTwinsInstanceId is a struct representing the Resource ID for a Digital Twins Instance +type DigitalTwinsInstanceId struct { + SubscriptionId string + ResourceGroupName string + ResourceName string +} + +// NewDigitalTwinsInstanceID returns a new DigitalTwinsInstanceId struct +func NewDigitalTwinsInstanceID(subscriptionId string, resourceGroupName string, resourceName string) DigitalTwinsInstanceId { + return DigitalTwinsInstanceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceName: resourceName, + } +} + +// ParseDigitalTwinsInstanceID parses 'input' into a DigitalTwinsInstanceId +func ParseDigitalTwinsInstanceID(input string) (*DigitalTwinsInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(DigitalTwinsInstanceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := DigitalTwinsInstanceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseDigitalTwinsInstanceIDInsensitively parses 'input' case-insensitively into a DigitalTwinsInstanceId +// note: this method should only be used for API response data and not user input +func ParseDigitalTwinsInstanceIDInsensitively(input string) (*DigitalTwinsInstanceId, error) { + parser := resourceids.NewParserFromResourceIdType(DigitalTwinsInstanceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := DigitalTwinsInstanceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateDigitalTwinsInstanceID checks that 'input' can be parsed as a Digital Twins Instance ID +func ValidateDigitalTwinsInstanceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDigitalTwinsInstanceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Digital Twins Instance ID +func (id DigitalTwinsInstanceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DigitalTwins/digitalTwinsInstances/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Digital Twins Instance ID +func (id DigitalTwinsInstanceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDigitalTwins", "Microsoft.DigitalTwins", "Microsoft.DigitalTwins"), + resourceids.StaticSegment("staticDigitalTwinsInstances", "digitalTwinsInstances", "digitalTwinsInstances"), + resourceids.UserSpecifiedSegment("resourceName", "resourceValue"), + } +} + +// String returns a human-readable description of this Digital Twins Instance ID +func (id DigitalTwinsInstanceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Name: %q", id.ResourceName), + } + return fmt.Sprintf("Digital Twins Instance (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/id_timeseriesdatabaseconnection.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/id_timeseriesdatabaseconnection.go new file mode 100644 index 000000000000..6280b2164cfc --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/id_timeseriesdatabaseconnection.go @@ -0,0 +1,137 @@ +package timeseriesdatabaseconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = TimeSeriesDatabaseConnectionId{} + +// TimeSeriesDatabaseConnectionId is a struct representing the Resource ID for a Time Series Database Connection +type TimeSeriesDatabaseConnectionId struct { + SubscriptionId string + ResourceGroupName string + ResourceName string + TimeSeriesDatabaseConnectionName string +} + +// NewTimeSeriesDatabaseConnectionID returns a new TimeSeriesDatabaseConnectionId struct +func NewTimeSeriesDatabaseConnectionID(subscriptionId string, resourceGroupName string, resourceName string, timeSeriesDatabaseConnectionName string) TimeSeriesDatabaseConnectionId { + return TimeSeriesDatabaseConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceName: resourceName, + TimeSeriesDatabaseConnectionName: timeSeriesDatabaseConnectionName, + } +} + +// ParseTimeSeriesDatabaseConnectionID parses 'input' into a TimeSeriesDatabaseConnectionId +func ParseTimeSeriesDatabaseConnectionID(input string) (*TimeSeriesDatabaseConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(TimeSeriesDatabaseConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := TimeSeriesDatabaseConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + } + + if id.TimeSeriesDatabaseConnectionName, ok = parsed.Parsed["timeSeriesDatabaseConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'timeSeriesDatabaseConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseTimeSeriesDatabaseConnectionIDInsensitively parses 'input' case-insensitively into a TimeSeriesDatabaseConnectionId +// note: this method should only be used for API response data and not user input +func ParseTimeSeriesDatabaseConnectionIDInsensitively(input string) (*TimeSeriesDatabaseConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(TimeSeriesDatabaseConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := TimeSeriesDatabaseConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + } + + if id.TimeSeriesDatabaseConnectionName, ok = parsed.Parsed["timeSeriesDatabaseConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'timeSeriesDatabaseConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateTimeSeriesDatabaseConnectionID checks that 'input' can be parsed as a Time Series Database Connection ID +func ValidateTimeSeriesDatabaseConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTimeSeriesDatabaseConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Time Series Database Connection ID +func (id TimeSeriesDatabaseConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DigitalTwins/digitalTwinsInstances/%s/timeSeriesDatabaseConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceName, id.TimeSeriesDatabaseConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Time Series Database Connection ID +func (id TimeSeriesDatabaseConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDigitalTwins", "Microsoft.DigitalTwins", "Microsoft.DigitalTwins"), + resourceids.StaticSegment("staticDigitalTwinsInstances", "digitalTwinsInstances", "digitalTwinsInstances"), + resourceids.UserSpecifiedSegment("resourceName", "resourceValue"), + resourceids.StaticSegment("staticTimeSeriesDatabaseConnections", "timeSeriesDatabaseConnections", "timeSeriesDatabaseConnections"), + resourceids.UserSpecifiedSegment("timeSeriesDatabaseConnectionName", "timeSeriesDatabaseConnectionValue"), + } +} + +// String returns a human-readable description of this Time Series Database Connection ID +func (id TimeSeriesDatabaseConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Name: %q", id.ResourceName), + fmt.Sprintf("Time Series Database Connection Name: %q", id.TimeSeriesDatabaseConnectionName), + } + return fmt.Sprintf("Time Series Database Connection (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_createorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_createorupdate_autorest.go new file mode 100644 index 000000000000..4c4691c65cc4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_createorupdate_autorest.go @@ -0,0 +1,79 @@ +package timeseriesdatabaseconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// CreateOrUpdate ... +func (c TimeSeriesDatabaseConnectionsClient) CreateOrUpdate(ctx context.Context, id TimeSeriesDatabaseConnectionId, input TimeSeriesDatabaseConnection) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c TimeSeriesDatabaseConnectionsClient) CreateOrUpdateThenPoll(ctx context.Context, id TimeSeriesDatabaseConnectionId, input TimeSeriesDatabaseConnection) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c TimeSeriesDatabaseConnectionsClient) preparerForCreateOrUpdate(ctx context.Context, id TimeSeriesDatabaseConnectionId, input TimeSeriesDatabaseConnection) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c TimeSeriesDatabaseConnectionsClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_delete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_delete_autorest.go new file mode 100644 index 000000000000..c6cf3a2d2f19 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_delete_autorest.go @@ -0,0 +1,78 @@ +package timeseriesdatabaseconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c TimeSeriesDatabaseConnectionsClient) Delete(ctx context.Context, id TimeSeriesDatabaseConnectionId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c TimeSeriesDatabaseConnectionsClient) DeleteThenPoll(ctx context.Context, id TimeSeriesDatabaseConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c TimeSeriesDatabaseConnectionsClient) preparerForDelete(ctx context.Context, id TimeSeriesDatabaseConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c TimeSeriesDatabaseConnectionsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_get_autorest.go new file mode 100644 index 000000000000..05319cf48348 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_get_autorest.go @@ -0,0 +1,68 @@ +package timeseriesdatabaseconnections + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *TimeSeriesDatabaseConnection +} + +// Get ... +func (c TimeSeriesDatabaseConnectionsClient) Get(ctx context.Context, id TimeSeriesDatabaseConnectionId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c TimeSeriesDatabaseConnectionsClient) preparerForGet(ctx context.Context, id TimeSeriesDatabaseConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c TimeSeriesDatabaseConnectionsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_list_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_list_autorest.go new file mode 100644 index 000000000000..9b136531398d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/method_list_autorest.go @@ -0,0 +1,186 @@ +package timeseriesdatabaseconnections + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]TimeSeriesDatabaseConnection + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []TimeSeriesDatabaseConnection +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c TimeSeriesDatabaseConnectionsClient) List(ctx context.Context, id DigitalTwinsInstanceId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c TimeSeriesDatabaseConnectionsClient) preparerForList(ctx context.Context, id DigitalTwinsInstanceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/timeSeriesDatabaseConnections", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c TimeSeriesDatabaseConnectionsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c TimeSeriesDatabaseConnectionsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []TimeSeriesDatabaseConnection `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "timeseriesdatabaseconnections.TimeSeriesDatabaseConnectionsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c TimeSeriesDatabaseConnectionsClient) ListComplete(ctx context.Context, id DigitalTwinsInstanceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, TimeSeriesDatabaseConnectionOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c TimeSeriesDatabaseConnectionsClient) ListCompleteMatchingPredicate(ctx context.Context, id DigitalTwinsInstanceId, predicate TimeSeriesDatabaseConnectionOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]TimeSeriesDatabaseConnection, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_azuredataexplorerconnectionproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_azuredataexplorerconnectionproperties.go new file mode 100644 index 000000000000..462cae29f7ab --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_azuredataexplorerconnectionproperties.go @@ -0,0 +1,50 @@ +package timeseriesdatabaseconnections + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ TimeSeriesDatabaseConnectionProperties = AzureDataExplorerConnectionProperties{} + +type AzureDataExplorerConnectionProperties struct { + AdxDatabaseName string `json:"adxDatabaseName"` + AdxEndpointUri string `json:"adxEndpointUri"` + AdxResourceId string `json:"adxResourceId"` + AdxTableName *string `json:"adxTableName,omitempty"` + EventHubConsumerGroup *string `json:"eventHubConsumerGroup,omitempty"` + EventHubEndpointUri string `json:"eventHubEndpointUri"` + EventHubEntityPath string `json:"eventHubEntityPath"` + EventHubNamespaceResourceId string `json:"eventHubNamespaceResourceId"` + + // Fields inherited from TimeSeriesDatabaseConnectionProperties + Identity *ManagedIdentityReference `json:"identity,omitempty"` + ProvisioningState *TimeSeriesDatabaseConnectionState `json:"provisioningState,omitempty"` +} + +var _ json.Marshaler = AzureDataExplorerConnectionProperties{} + +func (s AzureDataExplorerConnectionProperties) MarshalJSON() ([]byte, error) { + type wrapper AzureDataExplorerConnectionProperties + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureDataExplorerConnectionProperties: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureDataExplorerConnectionProperties: %+v", err) + } + decoded["connectionType"] = "AzureDataExplorer" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureDataExplorerConnectionProperties: %+v", err) + } + + return encoded, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_managedidentityreference.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_managedidentityreference.go new file mode 100644 index 000000000000..acb3fc80c5e4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_managedidentityreference.go @@ -0,0 +1,9 @@ +package timeseriesdatabaseconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIdentityReference struct { + Type *IdentityType `json:"type,omitempty"` + UserAssignedIdentity *string `json:"userAssignedIdentity,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_timeseriesdatabaseconnection.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_timeseriesdatabaseconnection.go new file mode 100644 index 000000000000..226e00f4919b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_timeseriesdatabaseconnection.go @@ -0,0 +1,48 @@ +package timeseriesdatabaseconnections + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TimeSeriesDatabaseConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties TimeSeriesDatabaseConnectionProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &TimeSeriesDatabaseConnection{} + +func (s *TimeSeriesDatabaseConnection) UnmarshalJSON(bytes []byte) error { + type alias TimeSeriesDatabaseConnection + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into TimeSeriesDatabaseConnection: %+v", err) + } + + s.Id = decoded.Id + s.Name = decoded.Name + s.SystemData = decoded.SystemData + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling TimeSeriesDatabaseConnection into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalTimeSeriesDatabaseConnectionPropertiesImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'TimeSeriesDatabaseConnection': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_timeseriesdatabaseconnectionproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_timeseriesdatabaseconnectionproperties.go new file mode 100644 index 000000000000..49b8634d1e16 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/model_timeseriesdatabaseconnectionproperties.go @@ -0,0 +1,48 @@ +package timeseriesdatabaseconnections + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TimeSeriesDatabaseConnectionProperties interface { +} + +func unmarshalTimeSeriesDatabaseConnectionPropertiesImplementation(input []byte) (TimeSeriesDatabaseConnectionProperties, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling TimeSeriesDatabaseConnectionProperties into map[string]interface: %+v", err) + } + + value, ok := temp["connectionType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureDataExplorer") { + var out AzureDataExplorerConnectionProperties + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureDataExplorerConnectionProperties: %+v", err) + } + return out, nil + } + + type RawTimeSeriesDatabaseConnectionPropertiesImpl struct { + Type string `json:"-"` + Values map[string]interface{} `json:"-"` + } + out := RawTimeSeriesDatabaseConnectionPropertiesImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/predicates.go new file mode 100644 index 000000000000..1cc38b461824 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/predicates.go @@ -0,0 +1,24 @@ +package timeseriesdatabaseconnections + +type TimeSeriesDatabaseConnectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TimeSeriesDatabaseConnectionOperationPredicate) Matches(input TimeSeriesDatabaseConnection) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/version.go new file mode 100644 index 000000000000..dc37e97cea7d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections/version.go @@ -0,0 +1,12 @@ +package timeseriesdatabaseconnections + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-10-31" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/timeseriesdatabaseconnections/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 73db72007a02..dac5a64543fb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -248,6 +248,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/desktopvirtualization/2022-02 github.com/hashicorp/go-azure-sdk/resource-manager/deviceprovisioningservices/2022-02-05/dpscertificate github.com/hashicorp/go-azure-sdk/resource-manager/deviceprovisioningservices/2022-02-05/iotdpsresource github.com/hashicorp/go-azure-sdk/resource-manager/deviceupdate/2022-10-01/deviceupdates +github.com/hashicorp/go-azure-sdk/resource-manager/digitaltwins/2022-10-31/timeseriesdatabaseconnections github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01 github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01/dns github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01/recordsets diff --git a/website/docs/r/digital_twins_time_series_database_connection.html.markdown b/website/docs/r/digital_twins_time_series_database_connection.html.markdown new file mode 100644 index 000000000000..699e6cfa4aaf --- /dev/null +++ b/website/docs/r/digital_twins_time_series_database_connection.html.markdown @@ -0,0 +1,161 @@ +--- +subcategory: "Digital Twins" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_digital_twins_time_series_database_connection" +description: |- + Manages a Digital Twins Time Series Database Connection. +--- + +# azurerm_digital_twins_time_series_database_connection + +Manages a Digital Twins Time Series Database Connection. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_digital_twins_instance" "example" { + name = "example-DT" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + + identity { + type = "SystemAssigned" + } +} + +resource "azurerm_eventhub_namespace" "example" { + name = "exampleEventHubNamespace" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + sku = "Standard" +} + +resource "azurerm_eventhub" "example" { + name = "exampleEventHub" + namespace_name = azurerm_eventhub_namespace.example.name + resource_group_name = azurerm_resource_group.example.name + partition_count = 2 + message_retention = 7 +} + +resource "azurerm_eventhub_consumer_group" "example" { + name = "example-consumergroup" + namespace_name = azurerm_eventhub_namespace.example.name + eventhub_name = azurerm_eventhub.example.name + resource_group_name = azurerm_resource_group.example.name +} + +resource "azurerm_kusto_cluster" "example" { + name = "examplekc" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + + sku { + name = "Dev(No SLA)_Standard_D11_v2" + capacity = 1 + } +} + +resource "azurerm_kusto_database" "example" { + name = "example-kusto-database" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + cluster_name = azurerm_kusto_cluster.example.name +} + +resource "azurerm_role_assignment" "database_contributor" { + scope = azurerm_kusto_database.example.id + principal_id = azurerm_digital_twins_instance.example.identity.0.principal_id + role_definition_name = "Contributor" +} + +resource "azurerm_role_assignment" "eventhub_data_owner" { + scope = azurerm_eventhub.example.id + principal_id = azurerm_digital_twins_instance.example.identity.0.principal_id + role_definition_name = "Azure Event Hubs Data Owner" +} + +resource "azurerm_kusto_database_principal_assignment" "example" { + name = "dataadmin" + resource_group_name = azurerm_resource_group.example.name + cluster_name = azurerm_kusto_cluster.example.name + database_name = azurerm_kusto_database.example.name + + tenant_id = azurerm_digital_twins_instance.example.identity.0.tenant_id + principal_id = azurerm_digital_twins_instance.example.identity.0.principal_id + principal_type = "App" + role = "Admin" +} + +resource "azurerm_digital_twins_time_series_database_connection" "example" { + name = "example-connection" + digital_twins_id = azurerm_digital_twins_instance.example.id + eventhub_name = azurerm_eventhub.example.name + eventhub_namespace_id = azurerm_eventhub_namespace.example.id + eventhub_namespace_endpoint_uri = "sb://${azurerm_eventhub_namespace.example.name}.servicebus.windows.net" + eventhub_consumer_group_name = azurerm_eventhub_consumer_group.example.name + kusto_cluster_id = azurerm_kusto_cluster.example.id + kusto_cluster_uri = azurerm_kusto_cluster.example.uri + kusto_database_name = azurerm_kusto_database.example.name + kusto_table_name = "exampleTable" + + depends_on = [ + azurerm_role_assignment.database_contributor, + azurerm_role_assignment.eventhub_data_owner, + azurerm_kusto_database_principal_assignment.example + ] +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) The name which should be used for this Digital Twins Time Series Database Connection. Changing this forces a new resource to be created. + +* `digital_twins_id` - (Required) The ID of the Digital Twins. Changing this forces a new resource to be created. + +* `eventhub_name` - (Required) Name of the Event Hub. Changing this forces a new resource to be created. + +* `eventhub_namespace_endpoint_uri` - (Required) URI of the Event Hub Namespace. Changing this forces a new resource to be created. + +* `eventhub_namespace_id` - (Required) The ID of the Event Hub Namespace. Changing this forces a new resource to be created. + +* `kusto_cluster_id` - (Required) The ID of the Kusto Cluster. Changing this forces a new resource to be created. + +* `kusto_cluster_uri` - (Required) URI of the Kusto Cluster. Changing this forces a new resource to be created. + +* `kusto_database_name` - (Required) Name of the Kusto Database. Changing this forces a new resource to be created. + +--- + +* `eventhub_consumer_group_name` - (Optional) Name of the Event Hub Consumer Group. Changing this forces a new resource to be created. + +* `kusto_table_name` - (Optional) Name of the Kusto Table. Changing this forces a new resource to be created. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Digital Twins Time Series Database Connection. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Digital Twins Time Series Database Connection. +* `read` - (Defaults to 5 minutes) Used when retrieving the Digital Twins Time Series Database Connection. +* `delete` - (Defaults to 30 minutes) Used when deleting the Digital Twins Time Series Database Connection. + +## Import + +Digital Twins Time Series Database Connections can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_digital_twins_time_series_database_connection.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.DigitalTwins/digitalTwinsInstances/dt1/timeSeriesDatabaseConnections/connection1 +```