From 8e3f545f7d1a9edcc8556f3de79726b7beba068e Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 11 Jul 2018 11:54:37 -0700 Subject: [PATCH 1/8] added new resource resource_arm_servicebus_queue_authorization_rule --- azurerm/provider.go | 247 +++++++++--------- ...arm_servicebus_queue_authorization_rule.go | 1 + ...ervicebus_queue_authorization_rule_test.go | 3 + 3 files changed, 128 insertions(+), 123 deletions(-) diff --git a/azurerm/provider.go b/azurerm/provider.go index 1baf6908822b..073fc1e3f528 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -117,129 +117,130 @@ func Provider() terraform.ResourceProvider { }, ResourcesMap: map[string]*schema.Resource{ - "azurerm_azuread_application": resourceArmActiveDirectoryApplication(), - "azurerm_application_gateway": resourceArmApplicationGateway(), - "azurerm_application_insights": resourceArmApplicationInsights(), - "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), - "azurerm_app_service": resourceArmAppService(), - "azurerm_app_service_plan": resourceArmAppServicePlan(), - "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), - "azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(), - "azurerm_app_service_slot": resourceArmAppServiceSlot(), - "azurerm_automation_account": resourceArmAutomationAccount(), - "azurerm_automation_credential": resourceArmAutomationCredential(), - "azurerm_automation_runbook": resourceArmAutomationRunbook(), - "azurerm_automation_schedule": resourceArmAutomationSchedule(), - "azurerm_availability_set": resourceArmAvailabilitySet(), - "azurerm_cdn_endpoint": resourceArmCdnEndpoint(), - "azurerm_cdn_profile": resourceArmCdnProfile(), - "azurerm_container_registry": resourceArmContainerRegistry(), - "azurerm_container_service": resourceArmContainerService(), - "azurerm_container_group": resourceArmContainerGroup(), - "azurerm_cosmosdb_account": resourceArmCosmosDBAccount(), - "azurerm_data_lake_store": resourceArmDataLakeStore(), - "azurerm_data_lake_store_firewall_rule": resourceArmDataLakeStoreFirewallRule(), - "azurerm_dns_a_record": resourceArmDnsARecord(), - "azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(), - "azurerm_dns_caa_record": resourceArmDnsCaaRecord(), - "azurerm_dns_cname_record": resourceArmDnsCNameRecord(), - "azurerm_dns_mx_record": resourceArmDnsMxRecord(), - "azurerm_dns_ns_record": resourceArmDnsNsRecord(), - "azurerm_dns_ptr_record": resourceArmDnsPtrRecord(), - "azurerm_dns_srv_record": resourceArmDnsSrvRecord(), - "azurerm_dns_txt_record": resourceArmDnsTxtRecord(), - "azurerm_dns_zone": resourceArmDnsZone(), - "azurerm_eventgrid_topic": resourceArmEventGridTopic(), - "azurerm_eventhub": resourceArmEventHub(), - "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), - "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), - "azurerm_eventhub_namespace": resourceArmEventHubNamespace(), - "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), - "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), - "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), - "azurerm_function_app": resourceArmFunctionApp(), - "azurerm_image": resourceArmImage(), - "azurerm_iothub": resourceArmIotHub(), - "azurerm_key_vault": resourceArmKeyVault(), - "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), - "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), - "azurerm_key_vault_key": resourceArmKeyVaultKey(), - "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), - "azurerm_kubernetes_cluster": resourceArmKubernetesCluster(), - "azurerm_lb": resourceArmLoadBalancer(), - "azurerm_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(), - "azurerm_lb_nat_rule": resourceArmLoadBalancerNatRule(), - "azurerm_lb_nat_pool": resourceArmLoadBalancerNatPool(), - "azurerm_lb_probe": resourceArmLoadBalancerProbe(), - "azurerm_lb_rule": resourceArmLoadBalancerRule(), - "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), - "azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(), - "azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace(), - "azurerm_managed_disk": resourceArmManagedDisk(), - "azurerm_management_lock": resourceArmManagementLock(), - "azurerm_metric_alertrule": resourceArmMetricAlertRule(), - "azurerm_mysql_configuration": resourceArmMySQLConfiguration(), - "azurerm_mysql_database": resourceArmMySqlDatabase(), - "azurerm_mysql_firewall_rule": resourceArmMySqlFirewallRule(), - "azurerm_mysql_server": resourceArmMySqlServer(), - "azurerm_network_interface": resourceArmNetworkInterface(), - "azurerm_network_security_group": resourceArmNetworkSecurityGroup(), - "azurerm_network_security_rule": resourceArmNetworkSecurityRule(), - "azurerm_network_watcher": resourceArmNetworkWatcher(), - "azurerm_packet_capture": resourceArmPacketCapture(), - "azurerm_policy_assignment": resourceArmPolicyAssignment(), - "azurerm_policy_definition": resourceArmPolicyDefinition(), - "azurerm_postgresql_configuration": resourceArmPostgreSQLConfiguration(), - "azurerm_postgresql_database": resourceArmPostgreSQLDatabase(), - "azurerm_postgresql_firewall_rule": resourceArmPostgreSQLFirewallRule(), - "azurerm_postgresql_server": resourceArmPostgreSQLServer(), - "azurerm_public_ip": resourceArmPublicIp(), - "azurerm_relay_namespace": resourceArmRelayNamespace(), - "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), - "azurerm_redis_cache": resourceArmRedisCache(), - "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), - "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_role_assignment": resourceArmRoleAssignment(), - "azurerm_role_definition": resourceArmRoleDefinition(), - "azurerm_route": resourceArmRoute(), - "azurerm_route_table": resourceArmRouteTable(), - "azurerm_search_service": resourceArmSearchService(), - "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), - "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_servicebus_queue": resourceArmServiceBusQueue(), - "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), - "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), - "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), - "azurerm_servicebus_topic": resourceArmServiceBusTopic(), - "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), - "azurerm_snapshot": resourceArmSnapshot(), - "azurerm_scheduler_job": resourceArmSchedulerJob(), - "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), - "azurerm_sql_database": resourceArmSqlDatabase(), - "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), - "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), - "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), - "azurerm_sql_server": resourceArmSqlServer(), - "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), - "azurerm_storage_account": resourceArmStorageAccount(), - "azurerm_storage_blob": resourceArmStorageBlob(), - "azurerm_storage_container": resourceArmStorageContainer(), - "azurerm_storage_share": resourceArmStorageShare(), - "azurerm_storage_queue": resourceArmStorageQueue(), - "azurerm_storage_table": resourceArmStorageTable(), - "azurerm_subnet": resourceArmSubnet(), - "azurerm_template_deployment": resourceArmTemplateDeployment(), - "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), - "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), - "azurerm_user_assigned_identity": resourceArmUserAssignedIdentity(), - "azurerm_virtual_machine": resourceArmVirtualMachine(), - "azurerm_virtual_machine_data_disk_attachment": resourceArmVirtualMachineDataDiskAttachment(), - "azurerm_virtual_machine_extension": resourceArmVirtualMachineExtensions(), - "azurerm_virtual_machine_scale_set": resourceArmVirtualMachineScaleSet(), - "azurerm_virtual_network": resourceArmVirtualNetwork(), - "azurerm_virtual_network_gateway": resourceArmVirtualNetworkGateway(), - "azurerm_virtual_network_gateway_connection": resourceArmVirtualNetworkGatewayConnection(), - "azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(), + "azurerm_azuread_application": resourceArmActiveDirectoryApplication(), + "azurerm_application_gateway": resourceArmApplicationGateway(), + "azurerm_application_insights": resourceArmApplicationInsights(), + "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), + "azurerm_app_service": resourceArmAppService(), + "azurerm_app_service_plan": resourceArmAppServicePlan(), + "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), + "azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(), + "azurerm_app_service_slot": resourceArmAppServiceSlot(), + "azurerm_automation_account": resourceArmAutomationAccount(), + "azurerm_automation_credential": resourceArmAutomationCredential(), + "azurerm_automation_runbook": resourceArmAutomationRunbook(), + "azurerm_automation_schedule": resourceArmAutomationSchedule(), + "azurerm_availability_set": resourceArmAvailabilitySet(), + "azurerm_cdn_endpoint": resourceArmCdnEndpoint(), + "azurerm_cdn_profile": resourceArmCdnProfile(), + "azurerm_container_registry": resourceArmContainerRegistry(), + "azurerm_container_service": resourceArmContainerService(), + "azurerm_container_group": resourceArmContainerGroup(), + "azurerm_cosmosdb_account": resourceArmCosmosDBAccount(), + "azurerm_data_lake_store": resourceArmDataLakeStore(), + "azurerm_data_lake_store_firewall_rule": resourceArmDataLakeStoreFirewallRule(), + "azurerm_dns_a_record": resourceArmDnsARecord(), + "azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(), + "azurerm_dns_caa_record": resourceArmDnsCaaRecord(), + "azurerm_dns_cname_record": resourceArmDnsCNameRecord(), + "azurerm_dns_mx_record": resourceArmDnsMxRecord(), + "azurerm_dns_ns_record": resourceArmDnsNsRecord(), + "azurerm_dns_ptr_record": resourceArmDnsPtrRecord(), + "azurerm_dns_srv_record": resourceArmDnsSrvRecord(), + "azurerm_dns_txt_record": resourceArmDnsTxtRecord(), + "azurerm_dns_zone": resourceArmDnsZone(), + "azurerm_eventgrid_topic": resourceArmEventGridTopic(), + "azurerm_eventhub": resourceArmEventHub(), + "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), + "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), + "azurerm_eventhub_namespace": resourceArmEventHubNamespace(), + "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), + "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), + "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), + "azurerm_function_app": resourceArmFunctionApp(), + "azurerm_image": resourceArmImage(), + "azurerm_iothub": resourceArmIotHub(), + "azurerm_key_vault": resourceArmKeyVault(), + "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), + "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), + "azurerm_key_vault_key": resourceArmKeyVaultKey(), + "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), + "azurerm_kubernetes_cluster": resourceArmKubernetesCluster(), + "azurerm_lb": resourceArmLoadBalancer(), + "azurerm_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(), + "azurerm_lb_nat_rule": resourceArmLoadBalancerNatRule(), + "azurerm_lb_nat_pool": resourceArmLoadBalancerNatPool(), + "azurerm_lb_probe": resourceArmLoadBalancerProbe(), + "azurerm_lb_rule": resourceArmLoadBalancerRule(), + "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), + "azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(), + "azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace(), + "azurerm_managed_disk": resourceArmManagedDisk(), + "azurerm_management_lock": resourceArmManagementLock(), + "azurerm_metric_alertrule": resourceArmMetricAlertRule(), + "azurerm_mysql_configuration": resourceArmMySQLConfiguration(), + "azurerm_mysql_database": resourceArmMySqlDatabase(), + "azurerm_mysql_firewall_rule": resourceArmMySqlFirewallRule(), + "azurerm_mysql_server": resourceArmMySqlServer(), + "azurerm_network_interface": resourceArmNetworkInterface(), + "azurerm_network_security_group": resourceArmNetworkSecurityGroup(), + "azurerm_network_security_rule": resourceArmNetworkSecurityRule(), + "azurerm_network_watcher": resourceArmNetworkWatcher(), + "azurerm_packet_capture": resourceArmPacketCapture(), + "azurerm_policy_assignment": resourceArmPolicyAssignment(), + "azurerm_policy_definition": resourceArmPolicyDefinition(), + "azurerm_postgresql_configuration": resourceArmPostgreSQLConfiguration(), + "azurerm_postgresql_database": resourceArmPostgreSQLDatabase(), + "azurerm_postgresql_firewall_rule": resourceArmPostgreSQLFirewallRule(), + "azurerm_postgresql_server": resourceArmPostgreSQLServer(), + "azurerm_public_ip": resourceArmPublicIp(), + "azurerm_relay_namespace": resourceArmRelayNamespace(), + "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), + "azurerm_redis_cache": resourceArmRedisCache(), + "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), + "azurerm_resource_group": resourceArmResourceGroup(), + "azurerm_role_assignment": resourceArmRoleAssignment(), + "azurerm_role_definition": resourceArmRoleDefinition(), + "azurerm_route": resourceArmRoute(), + "azurerm_route_table": resourceArmRouteTable(), + "azurerm_search_service": resourceArmSearchService(), + "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), + "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), + "azurerm_servicebus_queue": resourceArmServiceBusQueue(), + "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), + "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), + "azurerm_servicebus_subscription_authorization_rule": resourceArmServiceBusSubscriptionAuthorizationRule(), + "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), + "azurerm_servicebus_topic": resourceArmServiceBusTopic(), + "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), + "azurerm_snapshot": resourceArmSnapshot(), + "azurerm_scheduler_job": resourceArmSchedulerJob(), + "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), + "azurerm_sql_database": resourceArmSqlDatabase(), + "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), + "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), + "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), + "azurerm_sql_server": resourceArmSqlServer(), + "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), + "azurerm_storage_account": resourceArmStorageAccount(), + "azurerm_storage_blob": resourceArmStorageBlob(), + "azurerm_storage_container": resourceArmStorageContainer(), + "azurerm_storage_share": resourceArmStorageShare(), + "azurerm_storage_queue": resourceArmStorageQueue(), + "azurerm_storage_table": resourceArmStorageTable(), + "azurerm_subnet": resourceArmSubnet(), + "azurerm_template_deployment": resourceArmTemplateDeployment(), + "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), + "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), + "azurerm_user_assigned_identity": resourceArmUserAssignedIdentity(), + "azurerm_virtual_machine": resourceArmVirtualMachine(), + "azurerm_virtual_machine_data_disk_attachment": resourceArmVirtualMachineDataDiskAttachment(), + "azurerm_virtual_machine_extension": resourceArmVirtualMachineExtensions(), + "azurerm_virtual_machine_scale_set": resourceArmVirtualMachineScaleSet(), + "azurerm_virtual_network": resourceArmVirtualNetwork(), + "azurerm_virtual_network_gateway": resourceArmVirtualNetworkGateway(), + "azurerm_virtual_network_gateway_connection": resourceArmVirtualNetworkGatewayConnection(), + "azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(), }, } diff --git a/azurerm/resource_arm_servicebus_queue_authorization_rule.go b/azurerm/resource_arm_servicebus_queue_authorization_rule.go index 4ddca0e4ad6b..e578d457bc9a 100644 --- a/azurerm/resource_arm_servicebus_queue_authorization_rule.go +++ b/azurerm/resource_arm_servicebus_queue_authorization_rule.go @@ -107,6 +107,7 @@ func resourceArmServiceBusQueueAuthorizationRuleRead(d *schema.ResourceData, met d.SetId("") return nil } + return fmt.Errorf("Error making Read request on Azure ServiceBus Queue Authorization Rule %q (Queue %q / Namespace %q / Resource Group %q): %+v", name, queueName, namespaceName, resGroup, err) } diff --git a/azurerm/resource_arm_servicebus_queue_authorization_rule_test.go b/azurerm/resource_arm_servicebus_queue_authorization_rule_test.go index 681816f99591..9e370ee5ad56 100644 --- a/azurerm/resource_arm_servicebus_queue_authorization_rule_test.go +++ b/azurerm/resource_arm_servicebus_queue_authorization_rule_test.go @@ -185,7 +185,10 @@ resource "azurerm_servicebus_queue_authorization_rule" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" queue_name = "${azurerm_servicebus_queue.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" +<<<<<<< HEAD +======= +>>>>>>> added new resource resource_arm_servicebus_queue_authorization_rule listen = %[3]t send = %[4]t manage = %[5]t From 2154d4487f61fc3137ada55a32ca84e4ed8420ec Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 11 Jul 2018 13:42:06 -0700 Subject: [PATCH 2/8] updates & add docs --- azurerm/provider.go | 247 +++++++++--------- ...bus_queue_authorization_rule.html.markdown | 4 +- 2 files changed, 124 insertions(+), 127 deletions(-) diff --git a/azurerm/provider.go b/azurerm/provider.go index 073fc1e3f528..1baf6908822b 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -117,130 +117,129 @@ func Provider() terraform.ResourceProvider { }, ResourcesMap: map[string]*schema.Resource{ - "azurerm_azuread_application": resourceArmActiveDirectoryApplication(), - "azurerm_application_gateway": resourceArmApplicationGateway(), - "azurerm_application_insights": resourceArmApplicationInsights(), - "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), - "azurerm_app_service": resourceArmAppService(), - "azurerm_app_service_plan": resourceArmAppServicePlan(), - "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), - "azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(), - "azurerm_app_service_slot": resourceArmAppServiceSlot(), - "azurerm_automation_account": resourceArmAutomationAccount(), - "azurerm_automation_credential": resourceArmAutomationCredential(), - "azurerm_automation_runbook": resourceArmAutomationRunbook(), - "azurerm_automation_schedule": resourceArmAutomationSchedule(), - "azurerm_availability_set": resourceArmAvailabilitySet(), - "azurerm_cdn_endpoint": resourceArmCdnEndpoint(), - "azurerm_cdn_profile": resourceArmCdnProfile(), - "azurerm_container_registry": resourceArmContainerRegistry(), - "azurerm_container_service": resourceArmContainerService(), - "azurerm_container_group": resourceArmContainerGroup(), - "azurerm_cosmosdb_account": resourceArmCosmosDBAccount(), - "azurerm_data_lake_store": resourceArmDataLakeStore(), - "azurerm_data_lake_store_firewall_rule": resourceArmDataLakeStoreFirewallRule(), - "azurerm_dns_a_record": resourceArmDnsARecord(), - "azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(), - "azurerm_dns_caa_record": resourceArmDnsCaaRecord(), - "azurerm_dns_cname_record": resourceArmDnsCNameRecord(), - "azurerm_dns_mx_record": resourceArmDnsMxRecord(), - "azurerm_dns_ns_record": resourceArmDnsNsRecord(), - "azurerm_dns_ptr_record": resourceArmDnsPtrRecord(), - "azurerm_dns_srv_record": resourceArmDnsSrvRecord(), - "azurerm_dns_txt_record": resourceArmDnsTxtRecord(), - "azurerm_dns_zone": resourceArmDnsZone(), - "azurerm_eventgrid_topic": resourceArmEventGridTopic(), - "azurerm_eventhub": resourceArmEventHub(), - "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), - "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), - "azurerm_eventhub_namespace": resourceArmEventHubNamespace(), - "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), - "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), - "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), - "azurerm_function_app": resourceArmFunctionApp(), - "azurerm_image": resourceArmImage(), - "azurerm_iothub": resourceArmIotHub(), - "azurerm_key_vault": resourceArmKeyVault(), - "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), - "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), - "azurerm_key_vault_key": resourceArmKeyVaultKey(), - "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), - "azurerm_kubernetes_cluster": resourceArmKubernetesCluster(), - "azurerm_lb": resourceArmLoadBalancer(), - "azurerm_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(), - "azurerm_lb_nat_rule": resourceArmLoadBalancerNatRule(), - "azurerm_lb_nat_pool": resourceArmLoadBalancerNatPool(), - "azurerm_lb_probe": resourceArmLoadBalancerProbe(), - "azurerm_lb_rule": resourceArmLoadBalancerRule(), - "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), - "azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(), - "azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace(), - "azurerm_managed_disk": resourceArmManagedDisk(), - "azurerm_management_lock": resourceArmManagementLock(), - "azurerm_metric_alertrule": resourceArmMetricAlertRule(), - "azurerm_mysql_configuration": resourceArmMySQLConfiguration(), - "azurerm_mysql_database": resourceArmMySqlDatabase(), - "azurerm_mysql_firewall_rule": resourceArmMySqlFirewallRule(), - "azurerm_mysql_server": resourceArmMySqlServer(), - "azurerm_network_interface": resourceArmNetworkInterface(), - "azurerm_network_security_group": resourceArmNetworkSecurityGroup(), - "azurerm_network_security_rule": resourceArmNetworkSecurityRule(), - "azurerm_network_watcher": resourceArmNetworkWatcher(), - "azurerm_packet_capture": resourceArmPacketCapture(), - "azurerm_policy_assignment": resourceArmPolicyAssignment(), - "azurerm_policy_definition": resourceArmPolicyDefinition(), - "azurerm_postgresql_configuration": resourceArmPostgreSQLConfiguration(), - "azurerm_postgresql_database": resourceArmPostgreSQLDatabase(), - "azurerm_postgresql_firewall_rule": resourceArmPostgreSQLFirewallRule(), - "azurerm_postgresql_server": resourceArmPostgreSQLServer(), - "azurerm_public_ip": resourceArmPublicIp(), - "azurerm_relay_namespace": resourceArmRelayNamespace(), - "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), - "azurerm_redis_cache": resourceArmRedisCache(), - "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), - "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_role_assignment": resourceArmRoleAssignment(), - "azurerm_role_definition": resourceArmRoleDefinition(), - "azurerm_route": resourceArmRoute(), - "azurerm_route_table": resourceArmRouteTable(), - "azurerm_search_service": resourceArmSearchService(), - "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), - "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_servicebus_queue": resourceArmServiceBusQueue(), - "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), - "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), - "azurerm_servicebus_subscription_authorization_rule": resourceArmServiceBusSubscriptionAuthorizationRule(), - "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), - "azurerm_servicebus_topic": resourceArmServiceBusTopic(), - "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), - "azurerm_snapshot": resourceArmSnapshot(), - "azurerm_scheduler_job": resourceArmSchedulerJob(), - "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), - "azurerm_sql_database": resourceArmSqlDatabase(), - "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), - "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), - "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), - "azurerm_sql_server": resourceArmSqlServer(), - "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), - "azurerm_storage_account": resourceArmStorageAccount(), - "azurerm_storage_blob": resourceArmStorageBlob(), - "azurerm_storage_container": resourceArmStorageContainer(), - "azurerm_storage_share": resourceArmStorageShare(), - "azurerm_storage_queue": resourceArmStorageQueue(), - "azurerm_storage_table": resourceArmStorageTable(), - "azurerm_subnet": resourceArmSubnet(), - "azurerm_template_deployment": resourceArmTemplateDeployment(), - "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), - "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), - "azurerm_user_assigned_identity": resourceArmUserAssignedIdentity(), - "azurerm_virtual_machine": resourceArmVirtualMachine(), - "azurerm_virtual_machine_data_disk_attachment": resourceArmVirtualMachineDataDiskAttachment(), - "azurerm_virtual_machine_extension": resourceArmVirtualMachineExtensions(), - "azurerm_virtual_machine_scale_set": resourceArmVirtualMachineScaleSet(), - "azurerm_virtual_network": resourceArmVirtualNetwork(), - "azurerm_virtual_network_gateway": resourceArmVirtualNetworkGateway(), - "azurerm_virtual_network_gateway_connection": resourceArmVirtualNetworkGatewayConnection(), - "azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(), + "azurerm_azuread_application": resourceArmActiveDirectoryApplication(), + "azurerm_application_gateway": resourceArmApplicationGateway(), + "azurerm_application_insights": resourceArmApplicationInsights(), + "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), + "azurerm_app_service": resourceArmAppService(), + "azurerm_app_service_plan": resourceArmAppServicePlan(), + "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), + "azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(), + "azurerm_app_service_slot": resourceArmAppServiceSlot(), + "azurerm_automation_account": resourceArmAutomationAccount(), + "azurerm_automation_credential": resourceArmAutomationCredential(), + "azurerm_automation_runbook": resourceArmAutomationRunbook(), + "azurerm_automation_schedule": resourceArmAutomationSchedule(), + "azurerm_availability_set": resourceArmAvailabilitySet(), + "azurerm_cdn_endpoint": resourceArmCdnEndpoint(), + "azurerm_cdn_profile": resourceArmCdnProfile(), + "azurerm_container_registry": resourceArmContainerRegistry(), + "azurerm_container_service": resourceArmContainerService(), + "azurerm_container_group": resourceArmContainerGroup(), + "azurerm_cosmosdb_account": resourceArmCosmosDBAccount(), + "azurerm_data_lake_store": resourceArmDataLakeStore(), + "azurerm_data_lake_store_firewall_rule": resourceArmDataLakeStoreFirewallRule(), + "azurerm_dns_a_record": resourceArmDnsARecord(), + "azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(), + "azurerm_dns_caa_record": resourceArmDnsCaaRecord(), + "azurerm_dns_cname_record": resourceArmDnsCNameRecord(), + "azurerm_dns_mx_record": resourceArmDnsMxRecord(), + "azurerm_dns_ns_record": resourceArmDnsNsRecord(), + "azurerm_dns_ptr_record": resourceArmDnsPtrRecord(), + "azurerm_dns_srv_record": resourceArmDnsSrvRecord(), + "azurerm_dns_txt_record": resourceArmDnsTxtRecord(), + "azurerm_dns_zone": resourceArmDnsZone(), + "azurerm_eventgrid_topic": resourceArmEventGridTopic(), + "azurerm_eventhub": resourceArmEventHub(), + "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), + "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), + "azurerm_eventhub_namespace": resourceArmEventHubNamespace(), + "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), + "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), + "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), + "azurerm_function_app": resourceArmFunctionApp(), + "azurerm_image": resourceArmImage(), + "azurerm_iothub": resourceArmIotHub(), + "azurerm_key_vault": resourceArmKeyVault(), + "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), + "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), + "azurerm_key_vault_key": resourceArmKeyVaultKey(), + "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), + "azurerm_kubernetes_cluster": resourceArmKubernetesCluster(), + "azurerm_lb": resourceArmLoadBalancer(), + "azurerm_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(), + "azurerm_lb_nat_rule": resourceArmLoadBalancerNatRule(), + "azurerm_lb_nat_pool": resourceArmLoadBalancerNatPool(), + "azurerm_lb_probe": resourceArmLoadBalancerProbe(), + "azurerm_lb_rule": resourceArmLoadBalancerRule(), + "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), + "azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(), + "azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace(), + "azurerm_managed_disk": resourceArmManagedDisk(), + "azurerm_management_lock": resourceArmManagementLock(), + "azurerm_metric_alertrule": resourceArmMetricAlertRule(), + "azurerm_mysql_configuration": resourceArmMySQLConfiguration(), + "azurerm_mysql_database": resourceArmMySqlDatabase(), + "azurerm_mysql_firewall_rule": resourceArmMySqlFirewallRule(), + "azurerm_mysql_server": resourceArmMySqlServer(), + "azurerm_network_interface": resourceArmNetworkInterface(), + "azurerm_network_security_group": resourceArmNetworkSecurityGroup(), + "azurerm_network_security_rule": resourceArmNetworkSecurityRule(), + "azurerm_network_watcher": resourceArmNetworkWatcher(), + "azurerm_packet_capture": resourceArmPacketCapture(), + "azurerm_policy_assignment": resourceArmPolicyAssignment(), + "azurerm_policy_definition": resourceArmPolicyDefinition(), + "azurerm_postgresql_configuration": resourceArmPostgreSQLConfiguration(), + "azurerm_postgresql_database": resourceArmPostgreSQLDatabase(), + "azurerm_postgresql_firewall_rule": resourceArmPostgreSQLFirewallRule(), + "azurerm_postgresql_server": resourceArmPostgreSQLServer(), + "azurerm_public_ip": resourceArmPublicIp(), + "azurerm_relay_namespace": resourceArmRelayNamespace(), + "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), + "azurerm_redis_cache": resourceArmRedisCache(), + "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), + "azurerm_resource_group": resourceArmResourceGroup(), + "azurerm_role_assignment": resourceArmRoleAssignment(), + "azurerm_role_definition": resourceArmRoleDefinition(), + "azurerm_route": resourceArmRoute(), + "azurerm_route_table": resourceArmRouteTable(), + "azurerm_search_service": resourceArmSearchService(), + "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), + "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), + "azurerm_servicebus_queue": resourceArmServiceBusQueue(), + "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), + "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), + "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), + "azurerm_servicebus_topic": resourceArmServiceBusTopic(), + "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), + "azurerm_snapshot": resourceArmSnapshot(), + "azurerm_scheduler_job": resourceArmSchedulerJob(), + "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), + "azurerm_sql_database": resourceArmSqlDatabase(), + "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), + "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), + "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), + "azurerm_sql_server": resourceArmSqlServer(), + "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), + "azurerm_storage_account": resourceArmStorageAccount(), + "azurerm_storage_blob": resourceArmStorageBlob(), + "azurerm_storage_container": resourceArmStorageContainer(), + "azurerm_storage_share": resourceArmStorageShare(), + "azurerm_storage_queue": resourceArmStorageQueue(), + "azurerm_storage_table": resourceArmStorageTable(), + "azurerm_subnet": resourceArmSubnet(), + "azurerm_template_deployment": resourceArmTemplateDeployment(), + "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), + "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), + "azurerm_user_assigned_identity": resourceArmUserAssignedIdentity(), + "azurerm_virtual_machine": resourceArmVirtualMachine(), + "azurerm_virtual_machine_data_disk_attachment": resourceArmVirtualMachineDataDiskAttachment(), + "azurerm_virtual_machine_extension": resourceArmVirtualMachineExtensions(), + "azurerm_virtual_machine_scale_set": resourceArmVirtualMachineScaleSet(), + "azurerm_virtual_network": resourceArmVirtualNetwork(), + "azurerm_virtual_network_gateway": resourceArmVirtualNetworkGateway(), + "azurerm_virtual_network_gateway_connection": resourceArmVirtualNetworkGatewayConnection(), + "azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(), }, } diff --git a/website/docs/r/servicebus_queue_authorization_rule.html.markdown b/website/docs/r/servicebus_queue_authorization_rule.html.markdown index de62bb11621d..e5615a597022 100644 --- a/website/docs/r/servicebus_queue_authorization_rule.html.markdown +++ b/website/docs/r/servicebus_queue_authorization_rule.html.markdown @@ -1,4 +1,3 @@ - --- layout: "azurerm" page_title: "Azure Resource Manager: azurerm_servicebus_queue_authorization_rule" @@ -90,5 +89,4 @@ ServiceBus Queue Authorization Rules can be imported using the `resource id`, e. ```shell terraform import azurerm_servicebus_queue_authorization_rule.rule1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ServiceBus/namespaces/namespace1/queues/queue1/authorizationRules/rule1 -``` -`` +``` \ No newline at end of file From 428c4b608a34a5a9af08c6d2700151eb37b1beb1 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 11 Jul 2018 14:00:01 -0700 Subject: [PATCH 3/8] Update service bus topic auth rule tests --- .../resource_arm_servicebus_queue_authorization_rule_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/azurerm/resource_arm_servicebus_queue_authorization_rule_test.go b/azurerm/resource_arm_servicebus_queue_authorization_rule_test.go index 9e370ee5ad56..681816f99591 100644 --- a/azurerm/resource_arm_servicebus_queue_authorization_rule_test.go +++ b/azurerm/resource_arm_servicebus_queue_authorization_rule_test.go @@ -185,10 +185,7 @@ resource "azurerm_servicebus_queue_authorization_rule" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" queue_name = "${azurerm_servicebus_queue.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" -<<<<<<< HEAD -======= ->>>>>>> added new resource resource_arm_servicebus_queue_authorization_rule listen = %[3]t send = %[4]t manage = %[5]t From 92d53e32eb6e5ea5c5d16e2bfc94bd2be2e8b841 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 13 Jul 2018 12:47:02 -0700 Subject: [PATCH 4/8] new resource - azurerm_eventhub_namespace_authorizzation_rule --- azurerm/helpers/azure/eventhub.go | 145 ++++++++++++ ...rt_arm_eventhub_authorization_rule_test.go | 104 --------- azurerm/provider.go | 1 + azurerm/resource_arm_eventhub.go | 15 +- ...esource_arm_eventhub_authorization_rule.go | 175 ++++---------- ...ce_arm_eventhub_authorization_rule_test.go | 216 ++++++------------ .../resource_arm_eventhub_consumer_group.go | 22 +- azurerm/resource_arm_eventhub_namespace.go | 8 +- ...m_eventhub_namespace_authorization_rule.go | 150 ++++++++++++ ...nthub_namespace_authorization_rule_test.go | 185 +++++++++++++++ ...servicebus_namespace_authorization_rule.go | 11 +- ...arm_servicebus_queue_authorization_rule.go | 11 +- ...arm_servicebus_topic_authorization_rule.go | 11 +- examples/eventhub/main.tf | 61 +++++ examples/eventhub/outputs.tf | 0 examples/eventhub/variables.tf | 9 + ...namespace_authorization_rule.html.markdown | 82 +++++++ 17 files changed, 786 insertions(+), 420 deletions(-) create mode 100644 azurerm/helpers/azure/eventhub.go delete mode 100644 azurerm/import_arm_eventhub_authorization_rule_test.go create mode 100644 azurerm/resource_arm_eventhub_namespace_authorization_rule.go create mode 100644 azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go create mode 100644 examples/eventhub/main.tf create mode 100644 examples/eventhub/outputs.tf create mode 100644 examples/eventhub/variables.tf create mode 100644 website/docs/r/eventhub_namespace_authorization_rule.html.markdown diff --git a/azurerm/helpers/azure/eventhub.go b/azurerm/helpers/azure/eventhub.go new file mode 100644 index 000000000000..f346e9a3de66 --- /dev/null +++ b/azurerm/helpers/azure/eventhub.go @@ -0,0 +1,145 @@ +package azure + +import ( + "fmt" + "log" + "regexp" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" + + "github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub" +) + +//validation +func ValidateEventHubNamespaceName() schema.SchemaValidateFunc { + return validation.StringMatch( + regexp.MustCompile("^[a-zA-Z][-a-zA-Z0-9]{4,48}[a-zA-Z0-9]$"), + "The namespace name can contain only letters, numbers, and hyphens. The namespace must start with a letter, and it must end with a letter or number and be between 6 and 50 characters long.", + ) +} + +func ValidateEventHubName() schema.SchemaValidateFunc { + return validation.StringMatch( + regexp.MustCompile("^[a-zA-Z][-a-zA-Z0-9]{4,48}[a-zA-Z0-9]$"), + "The namespace name can contain only letters, numbers, and hyphens. The namespace must start with a letter, and it must end with a letter or number and be between 6 and 50 characters long.", + ) +} + +func ValidateEventHubConsumerName() schema.SchemaValidateFunc { + return validation.StringMatch( + regexp.MustCompile("^[a-zA-Z][-a-zA-Z0-9]{4,48}[a-zA-Z0-9]$"), + "The namespace name can contain only letters, numbers, and hyphens. The namespace must start with a letter, and it must end with a letter or number and be between 6 and 50 characters long.", + ) +} + +func ValidateEventHubAuthorizationRuleName() schema.SchemaValidateFunc { + return validation.StringMatch( + regexp.MustCompile("^[a-zA-Z0-9][-._a-zA-Z0-9]{0,48}([a-zA-Z0-9])?$"), + "The name can contain only letters, numbers, periods, hyphens and underscores. The name must start and end with a letter or number and be less the 50 characters long.", + ) +} + +//schema +func ExpandEventHubAuthorizationRuleRights(d *schema.ResourceData) *[]eventhub.AccessRights { + rights := []eventhub.AccessRights{} + + if d.Get("listen").(bool) { + rights = append(rights, eventhub.Listen) + } + + if d.Get("send").(bool) { + rights = append(rights, eventhub.Send) + } + + if d.Get("manage").(bool) { + rights = append(rights, eventhub.Manage) + } + + return &rights +} + +func FlattenEventHubAuthorizationRuleRights(rights *[]eventhub.AccessRights) (listen bool, send bool, manage bool) { + //zero (initial) value for a bool in go is false + + if rights != nil { + for _, right := range *rights { + switch right { + case eventhub.Listen: + listen = true + case eventhub.Send: + send = true + case eventhub.Manage: + manage = true + default: + log.Printf("[DEBUG] Unknown Authorization Rule Right '%s'", right) + } + } + } + + return +} + +func EventHubAuthorizationRuleSchemaFrom(s map[string]*schema.Schema) map[string]*schema.Schema { + + authSchema := map[string]*schema.Schema{ + "listen": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "send": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "manage": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "primary_key": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "primary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_key": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + } + return MergeSchema(s, authSchema) +} + +func EventHubAuthorizationRuleCustomizeDiff(d *schema.ResourceDiff, _ interface{}) error { + listen, hasListen := d.GetOk("listen") + send, hasSend := d.GetOk("send") + manage, hasManage := d.GetOk("manage") + + if !hasListen && !hasSend && !hasManage { + return fmt.Errorf("One of the `listen`, `send` or `manage` properties needs to be set") + } + + if manage.(bool) && !listen.(bool) && !send.(bool) { + return fmt.Errorf("if `manage` is set both `listen` and `send` must be set to true too") + } + + return nil +} diff --git a/azurerm/import_arm_eventhub_authorization_rule_test.go b/azurerm/import_arm_eventhub_authorization_rule_test.go deleted file mode 100644 index 9675c64aabe6..000000000000 --- a/azurerm/import_arm_eventhub_authorization_rule_test.go +++ /dev/null @@ -1,104 +0,0 @@ -package azurerm - -import ( - "testing" - - "github.com/hashicorp/terraform/helper/acctest" - "github.com/hashicorp/terraform/helper/resource" -) - -func TestAccAzureRMEventHubAuthorizationRule_importListen(t *testing.T) { - resourceName := "azurerm_eventhub_authorization_rule.test" - - ri := acctest.RandInt() - config := testAccAzureRMEventHubAuthorizationRule_listen(ri, testLocation()) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, - Steps: []resource.TestStep{ - { - Config: config, - }, - - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMEventHubAuthorizationRule_importSend(t *testing.T) { - resourceName := "azurerm_eventhub_authorization_rule.test" - - ri := acctest.RandInt() - config := testAccAzureRMEventHubAuthorizationRule_send(ri, testLocation()) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, - Steps: []resource.TestStep{ - { - Config: config, - }, - - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMEventHubAuthorizationRule_importReadWrite(t *testing.T) { - resourceName := "azurerm_eventhub_authorization_rule.test" - - ri := acctest.RandInt() - config := testAccAzureRMEventHubAuthorizationRule_readWrite(ri, testLocation()) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, - Steps: []resource.TestStep{ - { - Config: config, - }, - - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMEventHubAuthorizationRule_importManage(t *testing.T) { - resourceName := "azurerm_eventhub_authorization_rule.test" - - ri := acctest.RandInt() - config := testAccAzureRMEventHubAuthorizationRule_manage(ri, testLocation()) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, - Steps: []resource.TestStep{ - { - Config: config, - }, - - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} diff --git a/azurerm/provider.go b/azurerm/provider.go index 1baf6908822b..cdcd8afcd251 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -154,6 +154,7 @@ func Provider() terraform.ResourceProvider { "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), "azurerm_eventhub_namespace": resourceArmEventHubNamespace(), + "azurerm_eventhub_namespace_authorization_rule": resourceArmEventHubNamespaceAuthorizationRule(), "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), diff --git a/azurerm/resource_arm_eventhub.go b/azurerm/resource_arm_eventhub.go index 793b12839612..80f7774ecd6d 100644 --- a/azurerm/resource_arm_eventhub.go +++ b/azurerm/resource_arm_eventhub.go @@ -9,6 +9,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -24,15 +25,17 @@ func resourceArmEventHub() *schema.Resource { Schema: map[string]*schema.Schema{ "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubName(), }, "namespace_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubNamespaceName(), }, "resource_group_name": resourceGroupNameSchema(), diff --git a/azurerm/resource_arm_eventhub_authorization_rule.go b/azurerm/resource_arm_eventhub_authorization_rule.go index 5ddb3ed51c18..d9cfb33362c2 100644 --- a/azurerm/resource_arm_eventhub_authorization_rule.go +++ b/azurerm/resource_arm_eventhub_authorization_rule.go @@ -7,6 +7,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub" "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -16,112 +17,71 @@ func resourceArmEventHubAuthorizationRule() *schema.Resource { Read: resourceArmEventHubAuthorizationRuleRead, Update: resourceArmEventHubAuthorizationRuleCreateUpdate, Delete: resourceArmEventHubAuthorizationRuleDelete, + Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, - Schema: map[string]*schema.Schema{ + Schema: azure.EventHubAuthorizationRuleSchemaFrom(map[string]*schema.Schema{ "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubAuthorizationRuleName(), }, "namespace_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubNamespaceName(), }, "eventhub_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubName(), }, "resource_group_name": resourceGroupNameSchema(), "location": deprecatedLocationSchema(), + }), - "listen": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - - "send": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - - "manage": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - - "primary_key": { - Type: schema.TypeString, - Computed: true, - Sensitive: true, - }, - - "primary_connection_string": { - Type: schema.TypeString, - Computed: true, - Sensitive: true, - }, - - "secondary_key": { - Type: schema.TypeString, - Computed: true, - Sensitive: true, - }, - - "secondary_connection_string": { - Type: schema.TypeString, - Computed: true, - Sensitive: true, - }, - }, + CustomizeDiff: azure.EventHubAuthorizationRuleCustomizeDiff, } } func resourceArmEventHubAuthorizationRuleCreateUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*ArmClient).eventHubClient ctx := meta.(*ArmClient).StopContext + log.Printf("[INFO] preparing arguments for AzureRM EventHub Authorization Rule creation.") name := d.Get("name").(string) namespaceName := d.Get("namespace_name").(string) eventHubName := d.Get("eventhub_name").(string) - resGroup := d.Get("resource_group_name").(string) - - rights, err := expandEventHubAuthorizationRuleAccessRights(d) - if err != nil { - return err - } + resourceGroup := d.Get("resource_group_name").(string) parameters := eventhub.AuthorizationRule{ Name: &name, AuthorizationRuleProperties: &eventhub.AuthorizationRuleProperties{ - Rights: rights, + Rights: azure.ExpandEventHubAuthorizationRuleRights(d), }, } - _, err = client.CreateOrUpdateAuthorizationRule(ctx, resGroup, namespaceName, eventHubName, name, parameters) - if err != nil { - return err + if _, err := client.CreateOrUpdateAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name, parameters); err != nil { + return fmt.Errorf("Error creating/updating EventHub Authorization Rule %q (Resource Group %q): %+v", name, resourceGroup, err) } - read, err := client.GetAuthorizationRule(ctx, resGroup, namespaceName, eventHubName, name) + read, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name) if err != nil { return err } if read.ID == nil { - return fmt.Errorf("Cannot read EventHub Authorization Rule %s (resource group %s) ID", name, resGroup) + return fmt.Errorf("Cannot read EventHub Authorization Rule %s (resource group %s) ID", name, resourceGroup) } d.SetId(*read.ID) @@ -137,12 +97,13 @@ func resourceArmEventHubAuthorizationRuleRead(d *schema.ResourceData, meta inter if err != nil { return err } - resGroup := id.ResourceGroup + + name := id.Path["authorizationRules"] + resourceGroup := id.ResourceGroup namespaceName := id.Path["namespaces"] eventHubName := id.Path["eventhubs"] - name := id.Path["authorizationRules"] - resp, err := client.GetAuthorizationRule(ctx, resGroup, namespaceName, eventHubName, name) + resp, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") @@ -151,21 +112,26 @@ func resourceArmEventHubAuthorizationRuleRead(d *schema.ResourceData, meta inter return fmt.Errorf("Error making Read request on Azure EventHub Authorization Rule %s: %+v", name, err) } - keysResp, err := client.ListKeys(ctx, resGroup, namespaceName, eventHubName, name) - if err != nil { - return fmt.Errorf("Error making Read request on Azure EventHub Authorization Rule List Keys %s: %+v", name, err) - } - d.Set("name", name) d.Set("eventhub_name", eventHubName) d.Set("namespace_name", namespaceName) - d.Set("resource_group_name", resGroup) + d.Set("resource_group_name", resourceGroup) - flattenEventHubAuthorizationRuleAccessRights(d, resp) + if properties := resp.AuthorizationRuleProperties; properties != nil { + listen, send, manage := azure.FlattenEventHubAuthorizationRuleRights(properties.Rights) + d.Set("manage", manage) + d.Set("listen", listen) + d.Set("send", send) + } + + keysResp, err := client.ListKeys(ctx, resourceGroup, namespaceName, eventHubName, name) + if err != nil { + return fmt.Errorf("Error making Read request on Azure EventHub Authorization Rule List Keys %s: %+v", name, err) + } d.Set("primary_key", keysResp.PrimaryKey) - d.Set("primary_connection_string", keysResp.PrimaryConnectionString) d.Set("secondary_key", keysResp.SecondaryKey) + d.Set("primary_connection_string", keysResp.PrimaryConnectionString) d.Set("secondary_connection_string", keysResp.SecondaryConnectionString) return nil @@ -179,12 +145,13 @@ func resourceArmEventHubAuthorizationRuleDelete(d *schema.ResourceData, meta int if err != nil { return err } - resGroup := id.ResourceGroup + + name := id.Path["authorizationRules"] + resourceGroup := id.ResourceGroup namespaceName := id.Path["namespaces"] eventHubName := id.Path["eventhubs"] - name := id.Path["authorizationRules"] - resp, err := eventhubClient.DeleteAuthorizationRule(ctx, resGroup, namespaceName, eventHubName, name) + resp, err := eventhubClient.DeleteAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name) if resp.StatusCode != http.StatusOK { return fmt.Errorf("Error issuing Azure ARM delete request of EventHub Authorization Rule '%s': %+v", name, err) @@ -192,55 +159,3 @@ func resourceArmEventHubAuthorizationRuleDelete(d *schema.ResourceData, meta int return nil } - -func expandEventHubAuthorizationRuleAccessRights(d *schema.ResourceData) (*[]eventhub.AccessRights, error) { - canSend := d.Get("send").(bool) - canListen := d.Get("listen").(bool) - canManage := d.Get("manage").(bool) - rights := []eventhub.AccessRights{} - if canListen { - rights = append(rights, eventhub.Listen) - } - - if canSend { - rights = append(rights, eventhub.Send) - } - - if canManage { - rights = append(rights, eventhub.Manage) - } - - if len(rights) == 0 { - return nil, fmt.Errorf("At least one Authorization Rule State must be enabled (e.g. Listen/Manage/Send)") - } - - if canManage && !(canListen && canSend) { - return nil, fmt.Errorf("In order to enable the 'Manage' Authorization Rule - both the 'Listen' and 'Send' rules must be enabled") - } - - return &rights, nil -} - -func flattenEventHubAuthorizationRuleAccessRights(d *schema.ResourceData, resp eventhub.AuthorizationRule) { - - var canListen = false - var canSend = false - var canManage = false - - for _, right := range *resp.Rights { - switch right { - case eventhub.Listen: - canListen = true - case eventhub.Send: - canSend = true - case eventhub.Manage: - canManage = true - default: - log.Printf("[DEBUG] Unknown Authorization Rule Right '%s'", right) - } - } - - d.Set("listen", canListen) - d.Set("send", canSend) - d.Set("manage", canManage) -} diff --git a/azurerm/resource_arm_eventhub_authorization_rule_test.go b/azurerm/resource_arm_eventhub_authorization_rule_test.go index 7f7c4ea9f604..61f706d1e850 100644 --- a/azurerm/resource_arm_eventhub_authorization_rule_test.go +++ b/azurerm/resource_arm_eventhub_authorization_rule_test.go @@ -2,6 +2,7 @@ package azurerm import ( "fmt" + "strconv" "testing" "github.com/hashicorp/terraform/helper/acctest" @@ -11,27 +12,23 @@ import ( ) func TestAccAzureRMEventHubAuthorizationRule_listen(t *testing.T) { - ri := acctest.RandInt() - config := testAccAzureRMEventHubAuthorizationRule_listen(ri, testLocation()) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubAuthorizationRuleExists("azurerm_eventhub_authorization_rule.test"), - ), - }, - }, - }) + testAccAzureRMEventHubAuthorizationRule(t, true, false, false) } func TestAccAzureRMEventHubAuthorizationRule_send(t *testing.T) { - ri := acctest.RandInt() - config := testAccAzureRMEventHubAuthorizationRule_send(ri, testLocation()) + testAccAzureRMEventHubAuthorizationRule(t, false, true, false) +} + +func TestAccAzureRMEventHubAuthorizationRule_listensend(t *testing.T) { + testAccAzureRMEventHubAuthorizationRule(t, true, true, false) +} + +func TestAccAzureRMEventHubAuthorizationRule_manage(t *testing.T) { + testAccAzureRMEventHubAuthorizationRule(t, true, true, true) +} + +func testAccAzureRMEventHubAuthorizationRule(t *testing.T, listen, send, manage bool) { + resourceName := "azurerm_eventhub_authorization_rule.test" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -39,18 +36,32 @@ func TestAccAzureRMEventHubAuthorizationRule_send(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMEventHubAuthorizationRule_base(acctest.RandInt(), testLocation(), listen, send, manage), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubAuthorizationRuleExists("azurerm_eventhub_authorization_rule.test"), + testCheckAzureRMEventHubAuthorizationRuleExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "name"), + resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(resourceName, "eventhub_name"), + resource.TestCheckResourceAttrSet(resourceName, "primary_key"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(resourceName, "listen", strconv.FormatBool(listen)), + resource.TestCheckResourceAttr(resourceName, "send", strconv.FormatBool(send)), + resource.TestCheckResourceAttr(resourceName, "manage", strconv.FormatBool(manage)), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, }, }) } -func TestAccAzureRMEventHubAuthorizationRule_readwrite(t *testing.T) { - ri := acctest.RandInt() - config := testAccAzureRMEventHubAuthorizationRule_readWrite(ri, testLocation()) +func TestAccAzureRMEventHubAuthorizationRule_rightsUpdate(t *testing.T) { + resourceName := "azurerm_eventhub_authorization_rule.test" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -58,30 +69,34 @@ func TestAccAzureRMEventHubAuthorizationRule_readwrite(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMEventHubAuthorizationRule_base(acctest.RandInt(), testLocation(), true, false, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubAuthorizationRuleExists("azurerm_eventhub_authorization_rule.test"), + testCheckAzureRMEventHubAuthorizationRuleExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "listen", "true"), + resource.TestCheckResourceAttr(resourceName, "send", "false"), + resource.TestCheckResourceAttr(resourceName, "manage", "false"), ), }, - }, - }) -} - -func TestAccAzureRMEventHubAuthorizationRule_manage(t *testing.T) { - ri := acctest.RandInt() - config := testAccAzureRMEventHubAuthorizationRule_manage(ri, testLocation()) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, - Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMEventHubAuthorizationRule_base(acctest.RandInt(), testLocation(), true, true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubAuthorizationRuleExists("azurerm_eventhub_authorization_rule.test"), + testCheckAzureRMEventHubAuthorizationRuleExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "name"), + resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(resourceName, "primary_key"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(resourceName, "listen", "true"), + resource.TestCheckResourceAttr(resourceName, "send", "true"), + resource.TestCheckResourceAttr(resourceName, "manage", "true"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -142,138 +157,39 @@ func testCheckAzureRMEventHubAuthorizationRuleExists(name string) resource.TestC } } -func testAccAzureRMEventHubAuthorizationRule_listen(rInt int, location string) string { +func testAccAzureRMEventHubAuthorizationRule_base(rInt int, location string, listen, send, manage bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" + name = "acctestRG-%[1]d" + location = "%[2]s" } resource "azurerm_eventhub_namespace" "test" { - name = "acctesteventhubnamespace-%d" + name = "acctesteventhubnamespace-%[1]d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Standard" -} - -resource "azurerm_eventhub" "test" { - name = "acctesteventhub-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - partition_count = 2 - message_retention = 7 -} - -resource "azurerm_eventhub_authorization_rule" "test" { - name = "acctesteventhubrule-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - eventhub_name = "${azurerm_eventhub.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - listen = true - send = false - manage = false -} -`, rInt, location, rInt, rInt, rInt) -} - -func testAccAzureRMEventHubAuthorizationRule_send(rInt int, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} -resource "azurerm_eventhub_namespace" "test" { - name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard" } resource "azurerm_eventhub" "test" { - name = "acctesteventhub-%d" + name = "acctesteventhub-%[1]d" namespace_name = "${azurerm_eventhub_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" - partition_count = 2 - message_retention = 7 -} - -resource "azurerm_eventhub_authorization_rule" "test" { - name = "acctesteventhubrule-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - eventhub_name = "${azurerm_eventhub.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - listen = false - send = true - manage = false -} -`, rInt, location, rInt, rInt, rInt) -} - -func testAccAzureRMEventHubAuthorizationRule_readWrite(rInt int, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_eventhub_namespace" "test" { - name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Standard" -} -resource "azurerm_eventhub" "test" { - name = "acctesteventhub-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" partition_count = 2 - message_retention = 7 + message_retention = 1 } resource "azurerm_eventhub_authorization_rule" "test" { - name = "acctesteventhubrule-%d" + name = "acctest-%[1]d" namespace_name = "${azurerm_eventhub_namespace.test.name}" eventhub_name = "${azurerm_eventhub.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" - listen = true - send = true - manage = false -} -`, rInt, location, rInt, rInt, rInt) -} -func testAccAzureRMEventHubAuthorizationRule_manage(rInt int, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_eventhub_namespace" "test" { - name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Standard" -} - -resource "azurerm_eventhub" "test" { - name = "acctesteventhub-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - partition_count = 2 - message_retention = 7 -} - -resource "azurerm_eventhub_authorization_rule" "test" { - name = "acctesteventhubrule-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - eventhub_name = "${azurerm_eventhub.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - listen = true - send = true - manage = true + listen = %[3]t + send = %[4]t + manage = %[5]t } -`, rInt, location, rInt, rInt, rInt) +`, rInt, location, listen, send, manage) } diff --git a/azurerm/resource_arm_eventhub_consumer_group.go b/azurerm/resource_arm_eventhub_consumer_group.go index 694f6a9ef34f..b80acaf8253c 100644 --- a/azurerm/resource_arm_eventhub_consumer_group.go +++ b/azurerm/resource_arm_eventhub_consumer_group.go @@ -7,6 +7,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -22,21 +23,24 @@ func resourceArmEventHubConsumerGroup() *schema.Resource { Schema: map[string]*schema.Schema{ "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubConsumerName(), }, "namespace_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubNamespaceName(), }, "eventhub_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubName(), }, "resource_group_name": resourceGroupNameSchema(), diff --git a/azurerm/resource_arm_eventhub_namespace.go b/azurerm/resource_arm_eventhub_namespace.go index 845c057f502d..b69f6e49310b 100644 --- a/azurerm/resource_arm_eventhub_namespace.go +++ b/azurerm/resource_arm_eventhub_namespace.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -31,9 +32,10 @@ func resourceArmEventHubNamespace() *schema.Resource { Schema: map[string]*schema.Schema{ "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubNamespaceName(), }, "location": locationSchema(), diff --git a/azurerm/resource_arm_eventhub_namespace_authorization_rule.go b/azurerm/resource_arm_eventhub_namespace_authorization_rule.go new file mode 100644 index 000000000000..9a59032abb7d --- /dev/null +++ b/azurerm/resource_arm_eventhub_namespace_authorization_rule.go @@ -0,0 +1,150 @@ +package azurerm + +import ( + "fmt" + "log" + "net/http" + + "github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub" + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmEventHubNamespaceAuthorizationRule() *schema.Resource { + return &schema.Resource{ + Create: resourceArmEventHubNamespaceAuthorizationRuleCreateUpdate, + Read: resourceArmEventHubNamespaceAuthorizationRuleRead, + Update: resourceArmEventHubNamespaceAuthorizationRuleCreateUpdate, + Delete: resourceArmEventHubNamespaceAuthorizationRuleDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: azure.EventHubAuthorizationRuleSchemaFrom(map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubAuthorizationRuleName(), + }, + + "namespace_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateEventHubNamespaceName(), + }, + + "resource_group_name": resourceGroupNameSchema(), + + "location": deprecatedLocationSchema(), + }), + + CustomizeDiff: azure.EventHubAuthorizationRuleCustomizeDiff, + } +} + +func resourceArmEventHubNamespaceAuthorizationRuleCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).eventHubNamespacesClient + ctx := meta.(*ArmClient).StopContext + + log.Printf("[INFO] preparing arguments for AzureRM EventHub Namespace Authorization Rule creation.") + + name := d.Get("name").(string) + namespaceName := d.Get("namespace_name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + parameters := eventhub.AuthorizationRule{ + Name: &name, + AuthorizationRuleProperties: &eventhub.AuthorizationRuleProperties{ + Rights: azure.ExpandEventHubAuthorizationRuleRights(d), + }, + } + + if _, err := client.CreateOrUpdateAuthorizationRule(ctx, resourceGroup, namespaceName, name, parameters); err != nil { + return fmt.Errorf("Error creating/updating EventHub Namespace Authorization Rule %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + read, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, name) + if err != nil { + return err + } + + if read.ID == nil { + return fmt.Errorf("Cannot read EventHub Namespace Authorization Rule %s (resource group %s) ID", name, resourceGroup) + } + + d.SetId(*read.ID) + + return resourceArmEventHubNamespaceAuthorizationRuleRead(d, meta) +} + +func resourceArmEventHubNamespaceAuthorizationRuleRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).eventHubNamespacesClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + + name := id.Path["AuthorizationRules"] //this is different then eventhub where its authorizationRules + resourceGroup := id.ResourceGroup + namespaceName := id.Path["namespaces"] + + resp, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + return fmt.Errorf("Error making Read request on Azure EventHub Authorization Rule %s: %+v", name, err) + } + + d.Set("name", name) + d.Set("namespace_name", namespaceName) + d.Set("resource_group_name", resourceGroup) + + if properties := resp.AuthorizationRuleProperties; properties != nil { + listen, send, manage := azure.FlattenEventHubAuthorizationRuleRights(properties.Rights) + d.Set("manage", manage) + d.Set("listen", listen) + d.Set("send", send) + } + + keysResp, err := client.ListKeys(ctx, resourceGroup, namespaceName, name) + if err != nil { + return fmt.Errorf("Error making Read request on Azure EventHub Authorization Rule List Keys %s: %+v", name, err) + } + + d.Set("primary_key", keysResp.PrimaryKey) + d.Set("secondary_key", keysResp.SecondaryKey) + d.Set("primary_connection_string", keysResp.PrimaryConnectionString) + d.Set("secondary_connection_string", keysResp.SecondaryConnectionString) + + return nil +} + +func resourceArmEventHubNamespaceAuthorizationRuleDelete(d *schema.ResourceData, meta interface{}) error { + eventhubClient := meta.(*ArmClient).eventHubNamespacesClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + + name := id.Path["AuthorizationRules"] //this is different then eventhub where its authorizationRules + resourceGroup := id.ResourceGroup + namespaceName := id.Path["namespaces"] + + resp, err := eventhubClient.DeleteAuthorizationRule(ctx, resourceGroup, namespaceName, name) + + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("Error issuing Azure ARM delete request of EventHub Authorization Rule '%s': %+v", name, err) + } + + return nil +} diff --git a/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go b/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go new file mode 100644 index 000000000000..e46922428cee --- /dev/null +++ b/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go @@ -0,0 +1,185 @@ +package azurerm + +import ( + "fmt" + "strconv" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMEventHubNamespaceAuthorizationRule_listen(t *testing.T) { + testAccAzureRMEventHubNamespaceAuthorizationRule(t, true, false, false) +} + +func TestAccAzureRMEventHubNamespaceAuthorizationRule_send(t *testing.T) { + testAccAzureRMEventHubNamespaceAuthorizationRule(t, false, true, false) +} + +func TestAccAzureRMEventHubNamespaceAuthorizationRule_listensend(t *testing.T) { + testAccAzureRMEventHubNamespaceAuthorizationRule(t, true, true, false) +} + +func TestAccAzureRMEventHubNamespaceAuthorizationRule_manage(t *testing.T) { + testAccAzureRMEventHubNamespaceAuthorizationRule(t, true, true, true) +} + +func testAccAzureRMEventHubNamespaceAuthorizationRule(t *testing.T, listen, send, manage bool) { + resourceName := "azurerm_eventhub_namespace_authorization_rule.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceAuthorizationRule_base(acctest.RandInt(), testLocation(), listen, send, manage), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "name"), + resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(resourceName, "eventhub_name"), + resource.TestCheckResourceAttrSet(resourceName, "primary_key"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(resourceName, "listen", strconv.FormatBool(listen)), + resource.TestCheckResourceAttr(resourceName, "send", strconv.FormatBool(send)), + resource.TestCheckResourceAttr(resourceName, "manage", strconv.FormatBool(manage)), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMEventHubNamespaceAuthorizationRule_rightsUpdate(t *testing.T) { + resourceName := "azurerm_eventhub_namespace_authorization_rule.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespaceAuthorizationRule_base(acctest.RandInt(), testLocation(), true, false, false), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "listen", "true"), + resource.TestCheckResourceAttr(resourceName, "send", "false"), + resource.TestCheckResourceAttr(resourceName, "manage", "false"), + ), + }, + { + Config: testAccAzureRMEventHubNamespaceAuthorizationRule_base(acctest.RandInt(), testLocation(), true, true, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "name"), + resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(resourceName, "primary_key"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(resourceName, "listen", "true"), + resource.TestCheckResourceAttr(resourceName, "send", "true"), + resource.TestCheckResourceAttr(resourceName, "manage", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testCheckAzureRMEventHubNamespaceAuthorizationRuleDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*ArmClient).eventHubClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_eventhub_authorization_rule" { + continue + } + + name := rs.Primary.Attributes["name"] + namespaceName := rs.Primary.Attributes["namespace_name"] + eventHubName := rs.Primary.Attributes["eventhub_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := conn.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return err + } + } + } + + return nil +} + +func testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + name := rs.Primary.Attributes["name"] + namespaceName := rs.Primary.Attributes["namespace_name"] + eventHubName := rs.Primary.Attributes["eventhub_name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for Event Hub: %s", name) + } + + conn := testAccProvider.Meta().(*ArmClient).eventHubClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + resp, err := conn.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Event Hub Authorization Rule %q (eventhub %s, namespace %s / resource group: %s) does not exist", name, eventHubName, namespaceName, resourceGroup) + } + + return fmt.Errorf("Bad: Get on eventHubClient: %+v", err) + } + + return nil + } +} + +func testAccAzureRMEventHubNamespaceAuthorizationRule_base(rInt int, location string, listen, send, manage bool) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[1]d" + location = "%[2]s" +} + +resource "azurerm_eventhub_namespace" "test" { + name = "acctesteventhubnamespace-%[1]d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku = "Standard" +} + +resource "azurerm_eventhub_namespace_authorization_rule" "test" { + name = "acctest-%[1]d" + namespace_name = "${azurerm_eventhub_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + + listen = %[3]t + send = %[4]t + manage = %[5]t +} +`, rInt, location, listen, send, manage) +} diff --git a/azurerm/resource_arm_servicebus_namespace_authorization_rule.go b/azurerm/resource_arm_servicebus_namespace_authorization_rule.go index 065709010b52..bd1ed46b5806 100644 --- a/azurerm/resource_arm_servicebus_namespace_authorization_rule.go +++ b/azurerm/resource_arm_servicebus_namespace_authorization_rule.go @@ -51,7 +51,7 @@ func resourceArmServiceBusNamespaceAuthorizationRuleCreateUpdate(d *schema.Resou log.Printf("[INFO] preparing arguments for AzureRM ServiceBus Namespace Authorization Rule creation.") name := d.Get("name").(string) - resGroup := d.Get("resource_group_name").(string) + resourceGroup := d.Get("resource_group_name").(string) namespaceName := d.Get("namespace_name").(string) parameters := servicebus.SBAuthorizationRule{ @@ -61,18 +61,17 @@ func resourceArmServiceBusNamespaceAuthorizationRuleCreateUpdate(d *schema.Resou }, } - _, err := client.CreateOrUpdateAuthorizationRule(ctx, resGroup, namespaceName, name, parameters) - if err != nil { - return err + if _, err := client.CreateOrUpdateAuthorizationRule(ctx, resourceGroup, namespaceName, name, parameters); err != nil { + return fmt.Errorf("Error creating/updating ServiceBus Namespace Authorization Rule %q (Resource Group %q): %+v", name, resourceGroup, err) } - read, err := client.GetAuthorizationRule(ctx, resGroup, namespaceName, name) + read, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, name) if err != nil { return err } if read.ID == nil { - return fmt.Errorf("Cannot read ServiceBus Namespace Authorization Rule %s (resource group %s) ID", name, resGroup) + return fmt.Errorf("Cannot read ServiceBus Namespace Authorization Rule %s (resource group %s) ID", name, resourceGroup) } d.SetId(*read.ID) diff --git a/azurerm/resource_arm_servicebus_queue_authorization_rule.go b/azurerm/resource_arm_servicebus_queue_authorization_rule.go index e578d457bc9a..fd4b93e9aaba 100644 --- a/azurerm/resource_arm_servicebus_queue_authorization_rule.go +++ b/azurerm/resource_arm_servicebus_queue_authorization_rule.go @@ -57,7 +57,7 @@ func resourceArmServiceBusQueueAuthorizationRuleCreateUpdate(d *schema.ResourceD log.Printf("[INFO] preparing arguments for AzureRM ServiceBus Queue Authorization Rule creation.") name := d.Get("name").(string) - resGroup := d.Get("resource_group_name").(string) + resourceGroup := d.Get("resource_group_name").(string) namespaceName := d.Get("namespace_name").(string) queueName := d.Get("queue_name").(string) @@ -68,18 +68,17 @@ func resourceArmServiceBusQueueAuthorizationRuleCreateUpdate(d *schema.ResourceD }, } - _, err := client.CreateOrUpdateAuthorizationRule(ctx, resGroup, namespaceName, queueName, name, parameters) - if err != nil { - return err + if _, err := client.CreateOrUpdateAuthorizationRule(ctx, resourceGroup, namespaceName, queueName, name, parameters); err != nil { + return fmt.Errorf("Error creating/updating ServiceBus Queue Authorization Rule %q (Resource Group %q): %+v", name, resourceGroup, err) } - read, err := client.GetAuthorizationRule(ctx, resGroup, namespaceName, queueName, name) + read, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, queueName, name) if err != nil { return err } if read.ID == nil { - return fmt.Errorf("Cannot read ServiceBus Namespace Queue Authorization Rule %q (Queue %q / Namespace %q / Resource Group %q) ID", name, queueName, namespaceName, resGroup) + return fmt.Errorf("Cannot read ServiceBus Namespace Queue Authorization Rule %q (Queue %q / Namespace %q / Resource Group %q) ID", name, queueName, namespaceName, resourceGroup) } d.SetId(*read.ID) diff --git a/azurerm/resource_arm_servicebus_topic_authorization_rule.go b/azurerm/resource_arm_servicebus_topic_authorization_rule.go index 388f8accbda4..e20dae5c325a 100644 --- a/azurerm/resource_arm_servicebus_topic_authorization_rule.go +++ b/azurerm/resource_arm_servicebus_topic_authorization_rule.go @@ -59,7 +59,7 @@ func resourceArmServiceBusTopicAuthorizationRuleCreateUpdate(d *schema.ResourceD name := d.Get("name").(string) namespaceName := d.Get("namespace_name").(string) topicName := d.Get("topic_name").(string) - resGroup := d.Get("resource_group_name").(string) + resourceGroup := d.Get("resource_group_name").(string) parameters := servicebus.SBAuthorizationRule{ Name: &name, @@ -68,18 +68,17 @@ func resourceArmServiceBusTopicAuthorizationRuleCreateUpdate(d *schema.ResourceD }, } - _, err := client.CreateOrUpdateAuthorizationRule(ctx, resGroup, namespaceName, topicName, name, parameters) - if err != nil { - return err + if _, err := client.CreateOrUpdateAuthorizationRule(ctx, resourceGroup, namespaceName, topicName, name, parameters); err != nil { + return fmt.Errorf("Error creating/updating ServiceBus Topic Authorization Rule %q (Resource Group %q): %+v", name, resourceGroup, err) } - read, err := client.GetAuthorizationRule(ctx, resGroup, namespaceName, topicName, name) + read, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, topicName, name) if err != nil { return err } if read.ID == nil { - return fmt.Errorf("Cannot read ServiceBus Topic Authorization Rule %s (resource group %s) ID", name, resGroup) + return fmt.Errorf("Cannot read ServiceBus Topic Authorization Rule %s (resource group %s) ID", name, resourceGroup) } d.SetId(*read.ID) diff --git a/examples/eventhub/main.tf b/examples/eventhub/main.tf new file mode 100644 index 000000000000..ef94dddd62f2 --- /dev/null +++ b/examples/eventhub/main.tf @@ -0,0 +1,61 @@ +resource "azurerm_resource_group" "example" { + name = "${var.resource_group}" + location = "${var.location}" +} + +resource "random_integer" "ri" { + min = 10000 + max = 99999 +} + +resource "azurerm_eventhub_namespace" "example" { + name = "tfex-eventhub${random_integer.ri.result}-namespace" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + + sku = "Standard" + capacity = 2 + + tags { + environment = "Examples" + } +} + +resource "azurerm_eventhub_namespace_authorization_rule" "test" { + name = "tfex-eventhub-namespace-authrule" + namespace_name = "${azurerm_eventhub_namespace.example.name}" + eventhub_name = "${azurerm_eventhub.example.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + + listen = true + send = true + manage = false +} + +resource "azurerm_eventhub" "example" { + name = "tfex-eventhub${random_integer.ri.result}" + namespace_name = "${azurerm_eventhub_namespace.example.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + + partition_count = 2 + message_retention = 1 +} + +resource "azurerm_eventhub_authorization_rule" "test" { +name = "tfex-eventhub-authrule" +namespace_name = "${azurerm_eventhub_namespace.example.name}" +eventhub_name = "${azurerm_eventhub.example.name}" +resource_group_name = "${azurerm_resource_group.example.name}" + +listen = true +send = true +manage = true +} + +resource "azurerm_eventhub_consumer_group" "example" { + name = "tfex-eventhub${random_integer.ri.result}-consumer" + namespace_name = "${azurerm_eventhub_namespace.example.name}" + eventhub_name = "${azurerm_eventhub.example.name}" + resource_group_name = "${azurerm_resource_group.example.name}" + user_metadata = "some-meta-data" +} \ No newline at end of file diff --git a/examples/eventhub/outputs.tf b/examples/eventhub/outputs.tf new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/examples/eventhub/variables.tf b/examples/eventhub/variables.tf new file mode 100644 index 000000000000..5fec1720c26d --- /dev/null +++ b/examples/eventhub/variables.tf @@ -0,0 +1,9 @@ +variable "resource_group" { + description = "The name of the resource group in which to create the Service Bus" + default = "tfex-servicebus-topic_subscription" +} + +variable "location" { + description = "The location/region where the Service Bus is created. Changing this forces a new resource to be created." + default = "southcentralus" +} diff --git a/website/docs/r/eventhub_namespace_authorization_rule.html.markdown b/website/docs/r/eventhub_namespace_authorization_rule.html.markdown new file mode 100644 index 000000000000..75ddc4278bce --- /dev/null +++ b/website/docs/r/eventhub_namespace_authorization_rule.html.markdown @@ -0,0 +1,82 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_eventhub_namespace_authorization_rule" +sidebar_current: "docs-azurerm-resource-eventhub-namespace-authorization-rule" +description: |- + Manages a Event Hub Namespace authorization Rule within an Event Hub. +--- + +# azurerm_eventhub_namespace_authorization_rule + +Manages a Event Hub Namespace authorization Rule within an Event Hub. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "test" { + name = "resourceGroup1" + location = "West US" +} + +resource "azurerm_eventhub_namespace" "test" { + name = "acceptanceTestEventHubNamespace" + location = "West US" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "Basic" + capacity = 2 + + tags { + environment = "Production" + } +} + +resource "azurerm_eventhub_namespace_authorization_rule" "test" { + name = "navi" + namespace_name = "${azurerm_eventhub_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + + listen = true + send = false + manage = false +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the EventHub Namespace Authorization Rule resource. Changing this forces a new resource to be created. + +* `namespace_name` - (Required) Specifies the name of the EventHub Namespace. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which the EventHub Namespace exists. Changing this forces a new resource to be created. + +~> **NOTE** At least one of the 3 permissions below needs to be set. + +* `listen` - (Optional) Grants listen access to this this Authorization Rule. Defaults to `false`. + +* `send` - (Optional) Grants send access to this this Authorization Rule. Defaults to `false`. + +* `manage` - (Optional) Grants manage access to this this Authorization Rule. When this property is `true` - both `listen` and `send` must be too. Defaults to `false`. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The EventHub ID. + +* `primary_key` - The Primary Key for the Event Hubs authorization Rule. + +* `primary_connection_string` - The Primary Connection String for the Event Hubs authorization Rule. + +* `secondary_key` - The Secondary Key for the Event Hubs authorization Rule. + +* `secondary_connection_string` - The Secondary Connection String for the Event Hubs authorization Rule. + +## Import + +EventHubs can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_eventhub_namespace_authorization_rule.rule1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.EventHub/namespaces/namespace1/authorizationRules/rule1 +``` From 253148a460cea6a85bb864601f233e0340efe52c Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Jul 2018 14:42:11 +0200 Subject: [PATCH 5/8] Documentation fixes --- ...ub_namespace_authorization_rule.html.markdown | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/website/docs/r/eventhub_namespace_authorization_rule.html.markdown b/website/docs/r/eventhub_namespace_authorization_rule.html.markdown index 75ddc4278bce..d3efb9807f60 100644 --- a/website/docs/r/eventhub_namespace_authorization_rule.html.markdown +++ b/website/docs/r/eventhub_namespace_authorization_rule.html.markdown @@ -3,12 +3,12 @@ layout: "azurerm" page_title: "Azure Resource Manager: azurerm_eventhub_namespace_authorization_rule" sidebar_current: "docs-azurerm-resource-eventhub-namespace-authorization-rule" description: |- - Manages a Event Hub Namespace authorization Rule within an Event Hub. + Manages an Authorization Rule for an Event Hub Namespace. --- # azurerm_eventhub_namespace_authorization_rule -Manages a Event Hub Namespace authorization Rule within an Event Hub. +Manages an Authorization Rule for an Event Hub Namespace. ## Example Usage @@ -20,7 +20,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acceptanceTestEventHubNamespace" - location = "West US" + location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "Basic" capacity = 2 @@ -45,7 +45,7 @@ resource "azurerm_eventhub_namespace_authorization_rule" "test" { The following arguments are supported: -* `name` - (Required) Specifies the name of the EventHub Namespace Authorization Rule resource. Changing this forces a new resource to be created. +* `name` - (Required) Specifies the name of the Authorization Rule. Changing this forces a new resource to be created. * `namespace_name` - (Required) Specifies the name of the EventHub Namespace. Changing this forces a new resource to be created. @@ -65,13 +65,13 @@ The following attributes are exported: * `id` - The EventHub ID. -* `primary_key` - The Primary Key for the Event Hubs authorization Rule. +* `primary_key` - The Primary Key for the Authorization Rule. -* `primary_connection_string` - The Primary Connection String for the Event Hubs authorization Rule. +* `primary_connection_string` - The Primary Connection String for the Authorization Rule. -* `secondary_key` - The Secondary Key for the Event Hubs authorization Rule. +* `secondary_key` - The Secondary Key for the Authorization Rule. -* `secondary_connection_string` - The Secondary Connection String for the Event Hubs authorization Rule. +* `secondary_connection_string` - The Secondary Connection String for the Authorization Rule. ## Import From 7f186ed8d48db7b2d71b0379fb5b2022459937f9 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Jul 2018 15:04:13 +0200 Subject: [PATCH 6/8] Switching to use the Namespaces client --- ...arm_eventhub_namespace_authorization_rule_test.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go b/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go index e46922428cee..01086b2ef1cb 100644 --- a/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go +++ b/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go @@ -102,7 +102,7 @@ func TestAccAzureRMEventHubNamespaceAuthorizationRule_rightsUpdate(t *testing.T) } func testCheckAzureRMEventHubNamespaceAuthorizationRuleDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*ArmClient).eventHubClient + conn := testAccProvider.Meta().(*ArmClient).eventHubNamespacesClient ctx := testAccProvider.Meta().(*ArmClient).StopContext for _, rs := range s.RootModule().Resources { @@ -112,10 +112,9 @@ func testCheckAzureRMEventHubNamespaceAuthorizationRuleDestroy(s *terraform.Stat name := rs.Primary.Attributes["name"] namespaceName := rs.Primary.Attributes["namespace_name"] - eventHubName := rs.Primary.Attributes["eventhub_name"] resourceGroup := rs.Primary.Attributes["resource_group_name"] - resp, err := conn.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name) + resp, err := conn.GetAuthorizationRule(ctx, resourceGroup, namespaceName, name) if err != nil { if !utils.ResponseWasNotFound(resp.Response) { return err @@ -136,18 +135,17 @@ func testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(name string) resou name := rs.Primary.Attributes["name"] namespaceName := rs.Primary.Attributes["namespace_name"] - eventHubName := rs.Primary.Attributes["eventhub_name"] resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] if !hasResourceGroup { return fmt.Errorf("Bad: no resource group found in state for Event Hub: %s", name) } - conn := testAccProvider.Meta().(*ArmClient).eventHubClient + conn := testAccProvider.Meta().(*ArmClient).eventHubNamespacesClient ctx := testAccProvider.Meta().(*ArmClient).StopContext - resp, err := conn.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name) + resp, err := conn.GetAuthorizationRule(ctx, resourceGroup, namespaceName, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Event Hub Authorization Rule %q (eventhub %s, namespace %s / resource group: %s) does not exist", name, eventHubName, namespaceName, resourceGroup) + return fmt.Errorf("Bad: Event Hub Namespace Authorization Rule %q (namespace %q / resource group: %q) does not exist", name, namespaceName, resourceGroup) } return fmt.Errorf("Bad: Get on eventHubClient: %+v", err) From 22b3acdc84c66e266ffb072e41988be18640d2e8 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Jul 2018 15:06:34 +0200 Subject: [PATCH 7/8] Consistency --- azurerm/resource_arm_eventhub_authorization_rule_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_eventhub_authorization_rule_test.go b/azurerm/resource_arm_eventhub_authorization_rule_test.go index 61f706d1e850..99e5ddf0ef85 100644 --- a/azurerm/resource_arm_eventhub_authorization_rule_test.go +++ b/azurerm/resource_arm_eventhub_authorization_rule_test.go @@ -147,7 +147,7 @@ func testCheckAzureRMEventHubAuthorizationRuleExists(name string) resource.TestC resp, err := conn.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Event Hub Authorization Rule %q (eventhub %s, namespace %s / resource group: %s) does not exist", name, eventHubName, namespaceName, resourceGroup) + return fmt.Errorf("Bad: Event Hub Authorization Rule %q (eventhub %s / namespace %s / resource group: %s) does not exist", name, eventHubName, namespaceName, resourceGroup) } return fmt.Errorf("Bad: Get on eventHubClient: %+v", err) From 02525ee1d65f67d5c2a5c6669a4a1c4c12ecbb21 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Jul 2018 16:38:46 +0200 Subject: [PATCH 8/8] Fixing a test failure --- .../resource_arm_eventhub_namespace_authorization_rule_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go b/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go index 01086b2ef1cb..c718558ec67b 100644 --- a/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go +++ b/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go @@ -41,7 +41,6 @@ func testAccAzureRMEventHubNamespaceAuthorizationRule(t *testing.T, listen, send testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(resourceName), resource.TestCheckResourceAttrSet(resourceName, "name"), resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub_name"), resource.TestCheckResourceAttrSet(resourceName, "primary_key"), resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"),