diff --git a/.travis.yml b/.travis.yml index 8db23ad3830fd..49dd6ab0e4c3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,16 +34,12 @@ matrix: #- name: "make lintunused" # script: GOGC=5 make lintunused - name: "make tflint" - script: - - GO111MODULE=off go get -u github.com/hashicorp/terraform - - make tflint + script: make tflint - name: "make test" script: make test - name: "make depscheck" script: make depscheck - name: "make website-lint" - script: - - GO111MODULE=off go get -u github.com/hashicorp/terraform - - make website-lint + script: make website-lint - name: "make website-test" script: make website-test diff --git a/CHANGELOG.md b/CHANGELOG.md index e990219aceb41..b15039d367d4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,61 @@ -## 2.0.0 (Unreleased) +## 2.1.0 (Unreleased) + +FEATURES: + +* **New Data Source:** `azurerm_database_migration_project` [GH-5993] +* **New Data Source:** `azurerm_database_migration_service` [GH-5258] +* **New Data Source:** `azurerm_kusto_cluster` [GH-5942] +* **New Resource:** `azurerm_bot_channel_directline` [GH-5445] +* **New Resource:** `azurerm_database_migration_project` [GH-5993] +* **New Resource:** `azurerm_database_migration_service` [GH-5258] +* **New Resource:** `azurerm_hpc_cache` [GH-5528] +* **New Resource:** `azurerm_iotcentral_application` [GH-5446] +* **New Resource:** `azurerm_monitor_scheduled_query_rules_alert` [GH-5053] +* **New Resource:** `azurerm_monitor_scheduled_query_rules_log` [GH-5053] +* **New Resource:** `azurerm_spatial_anchors_account` [GH-6011] + +IMPROVEMENTS: + +* batch: upgrading to API version `2019-08-01` [GH-5967] +* netapp: upgrading to API version `2019-10-01` [GH-5485] +* `azurerm_application_gateway` - support up to `125` for the `capacity` property with V2 SKU's [GH-5906] +* `azurerm_automation_dsc_configuration` - support for the `tags` property [GH-5827] +* `azurerm_batch_pool` - support for the `public_ips` property [GH-5967] +* `azurerm_frontdoor` - exposed new attributes in `backend_pool_health_probe` block `enabled` and `probe_method` [GH-5924] +* `azurerm_function_app` - Added `os_type` field to facilitate support of `linux` function apps [GH-5839] +* `azurerm_kusto_cluster` - support for `enable_disk_encryption` and `enable_streaming_ingest` properties [GH-5855] +* `azurerm_netapp_account` - support for the `tags` property [GH-5995] +* `azurerm_netapp_pool` - support for the `tags` property [GH-5995] +* `azurerm_netapp_snapshot` - support for the `tags` property [GH-5995] +* `azurerm_netapp_volume` - support for the `tags` property [GH-5995] +* `azurerm_netapp_volume` - support for the `protocol_types` property [GH-5485] +* `azurerm_netapp_volume` - deprecated the `cifs_enabled`, `nfsv3_enabled`, and `nfsv4_enabled` properties in favour of `protocols_enabled` [GH-5485] +* `azurerm_network_watcher_flow_log` - support for the traffic analysis `interval_in_minutes` property [GH-5851] +* `azurerm_private_dns_a_record` - export the `fqdn` property [GH-5949] +* `azurerm_private_dns_aaaa_record` - export the `fqdn` property [GH-5949] +* `azurerm_private_dns_cname_record` - export the `fqdn` property [GH-5949] +* `azurerm_private_dns_mx_record` - export the `fqdn` property [GH-5949] +* `azurerm_private_dns_ptr_record` - export the `fqdn` property [GH-5949] +* `azurerm_private_dns_srv_record` - export the `fqdn` property [GH-5949] +* `azurerm_private_endpoint` - exposed `private_ip_address` as a computed attribute [GH-5838] +* `azurerm_redis_cache` - support for the `primary_connection_string` and `secondary_connection_string` properties [GH-5958] +* `azurerm_sql_server` - support for the `extended_auditing_policy` property [GH-5036] +* `azurerm_storage_account` - support up to 50 tags [GH-5934] +* `azurerm_virtual_wan` - support for the `type` property [GH-5877] + +BUG FIXES: + +* `azurerm_app_service_plan` - no longer sends an empty `app_service_environment_id` property on update [GH-5915] +* `azurerm_automation_schedule` - fix time validation [GH-5876] +* `azurerm_batch_pool` - `frontend_port_range ` is now set correctly. [GH-5941] +* `azurerm_dns_txt_record` - support records up to `1024` characters in length [GH-5837] +* `azurerm_frontdoor` - fix the way `backend_pool_load_balancing`/`backend_pool_health_probe` [GH-5924] +* `azurerm_frontdoor_firewall_policy` - add validation for Frontdoor WAF Name Restrictions [GH-5943] +* `azurerm_linux_virtual_machine_scale_set` - correct `source_image_id` validation [GH-5901] +* `azurerm_netapp_volume` - support volmes uoto `100TB` in size [GH-5485] +* `azurerm_search_service` - changing the properties `replica_count` & `partition_count` properties no longer force a new resource [GH-5935] + +## 2.0.0 (February 24, 2020) NOTES: @@ -10,42 +67,207 @@ FEATURES: * **Custom Timeouts:** - all resources within the Azure Provider now allow configuring custom timeouts - please [see Terraform's Timeout documentation](https://www.terraform.io/docs/configuration/resources.html#operation-timeouts) and the documentation in each data source resource for more information. * **Requires Import:** The Azure Provider now checks for the presence of an existing resource prior to creating it - which means that if you try and create a resource which already exists (without importing it) you'll be prompted to import this into the state. -* **New Resource:** `azurerm_linux_virtual_machine` [GH-5705] -* **New Resource:** `azurerm_linux_virtual_machine_scale_set` [GH-5705] -* **New Resource:** `azurerm_virtual_machine_scale_set_extension` [GH-5705] -* **New Resource:** `azurerm_windows_virtual_machine` [GH-5705] -* **New Resource:** `azurerm_windows_virtual_machine_scale_set` [GH-5705] +* **New Data Source:** `azurerm_app_service_environment` ([#5508](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5508)) +* **New Data Source:** `azurerm_eventhub_authorization_rule` ([#5805](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5805)) +* **New Resource:** `azurerm_app_service_environment` ([#5508](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5508)) +* **New Resource:** `azurerm_express_route_gateway` ([#5523](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5523)) +* **New Resource:** `azurerm_linux_virtual_machine` ([#5705](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5705)) +* **New Resource:** `azurerm_linux_virtual_machine_scale_set` ([#5705](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5705)) +* **New Resource:** `azurerm_network_interface_security_group_association` ([#5784](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5784)) +* **New Resource:** `azurerm_storage_account_customer_managed_key` ([#5668](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5668)) +* **New Resource:** `azurerm_virtual_machine_scale_set_extension` ([#5705](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5705)) +* **New Resource:** `azurerm_windows_virtual_machine` ([#5705](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5705)) +* **New Resource:** `azurerm_windows_virtual_machine_scale_set` ([#5705](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5705)) BREAKING CHANGES: -* Data Source: `azurerm_app_service_plan` - the deprecated `properties` block has been removed since these properties have been moved to the top level [GH-5717] -* Data Source: `azurerm_azuread_application` - This data source has been removed since it was deprecated [GH-5748] -* Data Source: `azurerm_azuread_service_principal` - This data source has been removed since it was deprecated [GH-5748] -* Data Source: `azurerm_role_definition` - removing the alias `VirtualMachineContributor` which has been deprecated in favour of the full name `Virtual Machine Contributor` [GH-5733] -* Data Source: `azurerm_scheduler_job_collection` - This data source has been removed since it was deprecated [GH-5712] -* `azurerm_app_service_plan` - the deprecated `properties` block has been removed since these properties have been moved to the top level [GH-5717] -* `azurerm_application_gateway` - updating the default value for the `body` field within the `match` block from `*` to an empty string [GH-5752] -* `azurerm_availability_set` - updating the default value for `managed` from `false` to `true` [GH-5724] -* `azurerm_azuread_application` - This resource has been removed since it was deprecated [GH-5748] -* `azurerm_azuread_service_principal_password` - This resource has been removed since it was deprecated [GH-5748] -* `azurerm_azuread_service_principal` - This resource has been removed since it was deprecated [GH-5748] -* `azurerm_container_service` - This resource has been removed since it was deprecated [GH-5709] -* `azurerm_kubernetes_cluster` - updating the default value for `load_balancer_sku` to `Standard` from `Basic` [GH-5747] -* `azurerm_log_analytics_workspace_linked_service` - This resource has been removed since it was deprecated [GH-5754] -* `azurerm_notification_hub_namesapce` - removing the `sku` block in favour of the `sku_name` argument [GH-5722] -* `azurerm_relay_namespace` - removing the `sku` block in favour of the `sku_name` field [GH-5719] -* `azurerm_scheduler_job` - This resource has been removed since it was deprecated [GH-5712] -* `azurerm_scheduler_job_collection` - This resource has been removed since it was deprecated [GH-5712] +* The Environment Variable `DISABLE_CORRELATION_REQUEST_ID` has been renamed to `ARM_DISABLE_CORRELATION_REQUEST_ID` to match the other Environment Variables +* The field `tags` is no longer `computed` +* Data Source: `azurerm_api_management` - removing the deprecated `sku` block ([#5725](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5725)) +* Data Source: `azurerm_app_service` - removing the deprecated field `subnet_mask` from the `site_config` block ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* Data Source: `azurerm_app_service_plan` - the deprecated `properties` block has been removed since these properties have been moved to the top level ([#5717](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5717)) +* Data Source: `azurerm_azuread_application` - This data source has been removed since it was deprecated ([#5748](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5748)) +* Data Source: `azurerm_azuread_service_principal` - This data source has been removed since it was deprecated ([#5748](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5748)) +* Data Source: `azurerm_builtin_role_definition` - the deprecated data source has been removed ([#5844](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5844)) +* Data Source: `azurerm_dns_zone` - removing the deprecated `zone_type` field ([#5794](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5794)) +* Data Source: `azurerm_dns_zone` - removing the deprecated `registration_virtual_network_ids` field ([#5794](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5794)) +* Data Source: `azurerm_dns_zone` - removing the deprecated `resolution_virtual_network_ids` field ([#5794](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5794)) +* Data Source: `azurerm_key_vault` - removing the `sku` block since this has been deprecated in favour of the `sku_name` field ([#5774](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5774)) +* Data Source: `azurerm_key_vault_key` - removing the deprecated `vault_uri` field ([#5774](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5774)) +* Data Source: `azurerm_key_vault_secret` - removing the deprecated `vault_uri` field ([#5774](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5774)) +* Data Source: `azurerm_kubernetes_cluster` - removing the field `dns_prefix` from the `agent_pool_profile` block ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* Data Source: `azurerm_network_interface` - removing the deprecated field `internal_fqdn` ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* Data Source: `azurerm_private_link_service` - removing the deprecated field `network_interface_ids` ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* Data Source: `azurerm_private_link_endpoint_connection` - the deprecated data source has been removed ([#5844](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5844)) +* Data Source: `azurerm_recovery_services_protection_policy_vm` has been renamed to `azurerm_backup_policy_vm` ([#5816](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5816)) +* Data Source: `azurerm_role_definition` - removing the alias `VirtualMachineContributor` which has been deprecated in favour of the full name `Virtual Machine Contributor` ([#5733](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5733)) +* Data Source: `azurerm_storage_account` - removing the `account_encryption_source` field since this is no longer configurable by Azure ([#5668](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5668)) +* Data Source: `azurerm_storage_account` - removing the `enable_blob_encryption` field since this is no longer configurable by Azure ([#5668](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5668)) +* Data Source: `azurerm_storage_account` - removing the `enable_file_encryption` field since this is no longer configurable by Azure ([#5668](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5668)) +* Data Source: `azurerm_scheduler_job_collection` - This data source has been removed since it was deprecated ([#5712](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5712)) +* Data Source: `azurerm_subnet` - removing the deprecated `ip_configuration` field ([#5801](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5801)) +* Data Source: `azurerm_virtual_network` - removing the deprecated `address_spaces` field ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_api_management` - removing the deprecated `sku` block ([#5725](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5725)) +* `azurerm_api_management` - removing the deprecated fields in the `security` block ([#5725](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5725)) +* `azurerm_application_gateway` - the field `fqdns` within the `backend_address_pool` block is no longer computed ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_application_gateway` - the field `ip_addresses` within the `backend_address_pool` block is no longer computed ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_application_gateway` - the deprecated field `fqdn_list` within the `backend_address_pool` block has been removed ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_application_gateway` - the deprecated field `ip_address_list` within the `backend_address_pool` block has been removed ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_application_gateway` - the deprecated field `disabled_ssl_protocols` has been removed ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_application_gateway` - the field `disabled_protocols` within the `ssl_policy` block is no longer computed ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_app_service` - removing the field `subnet_mask` from the `site_config` block ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_app_service` - the field `ip_address` within the `site_config` block now refers to a CIDR block, rather than an IP Address to match the Azure API ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_app_service` - removing the field `virtual_network_name` from the `site_config` block ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_app_service_plan` - the deprecated `properties` block has been removed since these properties have been moved to the top level ([#5717](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5717)) +* `azurerm_app_service_slot` - removing the field `subnet_mask` from the `site_config` block ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_app_service_slot` - the field `ip_address` within the `site_config` block now refers to a CIDR block, rather than an IP Address to match the Azure API ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_app_service_slot` - removing the field `virtual_network_name` from the `site_config` block ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_application_gateway` - updating the default value for the `body` field within the `match` block from `*` to an empty string ([#5752](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5752)) +* `azurerm_automation_account` - removing the `sku` block which has been deprecated in favour of the `sku_name` field ([#5781](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5781)) +* `azurerm_automation_credential` - removing the deprecated `account_name` field ([#5781](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5781)) +* `azurerm_automation_runbook` - removing the deprecated `account_name` field ([#5781](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5781)) +* `azurerm_automation_schedule` - removing the deprecated `account_name` field ([#5781](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5781)) +* `azurerm_autoscale_setting` - the deprecated resource has been removed ([#5844](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5844)) +* `azurerm_availability_set` - updating the default value for `managed` from `false` to `true` ([#5724](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5724)) +* `azurerm_azuread_application` - This resource has been removed since it was deprecated ([#5748](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5748)) +* `azurerm_azuread_service_principal_password` - This resource has been removed since it was deprecated ([#5748](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5748)) +* `azurerm_azuread_service_principal` - This resource has been removed since it was deprecated ([#5748](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5748)) +* `azurerm_client_config` - removing the deprecated field `service_principal_application_id` ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_client_config` - removing the deprecated field `service_principal_object_id` ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_cognitive_account` - removing the deprecated `sku_name` block ([#5797](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5797)) +* `azurerm_connection_monitor` - the deprecated resource has been removed ([#5844](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5844)) +* `azurerm_container_group` - removing the `port` field from the `container` block ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_container_group` - removing the `protocol` field from the `container` block ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_container_group` - the `ports` field is no longer Computed ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_container_group` - the `protocol` field within the `ports` block is no longer Computed and now defaults to `TCP` ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_container_group` - removing the deprecated field `command` ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_container_registry` - removing the deprecated `storage_account` block ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_container_service` - This resource has been removed since it was deprecated ([#5709](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5709)) +* `azurerm_cosmosdb_mongo_collection` - removing the deprecated `indexes` block ([#5853](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5853)) +* `azurerm_ddos_protection_plan` - the deprecated resource has been removed ([#5844](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5844)) +* `azurerm_devspace_controller` - removing the deprecated `sku` block ([#5795](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5795)) +* `azurerm_dns_cname_record` - removing the deprecated `records` field ([#5794](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5794)) +* `azurerm_dns_ns_record` - removing the deprecated `records` field ([#5794](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5794)) +* `azurerm_dns_zone` - removing the deprecated `zone_type` field ([#5794](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5794)) +* `azurerm_dns_zone` - removing the deprecated `registration_virtual_network_ids` field ([#5794](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5794)) +* `azurerm_dns_zone` - removing the deprecated `resolution_virtual_network_ids` field ([#5794](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5794)) +* `azurerm_eventhub` - removing the deprecated `location` field ([#5793](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5793)) +* `azurerm_eventhub_authorization_rule` - removing the deprecated `location` field ([#5793](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5793)) +* `azurerm_eventhub_consumer_group` - removing the deprecated `location` field ([#5793](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5793)) +* `azurerm_eventhub_namespace` - removing the deprecated `kafka_enabled` field since this is now managed by Azure ([#5793](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5793)) +* `azurerm_eventhub_namespace_authorization_rule` - removing the deprecated `location` field ([#5793](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5793)) +* `azurerm_firewall` - removing the deprecated field `internal_public_ip_address_id` from the `ip_configuration` block ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_firewall` - the field `public_ip_address_id` within the `ip_configuration` block is now required ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_frontdoor` - field `cache_enabled` within the `forwarding_configuration` block now defaults to `false` rather than `true` ([#5852](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5852)) +* `azurerm_frontdoor` - the field `cache_query_parameter_strip_directive` within the `forwarding_configuration` block now defaults to `StripAll` rather than `StripNone`. ([#5852](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5852)) +* `azurerm_frontdoor` - the field `forwarding_protocol` within the `forwarding_configuration` block now defaults to `HttpsOnly` rather than `MatchRequest` ([#5852](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5852)) +* `azurerm_function_app` - removing the field `virtual_network_name` from the `site_config` block ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_function_app` - updating the field `ip_address` within the `ip_restriction` block to accept a CIDR rather than an IP Address to match the updated API behaviour ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_iot_dps` - This resource has been removed since it was deprecated ([#5753](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5753)) +* `azurerm_iot_dps_certificate` - This resource has been removed since it was deprecated ([#5753](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5753)) +* `azurerm_iothub`- The deprecated `sku.tier` property will be removed. ([#5790](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5790)) +* `azurerm_iothub_dps` - The deprecated `sku.tier` property will be removed. ([#5790](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5790)) +* `azurerm_key_vault` - removing the `sku` block since this has been deprecated in favour of the `sku_name` field ([#5774](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5774)) +* `azurerm_key_vault_access_policy` - removing the deprecated field `vault_name` which has been superseded by the `key_vault_id` field ([#5774](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5774)) +* `azurerm_key_vault_access_policy` - removing the deprecated field `resource_group_name ` which has been superseded by the `key_vault_id` field ([#5774](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5774)) +* `azurerm_key_vault_certificate` - removing the deprecated `vault_uri` field ([#5774](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5774)) +* `azurerm_key_vault_key` - removing the deprecated `vault_uri` field ([#5774](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5774)) +* `azurerm_key_vault_secret` - removing the deprecated `vault_uri` field ([#5774](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5774)) +* `azurerm_kubernetes_cluster` - updating the default value for `load_balancer_sku` to `Standard` from `Basic` ([#5747](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5747)) +* `azurerm_kubernetes_cluster` - the block `default_node_pool` is now required ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_kubernetes_cluster` - removing the deprecated `agent_pool_profile` block ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_kubernetes_cluster` - the field `enable_pod_security_policy` is no longer computed ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_lb_backend_address_pool` - removing the deprecated `location` field ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_lb_nat_pool` - removing the deprecated `location` field ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_lb_nat_rule` - removing the deprecated `location` field ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_lb_probe` - removing the deprecated `location` field ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_lb_rule` - removing the deprecated `location` field ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_log_analytics_workspace_linked_service` - This resource has been removed since it was deprecated ([#5754](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5754)) +* `azurerm_log_analytics_linked_service` - The `resource_id` field has been moved from the `linked_service_properties` block to the top-level and the deprecated field `linked_service_properties` will be removed. This has been replaced by the `resource_id` resource ([#5775](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5775)) +* `azurerm_maps_account` - the `sku_name` field is now case-sensitive ([#5776](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5776)) +* `azurerm_mariadb_server` - removing the `sku` block since it's been deprecated in favour of the `sku_name` field ([#5777](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5777)) +* `azurerm_metric_alertrule` - the deprecated resource has been removed ([#5844](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5844)) +* `azurerm_monitor_metric_alert` - updating the default value for `auto_mitigate` from `false` to `true` ([#5773](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5773)) +* `azurerm_monitor_metric_alertrule` - the deprecated resource has been removed ([#5844](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5844)) +* `azurerm_mssql_elasticpool` - removing the deprecated `elastic_pool_properties` block ([#5744](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5744)) +* `azurerm_mysql_server` - removing the deprecated `sku` block ([#5743](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5743)) +* `azurerm_network_interface` - removing the deprecated `application_gateway_backend_address_pools_ids` field from the `ip_configurations` block ([#5784](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5784)) +* `azurerm_network_interface` - removing the deprecated `application_security_group_ids ` field from the `ip_configurations` block ([#5784](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5784)) +* `azurerm_network_interface` - removing the deprecated `load_balancer_backend_address_pools_ids ` field from the `ip_configurations` block ([#5784](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5784)) +* `azurerm_network_interface` - removing the deprecated `load_balancer_inbound_nat_rules_ids ` field from the `ip_configurations` block ([#5784](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5784)) +* `azurerm_network_interface` - removing the deprecated `internal_fqdn` field ([#5784](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5784)) +* `azurerm_network_interface` - removing the `network_security_group_id` field in favour of a new split-out resource `azurerm_network_interface_security_group_association` ([#5784](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5784)) +* `azurerm_network_interface_application_security_group_association` - removing the `ip_configuration_name` field associations between Network Interfaces and Application Security Groups now need to be made to all IP Configurations ([#5815](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5815)) +* `azurerm_network_interface` - the `virtual_machine_id` field is now computed-only since it's not setable ([#5784](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5784)) +* `azurerm_notification_hub_namesapce` - removing the `sku` block in favour of the `sku_name` argument ([#5722](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5722)) +* `azurerm_postgresql_server` - removing the `sku` block which has been deprecated in favour of the `sku_name` field ([#5721](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5721)) +* `azurerm_private_link_endpoint` - the deprecated resource has been removed ([#5844](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5844)) +* `azurerm_private_link_service` - removing the deprecated field `network_interface_ids` ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_public_ip` - making the `allocation_method` field required ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_public_ip` - removing the deprecated field `public_ip_address_allocation` ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* `azurerm_recovery_network_mapping` - the deprecated resource has been removed ([#5816](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5816)) +* `azurerm_recovery_replicated_vm` - the deprecated resource has been removed ([#5816](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5816)) +* `azurerm_recovery_services_fabric` - the deprecated resource has been removed ([#5816](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5816)) +* `azurerm_recovery_services_protected_vm` - the deprecated resource has been removed ([#5816](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5816)) +* `azurerm_recovery_services_protection_container` - the deprecated resource has been removed ([#5816](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5816)) +* `azurerm_recovery_services_protection_container_mapping` - the deprecated resource has been removed ([#5816](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5816)) +* `azurerm_recovery_services_protection_policy_vm` - the deprecated resource has been removed ([#5816](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5816)) +* `azurerm_recovery_services_replication_policy` - the deprecated resource has been removed ([#5816](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5816)) +* `azurerm_relay_namespace` - removing the `sku` block in favour of the `sku_name` field ([#5719](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5719)) +* `azurerm_scheduler_job` - This resource has been removed since it was deprecated ([#5712](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5712)) +* `azurerm_scheduler_job_collection` - This resource has been removed since it was deprecated ([#5712](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5712)) +* `azurerm_storage_account` - updating the default value for `account_kind` from `Storage` to `StorageV2` ([#5850](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5850)) +* `azurerm_storage_account` - removing the deprecated `account_type` field ([#5710](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5710)) +* `azurerm_storage_account` - removing the deprecated `enable_advanced_threat_protection` field ([#5710](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5710)) +* `azurerm_storage_account` - updating the default value for `enable_https_traffic_only` from `false` to `true` ([#5808](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5808)) +* `azurerm_storage_account` - removing the `account_encryption_source` field since this is no longer configurable by Azure ([#5668](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5668)) +* `azurerm_storage_account` - removing the `enable_blob_encryption` field since this is no longer configurable by Azure ([#5668](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5668)) +* `azurerm_storage_account` - removing the `enable_file_encryption` field since this is no longer configurable by Azure ([#5668](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5668)) +* `azurerm_storage_blob` - making the `type` field case-sensitive ([#5710](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5710)) +* `azurerm_storage_blob` - removing the deprecated `attempts` field ([#5710](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5710)) +* `azurerm_storage_blob` - removing the deprecated `resource_group_name` field ([#5710](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5710)) +* `azurerm_storage_container` - removing the deprecated `resource_group_name` field ([#5710](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5710)) +* `azurerm_storage_container` - removing the deprecated `properties` block ([#5710](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5710)) +* `azurerm_storage_queue` - removing the deprecated `resource_group_name` field ([#5710](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5710)) +* `azurerm_storage_share` - removing the deprecated `resource_group_name` field ([#5710](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5710)) +* `azurerm_storage_table` - removing the deprecated `resource_group_name` field ([#5710](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5710)) +* `azurerm_subnet` - removing the deprecated `ip_configuration` field ([#5801](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5801)) +* `azurerm_subnet` - removing the deprecated `network_security_group_id` field ([#5801](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5801)) +* `azurerm_subnet` - removing the deprecated `route_table_id` field ([#5801](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5801)) +* `azurerm_subnet` - making the `actions` list within the `service_delegation` block within the `service_endpoints` block non-computed ([#5801](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5801)) +* `azurerm_virtual_network_peering` - `allow_virtual_network_access` now defaults to true, matching the API and Portal behaviours. ([#5832](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5832)) +* `azurerm_virtual_wan` - removing the deprecated field `security_provider_name` ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) IMPROVEMENTS: -* Data Source: `azurerm_kubernetes_service_version` - support for filtering of preview releases [GH-5662] -* `azurerm_storage_account` - support for configuring `cors_rules` within the `blob_properties` block [GH-5425] -* `azurerm_windows_virtual_machine` - fixing a bug when provisioning from a Shared Gallery image [GH-5661] +* web: updating to API version `2019-08-01` ([#5823](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5823)) +* Data Source: `azurerm_kubernetes_service_version` - support for filtering of preview releases ([#5662](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5662)) +* `azurerm_dedicated_host` - support for setting `sku_name` to `DSv3-Type2` and `ESv3-Type2` ([#5768](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5768)) +* `azurerm_key_vault` - support for configuring `purge_protection_enabled` ([#5344](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5344)) +* `azurerm_key_vault` - support for configuring `soft_delete_enabled` ([#5344](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5344)) +* `azurerm_sql_database` - support for configuring `zone_redundant` ([#5772](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5772)) +* `azurerm_storage_account` - support for configuring the `static_website` block ([#5649](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5649)) +* `azurerm_storage_account` - support for configuring `cors_rules` within the `blob_properties` block ([#5425](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5425)) +* `azurerm_subnet` - support for delta updates ([#5801](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5801)) +* `azurerm_windows_virtual_machine` - fixing a bug when provisioning from a Shared Gallery image ([#5661](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5661)) BUG FIXES: -* `azurerm_signalr_service` - ensuring the SignalR segment is parsed in the correct case [GH-5737] +* `azurerm_application_insights` - the `application_type` field is now case sensitive as documented ([#5817](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5817)) +* `azurerm_api_management_api` - allows blank `path` field ([#5833](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5833)) +* `azurerm_eventhub_namespace` - the field `ip_rule` within the `network_rulesets` block now supports a maximum of 128 items ([#5831](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5831)) +* `azurerm_eventhub_namespace` - the field `virtual_network_rule` within the `network_rulesets` block now supports a maximum of 128 items ([#5831](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5831)) +* `azurerm_linux_virtual_machine` - using the delete custom timeout during deletion ([#5764](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5764)) +* `azurerm_netapp_account` - allowing the `-` character to be used in the `name` field ([#5842](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5842)) +* `azurerm_network_interface` - the `dns_servers` field now respects ordering ([#5784](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5784)) +* `azurerm_public_ip_prefix` - fixing the validation for the `prefix_length` to match the Azure API ([#5693](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5693)) +* `azurerm_recovery_services_vault` - using the requested cloud rather than the default ([#5825](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5825)) +* `azurerm_role_assignment` - validating that the `name` is a UUID ([#5624](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5624)) +* `azurerm_signalr_service` - ensuring the SignalR segment is parsed in the correct case ([#5737](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5737)) +* `azurerm_storage_account` - locking on the storage account resource when updating the storage account ([#5668](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5668)) +* `azurerm_subnet` - supporting updating of the `enforce_private_link_endpoint_network_policies` field ([#5801](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5801)) +* `azurerm_subnet` - supporting updating of the `enforce_private_link_service_network_policies` field ([#5801](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5801)) +* `azurerm_windows_virtual_machine` - using the delete custom timeout during deletion ([#5764](https://github.com/terraform-providers/terraform-provider-azurerm/issues/5764)) --- diff --git a/GNUmakefile b/GNUmakefile index b819f3fe933b7..a6b019fd30885 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -20,7 +20,7 @@ tools: GO111MODULE=off go get -u github.com/bflad/tfproviderdocs GO111MODULE=off go get -u github.com/katbyte/terrafmt -build: fmtcheck +build: fmtcheck generate go install build-docker: @@ -37,6 +37,9 @@ fmtcheck: @sh "$(CURDIR)/scripts/gofmtcheck.sh" @sh "$(CURDIR)/scripts/timeouts.sh" +generate: + go generate ./azurerm/internal/provider/ + goimports: @echo "==> Fixing imports code with goimports..." goimports -w $(PKG_NAME)/ @@ -120,6 +123,9 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO))) endif @$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME) +scaffold-website: + ./scripts/scaffold-website.sh + website-test: ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO))) echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..." @@ -127,4 +133,4 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO))) endif @$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME) -.PHONY: build build-docker test test-docker testacc vet fmt fmtcheck errcheck test-compile website website-test +.PHONY: build build-docker test test-docker testacc vet fmt fmtcheck errcheck scaffold-website test-compile website website-test diff --git a/README.md b/README.md index 60022faafd3d1..33eefeb0f4e3c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,9 @@ The AzureRM Provider supports Terraform 0.10.x and later - but Terraform 0.12.x provider "azurerm" { # We recommend pinning to the specific version of the Azure Provider you're using # since new versions are released frequently - version = "=1.43.0" + version = "=2.0.0" + + features {} # More information on the authentication methods supported by # the AzureRM Provider can be found here: @@ -45,7 +47,7 @@ Further [usage documentation is available on the Terraform website](https://www. ## Developer Requirements -* [Terraform](https://www.terraform.io/downloads.html) version 0.10.x + +* [Terraform](https://www.terraform.io/downloads.html) version 0.12.x + * [Go](https://golang.org/doc/install) version 1.13.x (to build the provider plugin) If you're on Windows you'll also need: @@ -93,7 +95,7 @@ $ make test The majority of tests in the provider are Acceptance Tests - which provisions real resources in Azure. It's possible to run the entire acceptance test suite by running `make testacc` - however it's likely you'll want to run a subset, which you can do using a prefix, by running: -``` +```sh make testacc SERVICE='resource' TESTARGS='-run=TestAccAzureRMResourceGroup' TESTTIMEOUT='60m' ``` @@ -110,3 +112,18 @@ The following Environment Variables must be set in your shell prior to running a **Note:** Acceptance tests create real resources in Azure which often cost money to run. +--- + +## Developer: Scaffolding the Website Documentation + +You can scaffold the documentation for a Data Source by running: + +```sh +$ make scaffold-website BRAND_NAME="Resource Group" RESOURCE_NAME="azurerm_resource_group" RESOURCE_TYPE="data" +``` + +You can scaffold the documentation for a Resource by running: + +```sh +$ make scaffold-website BRAND_NAME="Resource Group" RESOURCE_NAME="azurerm_resource_group" RESOURCE_TYPE="resource" RESOURCE_ID="/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1" +``` diff --git a/azurerm/helpers/azure/app_service.go b/azurerm/helpers/azure/app_service.go index f53c0fc555498..fd9ae4b636f2e 100644 --- a/azurerm/helpers/azure/app_service.go +++ b/azurerm/helpers/azure/app_service.go @@ -3,17 +3,22 @@ package azure import ( "fmt" "log" - "net" "regexp" "strings" - "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web" + "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2019-08-01/web" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) +const ( + // TODO: switch back once https://github.com/Azure/azure-rest-api-specs/pull/8435 has been fixed + SystemAssignedUserAssigned web.ManagedServiceIdentityType = "SystemAssigned, UserAssigned" +) + func SchemaAppServiceAadAuthSettings() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, @@ -225,7 +230,7 @@ func SchemaAppServiceIdentity() *schema.Schema { ValidateFunc: validation.StringInSlice([]string{ string(web.ManagedServiceIdentityTypeNone), string(web.ManagedServiceIdentityTypeSystemAssigned), - string(web.ManagedServiceIdentityTypeSystemAssignedUserAssigned), + string(SystemAssignedUserAssigned), string(web.ManagedServiceIdentityTypeUserAssigned), }, true), DiffSuppressFunc: suppress.CaseDifference, @@ -302,25 +307,15 @@ func SchemaAppServiceSiteConfig() *schema.Schema { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "ip_address": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.CIDR, }, "virtual_network_subnet_id": { Type: schema.TypeString, Optional: true, ValidateFunc: validation.StringIsNotEmpty, }, - "subnet_mask": { - Type: schema.TypeString, - Optional: true, - Computed: true, - // TODO we should fix this in 2.0 - // This attribute was made with the assumption that `ip_address` was the only valid option - // but `virtual_network_subnet_id` is being added and doesn't need a `subnet_mask`. - // We'll assume a default of "255.255.255.255" in the expand code when `ip_address` is specified - // and `subnet_mask` is not. - // Default: "255.255.255.255", - }, }, }, }, @@ -477,11 +472,6 @@ func SchemaAppServiceSiteConfig() *schema.Schema { }, false), }, - "virtual_network_name": { - Type: schema.TypeString, - Optional: true, - }, - "cors": SchemaWebCorsSettings(), "auto_swap_slot_name": { @@ -689,10 +679,6 @@ func SchemaAppServiceDataSourceSiteConfig() *schema.Schema { Type: schema.TypeString, Computed: true, }, - "subnet_mask": { - Type: schema.TypeString, - Computed: true, - }, }, }, }, @@ -777,11 +763,6 @@ func SchemaAppServiceDataSourceSiteConfig() *schema.Schema { Computed: true, }, - "virtual_network_name": { - Type: schema.TypeString, - Computed: true, - }, - "cors": { Type: schema.TypeList, Computed: true, @@ -1334,7 +1315,7 @@ func ExpandAppServiceIdentity(input []interface{}) *web.ManagedServiceIdentity { Type: identityType, } - if managedServiceIdentity.Type == web.ManagedServiceIdentityTypeUserAssigned || managedServiceIdentity.Type == web.ManagedServiceIdentityTypeSystemAssignedUserAssigned { + if managedServiceIdentity.Type == web.ManagedServiceIdentityTypeUserAssigned || managedServiceIdentity.Type == SystemAssignedUserAssigned { managedServiceIdentity.UserAssignedIdentities = identityIds } @@ -1439,31 +1420,20 @@ func ExpandAppServiceSiteConfig(input interface{}) (*web.SiteConfig, error) { ipAddress := restriction["ip_address"].(string) vNetSubnetID := restriction["virtual_network_subnet_id"].(string) if vNetSubnetID != "" && ipAddress != "" { - return siteConfig, fmt.Errorf(fmt.Sprintf("only one of `ip_address` or `virtual_network_subnet_id` can set set for `site_config.0.ip_restriction.%d`", i)) + return siteConfig, fmt.Errorf(fmt.Sprintf("only one of `ip_address` or `virtual_network_subnet_id` can be set for `site_config.0.ip_restriction.%d`", i)) } if vNetSubnetID == "" && ipAddress == "" { - return siteConfig, fmt.Errorf(fmt.Sprintf("one of `ip_address` or `virtual_network_subnet_id` must be set set for `site_config.0.ip_restriction.%d`", i)) + return siteConfig, fmt.Errorf(fmt.Sprintf("one of `ip_address` or `virtual_network_subnet_id` must be set for `site_config.0.ip_restriction.%d`", i)) } ipSecurityRestriction := web.IPSecurityRestriction{} + if ipAddress == "Any" { + continue + } + if ipAddress != "" { - mask := restriction["subnet_mask"].(string) - if mask == "" { - mask = "255.255.255.255" - } - // the 2018-02-01 API expects a blank subnet mask and an IP address in CIDR format: a.b.c.d/x - // so translate the IP and mask if necessary - restrictionMask := "" - cidrAddress := ipAddress - if mask != "" { - ipNet := net.IPNet{IP: net.ParseIP(ipAddress), Mask: net.IPMask(net.ParseIP(mask))} - cidrAddress = ipNet.String() - } else if !strings.Contains(ipAddress, "/") { - cidrAddress += "/32" - } - ipSecurityRestriction.IPAddress = &cidrAddress - ipSecurityRestriction.SubnetMask = &restrictionMask + ipSecurityRestriction.IPAddress = &ipAddress } if vNetSubnetID != "" { @@ -1519,10 +1489,6 @@ func ExpandAppServiceSiteConfig(input interface{}) (*web.SiteConfig, error) { siteConfig.MinTLSVersion = web.SupportedTLSVersions(v.(string)) } - if v, ok := config["virtual_network_name"]; ok { - siteConfig.VnetName = utils.String(v.(string)) - } - if v, ok := config["cors"]; ok { corsSettings := v.(interface{}) expand := ExpandWebCorsSettings(corsSettings) @@ -1587,20 +1553,14 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} { if vs := input.IPSecurityRestrictions; vs != nil { for _, v := range *vs { block := make(map[string]interface{}) + if ip := v.IPAddress; ip != nil { - // the 2018-02-01 API uses CIDR format (a.b.c.d/x), so translate that back to IP and mask - if strings.Contains(*ip, "/") { - ipAddr, ipNet, _ := net.ParseCIDR(*ip) - block["ip_address"] = ipAddr.String() - mask := net.IP(ipNet.Mask) - block["subnet_mask"] = mask.String() + if *ip == "Any" { + continue } else { block["ip_address"] = *ip } } - if subnet := v.SubnetMask; subnet != nil { - block["subnet_mask"] = *subnet - } if vNetSubnetID := v.VnetSubnetResourceID; vNetSubnetID != nil { block["virtual_network_subnet_id"] = *vNetSubnetID } @@ -1643,10 +1603,6 @@ func FlattenAppServiceSiteConfig(input *web.SiteConfig) []interface{} { result["windows_fx_version"] = *input.WindowsFxVersion } - if input.VnetName != nil { - result["virtual_network_name"] = *input.VnetName - } - result["scm_type"] = string(input.ScmType) result["ftps_state"] = string(input.FtpsState) result["min_tls_version"] = string(input.MinTLSVersion) diff --git a/azurerm/helpers/azure/app_service_schedule_backup.go b/azurerm/helpers/azure/app_service_schedule_backup.go index 0a91e3789518f..d26a3520e979b 100644 --- a/azurerm/helpers/azure/app_service_schedule_backup.go +++ b/azurerm/helpers/azure/app_service_schedule_backup.go @@ -9,9 +9,8 @@ import ( "github.com/Azure/go-autorest/autorest/date" - "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web" + "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2019-08-01/web" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" ) func SchemaAppServiceBackup() *schema.Schema { @@ -78,7 +77,7 @@ func SchemaAppServiceBackup() *schema.Schema { Type: schema.TypeString, Optional: true, DiffSuppressFunc: suppress.RFC3339Time, - ValidateFunc: validate.RFC3339Time, + ValidateFunc: validation.IsRFC3339Time, }, }, }, @@ -129,7 +128,7 @@ func ExpandAppServiceBackup(input []interface{}) *web.BackupRequest { } if v, ok := schedule["start_time"].(string); ok { - dateTimeToStart, _ := time.Parse(time.RFC3339, v) //validated by schema + dateTimeToStart, _ := time.Parse(time.RFC3339, v) // validated by schema backupSchedule.StartTime = &date.Time{Time: dateTimeToStart} } diff --git a/azurerm/helpers/azure/batch_account.go b/azurerm/helpers/azure/batch_account.go index 464792a9ecc21..305b4bac03392 100644 --- a/azurerm/helpers/azure/batch_account.go +++ b/azurerm/helpers/azure/batch_account.go @@ -3,7 +3,7 @@ package azure import ( "fmt" - "github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2018-12-01/batch" + "github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2019-08-01/batch" ) // ExpandBatchAccountKeyVaultReference expands Batch account KeyVault reference diff --git a/azurerm/helpers/azure/batch_pool.go b/azurerm/helpers/azure/batch_pool.go index e3d1ee8175785..86b46047ce903 100644 --- a/azurerm/helpers/azure/batch_pool.go +++ b/azurerm/helpers/azure/batch_pool.go @@ -7,7 +7,7 @@ import ( "strconv" "strings" - "github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2018-12-01/batch" + "github.com/Azure/azure-sdk-for-go/services/batch/mgmt/2019-08-01/batch" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -571,6 +571,11 @@ func ExpandBatchPoolNetworkConfiguration(list []interface{}) (*batch.NetworkConf } } + if v, ok := networkConfigValue["public_ips"]; ok { + publicIPsRaw := v.(*schema.Set).List() + networkConfiguration.PublicIPs = utils.ExpandStringSlice(publicIPsRaw) + } + if v, ok := networkConfigValue["endpoint_configuration"]; ok { endpoint, err := ExpandBatchPoolEndpointConfiguration(v.([]interface{})) if err != nil { @@ -582,7 +587,7 @@ func ExpandBatchPoolNetworkConfiguration(list []interface{}) (*batch.NetworkConf return networkConfiguration, nil } -//ExpandBatchPoolEndpointConfiguration expands Batch pool endpoint configuration +// ExpandBatchPoolEndpointConfiguration expands Batch pool endpoint configuration func ExpandBatchPoolEndpointConfiguration(list []interface{}) (*batch.PoolEndpointConfiguration, error) { if len(list) == 0 { return nil, nil @@ -621,7 +626,7 @@ func ExpandBatchPoolEndpointConfiguration(list []interface{}) (*batch.PoolEndpoi }, nil } -//ExpandBatchPoolNetworkSecurityGroupRule expands Batch pool network security group rule +// ExpandBatchPoolNetworkSecurityGroupRule expands Batch pool network security group rule func ExpandBatchPoolNetworkSecurityGroupRule(list []interface{}) ([]batch.NetworkSecurityGroupRule, error) { if len(list) == 0 { return nil, nil @@ -661,6 +666,10 @@ func FlattenBatchPoolNetworkConfiguration(networkConfig *batch.NetworkConfigurat result["subnet_id"] = *networkConfig.SubnetID } + if networkConfig.PublicIPs != nil { + result["public_ips"] = schema.NewSet(schema.HashString, utils.FlattenStringSlice(networkConfig.PublicIPs)) + } + if cfg := networkConfig.EndpointConfiguration; cfg != nil && cfg.InboundNatPools != nil && len(*cfg.InboundNatPools) != 0 { endpointConfigs := make([]interface{}, len(*cfg.InboundNatPools)) @@ -673,7 +682,7 @@ func FlattenBatchPoolNetworkConfiguration(networkConfig *batch.NetworkConfigurat inboundNatPoolMap["backend_port"] = *inboundNatPool.BackendPort } if inboundNatPool.FrontendPortRangeStart != nil && inboundNatPool.FrontendPortRangeEnd != nil { - inboundNatPoolMap["frontend_port_range"] = fmt.Sprintf("%d-%d", *inboundNatPool.FrontendPortRangeStart, inboundNatPool.FrontendPortRangeEnd) + inboundNatPoolMap["frontend_port_range"] = fmt.Sprintf("%d-%d", *inboundNatPool.FrontendPortRangeStart, *inboundNatPool.FrontendPortRangeEnd) } inboundNatPoolMap["protocol"] = inboundNatPool.Protocol diff --git a/azurerm/helpers/azure/contains.go b/azurerm/helpers/azure/contains.go new file mode 100644 index 0000000000000..d6357dc3cc5bb --- /dev/null +++ b/azurerm/helpers/azure/contains.go @@ -0,0 +1,11 @@ +package azure + +func SliceContainsValue(input []string, value string) bool { + for _, v := range input { + if v == value { + return true + } + } + + return false +} diff --git a/azurerm/helpers/azure/datalake.go b/azurerm/helpers/azure/datalake.go index 0434493f73cec..eb1c10355a1bf 100644 --- a/azurerm/helpers/azure/datalake.go +++ b/azurerm/helpers/azure/datalake.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) -//store and analytic account names are the same +// store and analytic account names are the same func ValidateDataLakeAccountName() schema.SchemaValidateFunc { return validation.StringMatch( regexp.MustCompile(`\A([a-z0-9]{3,24})\z`), diff --git a/azurerm/helpers/azure/elasticpool.go b/azurerm/helpers/azure/elasticpool.go index 222fe7183bc99..f1c3a9409fe4d 100644 --- a/azurerm/helpers/azure/elasticpool.go +++ b/azurerm/helpers/azure/elasticpool.go @@ -230,7 +230,7 @@ func MSSQLElasticPoolValidateSKU(diff *schema.ResourceDiff) error { return fmt.Errorf("Mismatch between SKU name '%s' and family '%s', expected '%s'", s.Name, s.Family, getFamilyFromName(s)) } - //get max GB and do validation based on SKU type + // get max GB and do validation based on SKU type if s.SkuType == DTU { s.MaxAllowedGB = getDTUMaxGB[strings.ToLower(s.Tier)][s.Capacity] return doDTUSKUValidation(s) diff --git a/azurerm/helpers/azure/eventhub.go b/azurerm/helpers/azure/eventhub.go index 9015731f15499..fcf8c67c3e9c8 100644 --- a/azurerm/helpers/azure/eventhub.go +++ b/azurerm/helpers/azure/eventhub.go @@ -11,7 +11,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub" ) -//validation +// validation func ValidateEventHubNamespaceName() schema.SchemaValidateFunc { return validation.StringMatch( regexp.MustCompile("^[a-zA-Z][-a-zA-Z0-9]{4,48}[a-zA-Z0-9]$"), @@ -40,7 +40,7 @@ func ValidateEventHubAuthorizationRuleName() schema.SchemaValidateFunc { ) } -//schema +// schema func ExpandEventHubAuthorizationRuleRights(d *schema.ResourceData) *[]eventhub.AccessRights { rights := make([]eventhub.AccessRights, 0) @@ -60,7 +60,7 @@ func ExpandEventHubAuthorizationRuleRights(d *schema.ResourceData) *[]eventhub.A } func FlattenEventHubAuthorizationRuleRights(rights *[]eventhub.AccessRights) (listen, send, manage bool) { - //zero (initial) value for a bool in go is false + // zero (initial) value for a bool in go is false if rights != nil { for _, right := range *rights { diff --git a/azurerm/helpers/azure/key_vault.go b/azurerm/helpers/azure/key_vault.go index 7957380bb5946..1460cd8d0dc85 100644 --- a/azurerm/helpers/azure/key_vault.go +++ b/azurerm/helpers/azure/key_vault.go @@ -59,7 +59,7 @@ func GetKeyVaultIDFromBaseUrl(ctx context.Context, client *keyvault.VaultsClient resourceGroup := vid.ResourceGroup name := vid.Path["vaults"] - //resp does not appear to contain the vault properties, so lets fetch them + // resp does not appear to contain the vault properties, so lets fetch them get, err := client.Get(ctx, resourceGroup, name) if err != nil { if utils.ResponseWasNotFound(get.Response) { diff --git a/azurerm/helpers/azure/location.go b/azurerm/helpers/azure/location.go index 15213c617abe9..8690718f83f2b 100644 --- a/azurerm/helpers/azure/location.go +++ b/azurerm/helpers/azure/location.go @@ -35,17 +35,6 @@ func SchemaLocationForDataSource() *schema.Schema { } } -func SchemaLocationDeprecated() *schema.Schema { - return &schema.Schema{ - Type: schema.TypeString, - ForceNew: true, - Optional: true, - StateFunc: NormalizeLocation, - DiffSuppressFunc: SuppressLocationDiff, - Deprecated: "location is no longer used", - } -} - // azure.NormalizeLocation is a function which normalises human-readable region/location // names (e.g. "West US") to the values used and returned by the Azure API (e.g. "westus"). // In state we track the API internal version as it is easier to go from the human form diff --git a/azurerm/helpers/azure/mssql.go b/azurerm/helpers/azure/mssql.go index de9e37befe34c..4f9ed77386ed9 100644 --- a/azurerm/helpers/azure/mssql.go +++ b/azurerm/helpers/azure/mssql.go @@ -6,7 +6,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" ) -//Your server name can contain only lowercase letters, numbers, and '-', but can't start or end with '-' or have more than 63 characters. +// Your server name can contain only lowercase letters, numbers, and '-', but can't start or end with '-' or have more than 63 characters. func ValidateMsSqlServerName(i interface{}, k string) (_ []string, errors []error) { if m, regexErrs := validate.RegExHelper(i, k, `^[0-9a-z]([-0-9a-z]{0,61}[0-9a-z])?$`); !m { errors = append(regexErrs, fmt.Errorf("%q can contain only lowercase letters, numbers, and '-', but can't start or end with '-' or have more than 63 characters.", k)) @@ -15,7 +15,7 @@ func ValidateMsSqlServerName(i interface{}, k string) (_ []string, errors []erro return nil, errors } -//Your database name can't end with '.' or ' ', can't contain '<,>,*,%,&,:,\,/,?' or control characters, and can't have more than 128 characters. +// Your database name can't end with '.' or ' ', can't contain '<,>,*,%,&,:,\,/,?' or control characters, and can't have more than 128 characters. func ValidateMsSqlDatabaseName(i interface{}, k string) (_ []string, errors []error) { if m, regexErrs := validate.RegExHelper(i, k, `^[^<>*%&:\\\/?]{0,127}[^\s.<>*%&:\\\/?]$`); !m { errors = append(regexErrs, fmt.Errorf(`%q can't end with '.' or ' ', can't contain '<,>,*,%%,&,:,\,/,?' or control characters, and can't have more than 128 characters.`, k)) @@ -32,9 +32,9 @@ func ValidateMsSqlFailoverGroupName(i interface{}, k string) (_ []string, errors return nil, errors } -//Following characters and any control characters are not allowed for resource name '%,&,\\\\,?,/'.\" -//The name can not end with characters: '. ' -//TODO: unsure about length, was able to deploy one at 120 +// Following characters and any control characters are not allowed for resource name '%,&,\\\\,?,/'.\" +// The name can not end with characters: '. ' +// TODO: unsure about length, was able to deploy one at 120 func ValidateMsSqlElasticPoolName(i interface{}, k string) (_ []string, errors []error) { if m, regexErrs := validate.RegExHelper(i, k, `^[^&%\\\/?]{0,127}[^\s.&%\\\/?]$`); !m { errors = append(regexErrs, fmt.Errorf(`%q can't end with '.' or ' ', can't contain '%%,&,\,/,?' or control characters, and can't have more than 128 characters.`, k)) diff --git a/azurerm/helpers/azure/mssql_test.go b/azurerm/helpers/azure/mssql_test.go index 0ebf853cb6d13..fbd391a4204f6 100644 --- a/azurerm/helpers/azure/mssql_test.go +++ b/azurerm/helpers/azure/mssql_test.go @@ -2,7 +2,7 @@ package azure import "testing" -//Your server name can contain only lowercase letters, numbers, and '-', but can't start or end with '-' or have more than 63 characters. +// Your server name can contain only lowercase letters, numbers, and '-', but can't start or end with '-' or have more than 63 characters. func TestValidateMsSqlServerName(t *testing.T) { cases := []struct { Value string @@ -63,7 +63,7 @@ func TestValidateMsSqlServerName(t *testing.T) { } } -//Your database name can't end with '.' or ' ', can't contain '<,>,*,%,&,:,\,/,?' or control characters, and can't have more than 128 characters. +// Your database name can't end with '.' or ' ', can't contain '<,>,*,%,&,:,\,/,?' or control characters, and can't have more than 128 characters. func TestValidateMsSqlDatabaseName(t *testing.T) { cases := []struct { Value string @@ -140,8 +140,8 @@ func TestValidateMsSqlDatabaseName(t *testing.T) { } } -//Following characters and any control characters are not allowed for resource name '%,&,\\\\,?,/'.\" -//The name can not end with characters: '. ' +// Following characters and any control characters are not allowed for resource name '%,&,\\\\,?,/'.\" +// The name can not end with characters: '. ' func TestValidateMsSqlElasticPoolName(t *testing.T) { cases := []struct { Value string diff --git a/azurerm/helpers/azure/resource_group.go b/azurerm/helpers/azure/resource_group.go index 7f6a5bf712516..8eba7a93d1965 100644 --- a/azurerm/helpers/azure/resource_group.go +++ b/azurerm/helpers/azure/resource_group.go @@ -18,15 +18,6 @@ func SchemaResourceGroupName() *schema.Schema { } } -func SchemaResourceGroupNameDeprecated() *schema.Schema { - return &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Computed: true, - Deprecated: "This field has been deprecated and is no longer used - will be removed in 2.0 of the Azure Provider", - } -} - func SchemaResourceGroupNameDiffSuppress() *schema.Schema { return &schema.Schema{ Type: schema.TypeString, diff --git a/azurerm/helpers/azure/servicebus.go b/azurerm/helpers/azure/servicebus.go index 4d0cce2b263b9..97ade4d9de514 100644 --- a/azurerm/helpers/azure/servicebus.go +++ b/azurerm/helpers/azure/servicebus.go @@ -11,7 +11,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/servicebus/mgmt/2017-04-01/servicebus" ) -//validation +// validation func ValidateServiceBusNamespaceName() schema.SchemaValidateFunc { return validation.StringMatch( regexp.MustCompile("^[a-zA-Z][-a-zA-Z0-9]{4,48}[a-zA-Z0-9]$"), @@ -66,7 +66,7 @@ func ExpandServiceBusAuthorizationRuleRights(d *schema.ResourceData) *[]serviceb } func FlattenServiceBusAuthorizationRuleRights(rights *[]servicebus.AccessRights) (listen, send, manage bool) { - //zero (initial) value for a bool in go is false + // zero (initial) value for a bool in go is false if rights != nil { for _, right := range *rights { @@ -86,7 +86,7 @@ func FlattenServiceBusAuthorizationRuleRights(rights *[]servicebus.AccessRights) return listen, send, manage } -//shared schema +// shared schema func MergeSchema(a map[string]*schema.Schema, b map[string]*schema.Schema) map[string]*schema.Schema { s := map[string]*schema.Schema{} diff --git a/azurerm/helpers/azure/validate.go b/azurerm/helpers/azure/validate.go index 5788b23b5e694..9dad815eb5bd2 100644 --- a/azurerm/helpers/azure/validate.go +++ b/azurerm/helpers/azure/validate.go @@ -18,7 +18,7 @@ func ValidateResourceID(i interface{}, k string) (warnings []string, errors []er return warnings, errors } -//true for a resource ID or an empty string +// true for a resource ID or an empty string func ValidateResourceIDOrEmpty(i interface{}, k string) (_ []string, errors []error) { v, ok := i.(string) if !ok { diff --git a/azurerm/helpers/azure/validate_test.go b/azurerm/helpers/azure/validate_test.go index b8b17ab474f0a..a668deb2b034e 100644 --- a/azurerm/helpers/azure/validate_test.go +++ b/azurerm/helpers/azure/validate_test.go @@ -73,7 +73,7 @@ func TestAzureResourceIDOrEmpty(t *testing.T) { ID: "nonsense", Errors: 1, }, - //as this function just calls TestAzureResourceId lets not be as comprehensive + // as this function just calls TestAzureResourceId lets not be as comprehensive { ID: "/providers/provider.name/", Errors: 0, diff --git a/azurerm/helpers/azure/web.go b/azurerm/helpers/azure/web.go index 6be741438c01f..1b7b313c8d689 100644 --- a/azurerm/helpers/azure/web.go +++ b/azurerm/helpers/azure/web.go @@ -1,7 +1,7 @@ package azure import ( - "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web" + "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2019-08-01/web" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) diff --git a/azurerm/helpers/tf/acctest.go b/azurerm/helpers/tf/acctest.go index 68ebf1ee88310..359fcf8d17143 100644 --- a/azurerm/helpers/tf/acctest.go +++ b/azurerm/helpers/tf/acctest.go @@ -13,9 +13,9 @@ func AccRandTimeInt() int { // 000000000000000000 // YYMMddHHmmsshhRRRR - //go format: 2006-01-02 15:04:05.00 + // go format: 2006-01-02 15:04:05.00 - timeStr := strings.Replace(time.Now().Local().Format("060102150405.00"), ".", "", 1) //no way to not have a .? + timeStr := strings.Replace(time.Now().Local().Format("060102150405.00"), ".", "", 1) // no way to not have a .? postfix := acctest.RandStringFromCharSet(4, "0123456789") i, err := strconv.Atoi(timeStr + postfix) diff --git a/azurerm/helpers/validate/base64.go b/azurerm/helpers/validate/base64.go deleted file mode 100644 index 08a85fd809cb7..0000000000000 --- a/azurerm/helpers/validate/base64.go +++ /dev/null @@ -1,11 +0,0 @@ -package validate - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" -) - -// deprecated: please use validation.StringIsBase64 instead -func Base64String() schema.SchemaValidateFunc { - return validation.StringIsBase64 -} diff --git a/azurerm/helpers/validate/bot.go b/azurerm/helpers/validate/bot.go index 430bbcec9d9fe..a04ece21c7aa0 100644 --- a/azurerm/helpers/validate/bot.go +++ b/azurerm/helpers/validate/bot.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -func ValidateBotMSTeamsCallingWebHook() schema.SchemaValidateFunc { +func BotMSTeamsCallingWebHook() schema.SchemaValidateFunc { return func(i interface{}, k string) (warnings []string, errors []error) { value := i.(string) if !strings.HasPrefix(value, "https://") || !strings.HasSuffix(value, "/") { diff --git a/azurerm/helpers/validate/bot_test.go b/azurerm/helpers/validate/bot_test.go index 756bcb0b592ba..9011efb63c938 100644 --- a/azurerm/helpers/validate/bot_test.go +++ b/azurerm/helpers/validate/bot_test.go @@ -32,7 +32,7 @@ func TestValidateBotMSTeamsCallingWebHook(t *testing.T) { } for _, tt := range tests { t.Run(tt.webhook, func(t *testing.T) { - _, err := ValidateBotMSTeamsCallingWebHook()(tt.webhook, "") + _, err := BotMSTeamsCallingWebHook()(tt.webhook, "") valid := err == nil if valid != tt.valid { t.Errorf("Expected valid status %t but got %t for input %s", tt.valid, valid, tt.webhook) diff --git a/azurerm/helpers/validate/float.go b/azurerm/helpers/validate/float.go deleted file mode 100644 index 6066d221be6bd..0000000000000 --- a/azurerm/helpers/validate/float.go +++ /dev/null @@ -1,11 +0,0 @@ -package validate - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" -) - -// deprecated: please use validation.FloatAtLeast instead -func FloatAtLeast(min float64) schema.SchemaValidateFunc { - return validation.FloatAtLeast(min) -} diff --git a/azurerm/helpers/validate/int.go b/azurerm/helpers/validate/int.go index 335a934da7606..6eecfc8fd34ce 100644 --- a/azurerm/helpers/validate/int.go +++ b/azurerm/helpers/validate/int.go @@ -4,14 +4,8 @@ import ( "fmt" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) -// deprecated: use validation.All(validation.IntBetween, validation.IntNotInSlice) -func IntBetweenAndNot(min, max, not int) schema.SchemaValidateFunc { - return validation.All(validation.IntBetween(min, max), validation.IntNotInSlice([]int{not})) -} - func IntBetweenAndNotInRange(min, max, rangeMin, rangeMax int) schema.SchemaValidateFunc { return func(i interface{}, k string) (_ []string, errors []error) { v, ok := i.(int) @@ -32,18 +26,3 @@ func IntBetweenAndNotInRange(min, max, rangeMin, rangeMax int) schema.SchemaVali return } } - -// deprecated: use validation.All(validation.IntBetween, validation.IntDivisibleBy) -func IntBetweenAndDivisibleBy(min, max, divisor int) schema.SchemaValidateFunc { // nolint: unparam - return validation.All(validation.IntBetween(min, max), validation.IntDivisibleBy(divisor)) -} - -// deprecated: use validation.IntDivisibleBy -func IntDivisibleBy(divisor int) schema.SchemaValidateFunc { // nolint: unparam - return validation.IntDivisibleBy(divisor) -} - -// deprecated: use validation.IntInSlice -func IntInSlice(valid []int) schema.SchemaValidateFunc { - return validation.IntInSlice(valid) -} diff --git a/azurerm/helpers/validate/strings.go b/azurerm/helpers/validate/strings.go index 22b4e81e327d6..d40a05d89ddc0 100644 --- a/azurerm/helpers/validate/strings.go +++ b/azurerm/helpers/validate/strings.go @@ -3,8 +3,6 @@ package validate import ( "fmt" "strings" - - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) // LowerCasedString validates that the string is lower-cased @@ -28,8 +26,3 @@ func LowerCasedString(i interface{}, k string) ([]string, []error) { return nil, nil } - -// deprecated use validation.StringIsNotEmpty instead -func NoEmptyStrings(i interface{}, k string) ([]string, []error) { - return validation.StringIsNotEmpty(i, k) -} diff --git a/azurerm/helpers/validate/time.go b/azurerm/helpers/validate/time.go index 7bce6bba290b1..027a8cf33ce9d 100644 --- a/azurerm/helpers/validate/time.go +++ b/azurerm/helpers/validate/time.go @@ -8,7 +8,6 @@ import ( "github.com/Azure/go-autorest/autorest/date" iso8601 "github.com/btubbs/datetime" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) func ISO8601Duration(i interface{}, k string) (warnings []string, errors []error) { @@ -26,11 +25,6 @@ func ISO8601Duration(i interface{}, k string) (warnings []string, errors []error return warnings, errors } -// deprecated use validation.IsRFC3339Time instead -func RFC3339Time(i interface{}, k string) (warnings []string, errors []error) { - return validation.IsRFC3339Time(i, k) -} - func ISO8601DateTime(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(string) if !ok { @@ -67,13 +61,3 @@ func RFC3339DateInFutureBy(d time.Duration) schema.SchemaValidateFunc { return warnings, errors } } - -// deprecated use validation.IsDayOfTheWeek instead -func DayOfTheWeek(ignoreCase bool) schema.SchemaValidateFunc { - return validation.IsDayOfTheWeek(ignoreCase) -} - -// deprecated use validation.IsMonth instead -func Month(ignoreCase bool) schema.SchemaValidateFunc { - return validation.IsMonth(ignoreCase) -} diff --git a/azurerm/helpers/validate/time_test.go b/azurerm/helpers/validate/time_test.go index b9751d6398f9e..aa106d7cca18b 100644 --- a/azurerm/helpers/validate/time_test.go +++ b/azurerm/helpers/validate/time_test.go @@ -5,48 +5,6 @@ import ( "time" ) -func TestRFC3339Time(t *testing.T) { - cases := []struct { - Time string - Errors int - }{ - { - Time: "", - Errors: 1, - }, - { - Time: "this is not a date", - Errors: 1, - }, - { - Time: "2000-01-01", - Errors: 1, - }, - { - Time: "2000-01-01T01:23:45", - Errors: 1, - }, - { - Time: "2000-01-01T01:23:45Z", - Errors: 0, - }, - { - Time: "2000-01-01T01:23:45+00:00", - Errors: 0, - }, - } - - for _, tc := range cases { - t.Run(tc.Time, func(t *testing.T) { - _, errors := RFC3339Time(tc.Time, "test") - - if len(errors) != tc.Errors { - t.Fatalf("Expected RFC3339Time to have %d not %d errors for %q", tc.Errors, len(errors), tc.Time) - } - }) - } -} - func TestISO8601DateTime(t *testing.T) { cases := []struct { Time string diff --git a/azurerm/helpers/validate/url.go b/azurerm/helpers/validate/url.go deleted file mode 100644 index 8027def99814f..0000000000000 --- a/azurerm/helpers/validate/url.go +++ /dev/null @@ -1,16 +0,0 @@ -package validate - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" -) - -// deprecated use validation.IsURLWithHTTPS instead -func URLIsHTTPS(i interface{}, k string) (_ []string, errors []error) { - return validation.IsURLWithHTTPS(i, k) -} - -// todo ad to sdk -// deprecated use validation.IsURLWithScheme instead -func URLIsHTTPOrHTTPS(i interface{}, k string) (_ []string, errors []error) { - return validation.IsURLWithScheme([]string{"http", "https"})(i, k) -} diff --git a/azurerm/helpers/validate/uuid.go b/azurerm/helpers/validate/uuid.go index 8911285e33daa..de482fc923138 100644 --- a/azurerm/helpers/validate/uuid.go +++ b/azurerm/helpers/validate/uuid.go @@ -1,24 +1,6 @@ package validate -import ( - "regexp" - - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" -) +import "regexp" //uuid regex helper var UUIDRegExp = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$") - -// deprecated use validation.IsUUID instead -func UUID(i interface{}, k string) (warnings []string, errors []error) { - return validation.IsUUID(i, k) -} - -func GUID(i interface{}, k string) (warnings []string, errors []error) { - return validation.IsUUID(i, k) -} - -// deprecated use validation.Any(validation.IsUUID, validation.StringIsEmpty) instead -func UUIDOrEmpty(i interface{}, k string) (warnings []string, errors []error) { - return validation.Any(validation.IsUUID, validation.StringIsEmpty)(i, k) -} diff --git a/azurerm/internal/acceptance/data.go b/azurerm/internal/acceptance/data.go index 3e79ea88bee17..e173e4d283488 100644 --- a/azurerm/internal/acceptance/data.go +++ b/azurerm/internal/acceptance/data.go @@ -24,7 +24,7 @@ type TestData struct { // Locations is a set of Azure Regions which should be used for this Test Locations Regions - // RandomString is a random integer which is unique to this test case + // RandomInteger is a random integer which is unique to this test case RandomInteger int // RandomString is a random 5 character string is unique to this test case @@ -52,7 +52,7 @@ type TestData struct { // BuildTestData generates some test data for the given resource func BuildTestData(t *testing.T, resourceType string, resourceLabel string) TestData { once.Do(func() { - azureProvider := provider.AzureProvider().(*schema.Provider) + azureProvider := provider.TestAzureProvider().(*schema.Provider) AzureProvider = azureProvider SupportedProviders = map[string]terraform.ResourceProvider{ @@ -90,6 +90,7 @@ func BuildTestData(t *testing.T, resourceType string, resourceLabel string) Test return testData } +// RandomIntOfLength is a random 8 to 18 digit integer which is unique to this test case func (td *TestData) RandomIntOfLength(len int) int { // len should not be // - greater then 18, longest a int can represent @@ -116,3 +117,13 @@ func (td *TestData) RandomIntOfLength(len int) int { return i } + +// RandomStringOfLength is a random 1 to 1024 character string which is unique to this test case +func (td *TestData) RandomStringOfLength(len int) string { + // len should not be less then 1 or greater than 1024 + if 1 > len || len > 1024 { + panic(fmt.Sprintf("Invalid Test: RandomStringOfLength: length argument must be between 1 and 1024 characters")) + } + + return acctest.RandString(len) +} diff --git a/azurerm/internal/azuresdkhacks/network_interface.go b/azurerm/internal/azuresdkhacks/network_interface.go new file mode 100644 index 0000000000000..8f4c849d71dec --- /dev/null +++ b/azurerm/internal/azuresdkhacks/network_interface.go @@ -0,0 +1,105 @@ +package azuresdkhacks + +import ( + "bytes" + "context" + "encoding/json" + "io/ioutil" + "net/http" + + "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" + "github.com/Azure/go-autorest/autorest" +) + +// UpdateNetworkInterfaceAllowingRemovalOfNSG patches our way around a design flaw in the Azure +// Resource Manager API <-> Azure SDK for Go where it's not possible to remove a Network Security Group +func UpdateNetworkInterfaceAllowingRemovalOfNSG(ctx context.Context, client *network.InterfacesClient, resourceGroupName string, networkInterfaceName string, parameters network.Interface) (result network.InterfacesCreateOrUpdateFuture, err error) { + req, err := updateNetworkInterfaceAllowingRemovalOfNSGPreparer(ctx, client, resourceGroupName, networkInterfaceName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "network.InterfacesClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = client.CreateOrUpdateSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "network.InterfacesClient", "CreateOrUpdate", result.Response(), "Failure sending request") + return + } + + return +} + +// updateNetworkInterfaceAllowingRemovalOfNSGPreparer prepares the CreateOrUpdate request but applies the +// necessary patches to be able to remove the NSG if required +func updateNetworkInterfaceAllowingRemovalOfNSGPreparer(ctx context.Context, client *network.InterfacesClient, resourceGroupName string, networkInterfaceName string, parameters network.Interface) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "networkInterfaceName": autorest.Encode("path", networkInterfaceName), + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2019-09-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + parameters.Etag = nil + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkInterfaces/{networkInterfaceName}", pathParameters), + withJsonWorkingAroundTheBrokenNetworkAPI(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +func withJsonWorkingAroundTheBrokenNetworkAPI(v network.Interface) autorest.PrepareDecorator { + return func(p autorest.Preparer) autorest.Preparer { + return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) { + r, err := p.Prepare(r) + if err == nil { + b, err := json.Marshal(v) + if err == nil { + // there's a few fields which can be intentionally set to nil - as such here we need to check if they should be nil and force them to be nil + var out map[string]interface{} + if err := json.Unmarshal(b, &out); err != nil { + return r, err + } + + // apply the hack + out = patchNICUpdateAPIIssue(v, out) + + // then reserialize it as needed + b, err = json.Marshal(out) + if err == nil { + r.ContentLength = int64(len(b)) + r.Body = ioutil.NopCloser(bytes.NewReader(b)) + } + } + } + return r, err + }) + } +} + +func patchNICUpdateAPIIssue(nic network.Interface, input map[string]interface{}) map[string]interface{} { + if nic.InterfacePropertiesFormat == nil { + return input + } + + output := input + + if v, ok := output["properties"]; ok { + props := v.(map[string]interface{}) + + if nic.InterfacePropertiesFormat.NetworkSecurityGroup == nil { + var hack *string // a nil-pointered string + props["networkSecurityGroup"] = hack + } + + output["properties"] = props + } + + return output +} diff --git a/azurerm/internal/azuresdkhacks/notes.go b/azurerm/internal/azuresdkhacks/notes.go new file mode 100644 index 0000000000000..f75c0ac1c827c --- /dev/null +++ b/azurerm/internal/azuresdkhacks/notes.go @@ -0,0 +1,15 @@ +package azuresdkhacks + +// There's a functional difference that exists between the Azure SDK for Go and Azure Resource Manager API +// where when performing a delta update unchanged fields are omitted from the response when they could +// also have a legitimate value of `null` (to remove/disable a sub-block). +// +// Ultimately the Azure SDK for Go has opted to serialise structs with `json:"name,omitempty"` which +// means that this value will be omitted if nil to allow for delta updates - however this means there's +// no means of removing/resetting a value of a nested object once provided since a `nil` object will be +// reset +// +// As such this set of well intentioned hacks is intended to force this behaviour where necessary. +// +// It's worth noting that these hacks are a last resort and the Swagger/API/SDK should almost always be +// fixed instead. diff --git a/azurerm/internal/clients/client.go b/azurerm/internal/clients/client.go index 00a9e5a180a76..05ab689cc52fc 100644 --- a/azurerm/internal/clients/client.go +++ b/azurerm/internal/clients/client.go @@ -18,6 +18,7 @@ import ( compute "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute/client" containerServices "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers/client" cosmosdb "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos/client" + datamigration "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration/client" databricks "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks/client" datafactory "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/client" datalake "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datalake/client" @@ -29,6 +30,7 @@ import ( frontdoor "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/frontdoor/client" hdinsight "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/hdinsight/client" healthcare "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/healthcare/client" + iotcentral "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iotcentral/client" iothub "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub/client" keyvault "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault/client" kusto "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/kusto/client" @@ -38,6 +40,7 @@ import ( maps "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/maps/client" mariadb "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mariadb/client" media "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/media/client" + mixedreality "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mixedreality/client" monitor "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/monitor/client" msi "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/msi/client" mssql "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mssql/client" @@ -73,65 +76,68 @@ type Client struct { Account *ResourceManagerAccount Features features.UserFeatures - AnalysisServices *analysisServices.Client - ApiManagement *apiManagement.Client - AppConfiguration *appConfiguration.Client - AppInsights *applicationInsights.Client - Authorization *authorization.Client - Automation *automation.Client - Batch *batch.Client - Bot *bot.Client - Cdn *cdn.Client - Cognitive *cognitiveServices.Client - Compute *compute.Client - Containers *containerServices.Client - Cosmos *cosmosdb.Client - DataBricks *databricks.Client - DataFactory *datafactory.Client - Datalake *datalake.Client - DevSpace *devspace.Client - DevTestLabs *devtestlabs.Client - Dns *dns.Client - EventGrid *eventgrid.Client - Eventhub *eventhub.Client - Frontdoor *frontdoor.Client - HDInsight *hdinsight.Client - HealthCare *healthcare.Client - IoTHub *iothub.Client - KeyVault *keyvault.Client - Kusto *kusto.Client - LogAnalytics *loganalytics.Client - Logic *logic.Client - ManagementGroups *managementgroup.Client - Maps *maps.Client - MariaDB *mariadb.Client - Media *media.Client - Monitor *monitor.Client - MSI *msi.Client - MSSQL *mssql.Client - MySQL *mysql.Client - NetApp *netapp.Client - Network *network.Client - NotificationHubs *notificationhub.Client - Policy *policy.Client - Portal *portal.Client - Postgres *postgres.Client - PrivateDns *privatedns.Client - RecoveryServices *recoveryServices.Client - Redis *redis.Client - Relay *relay.Client - Resource *resource.Client - Search *search.Client - SecurityCenter *securityCenter.Client - ServiceBus *serviceBus.Client - ServiceFabric *serviceFabric.Client - SignalR *signalr.Client - Storage *storage.Client - StreamAnalytics *streamAnalytics.Client - Subscription *subscription.Client - Sql *sql.Client - TrafficManager *trafficManager.Client - Web *web.Client + AnalysisServices *analysisServices.Client + ApiManagement *apiManagement.Client + AppConfiguration *appConfiguration.Client + AppInsights *applicationInsights.Client + Authorization *authorization.Client + Automation *automation.Client + Batch *batch.Client + Bot *bot.Client + Cdn *cdn.Client + Cognitive *cognitiveServices.Client + Compute *compute.Client + Containers *containerServices.Client + Cosmos *cosmosdb.Client + DatabaseMigration *datamigration.Client + DataBricks *databricks.Client + DataFactory *datafactory.Client + Datalake *datalake.Client + DevSpace *devspace.Client + DevTestLabs *devtestlabs.Client + Dns *dns.Client + EventGrid *eventgrid.Client + Eventhub *eventhub.Client + Frontdoor *frontdoor.Client + HDInsight *hdinsight.Client + HealthCare *healthcare.Client + IoTHub *iothub.Client + IoTCentral *iotcentral.Client + KeyVault *keyvault.Client + Kusto *kusto.Client + LogAnalytics *loganalytics.Client + Logic *logic.Client + ManagementGroups *managementgroup.Client + Maps *maps.Client + MariaDB *mariadb.Client + Media *media.Client + MixedReality *mixedreality.Client + Monitor *monitor.Client + MSI *msi.Client + MSSQL *mssql.Client + MySQL *mysql.Client + NetApp *netapp.Client + Network *network.Client + NotificationHubs *notificationhub.Client + Policy *policy.Client + Portal *portal.Client + Postgres *postgres.Client + PrivateDns *privatedns.Client + RecoveryServices *recoveryServices.Client + Redis *redis.Client + Relay *relay.Client + Resource *resource.Client + Search *search.Client + SecurityCenter *securityCenter.Client + ServiceBus *serviceBus.Client + ServiceFabric *serviceFabric.Client + SignalR *signalr.Client + Storage *storage.Client + StreamAnalytics *streamAnalytics.Client + Subscription *subscription.Client + Sql *sql.Client + TrafficManager *trafficManager.Client + Web *web.Client } // NOTE: it should be possible for this method to become Private once the top level Client's removed @@ -153,6 +159,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error client.Compute = compute.NewClient(o) client.Containers = containerServices.NewClient(o) client.Cosmos = cosmosdb.NewClient(o) + client.DatabaseMigration = datamigration.NewClient(o) client.DataBricks = databricks.NewClient(o) client.DataFactory = datafactory.NewClient(o) client.Datalake = datalake.NewClient(o) @@ -165,6 +172,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error client.HDInsight = hdinsight.NewClient(o) client.HealthCare = healthcare.NewClient(o) client.IoTHub = iothub.NewClient(o) + client.IoTCentral = iotcentral.NewClient(o) client.KeyVault = keyvault.NewClient(o) client.Kusto = kusto.NewClient(o) client.LogAnalytics = loganalytics.NewClient(o) @@ -173,6 +181,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error client.Maps = maps.NewClient(o) client.MariaDB = mariadb.NewClient(o) client.Media = media.NewClient(o) + client.MixedReality = mixedreality.NewClient(o) client.Monitor = monitor.NewClient(o) client.MSI = msi.NewClient(o) client.MSSQL = mssql.NewClient(o) diff --git a/azurerm/internal/features/two_point_oh.go b/azurerm/internal/features/two_point_oh.go deleted file mode 100644 index d028d8e883787..0000000000000 --- a/azurerm/internal/features/two_point_oh.go +++ /dev/null @@ -1,23 +0,0 @@ -package features - -// SupportsTwoPointZeroResources returns whether the new VM and VMSS resources from 2.0 -// should be supported -// -// There's 5 new resources coming as a part of 2.0, which are intentionally feature-flagged off -// until all 5 are supported: -// * `azurerm_linux_virtual_machine` -// * `azurerm_linux_virtual_machine_scale_set` -// * `azurerm_windows_virtual_machine` -// * `azurerm_windows_virtual_machine_scale_set` -// * `azurerm_virtual_machine_scale_set_extension` -// -// This feature-toggle defaults to off in 1.x versions of the Azure Provider, however this will -// become enabled by default in version 2.0 of the Azure Provider (where this toggle will be removed). -// As outlined in the announcement for v2.0 of the Azure Provider: -// https://github.com/terraform-providers/terraform-provider-azurerm/issues/2807 -// -// Operators wishing to beta-test these resources can opt-into them in 1.x versions of the -// Azure Provider by setting the Environment Variable 'ARM_PROVIDER_TWOPOINTZERO_RESOURCES' to 'true' -func SupportsTwoPointZeroResources() bool { - return true -} diff --git a/azurerm/internal/features/user_flags.go b/azurerm/internal/features/user_flags.go index f5b713b84f5ec..cc874f68dd205 100644 --- a/azurerm/internal/features/user_flags.go +++ b/azurerm/internal/features/user_flags.go @@ -3,6 +3,7 @@ package features type UserFeatures struct { VirtualMachine VirtualMachineFeatures VirtualMachineScaleSet VirtualMachineScaleSetFeatures + KeyVault KeyVaultFeatures } type VirtualMachineFeatures struct { @@ -12,3 +13,8 @@ type VirtualMachineFeatures struct { type VirtualMachineScaleSetFeatures struct { RollInstancesWhenRequired bool } + +type KeyVaultFeatures struct { + PurgeSoftDeleteOnDestroy bool + RecoverSoftDeletedKeyVaults bool +} diff --git a/azurerm/internal/provider/features.go b/azurerm/internal/provider/features.go index 40cbcd1ce1c3f..f5e56a24ba067 100644 --- a/azurerm/internal/provider/features.go +++ b/azurerm/internal/provider/features.go @@ -1,13 +1,13 @@ package provider import ( - "os" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) -func schemaFeatures() *schema.Schema { +func schemaFeatures(supportLegacyTestSuite bool) *schema.Schema { + // NOTE: if there's only one nested field these want to be Required (since there's no point + // specifying the block otherwise) - however for 2+ they should be optional features := map[string]*schema.Schema{ "virtual_machine": { Type: schema.TypeList, @@ -36,10 +36,30 @@ func schemaFeatures() *schema.Schema { }, }, }, + + "key_vault": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "recover_soft_deleted_key_vaults": { + Type: schema.TypeBool, + Optional: true, + }, + + "purge_soft_delete_on_destroy": { + Type: schema.TypeBool, + Optional: true, + }, + }, + }, + }, } - runningAcceptanceTests := os.Getenv("TF_ACC") != "" - if runningAcceptanceTests { + // this is a temporary hack to enable us to gradually add provider blocks to test configurations + // rather than doing it as a big-bang and breaking all open PR's + if supportLegacyTestSuite { return &schema.Schema{ Type: schema.TypeList, Optional: true, @@ -70,6 +90,10 @@ func expandFeatures(input []interface{}) features.UserFeatures { VirtualMachineScaleSet: features.VirtualMachineScaleSetFeatures{ RollInstancesWhenRequired: true, }, + KeyVault: features.KeyVaultFeatures{ + PurgeSoftDeleteOnDestroy: true, + RecoverSoftDeletedKeyVaults: true, + }, } if len(input) == 0 || input[0] == nil { @@ -78,6 +102,19 @@ func expandFeatures(input []interface{}) features.UserFeatures { val := input[0].(map[string]interface{}) + if raw, ok := val["key_vault"]; ok { + items := raw.([]interface{}) + if len(items) > 0 { + keyVaultRaw := items[0].(map[string]interface{}) + if v, ok := keyVaultRaw["purge_soft_delete_on_destroy"]; ok { + features.KeyVault.PurgeSoftDeleteOnDestroy = v.(bool) + } + if v, ok := keyVaultRaw["recover_soft_deleted_key_vaults"]; ok { + features.KeyVault.RecoverSoftDeletedKeyVaults = v.(bool) + } + } + } + if raw, ok := val["virtual_machine"]; ok { items := raw.([]interface{}) if len(items) > 0 { diff --git a/azurerm/internal/provider/features_test.go b/azurerm/internal/provider/features_test.go index 09be0cd828f3f..79b54bd585761 100644 --- a/azurerm/internal/provider/features_test.go +++ b/azurerm/internal/provider/features_test.go @@ -18,6 +18,10 @@ func TestExpandFeatures(t *testing.T) { Name: "Empty Block", Input: []interface{}{}, Expected: features.UserFeatures{ + KeyVault: features.KeyVaultFeatures{ + PurgeSoftDeleteOnDestroy: true, + RecoverSoftDeletedKeyVaults: true, + }, VirtualMachine: features.VirtualMachineFeatures{ DeleteOSDiskOnDeletion: true, }, @@ -27,7 +31,7 @@ func TestExpandFeatures(t *testing.T) { }, }, { - Name: "Complete", + Name: "Complete Enabled", Input: []interface{}{ map[string]interface{}{ "virtual_machine": []interface{}{ @@ -40,9 +44,19 @@ func TestExpandFeatures(t *testing.T) { "roll_instances_when_required": true, }, }, + "key_vault": []interface{}{ + map[string]interface{}{ + "purge_soft_delete_on_destroy": true, + "recover_soft_deleted_key_vaults": true, + }, + }, }, }, Expected: features.UserFeatures{ + KeyVault: features.KeyVaultFeatures{ + PurgeSoftDeleteOnDestroy: true, + RecoverSoftDeletedKeyVaults: true, + }, VirtualMachine: features.VirtualMachineFeatures{ DeleteOSDiskOnDeletion: true, }, @@ -51,6 +65,41 @@ func TestExpandFeatures(t *testing.T) { }, }, }, + { + Name: "Complete Disabled", + Input: []interface{}{ + map[string]interface{}{ + "virtual_machine": []interface{}{ + map[string]interface{}{ + "delete_os_disk_on_deletion": false, + }, + }, + "virtual_machine_scale_set": []interface{}{ + map[string]interface{}{ + "roll_instances_when_required": false, + }, + }, + "key_vault": []interface{}{ + map[string]interface{}{ + "purge_soft_delete_on_destroy": false, + "recover_soft_deleted_key_vaults": false, + }, + }, + }, + }, + Expected: features.UserFeatures{ + KeyVault: features.KeyVaultFeatures{ + PurgeSoftDeleteOnDestroy: false, + RecoverSoftDeletedKeyVaults: false, + }, + VirtualMachine: features.VirtualMachineFeatures{ + DeleteOSDiskOnDeletion: false, + }, + VirtualMachineScaleSet: features.VirtualMachineScaleSetFeatures{ + RollInstancesWhenRequired: false, + }, + }, + }, } for _, testCase := range testData { @@ -62,6 +111,76 @@ func TestExpandFeatures(t *testing.T) { } } +func TestExpandFeaturesKeyVault(t *testing.T) { + testData := []struct { + Name string + Input []interface{} + EnvVars map[string]interface{} + Expected features.UserFeatures + }{ + { + Name: "Empty Block", + Input: []interface{}{ + map[string]interface{}{ + "key_vault": []interface{}{}, + }, + }, + Expected: features.UserFeatures{ + KeyVault: features.KeyVaultFeatures{ + PurgeSoftDeleteOnDestroy: true, + RecoverSoftDeletedKeyVaults: true, + }, + }, + }, + { + Name: "Purge Soft Delete On Destroy and Recover Soft Deleted Key Vaults Enabled", + Input: []interface{}{ + map[string]interface{}{ + "key_vault": []interface{}{ + map[string]interface{}{ + "purge_soft_delete_on_destroy": true, + "recover_soft_deleted_key_vaults": true, + }, + }, + }, + }, + Expected: features.UserFeatures{ + KeyVault: features.KeyVaultFeatures{ + PurgeSoftDeleteOnDestroy: true, + RecoverSoftDeletedKeyVaults: true, + }, + }, + }, + { + Name: "Purge Soft Delete On Destroy and Recover Soft Deleted Key Vaults Disabled", + Input: []interface{}{ + map[string]interface{}{ + "key_vault": []interface{}{ + map[string]interface{}{ + "purge_soft_delete_on_destroy": false, + "recover_soft_deleted_key_vaults": false, + }, + }, + }, + }, + Expected: features.UserFeatures{ + KeyVault: features.KeyVaultFeatures{ + PurgeSoftDeleteOnDestroy: false, + RecoverSoftDeletedKeyVaults: false, + }, + }, + }, + } + + for _, testCase := range testData { + t.Logf("[DEBUG] Test Case: %q", testCase.Name) + result := expandFeatures(testCase.Input) + if !reflect.DeepEqual(result.KeyVault, testCase.Expected.KeyVault) { + t.Fatalf("Expected %+v but got %+v", result.KeyVault, testCase.Expected.KeyVault) + } + } +} + func TestExpandFeaturesVirtualMachine(t *testing.T) { testData := []struct { Name string diff --git a/azurerm/internal/provider/provider.go b/azurerm/internal/provider/provider.go index 275bd38598dea..c99cf79247ed8 100644 --- a/azurerm/internal/provider/provider.go +++ b/azurerm/internal/provider/provider.go @@ -15,6 +15,14 @@ import ( ) func AzureProvider() terraform.ResourceProvider { + return azureProvider(false) +} + +func TestAzureProvider() terraform.ResourceProvider { + return azureProvider(true) +} + +func azureProvider(supportLegacyTestSuite bool) terraform.ResourceProvider { // avoids this showing up in test output var debugLog = func(f string, v ...interface{}) { if os.Getenv("TF_LOG") == "" { @@ -136,10 +144,9 @@ func AzureProvider() terraform.ResourceProvider { }, "disable_correlation_request_id": { - Type: schema.TypeBool, - Optional: true, - // TODO: add an ARM_ prefix in 2.0w - DefaultFunc: schema.EnvDefaultFunc("DISABLE_CORRELATION_REQUEST_ID", false), + Type: schema.TypeBool, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("ARM_DISABLE_CORRELATION_REQUEST_ID", false), Description: "This will disable the x-ms-correlation-request-id header.", }, @@ -150,7 +157,7 @@ func AzureProvider() terraform.ResourceProvider { Description: "This will disable the Terraform Partner ID which is used if a custom `partner_id` isn't specified.", }, - "features": schemaFeatures(), + "features": schemaFeatures(supportLegacyTestSuite), // Advanced feature flags "skip_credentials_validation": { diff --git a/azurerm/internal/provider/provider_test.go b/azurerm/internal/provider/provider_test.go index d41e663cfa3ac..1e5a2d37844cb 100644 --- a/azurerm/internal/provider/provider_test.go +++ b/azurerm/internal/provider/provider_test.go @@ -2,23 +2,19 @@ package provider import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func TestProvider(t *testing.T) { - if err := AzureProvider().(*schema.Provider).InternalValidate(); err != nil { + if err := TestAzureProvider().(*schema.Provider).InternalValidate(); err != nil { t.Fatalf("err: %s", err) } } func TestDataSourcesSupportCustomTimeouts(t *testing.T) { - // this is required until 2.0 - os.Setenv("ARM_PROVIDER_CUSTOM_TIMEOUTS", "true") - - provider := AzureProvider().(*schema.Provider) + provider := TestAzureProvider().(*schema.Provider) for dataSourceName, dataSource := range provider.DataSourcesMap { t.Run(fmt.Sprintf("DataSource/%s", dataSourceName), func(t *testing.T) { t.Logf("[DEBUG] Testing Data Source %q..", dataSourceName) @@ -54,10 +50,7 @@ func TestDataSourcesSupportCustomTimeouts(t *testing.T) { } func TestResourcesSupportCustomTimeouts(t *testing.T) { - // this is required until 2.0 - os.Setenv("ARM_PROVIDER_CUSTOM_TIMEOUTS", "true") - - provider := AzureProvider().(*schema.Provider) + provider := TestAzureProvider().(*schema.Provider) for resourceName, resource := range provider.ResourcesMap { t.Run(fmt.Sprintf("Resource/%s", resourceName), func(t *testing.T) { t.Logf("[DEBUG] Testing Resource %q..", resourceName) diff --git a/azurerm/internal/provider/required_resource_providers.go b/azurerm/internal/provider/required_resource_providers.go index 652dcb2dbd383..71e51fd0aaad3 100644 --- a/azurerm/internal/provider/required_resource_providers.go +++ b/azurerm/internal/provider/required_resource_providers.go @@ -30,6 +30,7 @@ func RequiredResourceProviders() map[string]struct{} { "Microsoft.Databricks": {}, "Microsoft.DataLakeAnalytics": {}, "Microsoft.DataLakeStore": {}, + "Microsoft.DataMigration": {}, "Microsoft.DBforMySQL": {}, "Microsoft.DBforPostgreSQL": {}, "Microsoft.Devices": {}, @@ -62,6 +63,7 @@ func RequiredResourceProviders() map[string]struct{} { "Microsoft.ServiceFabric": {}, "Microsoft.Sql": {}, "Microsoft.Storage": {}, + "Microsoft.StorageCache": {}, "Microsoft.StreamAnalytics": {}, "Microsoft.Web": {}, } diff --git a/azurerm/internal/provider/services.go b/azurerm/internal/provider/services.go index 0006ecf98b830..2414de7030e13 100644 --- a/azurerm/internal/provider/services.go +++ b/azurerm/internal/provider/services.go @@ -15,6 +15,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datalake" @@ -26,6 +27,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/frontdoor" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/hdinsight" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/healthcare" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iotcentral" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/kusto" @@ -35,6 +37,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/maps" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mariadb" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/media" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mixedreality" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/monitor" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/msi" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mssql" @@ -63,6 +66,8 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web" ) +//go:generate go run ../tools/website-categories/main.go -path=../../../website/allowed-subcategories + func SupportedServices() []common.ServiceRegistration { return []common.ServiceRegistration{ analysisservices.Registration{}, @@ -81,6 +86,7 @@ func SupportedServices() []common.ServiceRegistration { databricks.Registration{}, datafactory.Registration{}, datalake.Registration{}, + databasemigration.Registration{}, devspace.Registration{}, devtestlabs.Registration{}, dns.Registration{}, @@ -90,6 +96,7 @@ func SupportedServices() []common.ServiceRegistration { hdinsight.Registration{}, healthcare.Registration{}, iothub.Registration{}, + iotcentral.Registration{}, keyvault.Registration{}, kusto.Registration{}, loganalytics.Registration{}, @@ -98,6 +105,7 @@ func SupportedServices() []common.ServiceRegistration { maps.Registration{}, mariadb.Registration{}, media.Registration{}, + mixedreality.Registration{}, monitor.Registration{}, msi.Registration{}, mssql.Registration{}, diff --git a/azurerm/internal/services/analysisservices/registration.go b/azurerm/internal/services/analysisservices/registration.go index 0686ff1a77c99..b37fe9fbba157 100644 --- a/azurerm/internal/services/analysisservices/registration.go +++ b/azurerm/internal/services/analysisservices/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Analysis Services" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Analysis Services", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{} diff --git a/azurerm/internal/services/analysisservices/tests/analysis_services_server_resource_test.go b/azurerm/internal/services/analysisservices/tests/analysis_services_server_resource_test.go index 53686c49f569f..4fa6b04b8e39e 100644 --- a/azurerm/internal/services/analysisservices/tests/analysis_services_server_resource_test.go +++ b/azurerm/internal/services/analysisservices/tests/analysis_services_server_resource_test.go @@ -211,6 +211,10 @@ func TestAccAzureRMAnalysisServicesServer_backupBlobContainerUri(t *testing.T) { func testAccAzureRMAnalysisServicesServer_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -218,8 +222,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_analysis_services_server" "test" { name = "acctestass%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "B1" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -227,6 +231,10 @@ resource "azurerm_analysis_services_server" "test" { func testAccAzureRMAnalysisServicesServer_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -234,8 +242,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_analysis_services_server" "test" { name = "acctestass%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "B1" tags = { @@ -247,6 +255,10 @@ resource "azurerm_analysis_services_server" "test" { func testAccAzureRMAnalysisServicesServer_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -254,8 +266,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_analysis_services_server" "test" { name = "acctestass%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "B1" tags = { @@ -268,6 +280,10 @@ resource "azurerm_analysis_services_server" "test" { func testAccAzureRMAnalysisServicesServer_querypoolConnectionMode(data acceptance.TestData, connectionMode string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -275,8 +291,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_analysis_services_server" "test" { name = "acctestass%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "B1" querypool_connection_mode = "%s" } @@ -285,6 +301,10 @@ resource "azurerm_analysis_services_server" "test" { func testAccAzureRMAnalysisServicesServer_firewallSettings1(data acceptance.TestData, enablePowerBIService bool) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -292,8 +312,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_analysis_services_server" "test" { name = "acctestass%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "B1" enable_power_bi_service = %t } @@ -302,6 +322,10 @@ resource "azurerm_analysis_services_server" "test" { func testAccAzureRMAnalysisServicesServer_firewallSettings2(data acceptance.TestData, enablePowerBIService bool) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -309,8 +333,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_analysis_services_server" "test" { name = "acctestass%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "B1" enable_power_bi_service = %t @@ -325,6 +349,10 @@ resource "azurerm_analysis_services_server" "test" { func testAccAzureRMAnalysisServicesServer_firewallSettings3(data acceptance.TestData, enablePowerBIService bool) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -332,8 +360,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_analysis_services_server" "test" { name = "acctestass%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "B1" enable_power_bi_service = %t @@ -354,6 +382,10 @@ resource "azurerm_analysis_services_server" "test" { func testAccAzureRMAnalysisServicesServer_adminUsers(data acceptance.TestData, adminUsers []string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -361,8 +393,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_analysis_services_server" "test" { name = "acctestass%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "B1" admin_users = ["%s"] } @@ -371,6 +403,10 @@ resource "azurerm_analysis_services_server" "test" { func testAccAzureRMAnalysisServicesServer_serverFullName(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -378,8 +414,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_analysis_services_server" "test" { name = "acctestass%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "B1" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -387,6 +423,10 @@ resource "azurerm_analysis_services_server" "test" { func testAccAzureRMAnalysisServicesServer_backupBlobContainerUri(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -394,8 +434,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestass%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_kind = "BlobStorage" account_tier = "Standard" account_replication_type = "LRS" @@ -403,13 +443,13 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "assbackup" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } data "azurerm_storage_account_blob_container_sas" "test" { - connection_string = "${azurerm_storage_account.test.primary_connection_string}" - container_name = "${azurerm_storage_container.test.name}" + connection_string = azurerm_storage_account.test.primary_connection_string + container_name = azurerm_storage_container.test.name https_only = true start = "2018-06-01" @@ -427,8 +467,8 @@ data "azurerm_storage_account_blob_container_sas" "test" { resource "azurerm_analysis_services_server" "test" { name = "acctestass%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "B1" backup_blob_container_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}${data.azurerm_storage_account_blob_container_sas.test.sas}" diff --git a/azurerm/internal/services/apimanagement/data_source_api_management.go b/azurerm/internal/services/apimanagement/data_source_api_management.go index f482b9cc0c902..329c8d0ff5b98 100644 --- a/azurerm/internal/services/apimanagement/data_source_api_management.go +++ b/azurerm/internal/services/apimanagement/data_source_api_management.go @@ -47,24 +47,6 @@ func dataSourceApiManagementService() *schema.Resource { Computed: true, }, - // TODO: Remove in 2.0 - "sku": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "capacity": { - Type: schema.TypeInt, - Computed: true, - }, - }, - }, - }, - "sku_name": { Type: schema.TypeString, Computed: true, @@ -211,15 +193,7 @@ func dataSourceApiManagementRead(d *schema.ResourceData, meta interface{}) error } } - if sku := resp.Sku; sku != nil { - // TODO: Remove in 2.0 - if err := d.Set("sku", flattenApiManagementServiceSku(resp.Sku)); err != nil { - return fmt.Errorf("Error setting `sku`: %+v", err) - } - if err := d.Set("sku_name", flattenApiManagementServiceSkuName(resp.Sku)); err != nil { - return fmt.Errorf("Error setting `sku_name`: %+v", err) - } - } + d.Set("sku_name", flattenApiManagementServiceSkuName(resp.Sku)) return tags.FlattenAndSet(d, resp.Tags) } diff --git a/azurerm/internal/services/apimanagement/registration.go b/azurerm/internal/services/apimanagement/registration.go index 475b49493c295..40c70ea6b70d2 100644 --- a/azurerm/internal/services/apimanagement/registration.go +++ b/azurerm/internal/services/apimanagement/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "API Management" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "API Management", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management.go b/azurerm/internal/services/apimanagement/resource_arm_api_management.go index ab575fd037f21..40cdf1d62f89e 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management.go @@ -75,41 +75,9 @@ func resourceArmApiManagementService() *schema.Resource { ValidateFunc: validate.ApiManagementServicePublisherEmail, }, - // TODO: Remove in 2.0 - "sku": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Deprecated: "This property has been deprecated in favour of the 'sku_name' property and will be removed in version 2.0 of the provider", - ConflictsWith: []string{"sku_name"}, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - string(apimanagement.SkuTypeDeveloper), - string(apimanagement.SkuTypeBasic), - string(apimanagement.SkuTypeStandard), - string(apimanagement.SkuTypePremium), - }, false), - }, - - "capacity": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntAtLeast(0), - }, - }, - }, - }, - "sku_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, // TODO: Remove computed in 2.0 - ConflictsWith: []string{"sku"}, + Type: schema.TypeString, + Required: true, ValidateFunc: azure.MinCapacitySkuNameInSlice([]string{ string(apimanagement.SkuTypeDeveloper), string(apimanagement.SkuTypeBasic), @@ -231,7 +199,7 @@ func resourceArmApiManagementService() *schema.Resource { "protocols": { Type: schema.TypeList, Optional: true, - Computed: true, // TODO: remove in 2.0 + Computed: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -247,115 +215,48 @@ func resourceArmApiManagementService() *schema.Resource { "security": { Type: schema.TypeList, Optional: true, - Computed: true, // TODO: Remove in 2.0 ? + Computed: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "enable_backend_ssl30": { - Type: schema.TypeBool, - Optional: true, - Computed: true, // TODO: Remove in 2.0 - ConflictsWith: []string{"security.0.disable_backend_ssl30"}, + Type: schema.TypeBool, + Optional: true, + Default: false, }, "enable_backend_tls10": { - Type: schema.TypeBool, - Optional: true, - Computed: true, // TODO: Remove in 2.0 - ConflictsWith: []string{"security.0.disable_backend_tls10"}, + Type: schema.TypeBool, + Optional: true, + Default: false, }, "enable_backend_tls11": { - Type: schema.TypeBool, - Optional: true, - Computed: true, // TODO: Remove in 2.0 - ConflictsWith: []string{"security.0.disable_backend_tls11"}, + Type: schema.TypeBool, + Optional: true, + Default: false, }, "enable_frontend_ssl30": { - Type: schema.TypeBool, - Optional: true, - Computed: true, // TODO: Remove in 2.0 - ConflictsWith: []string{"security.0.disable_frontend_ssl30"}, + Type: schema.TypeBool, + Optional: true, + Default: false, }, "enable_frontend_tls10": { - Type: schema.TypeBool, - Optional: true, - Computed: true, // TODO: Remove in 2.0 - ConflictsWith: []string{"security.0.disable_frontend_tls10"}, + Type: schema.TypeBool, + Optional: true, + Default: false, }, "enable_frontend_tls11": { - Type: schema.TypeBool, - Optional: true, - Computed: true, // TODO: Remove in 2.0 - ConflictsWith: []string{"security.0.disable_frontend_tls11"}, + Type: schema.TypeBool, + Optional: true, + Default: false, }, "enable_triple_des_ciphers": { - Type: schema.TypeBool, - Optional: true, - Computed: true, // TODO: Remove in 2.0 - ConflictsWith: []string{"security.0.disable_triple_des_chipers", "security.0.disable_triple_des_ciphers"}, - }, - - //the follow have all been replaced by the `enable` flags - "disable_backend_ssl30": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - ConflictsWith: []string{"security.0.enable_backend_ssl30"}, - Deprecated: "This field has been deprecated in favour of the `enable_backend_ssl30` which correctly reflects the boolean value. it will be removed in version 2.0 of the provider", - }, - "disable_backend_tls10": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - ConflictsWith: []string{"security.0.enable_backend_tls10"}, - Deprecated: "This field has been deprecated in favour of the `enable_backend_tls10` which correctly reflects the boolean value. it will be removed in version 2.0 of the provider", - }, - "disable_backend_tls11": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - ConflictsWith: []string{"security.0.enable_backend_tls11"}, - Deprecated: "This field has been deprecated in favour of the `enable_backend_tls11` which correctly reflects the boolean value. it will be removed in version 2.0 of the provider", - }, - "disable_frontend_ssl30": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - ConflictsWith: []string{"security.0.enable_frontend_ssl30"}, - Deprecated: "This field has been deprecated in favour of the `enable_frontend_ssl30` which correctly reflects the boolean value. it will be removed in version 2.0 of the provider", - }, - "disable_frontend_tls10": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - ConflictsWith: []string{"security.0.enable_frontend_tls10"}, - Deprecated: "This field has been deprecated in favour of the `enable_frontend_tls10` which correctly reflects the boolean value. it will be removed in version 2.0 of the provider", - }, - "disable_frontend_tls11": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - ConflictsWith: []string{"security.0.enable_frontend_tls11"}, - Deprecated: "This field has been deprecated in favour of the `enable_frontend_tls11` which correctly reflects the boolean value. it will be removed in version 2.0 of the provider", - }, - "disable_triple_des_chipers": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - Deprecated: "This field has been deprecated in favour of the `disable_triple_des_ciphers` property to correct the spelling. it will be removed in version 2.0 of the provider", - ConflictsWith: []string{"security.0.disable_triple_des_ciphers"}, - }, - "disable_triple_des_ciphers": { Type: schema.TypeBool, Optional: true, - // Default: false, // TODO: Remove in 2.0 - Computed: true, // TODO: Remove in 2.0 - ConflictsWith: []string{"security.0.enable_triple_des_ciphers"}, - Deprecated: "This field has been deprecated in favour of the `enable_triple_des_ciphers` which correctly reflects the boolean value. it will be removed in version 2.0 of the provider", + Default: false, }, }, }, @@ -512,13 +413,7 @@ func resourceArmApiManagementServiceCreateUpdate(d *schema.ResourceData, meta in ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - // TODO: Remove in 2.0 - sku := expandAzureRmApiManagementSku(d) - if sku == nil { - if sku = expandAzureRmApiManagementSkuName(d); sku == nil { - return fmt.Errorf("either 'sku_name' or 'sku' must be defined in the configuration file") - } - } + sku := expandAzureRmApiManagementSkuName(d) log.Printf("[INFO] preparing arguments for API Management Service creation.") @@ -738,14 +633,8 @@ func resourceArmApiManagementServiceRead(d *schema.ResourceData, meta interface{ } } - if sku := resp.Sku; sku != nil { - // TODO: Remove in 2.0 - if err := d.Set("sku", flattenApiManagementServiceSku(resp.Sku)); err != nil { - return fmt.Errorf("Error setting `sku`: %+v", err) - } - if err := d.Set("sku_name", flattenApiManagementServiceSkuName(resp.Sku)); err != nil { - return fmt.Errorf("Error setting `sku_name`: %+v", err) - } + if err := d.Set("sku_name", flattenApiManagementServiceSkuName(resp.Sku)); err != nil { + return fmt.Errorf("Error setting `sku_name`: %+v", err) } if err := d.Set("sign_in", flattenApiManagementSignInSettings(signInSettings)); err != nil { @@ -1030,29 +919,6 @@ func flattenAzureRmApiManagementMachineIdentity(identity *apimanagement.ServiceI return []interface{}{result} } -// TODO: Remove in 2.0 timeframe -func expandAzureRmApiManagementSku(d *schema.ResourceData) *apimanagement.ServiceSkuProperties { - var name string - var capacity int32 - - vs := d.Get("sku").([]interface{}) - - if len(vs) == 0 { - return nil - } - - // guaranteed by MinItems in the schema - v := vs[0].(map[string]interface{}) - - name = v["name"].(string) - capacity = int32(v["capacity"].(int)) - - return &apimanagement.ServiceSkuProperties{ - Name: apimanagement.SkuType(name), - Capacity: utils.Int32(capacity), - } -} - func expandAzureRmApiManagementSkuName(d *schema.ResourceData) *apimanagement.ServiceSkuProperties { vs := d.Get("sku_name").(string) @@ -1079,21 +945,6 @@ func flattenApiManagementServiceSkuName(input *apimanagement.ServiceSkuPropertie return fmt.Sprintf("%s_%d", string(input.Name), *input.Capacity) } -func flattenApiManagementServiceSku(input *apimanagement.ServiceSkuProperties) []interface{} { - if input == nil { - return []interface{}{} - } - - sku := make(map[string]interface{}) - - sku["name"] = string(input.Name) - if input.Capacity != nil { - sku["capacity"] = *input.Capacity - } - - return []interface{}{sku} -} - func expandApiManagementCustomProperties(d *schema.ResourceData) map[string]*string { backendProtocolSsl3 := false backendProtocolTls10 := false @@ -1103,61 +954,15 @@ func expandApiManagementCustomProperties(d *schema.ResourceData) map[string]*str frontendProtocolTls11 := false tripleDesCiphers := false - //if vs := d.Get("security").([]interface{}); len(vs) > 0 { - //v := vs[0].(map[string]interface{}) - // restore these in 2.0 - // backendProtocolSsl3 = v["enable_backend_ssl30"].(bool) - // backendProtocolTls10 = v["enable_backend_tls10"].(bool) - // backendProtocolTls11 = v["enable_backend_tls11"].(bool) - // frontendProtocolSsl3 = v["enable_frontend_ssl30"].(bool) - // frontendProtocolTls10 = v["enable_frontend_tls10"].(bool) - // frontendProtocolTls11 = v["enable_frontend_tls11"].(bool) - // tripleDesCiphers = v["enable_triple_des_ciphers"].(bool) - //} - - // remove all these for 2.0 - if c, ok := d.GetOkExists("security.0.enable_triple_des_ciphers"); ok { - tripleDesCiphers = c.(bool) - } else if c, ok := d.GetOkExists("security.0.disable_triple_des_ciphers"); ok { - tripleDesCiphers = c.(bool) - } else if c, ok := d.GetOkExists("security.0.disable_triple_des_chipers"); ok { - tripleDesCiphers = c.(bool) - } - - if c, ok := d.GetOkExists("security.0.enable_frontend_tls11"); ok { - frontendProtocolTls11 = c.(bool) - } else if c, ok := d.GetOkExists("security.0.disable_frontend_tls11"); ok { - frontendProtocolTls11 = c.(bool) - } - - if c, ok := d.GetOkExists("security.0.enable_frontend_tls10"); ok { - frontendProtocolTls10 = c.(bool) - } else if c, ok := d.GetOkExists("security.0.disable_frontend_tls10"); ok { - frontendProtocolTls10 = c.(bool) - } - - if c, ok := d.GetOkExists("security.0.enable_frontend_ssl30"); ok { - frontendProtocolSsl3 = c.(bool) - } else if c, ok := d.GetOkExists("security.0.disable_frontend_ssl30"); ok { - frontendProtocolSsl3 = c.(bool) - } - - if c, ok := d.GetOkExists("security.0.enable_backend_tls11"); ok { - backendProtocolTls11 = c.(bool) - } else if c, ok := d.GetOkExists("security.0.disable_backend_ssl30"); ok { - backendProtocolTls11 = c.(bool) - } - - if c, ok := d.GetOkExists("security.0.enable_backend_tls10"); ok { - backendProtocolTls10 = c.(bool) - } else if c, ok := d.GetOkExists("security.0.disable_backend_tls10"); ok { - backendProtocolTls10 = c.(bool) - } - - if c, ok := d.GetOkExists("security.0.enable_backend_ssl30"); ok { - backendProtocolSsl3 = c.(bool) - } else if c, ok := d.GetOkExists("security.0.disable_backend_ssl30"); ok { - backendProtocolSsl3 = c.(bool) + if vs := d.Get("security").([]interface{}); len(vs) > 0 { + v := vs[0].(map[string]interface{}) + backendProtocolSsl3 = v["enable_backend_ssl30"].(bool) + backendProtocolTls10 = v["enable_backend_tls10"].(bool) + backendProtocolTls11 = v["enable_backend_tls11"].(bool) + frontendProtocolSsl3 = v["enable_frontend_ssl30"].(bool) + frontendProtocolTls10 = v["enable_frontend_tls10"].(bool) + frontendProtocolTls11 = v["enable_frontend_tls11"].(bool) + tripleDesCiphers = v["enable_triple_des_ciphers"].(bool) } customProperties := map[string]*string{ @@ -1204,15 +1009,6 @@ func flattenApiManagementSecurityCustomProperties(input map[string]*string) []in output["enable_frontend_tls11"] = parseApiManagementNilableDictionary(input, apimFrontendProtocolTls11) output["enable_triple_des_ciphers"] = parseApiManagementNilableDictionary(input, apimTripleDesCiphers) - output["disable_backend_ssl30"] = parseApiManagementNilableDictionary(input, apimBackendProtocolSsl3) // TODO: Remove in 2.0 - output["disable_backend_tls10"] = parseApiManagementNilableDictionary(input, apimBackendProtocolTls10) // TODO: Remove in 2.0 - output["disable_backend_tls11"] = parseApiManagementNilableDictionary(input, apimBackendProtocolTls11) // TODO: Remove in 2.0 - output["disable_frontend_ssl30"] = parseApiManagementNilableDictionary(input, apimFrontendProtocolSsl3) // TODO: Remove in 2.0 - output["disable_frontend_tls10"] = parseApiManagementNilableDictionary(input, apimFrontendProtocolTls10) // TODO: Remove in 2.0 - output["disable_frontend_tls11"] = parseApiManagementNilableDictionary(input, apimFrontendProtocolTls11) // TODO: Remove in 2.0 - output["disable_triple_des_chipers"] = parseApiManagementNilableDictionary(input, apimTripleDesCiphers) // TODO: Remove in 2.0 - output["disable_triple_des_ciphers"] = parseApiManagementNilableDictionary(input, apimTripleDesCiphers) // TODO: Remove in 2.0 - return []interface{}{output} } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation.go index e4fd0bfb28081..8bb615228573c 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation.go @@ -8,7 +8,9 @@ import ( "github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -117,6 +119,19 @@ func resourceArmApiManagementApiOperationCreateUpdate(d *schema.ResourceData, me apiId := d.Get("api_name").(string) operationId := d.Get("operation_id").(string) + if features.ShouldResourcesBeImported() && d.IsNewResource() { + existing, err := client.Get(ctx, resourceGroup, serviceName, apiId, operationId) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing Operation %q (API %q / API Management Service %q / Resource Group %q): %s", operationId, apiId, serviceName, resourceGroup, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_api_management_api_operation", *existing.ID) + } + } + description := d.Get("description").(string) displayName := d.Get("display_name").(string) method := d.Get("method").(string) diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_identity_provider_aad.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_identity_provider_aad.go index 75879270f7f28..3cd60f701a13d 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_identity_provider_aad.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_identity_provider_aad.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -42,7 +41,7 @@ func resourceArmApiManagementIdentityProviderAAD() *schema.Resource { "client_id": { Type: schema.TypeString, Required: true, - ValidateFunc: validate.GUID, + ValidateFunc: validation.IsUUID, }, "client_secret": { @@ -57,7 +56,7 @@ func resourceArmApiManagementIdentityProviderAAD() *schema.Resource { Required: true, Elem: &schema.Schema{ Type: schema.TypeString, - ValidateFunc: validate.GUID, + ValidateFunc: validation.IsUUID, }, }, }, diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_identity_provider_microsoft.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_identity_provider_microsoft.go index f9effe135c332..b8498d0d456e7 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_identity_provider_microsoft.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_identity_provider_microsoft.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -42,7 +41,7 @@ func resourceArmApiManagementIdentityProviderMicrosoft() *schema.Resource { "client_id": { Type: schema.TypeString, Required: true, - ValidateFunc: validate.GUID, + ValidateFunc: validation.IsUUID, }, "client_secret": { diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_product_group.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_group.go index 22a1398578b0e..d8ef73d3181fd 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_product_group.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_group.go @@ -62,7 +62,7 @@ func resourceArmApiManagementProductGroupCreate(d *schema.ResourceData, meta int if !utils.ResponseWasNotFound(resp) { subscriptionId := meta.(*clients.Client).Account.SubscriptionId - resourceId := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s/groups/%s", subscriptionId, resourceGroup, serviceName, groupName, productId) + resourceId := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/products/%s/groups/%s", subscriptionId, resourceGroup, serviceName, productId, groupName) return tf.ImportAsExistsError("azurerm_api_management_product_group", resourceId) } } diff --git a/azurerm/internal/services/apimanagement/tests/data_source_api_management_api_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_api_test.go index d08c94c5f9755..a1b8aa4b16022 100644 --- a/azurerm/internal/services/apimanagement/tests/data_source_api_management_api_test.go +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_api_test.go @@ -63,10 +63,10 @@ func testAccDataSourceApiManagementApi_basic(data acceptance.TestData) string { %s data "azurerm_api_management_api" "test" { - name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management_api.test.api_management_name}" - resource_group_name = "${azurerm_api_management_api.test.resource_group_name}" - revision = "${azurerm_api_management_api.test.revision}" + name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management_api.test.api_management_name + resource_group_name = azurerm_api_management_api.test.resource_group_name + revision = azurerm_api_management_api.test.revision } `, template) } @@ -77,10 +77,10 @@ func testAccDataSourceApiManagementApi_complete(data acceptance.TestData) string %s data "azurerm_api_management_api" "test" { - name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management_api.test.api_management_name}" - resource_group_name = "${azurerm_api_management_api.test.resource_group_name}" - revision = "${azurerm_api_management_api.test.revision}" + name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management_api.test.api_management_name + resource_group_name = azurerm_api_management_api.test.resource_group_name + revision = azurerm_api_management_api.test.revision } `, template) } diff --git a/azurerm/internal/services/apimanagement/tests/data_source_api_management_api_version_set_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_api_version_set_test.go index 2c5005bfda88f..b5ed626b090a7 100644 --- a/azurerm/internal/services/apimanagement/tests/data_source_api_management_api_version_set_test.go +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_api_version_set_test.go @@ -33,9 +33,9 @@ func testAccDataSourceApiManagementApiVersionSet_basic(data acceptance.TestData) %s data "azurerm_api_management_api_version_set" "test" { - name = "${azurerm_api_management_api_version_set.test.name}" - resource_group_name = "${azurerm_api_management_api_version_set.test.resource_group_name}" - api_management_name = "${azurerm_api_management_api_version_set.test.api_management_name}" + name = azurerm_api_management_api_version_set.test.name + resource_group_name = azurerm_api_management_api_version_set.test.resource_group_name + api_management_name = azurerm_api_management_api_version_set.test.api_management_name } `, config) } diff --git a/azurerm/internal/services/apimanagement/tests/data_source_api_management_group_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_group_test.go index a5b18026b829f..376eae63d1df1 100644 --- a/azurerm/internal/services/apimanagement/tests/data_source_api_management_group_test.go +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_group_test.go @@ -30,6 +30,10 @@ func TestAccDataSourceAzureRMApiManagementGroup_basic(t *testing.T) { func testAccDataSourceApiManagementGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -37,28 +41,24 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } resource "azurerm_api_management_group" "test" { name = "acctestAMGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "Test Group" } data "azurerm_api_management_group" "test" { - name = "${azurerm_api_management_group.test.name}" - api_management_name = "${azurerm_api_management_group.test.api_management_name}" - resource_group_name = "${azurerm_api_management_group.test.resource_group_name}" + name = azurerm_api_management_group.test.name + api_management_name = azurerm_api_management_group.test.api_management_name + resource_group_name = azurerm_api_management_group.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/tests/data_source_api_management_product_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_product_test.go index 4c6ae3ae60170..ad89dbed8310f 100644 --- a/azurerm/internal/services/apimanagement/tests/data_source_api_management_product_test.go +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_product_test.go @@ -33,29 +33,28 @@ func TestAccDataSourceAzureRMApiManagementProduct_basic(t *testing.T) { func testAccDataSourceApiManagementProduct_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "amtestRG-%d" location = "%s" } resource "azurerm_api_management" "test" { - name = "acctestAM-%d" - publisher_name = "pub1" - publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } - - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "acctestAM-%d" + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Developer_1" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_api_management_product" "test" { product_id = "test-product" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Test Product" subscription_required = true approval_required = true @@ -66,9 +65,9 @@ resource "azurerm_api_management_product" "test" { } data "azurerm_api_management_product" "test" { - product_id = "${azurerm_api_management_product.test.product_id}" - api_management_name = "${azurerm_api_management_product.test.api_management_name}" - resource_group_name = "${azurerm_api_management_product.test.resource_group_name}" + product_id = azurerm_api_management_product.test.product_id + api_management_name = azurerm_api_management_product.test.api_management_name + resource_group_name = azurerm_api_management_product.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/tests/data_source_api_management_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_test.go index 0efd692c1e068..013ecddd5f3ff 100644 --- a/azurerm/internal/services/apimanagement/tests/data_source_api_management_test.go +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_test.go @@ -33,28 +33,27 @@ func TestAccDataSourceAzureRMApiManagement_basic(t *testing.T) { func testAccDataSourceApiManagement_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "amtestRG-%d" location = "%s" } resource "azurerm_api_management" "test" { - name = "acctestAM-%d" - publisher_name = "pub1" - publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } - - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "acctestAM-%d" + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Developer_1" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } data "azurerm_api_management" "test" { - name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_api_management.test.resource_group_name}" + name = azurerm_api_management.test.name + resource_group_name = azurerm_api_management.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go index d418a69cc6f53..3432d3b70f637 100644 --- a/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go @@ -32,29 +32,28 @@ func TestAccDataSourceAzureRMApiManagementUser_basic(t *testing.T) { func testAccDataSourceApiManagementUser_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "amtestRG-%d" location = "%s" } resource "azurerm_api_management" "test" { - name = "acctestAM-%d" - publisher_name = "pub1" - publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } - - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "acctestAM-%d" + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Developer_1" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_api_management_user" "test" { user_id = "test-user" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name first_name = "Acceptance" last_name = "Test" email = "azure-acctest%d@example.com" @@ -63,9 +62,9 @@ resource "azurerm_api_management_user" "test" { } data "azurerm_api_management_user" "test" { - user_id = "${azurerm_api_management_user.test.user_id}" - api_management_name = "${azurerm_api_management_user.test.api_management_name}" - resource_group_name = "${azurerm_api_management_user.test.resource_group_name}" + user_id = azurerm_api_management_user.test.user_id + api_management_name = azurerm_api_management_user.test.api_management_name + resource_group_name = azurerm_api_management_user.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_policy_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_policy_test.go index f2a6b6ecb6056..9743d0aed9ae9 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_policy_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_policy_test.go @@ -154,10 +154,10 @@ func testAccAzureRMApiManagementAPIOperationPolicy_basic(data acceptance.TestDat %s resource "azurerm_api_management_api_operation_policy" "test" { - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - operation_id = "${azurerm_api_management_api_operation.test.operation_id}" + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name + operation_id = azurerm_api_management_api_operation.test.operation_id xml_link = "https://gist.githubusercontent.com/riordanp/ca22f8113afae0eb38cc12d718fd048d/raw/d6ac89a2f35a6881a7729f8cb4883179dc88eea1/example.xml" } `, template) @@ -169,11 +169,11 @@ func testAccAzureRMApiManagementAPIOperationPolicy_requiresImport(data acceptanc %s resource "azurerm_api_management_api_operation_policy" "import" { - api_name = "${azurerm_api_management_api_policy.test.api_name}" - api_management_name = "${azurerm_api_management_api_policy.test.api_management_name}" - resource_group_name = "${azurerm_api_management_api_policy.test.resource_group_name}" - operation_id = "${azurerm_api_management_api_operation.test.operation_id}" - xml_link = "${azurerm_api_management_api_policy.test.xml_link}" + api_name = azurerm_api_management_api_policy.test.api_name + api_management_name = azurerm_api_management_api_policy.test.api_management_name + resource_group_name = azurerm_api_management_api_policy.test.resource_group_name + operation_id = azurerm_api_management_api_operation.test.operation_id + xml_link = azurerm_api_management_api_policy.test.xml_link } `, template) } @@ -184,10 +184,10 @@ func testAccAzureRMApiManagementAPIOperationPolicy_updated(data acceptance.TestD %s resource "azurerm_api_management_api_operation_policy" "test" { - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - operation_id = "${azurerm_api_management_api_operation.test.operation_id}" + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name + operation_id = azurerm_api_management_api_operation.test.operation_id xml_content = < @@ -197,6 +197,7 @@ resource "azurerm_api_management_api_operation_policy" "test" { XML + } `, template) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_test.go index dfbda05bd8862..bd1e3adf3c1d6 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_test.go @@ -211,9 +211,9 @@ func testAccAzureRMApiManagementApiOperation_basic(data acceptance.TestData) str resource "azurerm_api_management_api_operation" "test" { operation_id = "acctest-operation" - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "DELETE Resource" method = "DELETE" url_template = "/resource" @@ -228,9 +228,9 @@ func testAccAzureRMApiManagementApiOperation_customMethod(data acceptance.TestDa resource "azurerm_api_management_api_operation" "test" { operation_id = "acctest-operation" - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "HAMMERTIME Resource" method = "HAMMERTIME" url_template = "/resource" @@ -239,18 +239,18 @@ resource "azurerm_api_management_api_operation" "test" { } func testAccAzureRMApiManagementApiOperation_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMApiManagementApiOperation_template(data) + template := testAccAzureRMApiManagementApiOperation_basic(data) return fmt.Sprintf(` %s resource "azurerm_api_management_api_operation" "import" { - operation_id = "${azurerm_api_management_api_operation.test.operation_id}" - api_name = "${azurerm_api_management_api_operation.test.api_name}" - api_management_name = "${azurerm_api_management_api_operation.test.api_management_name}" - resource_group_name = "${azurerm_api_management_api_operation.test.resource_group_name}" - display_name = "${azurerm_api_management_api_operation.test.display_name}" - method = "${azurerm_api_management_api_operation.test.method}" - url_template = "${azurerm_api_management_api_operation.test.url_template}" + operation_id = azurerm_api_management_api_operation.test.operation_id + api_name = azurerm_api_management_api_operation.test.api_name + api_management_name = azurerm_api_management_api_operation.test.api_management_name + resource_group_name = azurerm_api_management_api_operation.test.resource_group_name + display_name = azurerm_api_management_api_operation.test.display_name + method = azurerm_api_management_api_operation.test.method + url_template = azurerm_api_management_api_operation.test.url_template } `, template) } @@ -262,9 +262,9 @@ func testAccAzureRMApiManagementApiOperation_requestRepresentation(data acceptan resource "azurerm_api_management_api_operation" "test" { operation_id = "acctest-operation" - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Acceptance Test Operation" method = "DELETE" url_template = "/user1" @@ -289,9 +289,9 @@ func testAccAzureRMApiManagementApiOperation_requestRepresentationUpdated(data a resource "azurerm_api_management_api_operation" "test" { operation_id = "acctest-operation" - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Acceptance Test Operation" method = "DELETE" url_template = "/user1" @@ -316,9 +316,9 @@ func testAccAzureRMApiManagementApiOperation_headers(data acceptance.TestData) s resource "azurerm_api_management_api_operation" "test" { operation_id = "acctest-operation" - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Acceptance Test Operation" method = "DELETE" url_template = "/user1" @@ -362,6 +362,7 @@ resource "azurerm_api_management_api_operation" "test" { SAMPLE + } } } @@ -375,9 +376,9 @@ func testAccAzureRMApiManagementApiOperation_representation(data acceptance.Test resource "azurerm_api_management_api_operation" "test" { operation_id = "acctest-operation" - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Acceptance Test Operation" method = "DELETE" url_template = "/user1" @@ -409,6 +410,7 @@ resource "azurerm_api_management_api_operation" "test" { SAMPLE + } } } @@ -422,9 +424,9 @@ func testAccAzureRMApiManagementApiOperation_representationUpdated(data acceptan resource "azurerm_api_management_api_operation" "test" { operation_id = "acctest-operation" - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Acceptance Test Operation" method = "DELETE" url_template = "/user1" @@ -456,6 +458,7 @@ resource "azurerm_api_management_api_operation" "test" { SAMPLE + } representation { @@ -477,6 +480,7 @@ SAMPLE } } SAMPLE + } } } @@ -485,6 +489,10 @@ SAMPLE func testAccAzureRMApiManagementApiOperation_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -492,21 +500,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "Butter Parser" path = "butter-parser" protocols = ["https", "http"] diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_policy_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_policy_test.go index 01f78f6b64255..84d83a1d33e31 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_policy_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_policy_test.go @@ -171,6 +171,10 @@ func testCheckAzureRMApiManagementAPIPolicyDestroy(s *terraform.State) error { func testAccAzureRMApiManagementAPIPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -178,21 +182,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "api1" path = "api1" protocols = ["https"] @@ -200,9 +200,9 @@ resource "azurerm_api_management_api" "test" { } resource "azurerm_api_management_api_policy" "test" { - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name xml_link = "https://gist.githubusercontent.com/riordanp/ca22f8113afae0eb38cc12d718fd048d/raw/d6ac89a2f35a6881a7729f8cb4883179dc88eea1/example.xml" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) @@ -214,16 +214,20 @@ func testAccAzureRMApiManagementAPIPolicy_requiresImport(data acceptance.TestDat %s resource "azurerm_api_management_api_policy" "import" { - api_name = "${azurerm_api_management_api_policy.test.api_name}" - api_management_name = "${azurerm_api_management_api_policy.test.api_management_name}" - resource_group_name = "${azurerm_api_management_api_policy.test.resource_group_name}" - xml_link = "${azurerm_api_management_api_policy.test.xml_link}" + api_name = azurerm_api_management_api_policy.test.api_name + api_management_name = azurerm_api_management_api_policy.test.api_management_name + resource_group_name = azurerm_api_management_api_policy.test.resource_group_name + xml_link = azurerm_api_management_api_policy.test.xml_link } `, template) } func testAccAzureRMApiManagementAPIPolicy_customPolicy(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -231,21 +235,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "api1" path = "api1" protocols = ["https"] @@ -253,9 +253,9 @@ resource "azurerm_api_management_api" "test" { } resource "azurerm_api_management_api_policy" "test" { - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name xml_content = < @@ -265,6 +265,7 @@ resource "azurerm_api_management_api_policy" "test" { XML + } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_schema_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_schema_test.go index 019fd65bb06b5..060951c3d6853 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_schema_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_schema_test.go @@ -118,34 +118,38 @@ func testAccAzureRMApiManagementApiSchema_basic(data acceptance.TestData) string %s resource "azurerm_api_management_api_schema" "test" { - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management_api.test.api_management_name}" - resource_group_name = "${azurerm_api_management_api.test.resource_group_name}" + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management_api.test.api_management_name + resource_group_name = azurerm_api_management_api.test.resource_group_name schema_id = "acctestSchema%d" content_type = "application/vnd.ms-azure-apim.xsd+xml" - value = "${file("testdata/api_management_api_schema.xml")}" + value = file("testdata/api_management_api_schema.xml") } `, template, data.RandomInteger) } func testAccAzureRMApiManagementApiSchema_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMApiManagementApiSchema_template(data) + template := testAccAzureRMApiManagementApiSchema_basic(data) return fmt.Sprintf(` %s -resource "azurerm_api_management_api_schema" "test" { - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - schema_id = "acctestSchema%d" - content_type = "application/vnd.ms-azure-apim.xsd+xml" - value = "${file("testdata/api_management_api_schema.xml")}" +resource "azurerm_api_management_api_schema" "import" { + api_name = azurerm_api_management_api_schema.test.name + api_management_name = azurerm_api_management_api_schema.test.api_management_name + resource_group_name = azurerm_api_management_api_schema.test.resource_group_name + schema_id = azurerm_api_management_api_schema.test.schema_id + content_type = azurerm_api_management_api_schema.test.content_type + value = azurerm_api_management_api_schema.test.value } -`, template, data.RandomInteger) +`, template) } func testAccAzureRMApiManagementApiSchema_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -153,21 +157,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "api1" path = "api1" protocols = ["https"] diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_test.go index a0b0bb8dbb76c..2e070de3d4662 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_test.go @@ -77,6 +77,29 @@ func TestAccAzureRMApiManagementApi_wordRevision(t *testing.T) { }) } +func TestAccAzureRMApiManagementApi_blankPath(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMApiManagementApiDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementApi_blankPath(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementApiExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "soap_pass_through", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "is_current", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "is_online", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "path", ""), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMApiManagementApi_version(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") @@ -321,8 +344,8 @@ func testAccAzureRMApiManagementApi_basic(data acceptance.TestData) string { resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "api1" path = "api1" protocols = ["https"] @@ -339,8 +362,8 @@ func testAccAzureRMApiManagementApi_basicClassic(data acceptance.TestData) strin resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "api1" path = "api1" protocols = ["https"] @@ -349,6 +372,23 @@ resource "azurerm_api_management_api" "test" { `, template, data.RandomInteger) } +func testAccAzureRMApiManagementApi_blankPath(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApi_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_api" "test" { + name = "acctestapi-%d" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name + display_name = "api1" + path = "" + protocols = ["https"] + revision = "1" +} +`, template, data.RandomInteger) +} + func testAccAzureRMApiManagementApi_wordRevision(data acceptance.TestData) string { template := testAccAzureRMApiManagementApi_template(data) return fmt.Sprintf(` @@ -356,8 +396,8 @@ func testAccAzureRMApiManagementApi_wordRevision(data acceptance.TestData) strin resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "api1" path = "api1" protocols = ["https"] @@ -373,8 +413,8 @@ func testAccAzureRMApiManagementApi_soapPassthrough(data acceptance.TestData) st resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "api1" path = "api1" protocols = ["https"] @@ -390,13 +430,13 @@ func testAccAzureRMApiManagementApi_requiresImport(data acceptance.TestData) str %s resource "azurerm_api_management_api" "import" { - name = "${azurerm_api_management_api.test.name}" - resource_group_name = "${azurerm_api_management_api.test.resource_group_name}" - api_management_name = "${azurerm_api_management_api.test.api_management_name}" - display_name = "${azurerm_api_management_api.test.display_name}" - path = "${azurerm_api_management_api.test.path}" - protocols = "${azurerm_api_management_api.test.protocols}" - revision = "${azurerm_api_management_api.test.revision}" + name = azurerm_api_management_api.test.name + resource_group_name = azurerm_api_management_api.test.resource_group_name + api_management_name = azurerm_api_management_api.test.api_management_name + display_name = azurerm_api_management_api.test.display_name + path = azurerm_api_management_api.test.path + protocols = azurerm_api_management_api.test.protocols + revision = azurerm_api_management_api.test.revision } `, template) } @@ -408,15 +448,15 @@ func testAccAzureRMApiManagementApi_importSwagger(data acceptance.TestData) stri resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "api1" path = "api1" protocols = ["https"] revision = "1" import { - content_value = "${file("testdata/api_management_api_swagger.json")}" + content_value = file("testdata/api_management_api_swagger.json") content_format = "swagger-json" } } @@ -430,15 +470,15 @@ func testAccAzureRMApiManagementApi_importWsdl(data acceptance.TestData) string resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "api1" path = "api1" protocols = ["https"] revision = "1" import { - content_value = "${file("testdata/api_management_api_wsdl.xml")}" + content_value = file("testdata/api_management_api_wsdl.xml") content_format = "wsdl" wsdl_selector { @@ -457,8 +497,8 @@ func testAccAzureRMApiManagementApi_complete(data acceptance.TestData) string { resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "Butter Parser" path = "butter-parser" protocols = ["https", "http"] @@ -481,28 +521,32 @@ func testAccAzureRMApiManagementApi_versionSet(data acceptance.TestData) string resource "azurerm_api_management_api_version_set" "test" { name = "acctestAMAVS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "Butter Parser" versioning_scheme = "Segment" } resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "api1" path = "api1" protocols = ["https"] revision = "1" version = "v1" - version_set_id = "${azurerm_api_management_api_version_set.test.id}" + version_set_id = azurerm_api_management_api_version_set.test.id } `, template, data.RandomInteger, data.RandomInteger) } func testAccAzureRMApiManagementApi_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -510,8 +554,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -523,6 +567,10 @@ resource "azurerm_api_management" "test" { // Remove in 2.0 func testAccAzureRMApiManagementApi_templateClassic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -530,15 +578,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_version_set_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_version_set_test.go index 660e2a0a763d5..e05f77f9c882f 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_version_set_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_version_set_test.go @@ -180,8 +180,8 @@ func testAccAzureRMApiManagementApiVersionSet_basic(data acceptance.TestData) st resource "azurerm_api_management_api_version_set" "test" { name = "acctestAMAVS-%d" - resource_group_name = "${azurerm_api_management.test.resource_group_name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_api_management.test.resource_group_name + api_management_name = azurerm_api_management.test.name description = "TestDescription1" display_name = "TestApiVersionSet1%d" versioning_scheme = "Segment" @@ -195,12 +195,12 @@ func testAccAzureRMApiManagementApiVersionSet_requiresImport(data acceptance.Tes %s resource "azurerm_api_management_api_version_set" "import" { - name = "${azurerm_api_management_api_version_set.test.name}" - resource_group_name = "${azurerm_api_management_api_version_set.test.resource_group_name}" - api_management_name = "${azurerm_api_management_api_version_set.test.api_management_name}" - description = "${azurerm_api_management_api_version_set.test.description}" - display_name = "${azurerm_api_management_api_version_set.test.display_name}" - versioning_scheme = "${azurerm_api_management_api_version_set.test.versioning_scheme}" + name = azurerm_api_management_api_version_set.test.name + resource_group_name = azurerm_api_management_api_version_set.test.resource_group_name + api_management_name = azurerm_api_management_api_version_set.test.api_management_name + description = azurerm_api_management_api_version_set.test.description + display_name = azurerm_api_management_api_version_set.test.display_name + versioning_scheme = azurerm_api_management_api_version_set.test.versioning_scheme } `, template) } @@ -212,8 +212,8 @@ func testAccAzureRMApiManagementApiVersionSet_header(data acceptance.TestData) s resource "azurerm_api_management_api_version_set" "test" { name = "acctestAMAVS-%d" - resource_group_name = "${azurerm_api_management.test.resource_group_name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_api_management.test.resource_group_name + api_management_name = azurerm_api_management.test.name description = "TestDescription1" display_name = "TestApiVersionSet1%d" versioning_scheme = "Header" @@ -229,8 +229,8 @@ func testAccAzureRMApiManagementApiVersionSet_query(data acceptance.TestData) st resource "azurerm_api_management_api_version_set" "test" { name = "acctestAMAVS-%d" - resource_group_name = "${azurerm_api_management.test.resource_group_name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_api_management.test.resource_group_name + api_management_name = azurerm_api_management.test.name description = "TestDescription1" display_name = "TestApiVersionSet1%d" versioning_scheme = "Query" @@ -246,8 +246,8 @@ func testAccAzureRMApiManagementApiVersionSet_update(data acceptance.TestData) s resource "azurerm_api_management_api_version_set" "test" { name = "acctestAMAVS-%d" - resource_group_name = "${azurerm_api_management.test.resource_group_name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_api_management.test.resource_group_name + api_management_name = azurerm_api_management.test.name description = "TestDescription2" display_name = "TestApiVersionSet2%d" versioning_scheme = "Segment" @@ -257,6 +257,10 @@ resource "azurerm_api_management_api_version_set" "test" { func testAccAzureRMApiManagementApiVersionSet_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -264,15 +268,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_authorization_server_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_authorization_server_test.go index bce30b68d9904..04f50bb655cf6 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_authorization_server_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_authorization_server_test.go @@ -132,8 +132,8 @@ func testAccAzureRMAPIManagementAuthorizationServer_basic(data acceptance.TestDa resource "azurerm_api_management_authorization_server" "test" { name = "acctestauthsrv-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "Test Group" authorization_endpoint = "https://azacctest.hashicorptest.com/client/authorize" client_id = "42424242-4242-4242-4242-424242424242" @@ -156,14 +156,14 @@ func testAccAzureRMAPIManagementAuthorizationServer_requiresImport(data acceptan %s resource "azurerm_api_management_authorization_server" "import" { - name = "${azurerm_api_management_authorization_server.test.name}" - resource_group_name = "${azurerm_api_management_authorization_server.test.resource_group_name}" - api_management_name = "${azurerm_api_management_authorization_server.test.api_management_name}" - display_name = "${azurerm_api_management_authorization_server.test.display_name}" - authorization_endpoint = "${azurerm_api_management_authorization_server.test.authorization_endpoint}" - client_id = "${azurerm_api_management_authorization_server.test.client_id}" - client_registration_endpoint = "${azurerm_api_management_authorization_server.test.client_registration_endpoint}" - grant_types = "${azurerm_api_management_authorization_server.test.grant_types}" + name = azurerm_api_management_authorization_server.test.name + resource_group_name = azurerm_api_management_authorization_server.test.resource_group_name + api_management_name = azurerm_api_management_authorization_server.test.api_management_name + display_name = azurerm_api_management_authorization_server.test.display_name + authorization_endpoint = azurerm_api_management_authorization_server.test.authorization_endpoint + client_id = azurerm_api_management_authorization_server.test.client_id + client_registration_endpoint = azurerm_api_management_authorization_server.test.client_registration_endpoint + grant_types = azurerm_api_management_authorization_server.test.grant_types authorization_methods = [ "GET", @@ -179,8 +179,8 @@ func testAccAzureRMAPIManagementAuthorizationServer_complete(data acceptance.Tes resource "azurerm_api_management_authorization_server" "test" { name = "acctestauthsrv-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "Test Group" authorization_endpoint = "https://azacctest.hashicorptest.com/client/authorize" client_id = "42424242-4242-4242-4242-424242424242" @@ -211,6 +211,10 @@ resource "azurerm_api_management_authorization_server" "test" { func testAccAzureRMAPIManagementAuthorizationServer_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -218,15 +222,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_backend_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_backend_test.go index dabe3c2633f0b..a0bdc81d6bffc 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_backend_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_backend_test.go @@ -302,8 +302,8 @@ func testAccAzureRMApiManagementBackend_basic(data acceptance.TestData, testName resource "azurerm_api_management_backend" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name protocol = "http" url = "https://acctest" } @@ -317,8 +317,8 @@ func testAccAzureRMApiManagementBackend_update(data acceptance.TestData) string resource "azurerm_api_management_backend" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name protocol = "soap" url = "https://updatedacctest" description = "description" @@ -343,16 +343,16 @@ func testAccAzureRMApiManagementBackend_allProperties(data acceptance.TestData) resource "azurerm_api_management_certificate" "test" { name = "example-cert" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - data = "${filebase64("testdata/keyvaultcert.pfx")}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name + data = filebase64("testdata/keyvaultcert.pfx") password = "" } resource "azurerm_api_management_backend" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name protocol = "http" url = "https://acctest" description = "description" @@ -364,7 +364,7 @@ resource "azurerm_api_management_backend" "test" { scheme = "scheme" } certificate = [ - "${azurerm_api_management_certificate.test.thumbprint}", + azurerm_api_management_certificate.test.thumbprint, ] header = { header1 = "header1value1,header1value2" @@ -395,20 +395,20 @@ func testAccAzureRMApiManagementBackend_serviceFabric(data acceptance.TestData) resource "azurerm_api_management_certificate" "test" { name = "example-cert" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - data = "${filebase64("testdata/keyvaultcert.pfx")}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name + data = filebase64("testdata/keyvaultcert.pfx") password = "" } resource "azurerm_api_management_backend" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name protocol = "http" url = "https://acctest" service_fabric_cluster { - client_certificate_thumbprint = "${azurerm_api_management_certificate.test.thumbprint}" + client_certificate_thumbprint = azurerm_api_management_certificate.test.thumbprint management_endpoints = [ "https://acctestsf.com", ] @@ -428,17 +428,21 @@ func testAccAzureRMApiManagementBackend_requiresImport(data acceptance.TestData) %s resource "azurerm_api_management_backend" "import" { - name = "${azurerm_api_management_backend.test.name}" - resource_group_name = "${azurerm_api_management_backend.test.resource_group_name}" - api_management_name = "${azurerm_api_management_backend.test.api_management_name}" - protocol = "${azurerm_api_management_backend.test.protocol}" - url = "${azurerm_api_management_backend.test.url}" + name = azurerm_api_management_backend.test.name + resource_group_name = azurerm_api_management_backend.test.resource_group_name + api_management_name = azurerm_api_management_backend.test.api_management_name + protocol = azurerm_api_management_backend.test.protocol + url = azurerm_api_management_backend.test.url } `, template) } func testAccAzureRMApiManagementBackend_template(data acceptance.TestData, testName string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d-%s" location = "%s" @@ -446,15 +450,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } `, data.RandomInteger, testName, data.Locations.Primary, data.RandomInteger, testName) } @@ -466,8 +466,8 @@ func testAccAzureRMApiManagementBackend_credentialsNoCertificate(data acceptance resource "azurerm_api_management_backend" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name protocol = "http" url = "https://acctest" description = "description" diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_certificate_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_certificate_test.go index 9e9f11a5df186..83c5cc9a2c324 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_certificate_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_certificate_test.go @@ -120,6 +120,10 @@ func testCheckAzureRMAPIManagementCertificateExists(resourceName string) resourc func testAccAzureRMAPIManagementCertificate_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -127,22 +131,18 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } resource "azurerm_api_management_certificate" "test" { name = "example-cert" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - data = "${filebase64("testdata/keyvaultcert.pfx")}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name + data = filebase64("testdata/keyvaultcert.pfx") password = "" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -154,11 +154,11 @@ func testAccAzureRMAPIManagementCertificate_requiresImport(data acceptance.TestD %s resource "azurerm_api_management_certificate" "import" { - name = "${azurerm_api_management_certificate.test.name}" - api_management_name = "${azurerm_api_management_certificate.test.api_management_name}" - resource_group_name = "${azurerm_api_management_certificate.test.resource_group_name}" - data = "${azurerm_api_management_certificate.test.data}" - password = "${azurerm_api_management_certificate.test.password}" + name = azurerm_api_management_certificate.test.name + api_management_name = azurerm_api_management_certificate.test.api_management_name + resource_group_name = azurerm_api_management_certificate.test.resource_group_name + data = azurerm_api_management_certificate.test.data + password = azurerm_api_management_certificate.test.password } `, template) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go index ba0ea2ee5247b..79aeb9642dd45 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go @@ -108,6 +108,10 @@ func testCheckAzureRMApiManagementDiagnosticExists(resourceName string) resource func testAccAzureRMApiManagementDiagnostic_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -115,8 +119,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" sku_name = "Developer_1" @@ -124,8 +128,8 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_diagnostic" "test" { identifier = "applicationinsights" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name enabled = true } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -137,10 +141,10 @@ func testAccAzureRMApiManagementDiagnostic_requiresImport(data acceptance.TestDa %s resource "azurerm_api_management_diagnostic" "import" { - identifier = "${azurerm_api_management_diagnostic.test.identifier}" - resource_group_name = "${azurerm_api_management_diagnostic.test.resource_group_name}" - api_management_name = "${azurerm_api_management_diagnostic.test.api_management_name}" - enabled = "${azurerm_api_management_diagnostic.test.enabled}" + identifier = azurerm_api_management_diagnostic.test.identifier + resource_group_name = azurerm_api_management_diagnostic.test.resource_group_name + api_management_name = azurerm_api_management_diagnostic.test.api_management_name + enabled = azurerm_api_management_diagnostic.test.enabled } `, template) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_test.go index fdfd6859b3f48..09e5dab51b8bc 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_test.go @@ -173,6 +173,10 @@ func testCheckAzureRMAPIManagementGroupExists(resourceName string) resource.Test func testAccAzureRMAPIManagementGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -180,8 +184,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -190,8 +194,8 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_group" "test" { name = "acctestAMGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "Test Group" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) @@ -203,16 +207,20 @@ func testAccAzureRMAPIManagementGroup_requiresImport(data acceptance.TestData) s %s resource "azurerm_api_management_group" "import" { - name = "${azurerm_api_management_group.test.name}" - resource_group_name = "${azurerm_api_management_group.test.resource_group_name}" - api_management_name = "${azurerm_api_management_group.test.api_management_name}" - display_name = "${azurerm_api_management_group.test.display_name}" + name = azurerm_api_management_group.test.name + resource_group_name = azurerm_api_management_group.test.resource_group_name + api_management_name = azurerm_api_management_group.test.api_management_name + display_name = azurerm_api_management_group.test.display_name } `, template) } func testAccAzureRMAPIManagementGroup_complete(data acceptance.TestData, displayName, description string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -220,8 +228,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -230,8 +238,8 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_group" "test" { name = "acctestAMGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "%s" description = "%s" type = "external" diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_user_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_user_test.go index 14c79d3a454f6..d29703caf6f36 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_user_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_user_test.go @@ -109,6 +109,10 @@ func testCheckAzureRMAPIManagementGroupUserExists(resourceName string) resource. func testAccAzureRMAPIManagementGroupUser_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -116,8 +120,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -126,25 +130,25 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_group" "test" { name = "acctestAMGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "Test Group" } resource "azurerm_api_management_user" "test" { user_id = "acctestuser%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name first_name = "Acceptance" last_name = "Test" email = "azure-acctest%d@example.com" } resource "azurerm_api_management_group_user" "test" { - user_id = "${azurerm_api_management_user.test.user_id}" - group_name = "${azurerm_api_management_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + user_id = azurerm_api_management_user.test.user_id + group_name = azurerm_api_management_group.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } @@ -155,10 +159,10 @@ func testAccAzureRMAPIManagementGroupUser_requiresImport(data acceptance.TestDat %s resource "azurerm_api_management_group_user" "import" { - user_id = "${azurerm_api_management_group_user.test.user_id}" - group_name = "${azurerm_api_management_group_user.test.group_name}" - api_management_name = "${azurerm_api_management_group_user.test.api_management_name}" - resource_group_name = "${azurerm_api_management_group_user.test.resource_group_name}" + user_id = azurerm_api_management_group_user.test.user_id + group_name = azurerm_api_management_group_user.test.group_name + api_management_name = azurerm_api_management_group_user.test.api_management_name + resource_group_name = azurerm_api_management_group_user.test.resource_group_name } `, template) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_aad_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_aad_test.go index 982dbaa45ba03..414be8ef8ff12 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_aad_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_aad_test.go @@ -141,6 +141,10 @@ func testCheckAzureRMApiManagementIdentityProviderAADExists(resourceName string) func testAccAzureRMApiManagementIdentityProviderAAD_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-api-%d" location = "%s" @@ -148,16 +152,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" sku_name = "Developer_1" } resource "azurerm_api_management_identity_provider_aad" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name client_id = "00000000-0000-0000-0000-000000000000" client_secret = "00000000000000000000000000000000" allowed_tenants = ["%s"] @@ -167,6 +171,10 @@ resource "azurerm_api_management_identity_provider_aad" "test" { func testAccAzureRMApiManagementIdentityProviderAAD_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-api-%d" location = "%s" @@ -174,16 +182,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" sku_name = "Developer_1" } resource "azurerm_api_management_identity_provider_aad" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name client_id = "11111111-1111-1111-1111-111111111111" client_secret = "11111111111111111111111111111111" allowed_tenants = ["%s", "%s"] @@ -197,11 +205,11 @@ func testAccAzureRMApiManagementIdentityProviderAAD_requiresImport(data acceptan %s resource "azurerm_api_management_identity_provider_aad" "import" { - resource_group_name = "${azurerm_api_management_identity_provider_aad.test.resource_group_name}" - api_management_name = "${azurerm_api_management_identity_provider_aad.test.api_management_name}" - client_id = "${azurerm_api_management_identity_provider_aad.test.client_id}" - client_secret = "${azurerm_api_management_identity_provider_aad.test.client_secret}" - allowed_tenants = "${azurerm_api_management_identity_provider_aad.test.allowed_tenants}" + resource_group_name = azurerm_api_management_identity_provider_aad.test.resource_group_name + api_management_name = azurerm_api_management_identity_provider_aad.test.api_management_name + client_id = azurerm_api_management_identity_provider_aad.test.client_id + client_secret = azurerm_api_management_identity_provider_aad.test.client_secret + allowed_tenants = azurerm_api_management_identity_provider_aad.test.allowed_tenants } `, template) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_facebook_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_facebook_test.go index daacd82573a57..225645cb933d1 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_facebook_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_facebook_test.go @@ -137,6 +137,10 @@ func testCheckAzureRMApiManagementIdentityProviderFacebookExists(resourceName st func testAccAzureRMApiManagementIdentityProviderFacebook_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-api-%d" location = "%s" @@ -144,16 +148,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" sku_name = "Developer_1" } resource "azurerm_api_management_identity_provider_facebook" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name app_id = "00000000000000000000000000000000" app_secret = "00000000000000000000000000000000" } @@ -162,6 +166,10 @@ resource "azurerm_api_management_identity_provider_facebook" "test" { func testAccAzureRMApiManagementIdentityProviderFacebook_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-api-%d" location = "%s" @@ -169,16 +177,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" sku_name = "Developer_1" } resource "azurerm_api_management_identity_provider_facebook" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name app_id = "11111111111111111111111111111111" app_secret = "11111111111111111111111111111111" } @@ -191,10 +199,10 @@ func testAccAzureRMApiManagementIdentityProviderFacebook_requiresImport(data acc %s resource "azurerm_api_management_identity_provider_facebook" "import" { - resource_group_name = "${azurerm_api_management_identity_provider_facebook.test.resource_group_name}" - api_management_name = "${azurerm_api_management_identity_provider_facebook.test.api_management_name}" - app_id = "${azurerm_api_management_identity_provider_facebook.test.app_id}" - app_secret = "${azurerm_api_management_identity_provider_facebook.test.app_secret}" + resource_group_name = azurerm_api_management_identity_provider_facebook.test.resource_group_name + api_management_name = azurerm_api_management_identity_provider_facebook.test.api_management_name + app_id = azurerm_api_management_identity_provider_facebook.test.app_id + app_secret = azurerm_api_management_identity_provider_facebook.test.app_secret } `, template) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_google_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_google_test.go index fd312367f7e03..8c566ce8f6b51 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_google_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_google_test.go @@ -136,6 +136,10 @@ func testCheckAzureRMApiManagementIdentityProviderGoogleExists(resourceName stri func testAccAzureRMApiManagementIdentityProviderGoogle_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-api-%d" location = "%s" @@ -143,16 +147,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" sku_name = "Developer_1" } resource "azurerm_api_management_identity_provider_google" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name client_id = "00000000.apps.googleusercontent.com" client_secret = "00000000000000000000000000000000" } @@ -161,6 +165,10 @@ resource "azurerm_api_management_identity_provider_google" "test" { func testAccAzureRMApiManagementIdentityProviderGoogle_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-api-%d" location = "%s" @@ -168,16 +176,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" sku_name = "Developer_1" } resource "azurerm_api_management_identity_provider_google" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name client_id = "11111111.apps.googleusercontent.com" client_secret = "11111111111111111111111111111111" } @@ -190,10 +198,10 @@ func testAccAzureRMApiManagementIdentityProviderGoogle_requiresImport(data accep %s resource "azurerm_api_management_identity_provider_google" "import" { - resource_group_name = "${azurerm_api_management_identity_provider_google.test.resource_group_name}" - api_management_name = "${azurerm_api_management_identity_provider_google.test.api_management_name}" - client_id = "${azurerm_api_management_identity_provider_google.test.client_id}" - client_secret = "${azurerm_api_management_identity_provider_google.test.client_secret}" + resource_group_name = azurerm_api_management_identity_provider_google.test.resource_group_name + api_management_name = azurerm_api_management_identity_provider_google.test.api_management_name + client_id = azurerm_api_management_identity_provider_google.test.client_id + client_secret = azurerm_api_management_identity_provider_google.test.client_secret } `, template) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_microsoft_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_microsoft_test.go index 1ead6b16570e3..801d8abab0061 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_microsoft_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_microsoft_test.go @@ -137,6 +137,10 @@ func testCheckAzureRMApiManagementIdentityProviderMicrosoftExists(resourceName s func testAccAzureRMApiManagementIdentityProviderMicrosoft_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-api-%d" location = "%s" @@ -144,16 +148,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" sku_name = "Developer_1" } resource "azurerm_api_management_identity_provider_microsoft" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name client_id = "00000000-0000-0000-0000-000000000000" client_secret = "00000000000000000000000000000000" } @@ -162,6 +166,10 @@ resource "azurerm_api_management_identity_provider_microsoft" "test" { func testAccAzureRMApiManagementIdentityProviderMicrosoft_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-api-%d" location = "%s" @@ -169,16 +177,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" sku_name = "Developer_1" } resource "azurerm_api_management_identity_provider_microsoft" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name client_id = "11111111-1111-1111-1111-111111111111" client_secret = "11111111111111111111111111111111" } @@ -191,10 +199,10 @@ func testAccAzureRMApiManagementIdentityProviderMicrosoft_requiresImport(data ac %s resource "azurerm_api_management_identity_provider_microsoft" "import" { - resource_group_name = "${azurerm_api_management_identity_provider_microsoft.test.resource_group_name}" - api_management_name = "${azurerm_api_management_identity_provider_microsoft.test.api_management_name}" - client_id = "${azurerm_api_management_identity_provider_microsoft.test.client_id}" - client_secret = "${azurerm_api_management_identity_provider_microsoft.test.client_secret}" + resource_group_name = azurerm_api_management_identity_provider_microsoft.test.resource_group_name + api_management_name = azurerm_api_management_identity_provider_microsoft.test.api_management_name + client_id = azurerm_api_management_identity_provider_microsoft.test.client_id + client_secret = azurerm_api_management_identity_provider_microsoft.test.client_secret } `, template) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_twitter_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_twitter_test.go index f7565a70f230e..47ad166d2f83b 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_twitter_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_twitter_test.go @@ -137,6 +137,10 @@ func testCheckAzureRMApiManagementIdentityProviderTwtterExists(resourceName stri func testAccAzureRMApiManagementIdentityProviderTwitter_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-api-%d" location = "%s" @@ -144,16 +148,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" sku_name = "Developer_1" } resource "azurerm_api_management_identity_provider_twitter" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name api_key = "00000000000000000000000000000000" api_secret_key = "00000000000000000000000000000000" } @@ -162,6 +166,10 @@ resource "azurerm_api_management_identity_provider_twitter" "test" { func testAccAzureRMApiManagementIdentityProviderTwitter_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-api-%d" location = "%s" @@ -169,16 +177,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" sku_name = "Developer_1" } resource "azurerm_api_management_identity_provider_twitter" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name api_key = "11111111111111111111111111111111" api_secret_key = "11111111111111111111111111111111" } @@ -191,10 +199,10 @@ func testAccAzureRMApiManagementIdentityProviderTwitter_requiresImport(data acce %s resource "azurerm_api_management_identity_provider_twitter" "import" { - resource_group_name = "${azurerm_api_management_identity_provider_twitter.test.resource_group_name}" - api_management_name = "${azurerm_api_management_identity_provider_twitter.test.api_management_name}" - api_key = "${azurerm_api_management_identity_provider_twitter.test.api_key}" - api_secret_key = "${azurerm_api_management_identity_provider_twitter.test.api_secret_key}" + resource_group_name = azurerm_api_management_identity_provider_twitter.test.resource_group_name + api_management_name = azurerm_api_management_identity_provider_twitter.test.api_management_name + api_key = azurerm_api_management_identity_provider_twitter.test.api_key + api_secret_key = azurerm_api_management_identity_provider_twitter.test.api_secret_key } `, template) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_logger_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_logger_test.go index 03b6eb97fbce6..87f5549ad5a6a 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_logger_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_logger_test.go @@ -254,6 +254,10 @@ func testCheckAzureRMApiManagementLoggerDestroy(s *terraform.State) error { func testAccAzureRMApiManagementLogger_basicEventHub(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -261,23 +265,23 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Basic" + location = "azurerm_resource_group.test.location" + resource_group_name = "azurerm_resource_group.test.name" + sku_name = "Basic_1" } resource "azurerm_eventhub" "test" { name = "acctesteventhub-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = "azurerm_eventhub_namespace.test.name" + resource_group_name = "azurerm_resource_group.test.name" partition_count = 2 message_retention = 1 } resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = "azurerm_resource_group.test.location" + resource_group_name = "azurerm_resource_group.test.name" publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -286,12 +290,12 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_logger" "test" { name = "acctestapimnglogger-%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = "azurerm_api_management.test.name" + resource_group_name = "azurerm_resource_group.test.name" eventhub { - name = "${azurerm_eventhub.test.name}" - connection_string = "${azurerm_eventhub_namespace.test.default_primary_connection_string}" + name = "azurerm_eventhub.test.name" + connection_string = "azurerm_eventhub_namespace.test.default_primary_connection_string" } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -303,13 +307,13 @@ func testAccAzureRMApiManagementLogger_requiresImport(data acceptance.TestData) %s resource "azurerm_api_management_logger" "import" { - name = "${azurerm_api_management_logger.test.name}" - api_management_name = "${azurerm_api_management_logger.test.api_management_name}" - resource_group_name = "${azurerm_api_management_logger.test.resource_group_name}" + name = azurerm_api_management_logger.test.name + api_management_name = azurerm_api_management_logger.test.api_management_name + resource_group_name = azurerm_api_management_logger.test.resource_group_name eventhub { - name = "${azurerm_eventhub.test.name}" - connection_string = "${azurerm_eventhub_namespace.test.default_primary_connection_string}" + name = azurerm_eventhub.test.name + connection_string = azurerm_eventhub_namespace.test.default_primary_connection_string } } `, template) @@ -317,6 +321,10 @@ resource "azurerm_api_management_logger" "import" { func testAccAzureRMApiManagementLogger_basicApplicationInsights(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -324,15 +332,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_insights" "test" { name = "acctestappinsights-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name application_type = "Other" } resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -341,11 +349,11 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_logger" "test" { name = "acctestapimnglogger-%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name application_insights { - instrumentation_key = "${azurerm_application_insights.test.instrumentation_key}" + instrumentation_key = azurerm_application_insights.test.instrumentation_key } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -353,6 +361,10 @@ resource "azurerm_api_management_logger" "test" { func testAccAzureRMApiManagementLogger_complete(data acceptance.TestData, description, buffered string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -360,15 +372,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_insights" "test" { name = "acctestappinsights-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name application_type = "Other" } resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -377,13 +389,13 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_logger" "test" { name = "acctestapimnglogger-%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name description = "%s" buffered = %s application_insights { - instrumentation_key = "${azurerm_application_insights.test.instrumentation_key}" + instrumentation_key = azurerm_application_insights.test.instrumentation_key } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, description, buffered) diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_openid_connect_provider_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_openid_connect_provider_test.go index 7a165628b67de..725e9293f4fd8 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_openid_connect_provider_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_openid_connect_provider_test.go @@ -136,8 +136,8 @@ func testAccAzureRMApiManagementOpenIDConnectProvider_basic(data acceptance.Test resource "azurerm_api_management_openid_connect_provider" "test" { name = "acctest-%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name client_id = "00001111-2222-3333-%d" client_secret = "%d-cwdavsxbacsaxZX-%d" display_name = "Initial Name" @@ -152,13 +152,13 @@ func testAccAzureRMApiManagementOpenIDConnectProvider_requiresImport(data accept %s resource "azurerm_api_management_openid_connect_provider" "import" { - name = "${azurerm_api_management_openid_connect_provider.test.name}" - api_management_name = "${azurerm_api_management_openid_connect_provider.test.api_management_name}" - resource_group_name = "${azurerm_api_management_openid_connect_provider.test.resource_group_name}" - client_id = "${azurerm_api_management_openid_connect_provider.test.client_id}" - client_secret = "${azurerm_api_management_openid_connect_provider.test.client_secret}" - display_name = "${azurerm_api_management_openid_connect_provider.test.display_name}" - metadata_endpoint = "${azurerm_api_management_openid_connect_provider.test.metadata_endpoint}" + name = azurerm_api_management_openid_connect_provider.test.name + api_management_name = azurerm_api_management_openid_connect_provider.test.api_management_name + resource_group_name = azurerm_api_management_openid_connect_provider.test.resource_group_name + client_id = azurerm_api_management_openid_connect_provider.test.client_id + client_secret = azurerm_api_management_openid_connect_provider.test.client_secret + display_name = azurerm_api_management_openid_connect_provider.test.display_name + metadata_endpoint = azurerm_api_management_openid_connect_provider.test.metadata_endpoint } `, template) } @@ -170,8 +170,8 @@ func testAccAzureRMApiManagementOpenIDConnectProvider_complete(data acceptance.T resource "azurerm_api_management_openid_connect_provider" "test" { name = "acctest-%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name client_id = "00001111-3333-2222-%d" client_secret = "%d-423egvwdcsjx-%d" display_name = "Updated Name" @@ -183,6 +183,10 @@ resource "azurerm_api_management_openid_connect_provider" "test" { func testAccAzureRMApiManagementOpenIDConnectProvider_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -190,15 +194,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_api_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_api_test.go index 5ab8edb53c6e6..c7d8cf61de3e1 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_api_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_api_test.go @@ -109,6 +109,10 @@ func testCheckAzureRMAPIManagementProductApiExists(resourceName string) resource func testAccAzureRMAPIManagementProductApi_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -116,8 +120,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -126,8 +130,8 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_product" "test" { product_id = "test-product" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Test Product" subscription_required = true approval_required = false @@ -136,8 +140,8 @@ resource "azurerm_api_management_product" "test" { resource "azurerm_api_management_api" "test" { name = "acctestapi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "api1" path = "api1" protocols = ["https"] @@ -145,10 +149,10 @@ resource "azurerm_api_management_api" "test" { } resource "azurerm_api_management_product_api" "test" { - product_id = "${azurerm_api_management_product.test.product_id}" - api_name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + product_id = azurerm_api_management_product.test.product_id + api_name = azurerm_api_management_api.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } @@ -159,10 +163,10 @@ func testAccAzureRMAPIManagementProductApi_requiresImport(data acceptance.TestDa %s resource "azurerm_api_management_product_api" "import" { - api_name = "${azurerm_api_management_product_api.test.api_name}" - product_id = "${azurerm_api_management_product_api.test.product_id}" - api_management_name = "${azurerm_api_management_product_api.test.api_management_name}" - resource_group_name = "${azurerm_api_management_product_api.test.resource_group_name}" + api_name = azurerm_api_management_product_api.test.api_name + product_id = azurerm_api_management_product_api.test.product_id + api_management_name = azurerm_api_management_product_api.test.api_management_name + resource_group_name = azurerm_api_management_product_api.test.resource_group_name } `, template) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_group_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_group_test.go index 3dc49b4a82286..0696f98213109 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_group_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_group_test.go @@ -109,6 +109,10 @@ func testCheckAzureRMAPIManagementProductGroupExists(resourceName string) resour func testAccAzureRMAPIManagementProductGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -116,8 +120,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -126,8 +130,8 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_product" "test" { product_id = "test-product" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Test Product" subscription_required = true approval_required = false @@ -136,16 +140,16 @@ resource "azurerm_api_management_product" "test" { resource "azurerm_api_management_group" "test" { name = "acctestAMGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name display_name = "Test Group" } resource "azurerm_api_management_product_group" "test" { - product_id = "${azurerm_api_management_product.test.product_id}" - group_name = "${azurerm_api_management_group.test.name}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + product_id = azurerm_api_management_product.test.product_id + group_name = azurerm_api_management_group.test.name + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } @@ -156,10 +160,10 @@ func testAccAzureRMAPIManagementProductGroup_requiresImport(data acceptance.Test %s resource "azurerm_api_management_product_group" "import" { - product_id = "${azurerm_api_management_product_group.test.product_id}" - group_name = "${azurerm_api_management_product_group.test.group_name}" - api_management_name = "${azurerm_api_management_product_group.test.api_management_name}" - resource_group_name = "${azurerm_api_management_product_group.test.resource_group_name}" + product_id = azurerm_api_management_product_group.test.product_id + group_name = azurerm_api_management_product_group.test.group_name + api_management_name = azurerm_api_management_product_group.test.api_management_name + resource_group_name = azurerm_api_management_product_group.test.resource_group_name } `, template) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_policy_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_policy_test.go index 0dbeffb131959..005f7fb710526 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_policy_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_policy_test.go @@ -146,6 +146,10 @@ func testCheckAzureRMApiManagementProductPolicyDestroy(s *terraform.State) error func testAccAzureRMApiManagementProductPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -153,30 +157,26 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } resource "azurerm_api_management_product" "test" { product_id = "test-product" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Test Product" subscription_required = false published = false } resource "azurerm_api_management_product_policy" "test" { - product_id = "${azurerm_api_management_product.test.product_id}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + product_id = azurerm_api_management_product.test.product_id + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name xml_link = "https://gist.githubusercontent.com/riordanp/ca22f8113afae0eb38cc12d718fd048d/raw/d6ac89a2f35a6881a7729f8cb4883179dc88eea1/example.xml" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -188,16 +188,20 @@ func testAccAzureRMApiManagementProductPolicy_requiresImport(data acceptance.Tes %s resource "azurerm_api_management_product_policy" "import" { - product_id = "${azurerm_api_management_product_policy.test.product_id}" - api_management_name = "${azurerm_api_management_product_policy.test.api_management_name}" - resource_group_name = "${azurerm_api_management_product_policy.test.resource_group_name}" - xml_link = "${azurerm_api_management_product_policy.test.xml_link}" + product_id = azurerm_api_management_product_policy.test.product_id + api_management_name = azurerm_api_management_product_policy.test.api_management_name + resource_group_name = azurerm_api_management_product_policy.test.resource_group_name + xml_link = azurerm_api_management_product_policy.test.xml_link } `, template) } func testAccAzureRMApiManagementProductPolicy_updated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -205,30 +209,26 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } resource "azurerm_api_management_product" "test" { product_id = "test-product" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Test Product" subscription_required = false published = false } resource "azurerm_api_management_product_policy" "test" { - product_id = "${azurerm_api_management_product.test.product_id}" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + product_id = azurerm_api_management_product.test.product_id + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name xml_content = < @@ -238,6 +238,7 @@ resource "azurerm_api_management_product_policy" "test" { XML + } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_test.go index 308a9e97f331f..729f486ece47a 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_test.go @@ -238,6 +238,10 @@ func testCheckAzureRMApiManagementProductExists(resourceName string) resource.Te func testAccAzureRMApiManagementProduct_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -245,8 +249,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -255,8 +259,8 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_product" "test" { product_id = "test-product" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Test Product" subscription_required = false published = false @@ -270,19 +274,23 @@ func testAccAzureRMApiManagementProduct_requiresImport(data acceptance.TestData) %s resource "azurerm_api_management_product" "import" { - product_id = "${azurerm_api_management_product.test.product_id}" - api_management_name = "${azurerm_api_management_product.test.api_management_name}" - resource_group_name = "${azurerm_api_management_product.test.resource_group_name}" - display_name = "${azurerm_api_management_product.test.display_name}" - subscription_required = "${azurerm_api_management_product.test.subscription_required}" - approval_required = "${azurerm_api_management_product.test.approval_required}" - published = "${azurerm_api_management_product.test.published}" + product_id = azurerm_api_management_product.test.product_id + api_management_name = azurerm_api_management_product.test.api_management_name + resource_group_name = azurerm_api_management_product.test.resource_group_name + display_name = azurerm_api_management_product.test.display_name + subscription_required = azurerm_api_management_product.test.subscription_required + approval_required = azurerm_api_management_product.test.approval_required + published = azurerm_api_management_product.test.published } `, template) } func testAccAzureRMApiManagementProduct_updated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -290,8 +298,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -300,8 +308,8 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_product" "test" { product_id = "test-product" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Test Updated Product" subscription_required = true approval_required = true @@ -313,6 +321,10 @@ resource "azurerm_api_management_product" "test" { func testAccAzureRMApiManagementProduct_subscriptionLimits(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -320,8 +332,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -330,8 +342,8 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_product" "test" { product_id = "test-product" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Test Product" subscription_required = true approval_required = true @@ -343,6 +355,10 @@ resource "azurerm_api_management_product" "test" { func testAccAzureRMApiManagementProduct_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -350,8 +366,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -360,8 +376,8 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_product" "test" { product_id = "test-product" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Test Product" subscription_required = true approval_required = true @@ -375,6 +391,10 @@ resource "azurerm_api_management_product" "test" { func testAccAzureRMApiManagementProduct_approvalRequiredError(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -382,21 +402,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } resource "azurerm_api_management_product" "test" { product_id = "test-product" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Test Product" approval_required = true subscription_required = false diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_property_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_property_test.go index 505406f7b9a69..a2cb8630738b6 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_property_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_property_test.go @@ -126,6 +126,10 @@ func testCheckAzureRMAPIManagementPropertyExists(resourceName string) resource.T func testAccAzureRMAPIManagementProperty_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -133,8 +137,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -143,8 +147,8 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_property" "test" { name = "acctestAMProperty-%d" - resource_group_name = "${azurerm_api_management.test.resource_group_name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_api_management.test.resource_group_name + api_management_name = azurerm_api_management.test.name display_name = "TestProperty%d" value = "Test Value" tags = ["tag1", "tag2"] @@ -154,6 +158,10 @@ resource "azurerm_api_management_property" "test" { func testAccAzureRMAPIManagementProperty_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -161,8 +169,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -171,8 +179,8 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_property" "test" { name = "acctestAMProperty-%d" - resource_group_name = "${azurerm_api_management.test.resource_group_name}" - api_management_name = "${azurerm_api_management.test.name}" + resource_group_name = azurerm_api_management.test.resource_group_name + api_management_name = azurerm_api_management.test.name display_name = "TestProperty2%d" value = "Test Value2" secret = true diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_subscription_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_subscription_test.go index 0c8745eb05361..89d64fdccf2d4 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_subscription_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_subscription_test.go @@ -182,10 +182,10 @@ func testAccAzureRMAPIManagementSubscription_basic(data acceptance.TestData) str %s resource "azurerm_api_management_subscription" "test" { - resource_group_name = "${azurerm_api_management.test.resource_group_name}" - api_management_name = "${azurerm_api_management.test.name}" - user_id = "${azurerm_api_management_user.test.id}" - product_id = "${azurerm_api_management_product.test.id}" + resource_group_name = azurerm_api_management.test.resource_group_name + api_management_name = azurerm_api_management.test.name + user_id = azurerm_api_management_user.test.id + product_id = azurerm_api_management_product.test.id display_name = "Butter Parser API Enterprise Edition" } `, template) @@ -197,11 +197,11 @@ func testAccAzureRMAPIManagementSubscription_requiresImport(data acceptance.Test %s resource "azurerm_api_management_subscription" "import" { - resource_group_name = "${azurerm_api_management_subscription.test.resource_group_name}" - api_management_name = "${azurerm_api_management_subscription.test.api_management_name}" - user_id = "${azurerm_api_management_subscription.test.user_id}" - product_id = "${azurerm_api_management_subscription.test.product_id}" - display_name = "${azurerm_api_management_subscription.test.display_name}" + resource_group_name = azurerm_api_management_subscription.test.resource_group_name + api_management_name = azurerm_api_management_subscription.test.api_management_name + user_id = azurerm_api_management_subscription.test.user_id + product_id = azurerm_api_management_subscription.test.product_id + display_name = azurerm_api_management_subscription.test.display_name } `, template) } @@ -212,10 +212,10 @@ func testAccAzureRMAPIManagementSubscription_update(data acceptance.TestData, st %s resource "azurerm_api_management_subscription" "test" { - resource_group_name = "${azurerm_api_management.test.resource_group_name}" - api_management_name = "${azurerm_api_management.test.name}" - user_id = "${azurerm_api_management_user.test.id}" - product_id = "${azurerm_api_management_product.test.id}" + resource_group_name = azurerm_api_management.test.resource_group_name + api_management_name = azurerm_api_management.test.name + user_id = azurerm_api_management_user.test.id + product_id = azurerm_api_management_product.test.id display_name = "Butter Parser API Enterprise Edition" state = "%s" } @@ -228,10 +228,10 @@ func testAccAzureRMAPIManagementSubscription_complete(data acceptance.TestData) %s resource "azurerm_api_management_subscription" "test" { - resource_group_name = "${azurerm_api_management.test.resource_group_name}" - api_management_name = "${azurerm_api_management.test.name}" - user_id = "${azurerm_api_management_user.test.id}" - product_id = "${azurerm_api_management_product.test.id}" + resource_group_name = azurerm_api_management.test.resource_group_name + api_management_name = azurerm_api_management.test.name + user_id = azurerm_api_management_user.test.id + product_id = azurerm_api_management_product.test.id display_name = "Butter Parser API Enterprise Edition" state = "active" } @@ -240,6 +240,10 @@ resource "azurerm_api_management_subscription" "test" { func testAccAzureRMAPIManagementSubscription_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -247,8 +251,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -257,8 +261,8 @@ resource "azurerm_api_management" "test" { resource "azurerm_api_management_product" "test" { product_id = "test-product" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name display_name = "Test Product" subscription_required = true approval_required = false @@ -267,8 +271,8 @@ resource "azurerm_api_management_product" "test" { resource "azurerm_api_management_user" "test" { user_id = "acctestuser%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name first_name = "Acceptance" last_name = "Test" email = "azure-acctest%d@example.com" diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_test.go index 7c75a6f2453b6..21277eec1878f 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_test.go @@ -2,7 +2,6 @@ package tests import ( "fmt" - "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -32,43 +31,6 @@ func TestAccAzureRMApiManagement_basic(t *testing.T) { }) } -// Remove in 2.0 -func TestAccAzureRMApiManagement_basicClassic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_api_management", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMApiManagementDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMApiManagement_basicClassic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -// Remove in 2.0 -func TestAccAzureRMApiManagement_basicNotDefined(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_api_management", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMApiManagementDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMApiManagement_basicNotDefined(data), - ExpectError: regexp.MustCompile("either 'sku_name' or 'sku' must be defined in the configuration file"), - }, - }, - }) -} - func TestAccAzureRMApiManagement_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -285,26 +247,10 @@ func testCheckAzureRMApiManagementExists(resourceName string) resource.TestCheck func testAccAzureRMApiManagement_basic(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_api_management" "test" { - name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - publisher_name = "pub1" - publisher_email = "pub1@email.com" - - sku_name = "Developer_1" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -// Remove in 2.0 -func testAccAzureRMApiManagement_basicClassic(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -312,39 +258,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" - sku { - name = "Developer" - capacity = 1 - } + sku_name = "Developer_1" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -// Remove in 2.0 -func testAccAzureRMApiManagement_basicNotDefined(data acceptance.TestData) string { +func testAccAzureRMApiManagement_policyXmlContent(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_api_management" "test" { - name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - publisher_name = "pub1" - publisher_email = "pub1@email.com" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +provider "azurerm" { + features {} } -func testAccAzureRMApiManagement_policyXmlContent(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -352,8 +281,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -367,6 +296,7 @@ resource "azurerm_api_management" "test" { XML + } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -374,6 +304,10 @@ XML func testAccAzureRMApiManagement_policyXmlLink(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -381,8 +315,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -397,6 +331,10 @@ resource "azurerm_api_management" "test" { func testAccAzureRMApiManagement_policyRemoved(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -404,8 +342,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -422,11 +360,11 @@ func testAccAzureRMApiManagement_requiresImport(data acceptance.TestData) string %s resource "azurerm_api_management" "import" { - name = "${azurerm_api_management.test.name}" - location = "${azurerm_api_management.test.location}" - resource_group_name = "${azurerm_api_management.test.resource_group_name}" - publisher_name = "${azurerm_api_management.test.publisher_name}" - publisher_email = "${azurerm_api_management.test.publisher_email}" + name = azurerm_api_management.test.name + location = azurerm_api_management.test.location + resource_group_name = azurerm_api_management.test.resource_group_name + publisher_name = azurerm_api_management.test.publisher_name + publisher_email = azurerm_api_management.test.publisher_email sku_name = "Developer_1" } @@ -435,6 +373,10 @@ resource "azurerm_api_management" "import" { func testAccAzureRMApiManagement_customProps(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -442,8 +384,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -459,6 +401,10 @@ resource "azurerm_api_management" "test" { func testAccAzureRMApiManagement_signInSignUpSettings(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -466,8 +412,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" @@ -492,6 +438,10 @@ resource "azurerm_api_management" "test" { func testAccAzureRMApiManagement_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test1" { name = "acctestRG-api1-%d" location = "%s" @@ -514,21 +464,21 @@ resource "azurerm_api_management" "test" { notification_sender_email = "notification@email.com" additional_location { - location = "${azurerm_resource_group.test2.location}" + location = azurerm_resource_group.test2.location } additional_location { - location = "${azurerm_resource_group.test3.location}" + location = azurerm_resource_group.test3.location } certificate { - encoded_certificate = "${filebase64("testdata/api_management_api_test.pfx")}" + encoded_certificate = filebase64("testdata/api_management_api_test.pfx") certificate_password = "terraform" store_name = "CertificateAuthority" } certificate { - encoded_certificate = "${filebase64("testdata/api_management_api_test.pfx")}" + encoded_certificate = filebase64("testdata/api_management_api_test.pfx") certificate_password = "terraform" store_name = "Root" } @@ -550,7 +500,7 @@ resource "azurerm_api_management" "test" { hostname_configuration { proxy { host_name = "api.terraform.io" - certificate = "${filebase64("testdata/api_management_api_test.pfx")}" + certificate = filebase64("testdata/api_management_api_test.pfx") certificate_password = "terraform" default_ssl_binding = true negotiate_client_certificate = false @@ -558,14 +508,14 @@ resource "azurerm_api_management" "test" { proxy { host_name = "api2.terraform.io" - certificate = "${filebase64("testdata/api_management_api2_test.pfx")}" + certificate = filebase64("testdata/api_management_api2_test.pfx") certificate_password = "terraform" negotiate_client_certificate = true } portal { host_name = "portal.terraform.io" - certificate = "${filebase64("testdata/api_management_portal_test.pfx")}" + certificate = filebase64("testdata/api_management_portal_test.pfx") certificate_password = "terraform" } } @@ -576,8 +526,8 @@ resource "azurerm_api_management" "test" { "Acceptance" = "Test" } - location = "${azurerm_resource_group.test1.location}" - resource_group_name = "${azurerm_resource_group.test1.name}" + location = azurerm_resource_group.test1.location + resource_group_name = azurerm_resource_group.test1.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.Locations.Ternary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_user_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_user_test.go index b3d7b1bae77da..c2a18ed1c961d 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_user_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_user_test.go @@ -267,8 +267,8 @@ func testAccAzureRMApiManagementUser_basic(data acceptance.TestData) string { resource "azurerm_api_management_user" "test" { user_id = "acctestuser%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name first_name = "Acceptance" last_name = "Test" email = "azure-acctest%d@example.com" @@ -282,13 +282,13 @@ func testAccAzureRMApiManagementUser_requiresImport(data acceptance.TestData) st %s resource "azurerm_api_management_user" "import" { - user_id = "${azurerm_api_management_user.test.user_id}" - api_management_name = "${azurerm_api_management_user.test.api_management_name}" - resource_group_name = "${azurerm_api_management_user.test.resource_group_name}" - first_name = "${azurerm_api_management_user.test.first_name}" - last_name = "${azurerm_api_management_user.test.last_name}" - email = "${azurerm_api_management_user.test.email}" - state = "${azurerm_api_management_user.test.state}" + user_id = azurerm_api_management_user.test.user_id + api_management_name = azurerm_api_management_user.test.api_management_name + resource_group_name = azurerm_api_management_user.test.resource_group_name + first_name = azurerm_api_management_user.test.first_name + last_name = azurerm_api_management_user.test.last_name + email = azurerm_api_management_user.test.email + state = azurerm_api_management_user.test.state } `, template) } @@ -300,8 +300,8 @@ func testAccAzureRMApiManagementUser_password(data acceptance.TestData) string { resource "azurerm_api_management_user" "test" { user_id = "acctestuser%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name first_name = "Acceptance" last_name = "Test" email = "azure-acctest%d@example.com" @@ -318,8 +318,8 @@ func testAccAzureRMApiManagementUser_updatedActive(data acceptance.TestData) str resource "azurerm_api_management_user" "test" { user_id = "acctestuser%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name first_name = "Acceptance" last_name = "Test" email = "azure-acctest%d@example.com" @@ -335,8 +335,8 @@ func testAccAzureRMApiManagementUser_updatedBlocked(data acceptance.TestData) st resource "azurerm_api_management_user" "test" { user_id = "acctestuser%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name first_name = "Acceptance Updated" last_name = "Test Updated" email = "azure-acctest%d@example.com" @@ -352,8 +352,8 @@ func testAccAzureRMApiManagementUser_invited(data acceptance.TestData) string { resource "azurerm_api_management_user" "test" { user_id = "acctestuser%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name first_name = "Acceptance" last_name = "Test User" email = "azure-acctest%d@example.com" @@ -370,8 +370,8 @@ func testAccAzureRMApiManagementUser_signUp(data acceptance.TestData) string { resource "azurerm_api_management_user" "test" { user_id = "acctestuser%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name first_name = "Acceptance" last_name = "Test User" email = "azure-acctest%d@example.com" @@ -388,8 +388,8 @@ func testAccAzureRMApiManagementUser_complete(data acceptance.TestData) string { resource "azurerm_api_management_user" "test" { user_id = "acctestuser%d" - api_management_name = "${azurerm_api_management.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = azurerm_api_management.test.name + resource_group_name = azurerm_resource_group.test.name first_name = "Acceptance" last_name = "Test" email = "azure-acctest%d@example.com" @@ -402,6 +402,10 @@ resource "azurerm_api_management_user" "test" { func testAccAzureRMApiManagementUser_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -409,8 +413,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_api_management" "test" { name = "acctestAM-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name publisher_name = "pub1" publisher_email = "pub1@email.com" diff --git a/azurerm/internal/services/appconfiguration/registration.go b/azurerm/internal/services/appconfiguration/registration.go index 31d7af75ab0d6..dd8d1a92fe0d4 100644 --- a/azurerm/internal/services/appconfiguration/registration.go +++ b/azurerm/internal/services/appconfiguration/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "App Configuration" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "App Configuration", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{} diff --git a/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go b/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go index 443fc88059f0a..445ed626dc4b2 100644 --- a/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go +++ b/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go @@ -234,6 +234,10 @@ func testCheckAzureAppConfigurationExists(resourceName string) resource.TestChec func testAccAzureAppConfiguration_free(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -241,8 +245,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_app_configuration" "test" { name = "testacc-appconf%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "free" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -250,6 +254,10 @@ resource "azurerm_app_configuration" "test" { func testAccAzureAppConfiguration_standard(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -257,8 +265,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_app_configuration" "test" { name = "testaccappconf%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "standard" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -270,17 +278,20 @@ func testAccAzureAppConfiguration_requiresImport(data acceptance.TestData) strin %s resource "azurerm_app_configuration" "import" { - name = "${azurerm_app_configuration.test.name}" - resource_group_name = "${azurerm_app_configuration.test.resource_group_name}" - location = "${azurerm_app_configuration.test.location}" - sku = "${azurerm_app_configuration.test.sku}" - + name = azurerm_app_configuration.test.name + resource_group_name = azurerm_app_configuration.test.resource_group_name + location = azurerm_app_configuration.test.location + sku = azurerm_app_configuration.test.sku } `, template) } func testAccAzureAppConfiguration_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -288,8 +299,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_app_configuration" "test" { name = "testaccappconf%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "free" tags = { @@ -301,6 +312,10 @@ resource "azurerm_app_configuration" "test" { func testAccAzureAppConfiguration_completeUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -308,8 +323,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_app_configuration" "test" { name = "testaccappconf%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "free" tags = { diff --git a/azurerm/internal/services/applicationinsights/registration.go b/azurerm/internal/services/applicationinsights/registration.go index 786526aec7538..ae2acee73a023 100644 --- a/azurerm/internal/services/applicationinsights/registration.go +++ b/azurerm/internal/services/applicationinsights/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Application Insights" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Application Insights", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go b/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go index d596b74ee05d8..e348c038a7984 100644 --- a/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go +++ b/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -48,10 +47,9 @@ func resourceArmApplicationInsights() *schema.Resource { "location": azure.SchemaLocation(), "application_type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - DiffSuppressFunc: suppress.CaseDifference, + Type: schema.TypeString, + Required: true, + ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ "web", "other", @@ -61,7 +59,7 @@ func resourceArmApplicationInsights() *schema.Resource { "store", "ios", "Node.JS", - }, true), + }, false), }, "retention_in_days": { @@ -164,14 +162,9 @@ func resourceArmApplicationInsightsCreateUpdate(d *schema.ResourceData, meta int Tags: tags.Expand(t), } - resp, err := client.CreateOrUpdate(ctx, resGroup, name, insightProperties) + _, err := client.CreateOrUpdate(ctx, resGroup, name, insightProperties) if err != nil { - // @tombuildsstuff - from 2018-08-14 the Create call started returning a 201 instead of 200 - // which doesn't match the Swagger - this works around it until that's fixed - // BUG: https://github.com/Azure/azure-sdk-for-go/issues/2465 - if resp.StatusCode != http.StatusCreated { - return fmt.Errorf("Error creating Application Insights %q (Resource Group %q): %+v", name, resGroup, err) - } + return fmt.Errorf("Error creating Application Insights %q (Resource Group %q): %+v", name, resGroup, err) } read, err := client.Get(ctx, resGroup, name) diff --git a/azurerm/internal/services/applicationinsights/tests/data_source_application_insights_test.go b/azurerm/internal/services/applicationinsights/tests/data_source_application_insights_test.go index c189f74ff8012..81b463feb3868 100644 --- a/azurerm/internal/services/applicationinsights/tests/data_source_application_insights_test.go +++ b/azurerm/internal/services/applicationinsights/tests/data_source_application_insights_test.go @@ -33,6 +33,10 @@ func TestAccDataSourceApplicationInsights_basic(t *testing.T) { func testAccResourceApplicationInsights_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%[2]s" @@ -40,8 +44,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_insights" "test" { name = "acctestappinsights-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name application_type = "other" tags = { @@ -50,8 +54,8 @@ resource "azurerm_application_insights" "test" { } data "azurerm_application_insights" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - name = "${azurerm_application_insights.test.name}" + resource_group_name = azurerm_resource_group.test.name + name = azurerm_application_insights.test.name } `, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_analytics_item_test.go b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_analytics_item_test.go index 35eb2d2962064..a4b4778cd49fc 100644 --- a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_analytics_item_test.go +++ b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_analytics_item_test.go @@ -174,6 +174,10 @@ func testCheckAzureRMApplicationInsightsAnalyticsItemExistsInternal(rs *terrafor func testAccAzureRMApplicationInsightsAnalyticsItem_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -181,14 +185,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_insights" "test" { name = "acctestappinsights-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name application_type = "web" } resource "azurerm_application_insights_analytics_item" "test" { name = "testquery" - application_insights_id = "${azurerm_application_insights.test.id}" + application_insights_id = azurerm_application_insights.test.id content = "requests #test" scope = "shared" type = "query" @@ -198,6 +202,10 @@ resource "azurerm_application_insights_analytics_item" "test" { func testAccAzureRMApplicationInsightsAnalyticsItem_basic2(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -205,14 +213,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_insights" "test" { name = "acctestappinsights-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name application_type = "web" } resource "azurerm_application_insights_analytics_item" "test" { name = "testquery" - application_insights_id = "${azurerm_application_insights.test.id}" + application_insights_id = azurerm_application_insights.test.id content = "requests #updated" scope = "shared" type = "query" @@ -222,6 +230,10 @@ resource "azurerm_application_insights_analytics_item" "test" { func testAccAzureRMApplicationInsightsAnalyticsItem_multiple(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -229,14 +241,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_insights" "test" { name = "acctestappinsights-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name application_type = "web" } resource "azurerm_application_insights_analytics_item" "test1" { name = "testquery1" - application_insights_id = "${azurerm_application_insights.test.id}" + application_insights_id = azurerm_application_insights.test.id content = "requests #test1" scope = "shared" type = "query" @@ -244,7 +256,7 @@ resource "azurerm_application_insights_analytics_item" "test1" { resource "azurerm_application_insights_analytics_item" "test2" { name = "testquery2" - application_insights_id = "${azurerm_application_insights.test.id}" + application_insights_id = azurerm_application_insights.test.id content = "requests #test2" scope = "user" type = "query" @@ -252,7 +264,7 @@ resource "azurerm_application_insights_analytics_item" "test2" { resource "azurerm_application_insights_analytics_item" "test3" { name = "testfunction1" - application_insights_id = "${azurerm_application_insights.test.id}" + application_insights_id = azurerm_application_insights.test.id content = "requests #test3" scope = "shared" type = "function" diff --git a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_api_key_test.go b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_api_key_test.go index 49db3778f3cbb..6b43ca8ba73b1 100644 --- a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_api_key_test.go +++ b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_api_key_test.go @@ -207,6 +207,10 @@ func testCheckAzureRMApplicationInsightsAPIKeyExists(resourceName string) resour func testAccAzureRMApplicationInsightsAPIKey_basic(data acceptance.TestData, readPerms, writePerms string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -214,14 +218,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_insights" "test" { name = "acctestappinsights-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name application_type = "web" } resource "azurerm_application_insights_api_key" "test" { name = "acctestappinsightsapikey-%d" - application_insights_id = "${azurerm_application_insights.test.id}" + application_insights_id = azurerm_application_insights.test.id read_permissions = %s write_permissions = %s } @@ -234,10 +238,10 @@ func testAccAzureRMApplicationInsightsAPIKey_requiresImport(data acceptance.Test %s resource "azurerm_application_insights_api_key" "import" { - name = "${azurerm_application_insights_api_key.test.name}" - application_insights_id = "${azurerm_application_insights_api_key.test.application_insights_id}" - read_permissions = "${azurerm_application_insights_api_key.test.read_permissions}" - write_permissions = "${azurerm_application_insights_api_key.test.write_permissions}" + name = azurerm_application_insights_api_key.test.name + application_insights_id = azurerm_application_insights_api_key.test.application_insights_id + read_permissions = azurerm_application_insights_api_key.test.read_permissions + write_permissions = azurerm_application_insights_api_key.test.write_permissions } `, template) } diff --git a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_test.go b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_test.go index 6d742ed2b8044..22ffbb3053b11 100644 --- a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_test.go +++ b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_test.go @@ -263,6 +263,10 @@ func TestAccAzureRMApplicationInsights_complete(t *testing.T) { func testAccAzureRMApplicationInsights_basic(data acceptance.TestData, applicationType string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -270,8 +274,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_insights" "test" { name = "acctestappinsights-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name application_type = "%s" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, applicationType) @@ -283,16 +287,20 @@ func testAccAzureRMApplicationInsights_requiresImport(data acceptance.TestData, %s resource "azurerm_application_insights" "import" { - name = "${azurerm_application_insights.test.name}" - location = "${azurerm_application_insights.test.location}" - resource_group_name = "${azurerm_application_insights.test.resource_group_name}" - application_type = "${azurerm_application_insights.test.application_type}" + name = azurerm_application_insights.test.name + location = azurerm_application_insights.test.location + resource_group_name = azurerm_application_insights.test.resource_group_name + application_type = azurerm_application_insights.test.application_type } `, template) } func testAccAzureRMApplicationInsights_complete(data acceptance.TestData, applicationType string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -300,8 +308,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_insights" "test" { name = "acctestappinsights-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name application_type = "%s" retention_in_days = 120 sampling_percentage = 50 diff --git a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_webtests_test.go b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_webtests_test.go index 96948b0b4df19..b9e892d9160cb 100644 --- a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_webtests_test.go +++ b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_webtests_test.go @@ -167,6 +167,10 @@ func testCheckAzureRMApplicationInsightsWebTestExists(resourceName string) resou func testAccAzureRMApplicationInsightsWebTests_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -174,16 +178,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_insights" "test" { name = "acctestappinsights-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name application_type = "web" } resource "azurerm_application_insights_web_test" "test" { name = "acctestappinsightswebtests-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - application_insights_id = "${azurerm_application_insights.test.id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + application_insights_id = azurerm_application_insights.test.id kind = "ping" geo_locations = ["us-tx-sn1-azr"] @@ -194,12 +198,17 @@ resource "azurerm_application_insights_web_test" "test" { XML + } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testAccAzureRMApplicationInsightsWebTests_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -207,16 +216,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_insights" "test" { name = "acctestappinsights-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name application_type = "web" } resource "azurerm_application_insights_web_test" "test" { name = "acctestappinsightswebtests-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - application_insights_id = "${azurerm_application_insights.test.id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + application_insights_id = azurerm_application_insights.test.id kind = "ping" frequency = 900 timeout = 120 @@ -230,6 +239,7 @@ resource "azurerm_application_insights_web_test" "test" { XML + } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } @@ -240,12 +250,12 @@ func testAccAzureRMApplicationInsightsWebTests_requiresImport(data acceptance.Te %s resource "azurerm_application_insights_web_test" "import" { - name = "${azurerm_application_insights_web_test.test.name}" - location = "${azurerm_application_insights_web_test.test.location}" - resource_group_name = "${azurerm_application_insights_web_test.test.resource_group_name}" - application_insights_id = "${azurerm_application_insights_web_test.test.application_insights_id}" - kind = "${azurerm_application_insights_web_test.test.kind}" - configuration = "${azurerm_application_insights_web_test.test.configuration}" + name = azurerm_application_insights_web_test.test.name + location = azurerm_application_insights_web_test.test.location + resource_group_name = azurerm_application_insights_web_test.test.resource_group_name + application_insights_id = azurerm_application_insights_web_test.test.application_insights_id + kind = azurerm_application_insights_web_test.test.kind + configuration = azurerm_application_insights_web_test.test.configuration } `, template) } diff --git a/azurerm/internal/services/authorization/client/client.go b/azurerm/internal/services/authorization/client/client.go index 756528480fa72..155708bebb0bb 100644 --- a/azurerm/internal/services/authorization/client/client.go +++ b/azurerm/internal/services/authorization/client/client.go @@ -19,8 +19,8 @@ func NewClient(o *common.ClientOptions) *Client { roleDefinitionsClient := authorization.NewRoleDefinitionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&roleDefinitionsClient.Client, o.ResourceManagerAuthorizer) - servicePrincipalsClient := graphrbac.NewServicePrincipalsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) - o.ConfigureClient(&servicePrincipalsClient.Client, o.ResourceManagerAuthorizer) + servicePrincipalsClient := graphrbac.NewServicePrincipalsClientWithBaseURI(o.GraphEndpoint, o.TenantID) + o.ConfigureClient(&servicePrincipalsClient.Client, o.GraphAuthorizer) return &Client{ RoleAssignmentsClient: &roleAssignmentsClient, diff --git a/azurerm/internal/services/authorization/data_source_builtin_role_definition.go b/azurerm/internal/services/authorization/data_source_builtin_role_definition.go deleted file mode 100644 index 3c47827503a19..0000000000000 --- a/azurerm/internal/services/authorization/data_source_builtin_role_definition.go +++ /dev/null @@ -1,190 +0,0 @@ -package authorization - -import ( - "fmt" - "time" - - "github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-09-01-preview/authorization" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" -) - -func dataSourceArmBuiltInRoleDefinition() *schema.Resource { - return &schema.Resource{ - Read: dataSourceArmBuiltInRoleDefinitionRead, - - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), - }, - - DeprecationMessage: `This Data Source has been deprecated in favour of the 'azurerm_role_definition' resource that now can look up role definitions by names. - -As such this Data Source will be removed in v2.0 of the AzureRM Provider. -`, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - }, - - // Computed - "description": { - Type: schema.TypeString, - Computed: true, - }, - "type": { - Type: schema.TypeString, - Computed: true, - }, - "permissions": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "actions": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "not_actions": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "data_actions": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - Set: schema.HashString, - }, - "not_data_actions": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - Set: schema.HashString, - }, - }, - }, - }, - "assignable_scopes": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - } -} - -func dataSourceArmBuiltInRoleDefinitionRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Authorization.RoleDefinitionsClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - name := d.Get("name").(string) - if name == "VirtualMachineContributor" { - name = "Virtual Machine Contributor" - } - filter := fmt.Sprintf("roleName eq '%s'", name) - roleDefinitions, err := client.List(ctx, "", filter) - if err != nil { - return fmt.Errorf("Error loading Role Definition List: %+v", err) - } - if len(roleDefinitions.Values()) != 1 { - return fmt.Errorf("Error loading Role Definition List: could not find role '%s'", name) - } - - roleDefinitionId := *roleDefinitions.Values()[0].ID - - d.SetId(roleDefinitionId) - - role, err := client.GetByID(ctx, roleDefinitionId) - if err != nil { - return fmt.Errorf("Error loading Role Definition: %+v", err) - } - - if props := role.RoleDefinitionProperties; props != nil { - d.Set("name", props.RoleName) - d.Set("description", props.Description) - d.Set("type", props.RoleType) - - permissions := flattenRoleDefinitionDataSourcePermissions(props.Permissions) - if err := d.Set("permissions", permissions); err != nil { - return err - } - - assignableScopes := flattenRoleDefinitionDataSourceAssignableScopes(props.AssignableScopes) - if err := d.Set("assignable_scopes", assignableScopes); err != nil { - return err - } - } - - return nil -} - -func flattenRoleDefinitionDataSourcePermissions(input *[]authorization.Permission) []interface{} { - permissions := make([]interface{}, 0) - if input == nil { - return permissions - } - - for _, permission := range *input { - output := make(map[string]interface{}) - - actions := make([]string, 0) - if s := permission.Actions; s != nil { - actions = *s - } - output["actions"] = actions - - dataActions := make([]interface{}, 0) - if s := permission.DataActions; s != nil { - for _, dataAction := range *s { - dataActions = append(dataActions, dataAction) - } - } - output["data_actions"] = schema.NewSet(schema.HashString, dataActions) - - notActions := make([]string, 0) - if s := permission.NotActions; s != nil { - notActions = *s - } - output["not_actions"] = notActions - - notDataActions := make([]interface{}, 0) - if s := permission.NotDataActions; s != nil { - for _, dataAction := range *s { - notDataActions = append(notDataActions, dataAction) - } - } - output["not_data_actions"] = schema.NewSet(schema.HashString, notDataActions) - - permissions = append(permissions, output) - } - - return permissions -} - -func flattenRoleDefinitionDataSourceAssignableScopes(input *[]string) []interface{} { - scopes := make([]interface{}, 0) - if input == nil { - return scopes - } - - for _, scope := range *input { - scopes = append(scopes, scope) - } - - return scopes -} diff --git a/azurerm/internal/services/authorization/data_source_client_config.go b/azurerm/internal/services/authorization/data_source_client_config.go index 165e183611fa4..21d1a7a613d4f 100644 --- a/azurerm/internal/services/authorization/data_source_client_config.go +++ b/azurerm/internal/services/authorization/data_source_client_config.go @@ -4,7 +4,6 @@ import ( "fmt" "time" - "github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -38,17 +37,6 @@ func dataSourceArmClientConfig() *schema.Resource { Type: schema.TypeString, Computed: true, }, - - "service_principal_application_id": { - Type: schema.TypeString, - Computed: true, - Deprecated: "This has been deprecated in favour of the `client_id` property", - }, - "service_principal_object_id": { - Type: schema.TypeString, - Computed: true, - Deprecated: "This has been deprecated in favour of the unified `authenticated_object_id` property", - }, }, } } @@ -58,7 +46,6 @@ func dataSourceArmClientConfigRead(d *schema.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - var servicePrincipal *graphrbac.ServicePrincipal if client.Account.AuthenticatedAsAServicePrincipal { spClient := client.Authorization.ServicePrincipalsClient // Application & Service Principal is 1:1 per tenant. Since we know the appId (client_id) @@ -73,8 +60,6 @@ func dataSourceArmClientConfigRead(d *schema.ResourceData, meta interface{}) err if listResult.Values() == nil || len(listResult.Values()) != 1 { return fmt.Errorf("Unexpected Service Principal query result: %#v", listResult.Values()) } - - servicePrincipal = &(listResult.Values())[0] } d.SetId(time.Now().UTC().String()) @@ -83,13 +68,5 @@ func dataSourceArmClientConfigRead(d *schema.ResourceData, meta interface{}) err d.Set("subscription_id", client.Account.SubscriptionId) d.Set("tenant_id", client.Account.TenantId) - if principal := servicePrincipal; principal != nil { - d.Set("service_principal_application_id", client.Account.ClientId) - d.Set("service_principal_object_id", principal.ObjectID) - } else { - d.Set("service_principal_application_id", "") - d.Set("service_principal_object_id", "") - } - return nil } diff --git a/azurerm/internal/services/authorization/registration.go b/azurerm/internal/services/authorization/registration.go index 47a95de3a2145..9fd6e42c3dd9f 100644 --- a/azurerm/internal/services/authorization/registration.go +++ b/azurerm/internal/services/authorization/registration.go @@ -11,12 +11,18 @@ func (r Registration) Name() string { return "Authorization" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Authorization", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), - "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_role_definition": dataSourceArmRoleDefinition(), + "azurerm_client_config": dataSourceArmClientConfig(), + "azurerm_role_definition": dataSourceArmRoleDefinition(), } } diff --git a/azurerm/internal/services/authorization/resource_arm_role_assignment.go b/azurerm/internal/services/authorization/resource_arm_role_assignment.go index 7afbdb0edc2cb..c3ffb6b93ba32 100644 --- a/azurerm/internal/services/authorization/resource_arm_role_assignment.go +++ b/azurerm/internal/services/authorization/resource_arm_role_assignment.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" @@ -36,10 +37,11 @@ func resourceArmRoleAssignment() *schema.Resource { Schema: map[string]*schema.Schema{ "name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ValidateFunc: validation.IsUUID, }, "scope": { @@ -192,7 +194,7 @@ func resourceArmRoleAssignmentRead(d *schema.ResourceData, meta interface{}) err d.Set("principal_id", props.PrincipalID) d.Set("principal_type", props.PrincipalType) - //allows for import when role name is used (also if the role name changes a plan will show a diff) + // allows for import when role name is used (also if the role name changes a plan will show a diff) if roleId := props.RoleDefinitionID; roleId != nil { roleResp, err := roleDefinitionsClient.GetByID(ctx, *roleId) if err != nil { diff --git a/azurerm/internal/services/authorization/tests/data_source_builtin_role_definition_test.go b/azurerm/internal/services/authorization/tests/data_source_builtin_role_definition_test.go deleted file mode 100644 index 805b443e014c0..0000000000000 --- a/azurerm/internal/services/authorization/tests/data_source_builtin_role_definition_test.go +++ /dev/null @@ -1,112 +0,0 @@ -package tests - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMBuiltInRoleDefinition_contributor(t *testing.T) { - data := acceptance.BuildTestData(t, "data.azurerm_builtin_role_definition", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceBuiltInRoleDefinition("Contributor"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"), - resource.TestCheckResourceAttrSet(data.ResourceName, "description"), - resource.TestCheckResourceAttrSet(data.ResourceName, "type"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "5"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/Delete"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.1", "Microsoft.Authorization/*/Write"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.2", "Microsoft.Authorization/elevateAccess/Action"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.3", "Microsoft.Blueprint/blueprintAssignments/write"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.4", "Microsoft.Blueprint/blueprintAssignments/delete"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMBuiltInRoleDefinition_owner(t *testing.T) { - data := acceptance.BuildTestData(t, "data.azurerm_builtin_role_definition", "test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceBuiltInRoleDefinition("Owner"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"), - resource.TestCheckResourceAttrSet(data.ResourceName, "description"), - resource.TestCheckResourceAttrSet(data.ResourceName, "type"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "0"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMBuiltInRoleDefinition_reader(t *testing.T) { - data := acceptance.BuildTestData(t, "data.azurerm_builtin_role_definition", "test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceBuiltInRoleDefinition("Reader"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7"), - resource.TestCheckResourceAttrSet(data.ResourceName, "description"), - resource.TestCheckResourceAttrSet(data.ResourceName, "type"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*/read"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "0"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMBuiltInRoleDefinition_virtualMachineContributor(t *testing.T) { - data := acceptance.BuildTestData(t, "data.azurerm_builtin_role_definition", "test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceBuiltInRoleDefinition("VirtualMachineContributor"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c"), - resource.TestCheckResourceAttrSet(data.ResourceName, "description"), - resource.TestCheckResourceAttrSet(data.ResourceName, "type"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "38"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "Microsoft.Authorization/*/read"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.15", "Microsoft.Network/networkSecurityGroups/join/action"), - resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "0"), - ), - }, - }, - }) -} - -func testAccDataSourceBuiltInRoleDefinition(name string) string { - return fmt.Sprintf(` -data "azurerm_builtin_role_definition" "test" { - name = "%s" -} -`, name) -} diff --git a/azurerm/internal/services/authorization/tests/data_source_client_config_test.go b/azurerm/internal/services/authorization/tests/data_source_client_config_test.go index 859f5fbcd718d..f33d956d2d3db 100644 --- a/azurerm/internal/services/authorization/tests/data_source_client_config_test.go +++ b/azurerm/internal/services/authorization/tests/data_source_client_config_test.go @@ -27,8 +27,6 @@ func TestAccDataSourceAzureRMClientConfig_basic(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "tenant_id", tenantId), resource.TestCheckResourceAttr(data.ResourceName, "subscription_id", subscriptionId), testAzureRMClientConfigGUIDAttr(data.ResourceName, "object_id"), - testAzureRMClientConfigGUIDAttr(data.ResourceName, "service_principal_application_id"), - testAzureRMClientConfigGUIDAttr(data.ResourceName, "service_principal_object_id"), ), }, }, diff --git a/azurerm/internal/services/authorization/tests/data_source_role_definition_test.go b/azurerm/internal/services/authorization/tests/data_source_role_definition_test.go index 74b292722433b..9b0558b5b2790 100644 --- a/azurerm/internal/services/authorization/tests/data_source_role_definition_test.go +++ b/azurerm/internal/services/authorization/tests/data_source_role_definition_test.go @@ -157,6 +157,10 @@ func TestAccDataSourceAzureRMRoleDefinition_builtIn_virtualMachineContributor(t func testAccDataSourceAzureRMRoleDefinition_builtIn(name string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_role_definition" "test" { name = "%s" } @@ -165,12 +169,17 @@ data "azurerm_role_definition" "test" { func testAccDataSourceRoleDefinition_basic(id string, data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_subscription" "primary" {} +provider "azurerm" { + features {} +} + +data "azurerm_subscription" "primary" { +} resource "azurerm_role_definition" "test" { role_definition_id = "%s" name = "acctestrd-%d" - scope = "${data.azurerm_subscription.primary.id}" + scope = data.azurerm_subscription.primary.id description = "Created by the Data Source Role Definition Acceptance Test" permissions { @@ -184,13 +193,13 @@ resource "azurerm_role_definition" "test" { } assignable_scopes = [ - "${data.azurerm_subscription.primary.id}", + data.azurerm_subscription.primary.id, ] } data "azurerm_role_definition" "test" { - role_definition_id = "${azurerm_role_definition.test.role_definition_id}" - scope = "${data.azurerm_subscription.primary.id}" + role_definition_id = azurerm_role_definition.test.role_definition_id + scope = data.azurerm_subscription.primary.id } `, id, data.RandomInteger) } @@ -200,8 +209,8 @@ func testAccDataSourceRoleDefinition_byName(id string, data acceptance.TestData) %s data "azurerm_role_definition" "byName" { - name = "${azurerm_role_definition.test.name}" - scope = "${data.azurerm_subscription.primary.id}" + name = azurerm_role_definition.test.name + scope = data.azurerm_subscription.primary.id } `, testAccDataSourceRoleDefinition_basic(id, data)) } diff --git a/azurerm/internal/services/authorization/tests/resource_arm_role_assignment_test.go b/azurerm/internal/services/authorization/tests/resource_arm_role_assignment_test.go index 0b30cb6b1edd0..6f14ad186156b 100644 --- a/azurerm/internal/services/authorization/tests/resource_arm_role_assignment_test.go +++ b/azurerm/internal/services/authorization/tests/resource_arm_role_assignment_test.go @@ -342,29 +342,35 @@ data "azurerm_subscription" "primary" {} data "azurerm_client_config" "test" {} -data "azurerm_builtin_role_definition" "test" { +data "azurerm_role_definition" "test" { name = "Monitoring Reader" } resource "azurerm_role_assignment" "test" { scope = "${data.azurerm_subscription.primary.id}" - role_definition_id = "${data.azurerm_subscription.primary.id}${data.azurerm_builtin_role_definition.test.id}" - principal_id = "${data.azurerm_client_config.test.service_principal_object_id}" + role_definition_id = "${data.azurerm_subscription.primary.id}${data.azurerm_role_definition.test.id}" + principal_id = "${data.azurerm_client_config.test.object_id}" } ` } func testAccAzureRMRoleAssignment_roleNameConfig(id string) string { return fmt.Sprintf(` -data "azurerm_subscription" "primary" {} +provider "azurerm" { + features {} +} -data "azurerm_client_config" "test" {} +data "azurerm_subscription" "primary" { +} + +data "azurerm_client_config" "test" { +} resource "azurerm_role_assignment" "test" { name = "%s" - scope = "${data.azurerm_subscription.primary.id}" + scope = data.azurerm_subscription.primary.id role_definition_name = "Log Analytics Reader" - principal_id = "${data.azurerm_client_config.test.service_principal_object_id}" + principal_id = data.azurerm_client_config.test.object_id } `, id) } @@ -374,58 +380,76 @@ func testAccAzureRMRoleAssignment_requiresImportConfig(id string) string { %s resource "azurerm_role_assignment" "import" { - name = "${azurerm_role_assignment.test.name}" - scope = "${azurerm_role_assignment.test.id}" - role_definition_name = "${azurerm_role_assignment.test.role_definition_name}" - principal_id = "${azurerm_role_assignment.test.principal_id}" + name = azurerm_role_assignment.test.name + scope = azurerm_role_assignment.test.id + role_definition_name = azurerm_role_assignment.test.role_definition_name + principal_id = azurerm_role_assignment.test.principal_id } `, testAccAzureRMRoleAssignment_roleNameConfig(id)) } func testAccAzureRMRoleAssignment_dataActionsConfig(id string) string { return fmt.Sprintf(` -data "azurerm_subscription" "primary" {} +provider "azurerm" { + features {} +} -data "azurerm_client_config" "test" {} +data "azurerm_subscription" "primary" { +} + +data "azurerm_client_config" "test" { +} resource "azurerm_role_assignment" "test" { name = "%s" - scope = "${data.azurerm_subscription.primary.id}" + scope = data.azurerm_subscription.primary.id role_definition_name = "Virtual Machine User Login" - principal_id = "${data.azurerm_client_config.test.service_principal_object_id}" + principal_id = data.azurerm_client_config.test.object_id } `, id) } func testAccAzureRMRoleAssignment_builtinConfig(id string) string { return fmt.Sprintf(` -data "azurerm_subscription" "primary" {} +provider "azurerm" { + features {} +} -data "azurerm_client_config" "test" {} +data "azurerm_subscription" "primary" { +} -data "azurerm_builtin_role_definition" "test" { +data "azurerm_client_config" "test" { +} + +data "azurerm_role_definition" "test" { name = "Site Recovery Reader" } resource "azurerm_role_assignment" "test" { name = "%s" - scope = "${data.azurerm_subscription.primary.id}" - role_definition_id = "${data.azurerm_subscription.primary.id}${data.azurerm_builtin_role_definition.test.id}" - principal_id = "${data.azurerm_client_config.test.service_principal_object_id}" + scope = data.azurerm_subscription.primary.id + role_definition_id = "${data.azurerm_subscription.primary.id}${data.azurerm_role_definition.test.id}" + principal_id = data.azurerm_client_config.test.object_id } `, id) } func testAccAzureRMRoleAssignment_customConfig(roleDefinitionId string, roleAssignmentId string, rInt int) string { return fmt.Sprintf(` -data "azurerm_subscription" "primary" {} +provider "azurerm" { + features {} +} -data "azurerm_client_config" "test" {} +data "azurerm_subscription" "primary" { +} + +data "azurerm_client_config" "test" { +} resource "azurerm_role_definition" "test" { role_definition_id = "%s" name = "acctestrd-%d" - scope = "${data.azurerm_subscription.primary.id}" + scope = data.azurerm_subscription.primary.id description = "Created by the Role Assignment Acceptance Test" permissions { @@ -434,57 +458,67 @@ resource "azurerm_role_definition" "test" { } assignable_scopes = [ - "${data.azurerm_subscription.primary.id}", + data.azurerm_subscription.primary.id, ] } resource "azurerm_role_assignment" "test" { name = "%s" - scope = "${data.azurerm_subscription.primary.id}" - role_definition_id = "${azurerm_role_definition.test.id}" - principal_id = "${data.azurerm_client_config.test.service_principal_object_id}" + scope = data.azurerm_subscription.primary.id + role_definition_id = azurerm_role_definition.test.id + principal_id = data.azurerm_client_config.test.object_id } `, roleDefinitionId, rInt, roleAssignmentId) } func testAccAzureRMRoleAssignment_servicePrincipal(rInt int, roleAssignmentID string) string { return fmt.Sprintf(` -data "azurerm_subscription" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_subscription" "current" { +} resource "azuread_application" "test" { name = "acctestspa-%d" } resource "azuread_service_principal" "test" { - application_id = "${azuread_application.test.application_id}" + application_id = azuread_application.test.application_id } resource "azurerm_role_assignment" "test" { name = "%s" - scope = "${data.azurerm_subscription.current.id}" + scope = data.azurerm_subscription.current.id role_definition_name = "Reader" - principal_id = "${azuread_service_principal.test.id}" + principal_id = azuread_service_principal.test.id } `, rInt, roleAssignmentID) } func testAccAzureRMRoleAssignment_servicePrincipalWithType(rInt int, roleAssignmentID string) string { return fmt.Sprintf(` -data "azurerm_subscription" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_subscription" "current" { +} resource "azuread_application" "test" { name = "acctestspa-%d" } resource "azuread_service_principal" "test" { - application_id = "${azuread_application.test.application_id}" + application_id = azuread_application.test.application_id } resource "azurerm_role_assignment" "test" { name = "%s" - scope = "${data.azurerm_subscription.current.id}" + scope = data.azurerm_subscription.current.id role_definition_name = "Reader" - principal_id = "${azuread_service_principal.test.id}" + principal_id = azuread_service_principal.test.id skip_service_principal_aad_check = true } `, rInt, roleAssignmentID) @@ -492,7 +526,12 @@ resource "azurerm_role_assignment" "test" { func testAccAzureRMRoleAssignment_group(rInt int, roleAssignmentID string) string { return fmt.Sprintf(` -data "azurerm_subscription" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_subscription" "current" { +} resource "azuread_group" "test" { name = "acctestspa-%d" @@ -500,18 +539,24 @@ resource "azuread_group" "test" { resource "azurerm_role_assignment" "test" { name = "%s" - scope = "${data.azurerm_subscription.current.id}" + scope = data.azurerm_subscription.current.id role_definition_name = "Reader" - principal_id = "${azuread_group.test.id}" + principal_id = azuread_group.test.id } `, rInt, roleAssignmentID) } func testAccAzureRMRoleAssignment_managementGroupConfig(groupId string) string { return fmt.Sprintf(` -data "azurerm_subscription" "primary" {} +provider "azurerm" { + features {} +} -data "azurerm_client_config" "test" {} +data "azurerm_subscription" "primary" { +} + +data "azurerm_client_config" "test" { +} data "azurerm_role_definition" "test" { name = "Monitoring Reader" @@ -522,9 +567,9 @@ resource "azurerm_management_group" "test" { } resource "azurerm_role_assignment" "test" { - scope = "${azurerm_management_group.test.id}" - role_definition_id = "${data.azurerm_role_definition.test.id}" - principal_id = "${data.azurerm_client_config.test.service_principal_object_id}" + scope = azurerm_management_group.test.id + role_definition_id = data.azurerm_role_definition.test.id + principal_id = data.azurerm_client_config.test.object_id } `, groupId) } diff --git a/azurerm/internal/services/authorization/tests/resource_arm_role_definition_test.go b/azurerm/internal/services/authorization/tests/resource_arm_role_definition_test.go index 5f22bd76ab0dd..fe6534b17ae97 100644 --- a/azurerm/internal/services/authorization/tests/resource_arm_role_definition_test.go +++ b/azurerm/internal/services/authorization/tests/resource_arm_role_definition_test.go @@ -224,12 +224,17 @@ func testCheckAzureRMRoleDefinitionDestroy(s *terraform.State) error { func testAccAzureRMRoleDefinition_basic(id string, data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_subscription" "primary" {} +provider "azurerm" { + features {} +} + +data "azurerm_subscription" "primary" { +} resource "azurerm_role_definition" "test" { role_definition_id = "%s" name = "acctestrd-%d" - scope = "${data.azurerm_subscription.primary.id}" + scope = data.azurerm_subscription.primary.id permissions { actions = ["*"] @@ -237,7 +242,7 @@ resource "azurerm_role_definition" "test" { } assignable_scopes = [ - "${data.azurerm_subscription.primary.id}", + data.azurerm_subscription.primary.id, ] } `, id, data.RandomInteger) @@ -248,9 +253,9 @@ func testAccAzureRMRoleDefinition_requiresImport(id string, data acceptance.Test %s resource "azurerm_role_definition" "import" { - role_definition_id = "${azurerm_role_definition.test.role_definition_id}" - name = "${azurerm_role_definition.test.name}" - scope = "${azurerm_role_definition.test.scope}" + role_definition_id = azurerm_role_definition.test.role_definition_id + name = azurerm_role_definition.test.name + scope = azurerm_role_definition.test.scope permissions { actions = ["*"] @@ -258,7 +263,7 @@ resource "azurerm_role_definition" "import" { } assignable_scopes = [ - "${data.azurerm_subscription.primary.id}", + data.azurerm_subscription.primary.id, ] } `, testAccAzureRMRoleDefinition_basic(id, data)) @@ -266,12 +271,17 @@ resource "azurerm_role_definition" "import" { func testAccAzureRMRoleDefinition_complete(id string, data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_subscription" "primary" {} +provider "azurerm" { + features {} +} + +data "azurerm_subscription" "primary" { +} resource "azurerm_role_definition" "test" { role_definition_id = "%s" name = "acctestrd-%d" - scope = "${data.azurerm_subscription.primary.id}" + scope = data.azurerm_subscription.primary.id description = "Acceptance Test Role Definition" permissions { @@ -282,7 +292,7 @@ resource "azurerm_role_definition" "test" { } assignable_scopes = [ - "${data.azurerm_subscription.primary.id}", + data.azurerm_subscription.primary.id, ] } `, id, data.RandomInteger) @@ -290,12 +300,17 @@ resource "azurerm_role_definition" "test" { func testAccAzureRMRoleDefinition_updated(id string, data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_subscription" "primary" {} +provider "azurerm" { + features {} +} + +data "azurerm_subscription" "primary" { +} resource "azurerm_role_definition" "test" { role_definition_id = "%s" name = "acctestrd-%d-updated" - scope = "${data.azurerm_subscription.primary.id}" + scope = data.azurerm_subscription.primary.id description = "Acceptance Test Role Definition" permissions { @@ -304,7 +319,7 @@ resource "azurerm_role_definition" "test" { } assignable_scopes = [ - "${data.azurerm_subscription.primary.id}", + data.azurerm_subscription.primary.id, ] } `, id, data.RandomInteger) @@ -312,11 +327,16 @@ resource "azurerm_role_definition" "test" { func testAccAzureRMRoleDefinition_emptyId(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_subscription" "primary" {} +provider "azurerm" { + features {} +} + +data "azurerm_subscription" "primary" { +} resource "azurerm_role_definition" "test" { name = "acctestrd-%d" - scope = "${data.azurerm_subscription.primary.id}" + scope = data.azurerm_subscription.primary.id permissions { actions = ["*"] @@ -324,7 +344,7 @@ resource "azurerm_role_definition" "test" { } assignable_scopes = [ - "${data.azurerm_subscription.primary.id}", + data.azurerm_subscription.primary.id, ] } `, data.RandomInteger) @@ -332,11 +352,16 @@ resource "azurerm_role_definition" "test" { func testAccAzureRMRoleDefinition_updateEmptyId(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_subscription" "primary" {} +provider "azurerm" { + features {} +} + +data "azurerm_subscription" "primary" { +} resource "azurerm_role_definition" "test" { name = "acctestrd-%d" - scope = "${data.azurerm_subscription.primary.id}" + scope = data.azurerm_subscription.primary.id permissions { actions = ["*"] @@ -344,7 +369,7 @@ resource "azurerm_role_definition" "test" { } assignable_scopes = [ - "${data.azurerm_subscription.primary.id}", + data.azurerm_subscription.primary.id, ] } `, data.RandomInteger) diff --git a/azurerm/internal/services/automation/registration.go b/azurerm/internal/services/automation/registration.go index 26bc8d7ddf132..9c3fb84ac1b0e 100644 --- a/azurerm/internal/services/automation/registration.go +++ b/azurerm/internal/services/automation/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Automation" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Automation", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/automation/resource_arm_automation_account.go b/azurerm/internal/services/automation/resource_arm_automation_account.go index bc04ffee144b9..ed612228403b2 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_account.go +++ b/azurerm/internal/services/automation/resource_arm_automation_account.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -47,34 +46,9 @@ func resourceArmAutomationAccount() *schema.Resource { "resource_group_name": azure.SchemaResourceGroupName(), - // Remove in 2.0 - "sku": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Deprecated: "This property has been deprecated in favour of the 'sku_name' property and will be removed in version 2.0 of the provider", - ConflictsWith: []string{"sku_name"}, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Optional: true, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(automation.Basic), - string(automation.Free), - }, true), - }, - }, - }, - }, - "sku_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ConflictsWith: []string{"sku"}, + Type: schema.TypeString, + Required: true, ValidateFunc: validation.StringInSlice([]string{ string(automation.Basic), string(automation.Free), @@ -104,25 +78,8 @@ func resourceArmAutomationAccountCreateUpdate(d *schema.ResourceData, meta inter ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - // Remove in 2.0 - var sku automation.Sku - - if inputs := d.Get("sku").([]interface{}); len(inputs) != 0 { - input := inputs[0].(map[string]interface{}) - v := input["name"].(string) - - sku = automation.Sku{ - Name: automation.SkuNameEnum(v), - } - } else { - // Keep in 2.0 - sku = automation.Sku{ - Name: automation.SkuNameEnum(d.Get("sku_name").(string)), - } - } - - if sku.Name == "" { - return fmt.Errorf("either 'sku_name' or 'sku' must be defined in the configuration file") + sku := automation.Sku{ + Name: automation.SkuNameEnum(d.Get("sku_name").(string)), } log.Printf("[INFO] preparing arguments for Automation Account create/update.") @@ -214,11 +171,6 @@ func resourceArmAutomationAccountRead(d *schema.ResourceData, meta interface{}) } if sku := resp.Sku; sku != nil { - // Remove in 2.0 - if err := d.Set("sku", flattenAutomationAccountSku(sku)); err != nil { - return fmt.Errorf("Error setting 'sku': %+v", err) - } - if err := d.Set("sku_name", string(sku.Name)); err != nil { return fmt.Errorf("Error setting 'sku_name': %+v", err) } @@ -263,14 +215,3 @@ func resourceArmAutomationAccountDelete(d *schema.ResourceData, meta interface{} return nil } - -// Remove in 2.0 -func flattenAutomationAccountSku(sku *automation.Sku) []interface{} { - if sku == nil { - return []interface{}{} - } - - result := map[string]interface{}{} - result["name"] = string(sku.Name) - return []interface{}{result} -} diff --git a/azurerm/internal/services/automation/resource_arm_automation_credential.go b/azurerm/internal/services/automation/resource_arm_automation_credential.go index 13d9a8040d09d..62e01a9cea3ff 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_credential.go +++ b/azurerm/internal/services/automation/resource_arm_automation_credential.go @@ -42,24 +42,11 @@ func resourceArmAutomationCredential() *schema.Resource { "resource_group_name": azure.SchemaResourceGroupName(), - //this is AutomationAccountName in the SDK - "account_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - Deprecated: "account_name has been renamed to automation_account_name for clarity and to match the azure API", - ConflictsWith: []string{"automation_account_name"}, - ValidateFunc: azure.ValidateAutomationAccountName(), - }, - "automation_account_name": { - Type: schema.TypeString, - Optional: true, //todo change to required once account_name has been removed - Computed: true, // todo remove once account_name has been removed - ForceNew: true, - ConflictsWith: []string{"account_name"}, // todo remove once account_name has been removed - ValidateFunc: azure.ValidateAutomationAccountName(), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateAutomationAccountName(), }, "username": { @@ -90,13 +77,7 @@ func resourceArmAutomationCredentialCreateUpdate(d *schema.ResourceData, meta in name := d.Get("name").(string) resGroup := d.Get("resource_group_name").(string) - // todo remove this once `account_name` is removed - accountName := "" - if v, ok := d.GetOk("automation_account_name"); ok { - accountName = v.(string) - } else if v, ok := d.GetOk("account_name"); ok { - accountName = v.(string) - } + accountName := d.Get("automation_account_name").(string) if features.ShouldResourcesBeImported() && d.IsNewResource() { existing, err := client.Get(ctx, resGroup, accountName, name) @@ -168,7 +149,6 @@ func resourceArmAutomationCredentialRead(d *schema.ResourceData, meta interface{ d.Set("name", resp.Name) d.Set("resource_group_name", resGroup) d.Set("automation_account_name", accountName) - d.Set("account_name", accountName) if props := resp.CredentialProperties; props != nil { d.Set("username", props.UserName) } diff --git a/azurerm/internal/services/automation/resource_arm_automation_dsc_configuration.go b/azurerm/internal/services/automation/resource_arm_automation_dsc_configuration.go index a741b96e7ccba..79e4b1f7fe484 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_dsc_configuration.go +++ b/azurerm/internal/services/automation/resource_arm_automation_dsc_configuration.go @@ -14,6 +14,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -79,6 +80,8 @@ func resourceArmAutomationDscConfiguration() *schema.Resource { Type: schema.TypeString, Computed: true, }, + + "tags": tags.Schema(), }, } } @@ -111,6 +114,7 @@ func resourceArmAutomationDscConfigurationCreateUpdate(d *schema.ResourceData, m location := azure.NormalizeLocation(d.Get("location").(string)) logVerbose := d.Get("log_verbose").(bool) description := d.Get("description").(string) + t := d.Get("tags").(map[string]interface{}) parameters := automation.DscConfigurationCreateOrUpdateParameters{ DscConfigurationCreateOrUpdateProperties: &automation.DscConfigurationCreateOrUpdateProperties{ @@ -122,6 +126,7 @@ func resourceArmAutomationDscConfigurationCreateUpdate(d *schema.ResourceData, m }, }, Location: utils.String(location), + Tags: tags.Expand(t), } if _, err := client.CreateOrUpdate(ctx, resGroup, accName, name, parameters); err != nil { @@ -192,7 +197,7 @@ func resourceArmAutomationDscConfigurationRead(d *schema.ResourceData, meta inte d.Set("content_embedded", content) - return nil + return tags.FlattenAndSet(d, resp.Tags) } func resourceArmAutomationDscConfigurationDelete(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/internal/services/automation/resource_arm_automation_job_schedule.go b/azurerm/internal/services/automation/resource_arm_automation_job_schedule.go index 469de5a3e3721..105cc25c134d9 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_job_schedule.go +++ b/azurerm/internal/services/automation/resource_arm_automation_job_schedule.go @@ -8,6 +8,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" uuid "github.com/satori/go.uuid" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" @@ -86,9 +87,10 @@ func resourceArmAutomationJobSchedule() *schema.Resource { }, "job_schedule_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.IsUUID, }, }, } @@ -102,17 +104,21 @@ func resourceArmAutomationJobScheduleCreate(d *schema.ResourceData, meta interfa log.Printf("[INFO] preparing arguments for AzureRM Automation Job Schedule creation.") jobScheduleUUID := uuid.NewV4() - resGroup := d.Get("resource_group_name").(string) + if jobScheduleID, ok := d.GetOk("job_schedule_id"); ok { + jobScheduleUUID = uuid.FromStringOrNil(jobScheduleID.(string)) + } + + resourceGroup := d.Get("resource_group_name").(string) accountName := d.Get("automation_account_name").(string) runbookName := d.Get("runbook_name").(string) scheduleName := d.Get("schedule_name").(string) if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, resGroup, accountName, jobScheduleUUID) + existing, err := client.Get(ctx, resourceGroup, accountName, jobScheduleUUID) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing Automation Job Schedule %q (Account %q / Resource Group %q): %s", jobScheduleUUID, accountName, resGroup, err) + return fmt.Errorf("Error checking for presence of existing Automation Job Schedule %q (Account %q / Resource Group %q): %s", jobScheduleUUID, accountName, resourceGroup, err) } } @@ -148,17 +154,17 @@ func resourceArmAutomationJobScheduleCreate(d *schema.ResourceData, meta interfa properties.RunOn = &value } - if _, err := client.Create(ctx, resGroup, accountName, jobScheduleUUID, parameters); err != nil { + if _, err := client.Create(ctx, resourceGroup, accountName, jobScheduleUUID, parameters); err != nil { return err } - read, err := client.Get(ctx, resGroup, accountName, jobScheduleUUID) + read, err := client.Get(ctx, resourceGroup, accountName, jobScheduleUUID) if err != nil { return err } if read.ID == nil { - return fmt.Errorf("Cannot read Automation Job Schedule '%s' (Account %q / Resource Group %s) ID", jobScheduleUUID, accountName, resGroup) + return fmt.Errorf("Cannot read Automation Job Schedule '%s' (Account %q / Resource Group %s) ID", jobScheduleUUID, accountName, resourceGroup) } d.SetId(*read.ID) @@ -178,10 +184,10 @@ func resourceArmAutomationJobScheduleRead(d *schema.ResourceData, meta interface jobScheduleID := id.Path["jobSchedules"] jobScheduleUUID := uuid.FromStringOrNil(jobScheduleID) - resGroup := id.ResourceGroup + resourceGroup := id.ResourceGroup accountName := id.Path["automationAccounts"] - resp, err := client.Get(ctx, resGroup, accountName, jobScheduleUUID) + resp, err := client.Get(ctx, resourceGroup, accountName, jobScheduleUUID) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") @@ -192,7 +198,7 @@ func resourceArmAutomationJobScheduleRead(d *schema.ResourceData, meta interface } d.Set("job_schedule_id", resp.JobScheduleID) - d.Set("resource_group_name", resGroup) + d.Set("resource_group_name", resourceGroup) d.Set("automation_account_name", accountName) d.Set("runbook_name", resp.JobScheduleProperties.Runbook.Name) d.Set("schedule_name", resp.JobScheduleProperties.Schedule.Name) @@ -224,10 +230,10 @@ func resourceArmAutomationJobScheduleDelete(d *schema.ResourceData, meta interfa jobScheduleID := id.Path["jobSchedules"] jobScheduleUUID := uuid.FromStringOrNil(jobScheduleID) - resGroup := id.ResourceGroup + resourceGroup := id.ResourceGroup accountName := id.Path["automationAccounts"] - resp, err := client.Delete(ctx, resGroup, accountName, jobScheduleUUID) + resp, err := client.Delete(ctx, resourceGroup, accountName, jobScheduleUUID) if err != nil { if !utils.ResponseWasNotFound(resp) { return fmt.Errorf("Error issuing AzureRM delete request for Automation Job Schedule '%s': %+v", jobScheduleUUID, err) diff --git a/azurerm/internal/services/automation/resource_arm_automation_runbook.go b/azurerm/internal/services/automation/resource_arm_automation_runbook.go index 25c01f9f48d88..2edf3bb69747d 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_runbook.go +++ b/azurerm/internal/services/automation/resource_arm_automation_runbook.go @@ -46,7 +46,7 @@ func resourceArmAutomationRunbook() *schema.Resource { ValidateFunc: azure.ValidateAutomationRunbookName(), }, - "account_name": { + "automation_account_name": { Type: schema.TypeString, Required: true, ForceNew: true, @@ -143,7 +143,7 @@ func resourceArmAutomationRunbookCreateUpdate(d *schema.ResourceData, meta inter log.Printf("[INFO] preparing arguments for AzureRM Automation Runbook creation.") name := d.Get("name").(string) - accName := d.Get("account_name").(string) + accName := d.Get("automation_account_name").(string) resGroup := d.Get("resource_group_name").(string) if features.ShouldResourcesBeImported() && d.IsNewResource() { @@ -243,7 +243,7 @@ func resourceArmAutomationRunbookRead(d *schema.ResourceData, meta interface{}) d.Set("location", azure.NormalizeLocation(*location)) } - d.Set("account_name", accName) + d.Set("automation_account_name", accName) if props := resp.RunbookProperties; props != nil { d.Set("log_verbose", props.LogVerbose) d.Set("log_progress", props.LogProgress) diff --git a/azurerm/internal/services/automation/resource_arm_automation_schedule.go b/azurerm/internal/services/automation/resource_arm_automation_schedule.go index dd889645a0b85..5beb6fefc6767 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_schedule.go +++ b/azurerm/internal/services/automation/resource_arm_automation_schedule.go @@ -14,7 +14,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/set" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -49,23 +48,11 @@ func resourceArmAutomationSchedule() *schema.Resource { "resource_group_name": azure.SchemaResourceGroupName(), - //this is AutomationAccountName in the SDK - "account_name": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Deprecated: "account_name has been renamed to automation_account_name for clarity and to match the azure API", - ConflictsWith: []string{"automation_account_name"}, - ValidateFunc: azure.ValidateAutomationAccountName(), - }, - "automation_account_name": { - Type: schema.TypeString, - Optional: true, //todo change to required once account_name has been removed - Computed: true, - //ForceNew: true, //todo this needs to come back once account_name has been removed - ConflictsWith: []string{"account_name"}, - ValidateFunc: azure.ValidateAutomationAccountName(), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateAutomationAccountName(), }, "frequency": { @@ -81,11 +68,11 @@ func resourceArmAutomationSchedule() *schema.Resource { }, true), }, - //ignored when frequency is `OneTime` + // ignored when frequency is `OneTime` "interval": { Type: schema.TypeInt, Optional: true, - Computed: true, //defaults to 1 if frequency is not OneTime + Computed: true, // defaults to 1 if frequency is not OneTime ValidateFunc: validation.IntBetween(1, 100), }, @@ -94,16 +81,16 @@ func resourceArmAutomationSchedule() *schema.Resource { Optional: true, Computed: true, DiffSuppressFunc: suppress.RFC3339Time, - ValidateFunc: validate.RFC3339DateInFutureBy(time.Duration(5) * time.Minute), - //defaults to now + 7 minutes in create function if not set + ValidateFunc: validation.IsRFC3339Time, + // defaults to now + 7 minutes in create function if not set }, "expiry_time": { Type: schema.TypeString, Optional: true, - Computed: true, //same as start time when OneTime, ridiculous value when recurring: "9999-12-31T15:59:00-08:00" + Computed: true, // same as start time when OneTime, ridiculous value when recurring: "9999-12-31T15:59:00-08:00" DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validate.RFC3339Time, + ValidateFunc: validation.IsRFC3339Time, }, "description": { @@ -115,7 +102,7 @@ func resourceArmAutomationSchedule() *schema.Resource { Type: schema.TypeString, Optional: true, Default: "UTC", - //todo figure out how to validate this properly + // todo figure out how to validate this properly }, "week_days": { @@ -206,24 +193,6 @@ func resourceArmAutomationSchedule() *schema.Resource { return fmt.Errorf("`monthly_occurrence` can only be set when frequency is `Month`") } - _, hasAccount := diff.GetOk("automation_account_name") - _, hasAutomationAccountWeb := diff.GetOk("account_name") - if !hasAccount && !hasAutomationAccountWeb { - return fmt.Errorf("`automation_account_name` must be set") - } - - //if automation_account_name changed or account_name changed to or from nil force a new resource - //remove once we remove the deprecated property - oAan, nAan := diff.GetChange("automation_account_name") - if oAan != "" && nAan != "" { - diff.ForceNew("automation_account_name") - } - - oAn, nAn := diff.GetChange("account_name") - if oAn != "" && nAn != "" { - diff.ForceNew("account_name") - } - return nil }, } @@ -238,14 +207,7 @@ func resourceArmAutomationScheduleCreateUpdate(d *schema.ResourceData, meta inte name := d.Get("name").(string) resGroup := d.Get("resource_group_name").(string) - //CustomizeDiff should ensure one of these two is set - // todo remove this once `account_name` is removed - accountName := "" - if v, ok := d.GetOk("automation_account_name"); ok { - accountName = v.(string) - } else if v, ok := d.GetOk("account_name"); ok { - accountName = v.(string) - } + accountName := d.Get("automation_account_name").(string) if features.ShouldResourcesBeImported() && d.IsNewResource() { existing, err := client.Get(ctx, resGroup, accountName, name) @@ -274,20 +236,24 @@ func resourceArmAutomationScheduleCreateUpdate(d *schema.ResourceData, meta inte } properties := parameters.ScheduleCreateOrUpdateProperties - //start time can default to now + 7 (5 could be invalid by the time the API is called) + // start time can default to now + 7 (5 could be invalid by the time the API is called) if v, ok := d.GetOk("start_time"); ok { - t, _ := time.Parse(time.RFC3339, v.(string)) //should be validated by the schema + t, _ := time.Parse(time.RFC3339, v.(string)) // should be validated by the schema + duration := time.Duration(5) * time.Minute + if time.Until(t) < duration { + return fmt.Errorf("start_time is %q and should be at least %q in the future", t, duration) + } properties.StartTime = &date.Time{Time: t} } else { properties.StartTime = &date.Time{Time: time.Now().Add(time.Duration(7) * time.Minute)} } if v, ok := d.GetOk("expiry_time"); ok { - t, _ := time.Parse(time.RFC3339, v.(string)) //should be validated by the schema + t, _ := time.Parse(time.RFC3339, v.(string)) // should be validated by the schema properties.ExpiryTime = &date.Time{Time: t} } - //only pay attention to interval if frequency is not OneTime, and default it to 1 if not set + // only pay attention to interval if frequency is not OneTime, and default it to 1 if not set if properties.Frequency != automation.OneTime { if v, ok := d.GetOk("interval"); ok { properties.Interval = utils.Int32(int32(v.(int))) @@ -296,7 +262,7 @@ func resourceArmAutomationScheduleCreateUpdate(d *schema.ResourceData, meta inte } } - //only pay attention to the advanced schedule fields if frequency is either Week or Month + // only pay attention to the advanced schedule fields if frequency is either Week or Month if properties.Frequency == automation.Week || properties.Frequency == automation.Month { advancedRef, err := expandArmAutomationScheduleAdvanced(d, d.Id() != "") if err != nil { @@ -350,7 +316,6 @@ func resourceArmAutomationScheduleRead(d *schema.ResourceData, meta interface{}) d.Set("name", resp.Name) d.Set("resource_group_name", resGroup) d.Set("automation_account_name", accountName) - d.Set("account_name", accountName) // todo remove once `account_name` is removed d.Set("frequency", string(resp.Frequency)) if v := resp.StartTime; v != nil { @@ -360,7 +325,7 @@ func resourceArmAutomationScheduleRead(d *schema.ResourceData, meta interface{}) d.Set("expiry_time", v.Format(time.RFC3339)) } if v := resp.Interval; v != nil { - //seems to me missing its type in swagger, leading to it being a interface{} float64 + // seems to me missing its type in swagger, leading to it being a interface{} float64 d.Set("interval", int(v.(float64))) } if v := resp.Description; v != nil { diff --git a/azurerm/internal/services/automation/resource_arm_automation_variable_datetime.go b/azurerm/internal/services/automation/resource_arm_automation_variable_datetime.go index 80b76aca33e6e..2d4b48093c7e8 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_variable_datetime.go +++ b/azurerm/internal/services/automation/resource_arm_automation_variable_datetime.go @@ -4,7 +4,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" ) func resourceArmAutomationVariableDateTime() *schema.Resource { @@ -25,7 +25,7 @@ func resourceArmAutomationVariableDateTime() *schema.Resource { Delete: schema.DefaultTimeout(30 * time.Minute), }, - Schema: resourceAutomationVariableCommonSchema(schema.TypeString, validate.RFC3339Time), + Schema: resourceAutomationVariableCommonSchema(schema.TypeString, validation.IsRFC3339Time), } } diff --git a/azurerm/internal/services/automation/tests/data_source_automation_account_test.go b/azurerm/internal/services/automation/tests/data_source_automation_account_test.go index 434c6dc5c372d..902c56fa0af6b 100644 --- a/azurerm/internal/services/automation/tests/data_source_automation_account_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_account_test.go @@ -28,19 +28,25 @@ func TestAccDataSourceAutomationAccount(t *testing.T) { func testAccDataSourceAutomationAccount_complete(resourceGroupName string, data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "%s" location = "%s" } + resource "azurerm_automation_account" "test" { name = "acctestautomationAccount-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "Basic" } + data "azurerm_automation_account" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - name = "${azurerm_automation_account.test.name}" + resource_group_name = azurerm_resource_group.test.name + name = azurerm_automation_account.test.name } `, resourceGroupName, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/automation/tests/data_source_automation_variable_bool_test.go b/azurerm/internal/services/automation/tests/data_source_automation_variable_bool_test.go index a8ea6810cd827..4acb067709edb 100644 --- a/azurerm/internal/services/automation/tests/data_source_automation_variable_bool_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_variable_bool_test.go @@ -31,9 +31,9 @@ func testAccDataSourceAutomationVariableBool_basic(data acceptance.TestData) str %s data "azurerm_automation_variable_bool" "test" { - name = "${azurerm_automation_variable_bool.test.name}" - resource_group_name = "${azurerm_automation_variable_bool.test.resource_group_name}" - automation_account_name = "${azurerm_automation_variable_bool.test.automation_account_name}" + name = azurerm_automation_variable_bool.test.name + resource_group_name = azurerm_automation_variable_bool.test.resource_group_name + automation_account_name = azurerm_automation_variable_bool.test.automation_account_name } `, config) } diff --git a/azurerm/internal/services/automation/tests/data_source_automation_variable_datetime_test.go b/azurerm/internal/services/automation/tests/data_source_automation_variable_datetime_test.go index 34ba86460c1e8..f4c0874619ca0 100644 --- a/azurerm/internal/services/automation/tests/data_source_automation_variable_datetime_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_variable_datetime_test.go @@ -31,9 +31,9 @@ func testAccDataSourceAutomationVariableDateTime_basic(data acceptance.TestData) %s data "azurerm_automation_variable_datetime" "test" { - name = "${azurerm_automation_variable_datetime.test.name}" - resource_group_name = "${azurerm_automation_variable_datetime.test.resource_group_name}" - automation_account_name = "${azurerm_automation_variable_datetime.test.automation_account_name}" + name = azurerm_automation_variable_datetime.test.name + resource_group_name = azurerm_automation_variable_datetime.test.resource_group_name + automation_account_name = azurerm_automation_variable_datetime.test.automation_account_name } `, config) } diff --git a/azurerm/internal/services/automation/tests/data_source_automation_variable_int_test.go b/azurerm/internal/services/automation/tests/data_source_automation_variable_int_test.go index 8a982d34dfb07..886bafcf646d6 100644 --- a/azurerm/internal/services/automation/tests/data_source_automation_variable_int_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_variable_int_test.go @@ -31,9 +31,9 @@ func testAccDataSourceAutomationVariableInt_basic(data acceptance.TestData) stri %s data "azurerm_automation_variable_int" "test" { - name = "${azurerm_automation_variable_int.test.name}" - resource_group_name = "${azurerm_automation_variable_int.test.resource_group_name}" - automation_account_name = "${azurerm_automation_variable_int.test.automation_account_name}" + name = azurerm_automation_variable_int.test.name + resource_group_name = azurerm_automation_variable_int.test.resource_group_name + automation_account_name = azurerm_automation_variable_int.test.automation_account_name } `, config) } diff --git a/azurerm/internal/services/automation/tests/data_source_automation_variable_string_test.go b/azurerm/internal/services/automation/tests/data_source_automation_variable_string_test.go index 995bcd8d32de2..426b20dd90d30 100644 --- a/azurerm/internal/services/automation/tests/data_source_automation_variable_string_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_variable_string_test.go @@ -31,9 +31,9 @@ func testAccDataSourceAutomationVariableString_basic(data acceptance.TestData) s %s data "azurerm_automation_variable_string" "test" { - name = "${azurerm_automation_variable_string.test.name}" - resource_group_name = "${azurerm_automation_variable_string.test.resource_group_name}" - automation_account_name = "${azurerm_automation_variable_string.test.automation_account_name}" + name = azurerm_automation_variable_string.test.name + resource_group_name = azurerm_automation_variable_string.test.resource_group_name + automation_account_name = azurerm_automation_variable_string.test.automation_account_name } `, config) } diff --git a/azurerm/internal/services/automation/tests/resource_arm_automation_account_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_account_test.go index a44de6d452e4f..74a182fbbafe3 100644 --- a/azurerm/internal/services/automation/tests/resource_arm_automation_account_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_account_test.go @@ -2,7 +2,6 @@ package tests import ( "fmt" - "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -36,47 +35,6 @@ func TestAccAzureRMAutomationAccount_basic(t *testing.T) { }) } -// Remove in 2.0 -func TestAccAzureRMAutomationAccount_basicClassic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_automation_account", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMAutomationAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutomationAccount_basicClassic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationAccountExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Basic"), - resource.TestCheckResourceAttrSet(data.ResourceName, "dsc_server_endpoint"), - resource.TestCheckResourceAttrSet(data.ResourceName, "dsc_primary_access_key"), - resource.TestCheckResourceAttrSet(data.ResourceName, "dsc_secondary_access_key"), - ), - }, - data.ImportStep(), - }, - }) -} - -// Remove in 2.0 -func TestAccAzureRMAutomationAccount_basicNotDefined(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_automation_account", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMAutomationAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutomationAccount_basicNotDefined(data), - ExpectError: regexp.MustCompile("either 'sku_name' or 'sku' must be defined in the configuration file"), - }, - }, - }) -} - func TestAccAzureRMAutomationAccount_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -185,24 +143,10 @@ func testCheckAzureRMAutomationAccountExists(resourceName string) resource.TestC func testAccAzureRMAutomationAccount_basic(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_automation_account" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku_name = "Basic" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -// Remove in 2.0 -func testAccAzureRMAutomationAccount_basicClassic(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -210,28 +154,10 @@ resource "azurerm_resource_group" "test" { resource "azurerm_automation_account" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "Basic" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name -// Remove in 2.0 -func testAccAzureRMAutomationAccount_basicNotDefined(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_automation_account" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + sku_name = "Basic" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -242,9 +168,9 @@ func testAccAzureRMAutomationAccount_requiresImport(data acceptance.TestData) st %s resource "azurerm_automation_account" "import" { - name = "${azurerm_automation_account.test.name}" - location = "${azurerm_automation_account.test.location}" - resource_group_name = "${azurerm_automation_account.test.resource_group_name}" + name = azurerm_automation_account.test.name + location = azurerm_automation_account.test.location + resource_group_name = azurerm_automation_account.test.resource_group_name sku_name = "Basic" } @@ -253,6 +179,10 @@ resource "azurerm_automation_account" "import" { func testAccAzureRMAutomationAccount_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -260,8 +190,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_automation_account" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "Basic" diff --git a/azurerm/internal/services/automation/tests/resource_arm_automation_certificate_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_certificate_test.go index 57ed01c00ab6e..cf649eeb49eab 100644 --- a/azurerm/internal/services/automation/tests/resource_arm_automation_certificate_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_certificate_test.go @@ -173,6 +173,10 @@ func testCheckAzureRMAutomationCertificateExists(resourceName string) resource.T func testAccAzureRMAutomationCertificate_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -202,15 +206,18 @@ func testAccAzureRMAutomationCertificate_requiresImport(data acceptance.TestData resource "azurerm_automation_certificate" "import" { name = azurerm_automation_certificate.test.name resource_group_name = azurerm_automation_certificate.test.resource_group_name - automation_account_name = azurerm_automation_certificate.test.account_name + automation_account_name = azurerm_automation_certificate.test.automation_account_name base64 = azurerm_automation_certificate.test.base64 - thumbprint = azurerm_automation_certificate.test.thumbprint } `, template) } func testAccAzureRMAutomationCertificate_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -235,6 +242,10 @@ resource "azurerm_automation_certificate" "test" { func testAccAzureRMAutomationCertificate_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/automation/tests/resource_arm_automation_credential_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_credential_test.go index e5220a6ce8f06..63794d340812c 100644 --- a/azurerm/internal/services/automation/tests/resource_arm_automation_credential_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_credential_test.go @@ -144,6 +144,10 @@ func testCheckAzureRMAutomationCredentialExists(resourceName string) resource.Te func testAccAzureRMAutomationCredential_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -151,18 +155,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_automation_account" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "Basic" - } + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "Basic" } resource "azurerm_automation_credential" "test" { name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - automation_account_name = "${azurerm_automation_account.test.name}" + resource_group_name = azurerm_resource_group.test.name + automation_account_name = azurerm_automation_account.test.name username = "test_user" password = "test_pwd" } @@ -175,17 +176,21 @@ func testAccAzureRMAutomationCredential_requiresImport(data acceptance.TestData) %s resource "azurerm_automation_credential" "import" { - name = "${azurerm_automation_credential.test.name}" - resource_group_name = "${azurerm_automation_credential.test.resource_group_name}" - automation_account_name = "${azurerm_automation_credential.test.automation_account_name}" - username = "${azurerm_automation_credential.test.username}" - password = "${azurerm_automation_credential.test.password}" + name = azurerm_automation_credential.test.name + resource_group_name = azurerm_automation_credential.test.resource_group_name + automation_account_name = azurerm_automation_credential.test.automation_account_name + username = azurerm_automation_credential.test.username + password = azurerm_automation_credential.test.password } `, template) } func testAccAzureRMAutomationCredential_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -193,18 +198,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_automation_account" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "Basic" - } + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "Basic" } resource "azurerm_automation_credential" "test" { name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - automation_account_name = "${azurerm_automation_account.test.name}" + resource_group_name = azurerm_resource_group.test.name + automation_account_name = azurerm_automation_account.test.name username = "test_user" password = "test_pwd" description = "This is a test credential for terraform acceptance test" diff --git a/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_configuration_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_configuration_test.go index 42e9c066a2929..060332e8a7214 100644 --- a/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_configuration_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_configuration_test.go @@ -28,6 +28,8 @@ func TestAccAzureRMAutomationDscConfiguration_basic(t *testing.T) { resource.TestCheckResourceAttrSet(data.ResourceName, "log_verbose"), resource.TestCheckResourceAttrSet(data.ResourceName, "state"), resource.TestCheckResourceAttr(data.ResourceName, "content_embedded", "configuration acctest {}"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "prod"), ), }, data.ImportStep(), @@ -126,6 +128,10 @@ func testCheckAzureRMAutomationDscConfigurationExists(resourceName string) resou func testAccAzureRMAutomationDscConfiguration_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -135,10 +141,7 @@ resource "azurerm_automation_account" "test" { name = "acctest-%d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "Basic" - } + sku_name = "Basic" } resource "azurerm_automation_dsc_configuration" "test" { @@ -148,6 +151,10 @@ resource "azurerm_automation_dsc_configuration" "test" { location = "${azurerm_resource_group.test.location}" content_embedded = "configuration acctest {}" description = "test" + + tags = { + ENV = "prod" + } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -158,12 +165,12 @@ func testAccAzureRMAutomationDscConfiguration_requiresImport(data acceptance.Tes %s resource "azurerm_automation_dsc_configuration" "import" { - name = "${azurerm_automation_dsc_configuration.test.name}" - resource_group_name = "${azurerm_automation_dsc_configuration.test.resource_group_name}" - automation_account_name = "${azurerm_automation_dsc_configuration.test.automation_account_name}" - location = "${azurerm_automation_dsc_configuration.test.location}" - content_embedded = "${azurerm_automation_dsc_configuration.test.content_embedded}" - description = "${azurerm_automation_dsc_configuration.test.description}" + name = azurerm_automation_dsc_configuration.test.name + resource_group_name = azurerm_automation_dsc_configuration.test.resource_group_name + automation_account_name = azurerm_automation_dsc_configuration.test.automation_account_name + location = azurerm_automation_dsc_configuration.test.location + content_embedded = azurerm_automation_dsc_configuration.test.content_embedded + description = azurerm_automation_dsc_configuration.test.description } `, template) } diff --git a/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_nodeconfiguration_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_nodeconfiguration_test.go index deded2a5d0c23..1c2cf6aa071fe 100644 --- a/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_nodeconfiguration_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_nodeconfiguration_test.go @@ -123,6 +123,10 @@ func testCheckAzureRMAutomationDscNodeConfigurationExists(resourceName string) r func testAccAzureRMAutomationDscNodeConfiguration_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -130,27 +134,24 @@ resource "azurerm_resource_group" "test" { resource "azurerm_automation_account" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "Basic" - } + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "Basic" } resource "azurerm_automation_dsc_configuration" "test" { name = "acctest" - resource_group_name = "${azurerm_resource_group.test.name}" - automation_account_name = "${azurerm_automation_account.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + automation_account_name = azurerm_automation_account.test.name + location = azurerm_resource_group.test.location content_embedded = "configuration acctest {}" } resource "azurerm_automation_dsc_nodeconfiguration" "test" { name = "acctest.localhost" - resource_group_name = "${azurerm_resource_group.test.name}" - automation_account_name = "${azurerm_automation_account.test.name}" - depends_on = ["azurerm_automation_dsc_configuration.test"] + resource_group_name = azurerm_resource_group.test.name + automation_account_name = azurerm_automation_account.test.name + depends_on = [azurerm_automation_dsc_configuration.test] content_embedded = < 0 && managedDiskType != "" { return nil, fmt.Errorf("[ERROR] Conflict between `vhd_containers` and `managed_disk_type` on `storage_profile_os_disk` (only one or the other can be used)") } - //END: code to be removed after GH-13016 is merged + // END: code to be removed after GH-13016 is merged return osDisk, nil } diff --git a/azurerm/internal/services/compute/ssh_keys.go b/azurerm/internal/services/compute/ssh_keys.go index 78e34ada7e223..9f12ff850435f 100644 --- a/azurerm/internal/services/compute/ssh_keys.go +++ b/azurerm/internal/services/compute/ssh_keys.go @@ -143,7 +143,7 @@ func ValidateSSHKey(i interface{}, k string) (warnings []string, errors []error) if pubKey.Type() != ssh.KeyAlgoRSA { return nil, []error{fmt.Errorf("Error - only ssh-rsa keys with 2048 bits or higher are supported by Azure")} } else { - //check length - held at bytes 20 and 21 for ssh-rsa + // check length - held at bytes 20 and 21 for ssh-rsa sizeRaw := []byte{byteStr[20], byteStr[21]} sizeDec := binary.BigEndian.Uint16(sizeRaw) if sizeDec < 257 { diff --git a/azurerm/internal/services/compute/tests/data_source_availability_set_test.go b/azurerm/internal/services/compute/tests/data_source_availability_set_test.go index d980c8a595a64..579cae0a9903d 100644 --- a/azurerm/internal/services/compute/tests/data_source_availability_set_test.go +++ b/azurerm/internal/services/compute/tests/data_source_availability_set_test.go @@ -31,6 +31,10 @@ func TestAccDataSourceAvailabilitySet_basic(t *testing.T) { func testAccDataSourceAvailabilitySet_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%[2]s" @@ -38,8 +42,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_availability_set" "test" { name = "acctestavset-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { "foo" = "bar" @@ -47,8 +51,8 @@ resource "azurerm_availability_set" "test" { } data "azurerm_availability_set" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - name = "${azurerm_availability_set.test.name}" + resource_group_name = azurerm_resource_group.test.name + name = azurerm_availability_set.test.name } `, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/compute/tests/data_source_dedicated_host_group_test.go b/azurerm/internal/services/compute/tests/data_source_dedicated_host_group_test.go index 12ea8a473fec9..bd4d461a020de 100644 --- a/azurerm/internal/services/compute/tests/data_source_dedicated_host_group_test.go +++ b/azurerm/internal/services/compute/tests/data_source_dedicated_host_group_test.go @@ -35,8 +35,8 @@ func testAccDataSourceDedicatedHostGroup_basic(data acceptance.TestData) string %s data "azurerm_dedicated_host_group" "test" { - name = "${azurerm_dedicated_host_group.test.name}" - resource_group_name = "${azurerm_dedicated_host_group.test.resource_group_name}" + name = azurerm_dedicated_host_group.test.name + resource_group_name = azurerm_dedicated_host_group.test.resource_group_name } `, config) } diff --git a/azurerm/internal/services/compute/tests/data_source_disk_encryption_set_test.go b/azurerm/internal/services/compute/tests/data_source_disk_encryption_set_test.go index 90861b836795e..35478e39c3282 100644 --- a/azurerm/internal/services/compute/tests/data_source_disk_encryption_set_test.go +++ b/azurerm/internal/services/compute/tests/data_source_disk_encryption_set_test.go @@ -42,8 +42,8 @@ func testAccDataSourceDiskEncryptionSet_basic(data acceptance.TestData) string { %s data "azurerm_disk_encryption_set" "test" { - name = "${azurerm_disk_encryption_set.test.name}" - resource_group_name = "${azurerm_disk_encryption_set.test.resource_group_name}" + name = azurerm_disk_encryption_set.test.name + resource_group_name = azurerm_disk_encryption_set.test.resource_group_name } `, config) } diff --git a/azurerm/internal/services/compute/tests/data_source_image_test.go b/azurerm/internal/services/compute/tests/data_source_image_test.go index 42414e19d92ac..77e97bd97a050 100644 --- a/azurerm/internal/services/compute/tests/data_source_image_test.go +++ b/azurerm/internal/services/compute/tests/data_source_image_test.go @@ -62,6 +62,10 @@ func TestAccDataSourceAzureRMImage_localFilter(t *testing.T) { func testAccDataSourceAzureRMImageBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -70,42 +74,42 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "internal" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" domain_name_label = "acctestpip%d" } resource "azurerm_network_interface" "testsource" { name = "acctestnic-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfigurationsource" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -116,16 +120,15 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "blob" } resource "azurerm_virtual_machine" "testsource" { name = "acctestvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.testsource.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.testsource.id] vm_size = "Standard_D1_v2" storage_image_reference { @@ -161,13 +164,13 @@ resource "azurerm_virtual_machine" "testsource" { resource "azurerm_image" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name os_disk { os_type = "Linux" os_state = "Generalized" - blob_uri = "${azurerm_virtual_machine.testsource.storage_os_disk.0.vhd_uri}" + blob_uri = azurerm_virtual_machine.testsource.storage_os_disk[0].vhd_uri size_gb = 30 caching = "None" } @@ -179,18 +182,22 @@ resource "azurerm_image" "test" { } data "azurerm_image" "test" { - name = "${azurerm_image.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_image.test.name + resource_group_name = azurerm_resource_group.test.name } output "location" { - value = "${data.azurerm_image.test.location}" + value = data.azurerm_image.test.location } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccDataSourceAzureRMImageLocalFilter(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -199,42 +206,42 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "internal" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" domain_name_label = "acctestpip%d" } resource "azurerm_network_interface" "testsource" { name = "acctestnic-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfigurationsource" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -245,16 +252,15 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "blob" } resource "azurerm_virtual_machine" "testsource" { name = "acctestvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.testsource.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.testsource.id] vm_size = "Standard_D1_v2" storage_image_reference { @@ -290,13 +296,13 @@ resource "azurerm_virtual_machine" "testsource" { resource "azurerm_image" "abc" { name = "abc-acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name os_disk { os_type = "Linux" os_state = "Generalized" - blob_uri = "${azurerm_virtual_machine.testsource.storage_os_disk.0.vhd_uri}" + blob_uri = azurerm_virtual_machine.testsource.storage_os_disk[0].vhd_uri size_gb = 30 caching = "None" } @@ -309,13 +315,13 @@ resource "azurerm_image" "abc" { resource "azurerm_image" "def" { name = "def-acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name os_disk { os_type = "Linux" os_state = "Generalized" - blob_uri = "${azurerm_virtual_machine.testsource.storage_os_disk.0.vhd_uri}" + blob_uri = azurerm_virtual_machine.testsource.storage_os_disk[0].vhd_uri size_gb = 30 caching = "None" } @@ -328,14 +334,13 @@ resource "azurerm_image" "def" { data "azurerm_image" "test1" { name_regex = "^def-acctest-\\d+" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } data "azurerm_image" "test2" { name_regex = "^[a-z]+-acctest-\\d+" sort_descending = true - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } - `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/tests/data_source_managed_disk_test.go b/azurerm/internal/services/compute/tests/data_source_managed_disk_test.go index 45474cdd397f0..c15a958c7ff10 100644 --- a/azurerm/internal/services/compute/tests/data_source_managed_disk_test.go +++ b/azurerm/internal/services/compute/tests/data_source_managed_disk_test.go @@ -58,6 +58,10 @@ func TestAccDataSourceAzureRMManagedDisk_basic_withUltraSSD(t *testing.T) { func testAccDataSourceAzureRMManagedDiskBasic(data acceptance.TestData, name string, resourceGroupName string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "%s" location = "%s" @@ -65,8 +69,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Premium_LRS" create_option = "Empty" disk_size_gb = "10" @@ -78,14 +82,18 @@ resource "azurerm_managed_disk" "test" { } data "azurerm_managed_disk" "test" { - name = "${azurerm_managed_disk.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_managed_disk.test.name + resource_group_name = azurerm_resource_group.test.name } `, resourceGroupName, data.Locations.Primary, name) } func testAccDataSourceAzureRMManagedDisk_basic_withUltraSSD(data acceptance.TestData, name string, resourceGroupName string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "%s" location = "%s" @@ -93,8 +101,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "UltraSSD_LRS" create_option = "Empty" disk_size_gb = "4" @@ -108,8 +116,8 @@ resource "azurerm_managed_disk" "test" { } data "azurerm_managed_disk" "test" { - name = "${azurerm_managed_disk.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_managed_disk.test.name + resource_group_name = azurerm_resource_group.test.name } `, resourceGroupName, data.Locations.Primary, name) } diff --git a/azurerm/internal/services/compute/tests/data_source_platform_image_test.go b/azurerm/internal/services/compute/tests/data_source_platform_image_test.go index 4985a8ac7563e..e02d81ed85132 100644 --- a/azurerm/internal/services/compute/tests/data_source_platform_image_test.go +++ b/azurerm/internal/services/compute/tests/data_source_platform_image_test.go @@ -30,6 +30,10 @@ func TestAccDataSourceAzureRMPlatformImage_basic(t *testing.T) { func testAccDataSourceAzureRMPlatformImageBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_platform_image" "test" { location = "%s" publisher = "Canonical" diff --git a/azurerm/internal/services/compute/tests/data_source_proximity_placement_group_test.go b/azurerm/internal/services/compute/tests/data_source_proximity_placement_group_test.go index 4b0e20fdc7950..b309997e7db50 100644 --- a/azurerm/internal/services/compute/tests/data_source_proximity_placement_group_test.go +++ b/azurerm/internal/services/compute/tests/data_source_proximity_placement_group_test.go @@ -34,8 +34,8 @@ func testAccProximityPlacementGroupDataSource_basic(data acceptance.TestData) st %s data "azurerm_proximity_placement_group" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - name = "${azurerm_proximity_placement_group.test.name}" + resource_group_name = azurerm_resource_group.test.name + name = azurerm_proximity_placement_group.test.name } `, testAccProximityPlacementGroup_withTags(data)) } diff --git a/azurerm/internal/services/compute/tests/data_source_shared_image_gallery_test.go b/azurerm/internal/services/compute/tests/data_source_shared_image_gallery_test.go index 445bde7db8455..73390f89d7de7 100644 --- a/azurerm/internal/services/compute/tests/data_source_shared_image_gallery_test.go +++ b/azurerm/internal/services/compute/tests/data_source_shared_image_gallery_test.go @@ -53,8 +53,8 @@ func testAccDataSourceSharedImageGallery_basic(data acceptance.TestData) string %s data "azurerm_shared_image_gallery" "test" { - name = "${azurerm_shared_image_gallery.test.name}" - resource_group_name = "${azurerm_shared_image_gallery.test.resource_group_name}" + name = azurerm_shared_image_gallery.test.name + resource_group_name = azurerm_shared_image_gallery.test.resource_group_name } `, template) } @@ -65,8 +65,8 @@ func testAccDataSourceSharedImageGallery_complete(data acceptance.TestData) stri %s data "azurerm_shared_image_gallery" "test" { - name = "${azurerm_shared_image_gallery.test.name}" - resource_group_name = "${azurerm_shared_image_gallery.test.resource_group_name}" + name = azurerm_shared_image_gallery.test.name + resource_group_name = azurerm_shared_image_gallery.test.resource_group_name } `, template) } diff --git a/azurerm/internal/services/compute/tests/data_source_shared_image_test.go b/azurerm/internal/services/compute/tests/data_source_shared_image_test.go index 8dd2b7dd3f01b..2057013f644e9 100644 --- a/azurerm/internal/services/compute/tests/data_source_shared_image_test.go +++ b/azurerm/internal/services/compute/tests/data_source_shared_image_test.go @@ -48,9 +48,9 @@ func testAccDataSourceSharedImage_basic(data acceptance.TestData) string { %s data "azurerm_shared_image" "test" { - name = "${azurerm_shared_image.test.name}" - gallery_name = "${azurerm_shared_image.test.gallery_name}" - resource_group_name = "${azurerm_shared_image.test.resource_group_name}" + name = azurerm_shared_image.test.name + gallery_name = azurerm_shared_image.test.gallery_name + resource_group_name = azurerm_shared_image.test.resource_group_name } `, template) } @@ -61,9 +61,9 @@ func testAccDataSourceSharedImage_complete(data acceptance.TestData) string { %s data "azurerm_shared_image" "test" { - name = "${azurerm_shared_image.test.name}" - gallery_name = "${azurerm_shared_image.test.gallery_name}" - resource_group_name = "${azurerm_shared_image.test.resource_group_name}" + name = azurerm_shared_image.test.name + gallery_name = azurerm_shared_image.test.gallery_name + resource_group_name = azurerm_shared_image.test.resource_group_name } `, template) } diff --git a/azurerm/internal/services/compute/tests/data_source_shared_image_version_test.go b/azurerm/internal/services/compute/tests/data_source_shared_image_version_test.go index 0818fd5a9755c..36e9082fec697 100644 --- a/azurerm/internal/services/compute/tests/data_source_shared_image_version_test.go +++ b/azurerm/internal/services/compute/tests/data_source_shared_image_version_test.go @@ -48,10 +48,10 @@ func testAccDataSourceSharedImageVersion_basic(data acceptance.TestData, usernam %s data "azurerm_shared_image_version" "test" { - name = "${azurerm_shared_image_version.test.name}" - gallery_name = "${azurerm_shared_image_version.test.gallery_name}" - image_name = "${azurerm_shared_image_version.test.image_name}" - resource_group_name = "${azurerm_shared_image_version.test.resource_group_name}" + name = azurerm_shared_image_version.test.name + gallery_name = azurerm_shared_image_version.test.gallery_name + image_name = azurerm_shared_image_version.test.image_name + resource_group_name = azurerm_shared_image_version.test.resource_group_name } `, template) } diff --git a/azurerm/internal/services/compute/tests/data_source_snapshot_test.go b/azurerm/internal/services/compute/tests/data_source_snapshot_test.go index 18eedd4b7a1e8..b5fba7dd98d79 100644 --- a/azurerm/internal/services/compute/tests/data_source_snapshot_test.go +++ b/azurerm/internal/services/compute/tests/data_source_snapshot_test.go @@ -47,6 +47,10 @@ func TestAccDataSourceAzureRMSnapshot_encryption(t *testing.T) { func testAccDataSourceAzureRMSnapshot_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -54,8 +58,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "acctestmd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = "10" @@ -63,21 +67,25 @@ resource "azurerm_managed_disk" "test" { resource "azurerm_snapshot" "test" { name = "acctestss_%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name create_option = "Copy" - source_uri = "${azurerm_managed_disk.test.id}" + source_uri = azurerm_managed_disk.test.id } data "azurerm_snapshot" "snapshot" { - name = "${azurerm_snapshot.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_snapshot.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testAccDataSourceAzureRMSnapshot_encryption(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_client_config" "current" {} resource "azurerm_resource_group" "test" { @@ -106,7 +114,7 @@ resource "azurerm_key_vault" "test" { access_policy { tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + object_id = "${data.azurerm_client_config.current.object_id}" key_permissions = [ "create", diff --git a/azurerm/internal/services/compute/tests/data_source_virtual_machine_test.go b/azurerm/internal/services/compute/tests/data_source_virtual_machine_test.go index 3b2f2adf064e1..391f04c0ba218 100644 --- a/azurerm/internal/services/compute/tests/data_source_virtual_machine_test.go +++ b/azurerm/internal/services/compute/tests/data_source_virtual_machine_test.go @@ -27,6 +27,10 @@ func TestAccDataSourceVirtualMachine_basic(t *testing.T) { func testAccDataSourceVirtualMachine_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%[2]s" @@ -35,49 +39,48 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%[1]d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_network_interface" "test" { name = "acctni-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "dynamic" } } resource "azurerm_storage_account" "test" { name = "accsa%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } resource "azurerm_virtual_machine" "test" { name = "acctvm-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.test.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.test.id] vm_size = "Standard_D1_v2" storage_image_reference { @@ -106,8 +109,8 @@ resource "azurerm_virtual_machine" "test" { } data "azurerm_virtual_machine" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - name = "${azurerm_virtual_machine.test.name}" + resource_group_name = azurerm_resource_group.test.name + name = azurerm_virtual_machine.test.name } `, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/compute/tests/linux_virtual_machine_resource_disk_os_test.go b/azurerm/internal/services/compute/tests/linux_virtual_machine_resource_disk_os_test.go index 0c77de60d552f..5243a950f8811 100644 --- a/azurerm/internal/services/compute/tests/linux_virtual_machine_resource_disk_os_test.go +++ b/azurerm/internal/services/compute/tests/linux_virtual_machine_resource_disk_os_test.go @@ -480,7 +480,7 @@ resource "azurerm_key_vault" "test" { resource "azurerm_key_vault_access_policy" "service-principal" { key_vault_id = azurerm_key_vault.test.id tenant_id = data.azurerm_client_config.current.tenant_id - object_id = data.azurerm_client_config.current.service_principal_object_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", diff --git a/azurerm/internal/services/compute/tests/linux_virtual_machine_resource_other_test.go b/azurerm/internal/services/compute/tests/linux_virtual_machine_resource_other_test.go index 7ce162b5461d9..ec3b13a7ba369 100644 --- a/azurerm/internal/services/compute/tests/linux_virtual_machine_resource_other_test.go +++ b/azurerm/internal/services/compute/tests/linux_virtual_machine_resource_other_test.go @@ -781,7 +781,7 @@ resource "azurerm_key_vault" "test" { access_policy { tenant_id = data.azurerm_client_config.current.tenant_id - object_id = data.azurerm_client_config.current.service_principal_object_id + object_id = data.azurerm_client_config.current.object_id certificate_permissions = [ "create", diff --git a/azurerm/internal/services/compute/tests/resource_arm_availability_set_test.go b/azurerm/internal/services/compute/tests/resource_arm_availability_set_test.go index a7400b08196e2..a9d1908962d72 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_availability_set_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_availability_set_test.go @@ -266,6 +266,10 @@ func testCheckAzureRMAvailabilitySetDestroy(s *terraform.State) error { func testAccAzureRMAvailabilitySet_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -273,8 +277,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_availability_set" "test" { name = "acctestavset-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -285,15 +289,19 @@ func testAccAzureRMAvailabilitySet_requiresImport(data acceptance.TestData) stri %s resource "azurerm_availability_set" "import" { - name = "${azurerm_availability_set.test.name}" - location = "${azurerm_availability_set.test.location}" - resource_group_name = "${azurerm_availability_set.test.resource_group_name}" + name = azurerm_availability_set.test.name + location = azurerm_availability_set.test.location + resource_group_name = azurerm_availability_set.test.resource_group_name } `, template) } func testAccAzureRMAvailabilitySet_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -301,8 +309,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_availability_set" "test" { name = "acctestavset-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { environment = "Production" @@ -314,6 +322,10 @@ resource "azurerm_availability_set" "test" { func testAccAzureRMAvailabilitySet_withUpdatedTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -321,8 +333,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_availability_set" "test" { name = "acctestavset-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { environment = "staging" @@ -333,6 +345,10 @@ resource "azurerm_availability_set" "test" { func testAccAzureRMAvailabilitySet_withPPG(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -340,22 +356,26 @@ resource "azurerm_resource_group" "test" { resource "azurerm_proximity_placement_group" "test" { name = "acctestPPG-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_availability_set" "test" { name = "acctestavset-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name - proximity_placement_group_id = "${azurerm_proximity_placement_group.test.id}" + proximity_placement_group_id = azurerm_proximity_placement_group.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testAccAzureRMAvailabilitySet_withDomainCounts(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -363,8 +383,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_availability_set" "test" { name = "acctestavset-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name platform_update_domain_count = 3 platform_fault_domain_count = 3 } @@ -373,6 +393,10 @@ resource "azurerm_availability_set" "test" { func testAccAzureRMAvailabilitySet_unmanaged(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -380,8 +404,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_availability_set" "test" { name = "acctestavset-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name platform_update_domain_count = 3 platform_fault_domain_count = 3 managed = false diff --git a/azurerm/internal/services/compute/tests/resource_arm_dedicated_host_group_test.go b/azurerm/internal/services/compute/tests/resource_arm_dedicated_host_group_test.go index 30138a33e96a4..d95192831f300 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_dedicated_host_group_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_dedicated_host_group_test.go @@ -131,6 +131,10 @@ func testCheckAzureRMDedicatedHostGroupDestroy(s *terraform.State) error { func testAccAzureRMDedicatedHostGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-compute-%d" location = "%s" @@ -138,8 +142,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dedicated_host_group" "test" { name = "acctestDHG-compute-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location platform_fault_domain_count = 2 } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -150,9 +154,9 @@ func testAccAzureRMDedicatedHostGroup_requiresImport(data acceptance.TestData) s return fmt.Sprintf(` %s resource "azurerm_dedicated_host_group" "import" { - resource_group_name = "${azurerm_dedicated_host_group.test.resource_group_name}" - name = "${azurerm_dedicated_host_group.test.name}" - location = "${azurerm_dedicated_host_group.test.location}" + resource_group_name = azurerm_dedicated_host_group.test.resource_group_name + name = azurerm_dedicated_host_group.test.name + location = azurerm_dedicated_host_group.test.location platform_fault_domain_count = 2 } `, template) @@ -160,6 +164,10 @@ resource "azurerm_dedicated_host_group" "import" { func testAccAzureRMDedicatedHostGroup_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-compute-%d" location = "%s" @@ -167,8 +175,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dedicated_host_group" "test" { name = "acctestDHG-compute-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location platform_fault_domain_count = 2 zones = ["1"] tags = { diff --git a/azurerm/internal/services/compute/tests/resource_arm_dedicated_host_test.go b/azurerm/internal/services/compute/tests/resource_arm_dedicated_host_test.go index b3ab2b1549606..b7024fa7d8f6e 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_dedicated_host_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_dedicated_host_test.go @@ -313,6 +313,10 @@ resource "azurerm_dedicated_host" "import" { func testAccAzureRMDedicatedHost_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-compute-%d" location = "%s" diff --git a/azurerm/internal/services/compute/tests/resource_arm_disk_encryption_set_test.go b/azurerm/internal/services/compute/tests/resource_arm_disk_encryption_set_test.go index 4f4fbaead703f..f0e23216c407d 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_disk_encryption_set_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_disk_encryption_set_test.go @@ -220,6 +220,10 @@ func testAccAzureRMDiskEncryptionSet_dependencies(data acceptance.TestData) stri location := "northeurope" return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_client_config" "current" {} resource "azurerm_resource_group" "test" { @@ -236,7 +240,7 @@ resource "azurerm_key_vault" "test" { access_policy { tenant_id = data.azurerm_client_config.current.tenant_id - object_id = data.azurerm_client_config.current.service_principal_object_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", diff --git a/azurerm/internal/services/compute/tests/resource_arm_image_test.go b/azurerm/internal/services/compute/tests/resource_arm_image_test.go index 15fa23a9391bd..8a1cfe7ca04dc 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_image_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_image_test.go @@ -34,7 +34,7 @@ func TestAccAzureRMImage_standaloneImage(t *testing.T) { CheckDestroy: testCheckAzureRMImageDestroy, Steps: []resource.TestStep{ { - //need to create a vm and then reference it in the image creation + // need to create a vm and then reference it in the image creation Config: testAccAzureRMImage_standaloneImage_setup(data, userName, password, hostName, "LRS"), Destroy: false, Check: resource.ComposeTestCheckFunc( @@ -67,7 +67,7 @@ func TestAccAzureRMImage_standaloneImage_hyperVGeneration_V2(t *testing.T) { CheckDestroy: testCheckAzureRMImageDestroy, Steps: []resource.TestStep{ { - //need to create a vm and then reference it in the image creation + // need to create a vm and then reference it in the image creation Config: testAccAzureRMImage_standaloneImage_setup(data, userName, password, hostName, "LRS"), Destroy: false, Check: resource.ComposeTestCheckFunc( @@ -100,7 +100,7 @@ func TestAccAzureRMImage_standaloneImageZoneRedundant(t *testing.T) { CheckDestroy: testCheckAzureRMImageDestroy, Steps: []resource.TestStep{ { - //need to create a vm and then reference it in the image creation + // need to create a vm and then reference it in the image creation Config: testAccAzureRMImage_standaloneImage_setup(data, userName, password, hostName, "ZRS"), Destroy: false, Check: resource.ComposeTestCheckFunc( @@ -139,7 +139,7 @@ func TestAccAzureRMImage_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMImageDestroy, Steps: []resource.TestStep{ { - //need to create a vm and then reference it in the image creation + // need to create a vm and then reference it in the image creation Config: testAccAzureRMImage_standaloneImage_setup(data, userName, password, hostName, "LRS"), Destroy: false, Check: resource.ComposeTestCheckFunc( @@ -176,7 +176,7 @@ func TestAccAzureRMImage_customImageVMFromVHD(t *testing.T) { CheckDestroy: testCheckAzureRMImageDestroy, Steps: []resource.TestStep{ { - //need to create a vm and then reference it in the image creation + // need to create a vm and then reference it in the image creation Config: testAccAzureRMImage_customImage_fromVHD_setup(data, userName, password, hostName, data.Locations.Primary), Destroy: false, Check: resource.ComposeTestCheckFunc( @@ -209,7 +209,7 @@ func TestAccAzureRMImage_customImageVMFromVM(t *testing.T) { CheckDestroy: testCheckAzureRMImageDestroy, Steps: []resource.TestStep{ { - //need to create a vm and then reference it in the image creation + // need to create a vm and then reference it in the image creation Config: testAccAzureRMImage_customImage_fromVM_sourceVM(data, userName, password, hostName, data.Locations.Primary), Destroy: false, Check: resource.ComposeTestCheckFunc( @@ -242,7 +242,7 @@ func TestAccAzureRMImageVMSS_customImageVMSSFromVHD(t *testing.T) { CheckDestroy: testCheckAzureRMImageDestroy, Steps: []resource.TestStep{ { - //need to create a vm and then reference it in the image creation + // need to create a vm and then reference it in the image creation Config: testAccAzureRMImageVMSS_customImage_fromVHD_setup(data, userName, password, hostName, data.Locations.Primary), Destroy: false, Check: resource.ComposeTestCheckFunc( @@ -334,7 +334,7 @@ func testGeneralizeVMImage(resourceGroup string, vmName string, userName string, } func deprovisionVM(userName string, password string, hostName string, port string) error { - //SSH into the machine and execute a waagent deprovisioning command + // SSH into the machine and execute a waagent deprovisioning command var b bytes.Buffer cmd := "sudo waagent -verbose -deprovision+user -force" @@ -501,6 +501,10 @@ func testCheckAzureRMImageDestroy(s *terraform.State) error { func testAccAzureRMImage_standaloneImage_setup(data acceptance.TestData, userName string, password string, hostName string, storageType string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -509,42 +513,42 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_public_ip" "test" { name = "acctpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" domain_name_label = "%s" } resource "azurerm_network_interface" "testsource" { name = "acctnicsource-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfigurationsource" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_storage_account" "test" { name = "accsa%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "%s" @@ -555,16 +559,15 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "blob" } resource "azurerm_virtual_machine" "testsource" { name = "testsource" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.testsource.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.testsource.id] vm_size = "Standard_D1_v2" storage_image_reference { @@ -607,6 +610,10 @@ func testAccAzureRMImage_standaloneImage_provision(data acceptance.TestData, use } return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -615,42 +622,42 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_public_ip" "test" { name = "acctpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" domain_name_label = "%s" } resource "azurerm_network_interface" "testsource" { name = "acctnicsource-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfigurationsource" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_storage_account" "test" { name = "accsa%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "%s" @@ -661,16 +668,15 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "blob" } resource "azurerm_virtual_machine" "testsource" { name = "testsource" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.testsource.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.testsource.id] vm_size = "Standard_D1_v2" storage_image_reference { @@ -706,9 +712,10 @@ resource "azurerm_virtual_machine" "testsource" { resource "azurerm_image" "test" { name = "accteste" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name zone_resilient = %t + %s os_disk { @@ -733,9 +740,9 @@ func testAccAzureRMImage_standaloneImage_requiresImport(data acceptance.TestData %s resource "azurerm_image" "import" { - name = "${azurerm_image.test.name}" - location = "${azurerm_image.test.location}" - resource_group_name = "${azurerm_image.test.resource_group_name}" + name = azurerm_image.test.name + location = azurerm_image.test.location + resource_group_name = azurerm_image.test.resource_group_name os_disk { os_type = "Linux" @@ -755,6 +762,10 @@ resource "azurerm_image" "import" { func testAccAzureRMImage_customImage_fromVHD_setup(data acceptance.TestData, userName string, password string, hostName string, location string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -763,42 +774,42 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_public_ip" "test" { name = "acctpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" domain_name_label = "%s" } resource "azurerm_network_interface" "testsource" { name = "acctnicsource-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfigurationsource" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_storage_account" "test" { name = "accsa%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -809,16 +820,15 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "blob" } resource "azurerm_virtual_machine" "testsource" { name = "testsource" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.testsource.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.testsource.id] vm_size = "Standard_D1_v2" storage_image_reference { @@ -856,6 +866,10 @@ resource "azurerm_virtual_machine" "testsource" { func testAccAzureRMImage_customImage_fromVHD_provision(data acceptance.TestData, userName string, password string, hostName string, location string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -864,42 +878,42 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_public_ip" "test" { name = "acctpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" domain_name_label = "%s" } resource "azurerm_network_interface" "testsource" { name = "acctnicsource-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfigurationsource" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_storage_account" "test" { name = "accsa%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -910,16 +924,15 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "blob" } resource "azurerm_virtual_machine" "testsource" { name = "testsource" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.testsource.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.testsource.id] vm_size = "Standard_D1_v2" storage_image_reference { @@ -955,8 +968,8 @@ resource "azurerm_virtual_machine" "testsource" { resource "azurerm_image" "testdestination" { name = "accteste" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name os_disk { os_type = "Linux" @@ -974,25 +987,25 @@ resource "azurerm_image" "testdestination" { resource "azurerm_network_interface" "testdestination" { name = "acctnicdest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfiguration2" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } resource "azurerm_virtual_machine" "testdestination" { name = "acctvm" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.testdestination.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.testdestination.id] vm_size = "Standard_D1_v2" storage_image_reference { - id = "${azurerm_image.testdestination.id}" + id = azurerm_image.testdestination.id } storage_os_disk { @@ -1021,6 +1034,10 @@ resource "azurerm_virtual_machine" "testdestination" { func testAccAzureRMImage_customImage_fromVM_sourceVM(data acceptance.TestData, userName string, password string, hostName string, location string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1029,43 +1046,43 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_public_ip" "test" { name = "acctpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" domain_name_label = "%s" } resource "azurerm_network_interface" "testsource" { name = "acctnicsource-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfigurationsource" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_virtual_machine" "testsource" { name = "testsource" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.testsource.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.testsource.id] vm_size = "Standard_D1_v2" storage_image_reference { @@ -1101,6 +1118,10 @@ resource "azurerm_virtual_machine" "testsource" { func testAccAzureRMImage_customImage_fromVM_destinationVM(data acceptance.TestData, userName string, password string, hostName string, location string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1109,43 +1130,43 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_public_ip" "test" { name = "acctpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" domain_name_label = "%s" } resource "azurerm_network_interface" "testsource" { name = "acctnicsource-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfigurationsource" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_virtual_machine" "testsource" { name = "testsource" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.testsource.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.testsource.id] vm_size = "Standard_D1_v2" storage_image_reference { @@ -1179,9 +1200,9 @@ resource "azurerm_virtual_machine" "testsource" { resource "azurerm_image" "testdestination" { name = "acctestdest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - source_virtual_machine_id = "${azurerm_virtual_machine.testsource.id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + source_virtual_machine_id = azurerm_virtual_machine.testsource.id tags = { environment = "acctest" @@ -1191,25 +1212,25 @@ resource "azurerm_image" "testdestination" { resource "azurerm_network_interface" "testdestination" { name = "acctnicdest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfiguration2" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } resource "azurerm_virtual_machine" "testdestination" { name = "testdestination" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.testdestination.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.testdestination.id] vm_size = "Standard_D1_v2" storage_image_reference { - id = "${azurerm_image.testdestination.id}" + id = azurerm_image.testdestination.id } storage_os_disk { @@ -1238,6 +1259,10 @@ resource "azurerm_virtual_machine" "testdestination" { func testAccAzureRMImageVMSS_customImage_fromVHD_setup(data acceptance.TestData, userName string, password string, hostName string, location string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1246,42 +1271,42 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_public_ip" "test" { name = "acctpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" domain_name_label = "%s" } resource "azurerm_network_interface" "testsource" { name = "acctnicsource-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfigurationsource" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_storage_account" "test" { name = "accsa%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -1292,16 +1317,15 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "blob" } resource "azurerm_virtual_machine" "testsource" { name = "testsource" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.testsource.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.testsource.id] vm_size = "Standard_D1_v2" storage_image_reference { @@ -1339,6 +1363,10 @@ resource "azurerm_virtual_machine" "testsource" { func testAccAzureRMImageVMSS_customImage_fromVHD_provision(data acceptance.TestData, userName string, password string, hostName string, location string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1347,42 +1375,42 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_public_ip" "test" { name = "acctpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" domain_name_label = "%s" } resource "azurerm_network_interface" "testsource" { name = "acctnicsource-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfigurationsource" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_storage_account" "test" { name = "accsa%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -1393,16 +1421,15 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "blob" } resource "azurerm_virtual_machine" "testsource" { name = "testsource" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.testsource.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.testsource.id] vm_size = "Standard_D1_v2" storage_image_reference { @@ -1438,8 +1465,8 @@ resource "azurerm_virtual_machine" "testsource" { resource "azurerm_image" "testdestination" { name = "accteste" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name os_disk { os_type = "Linux" @@ -1457,8 +1484,8 @@ resource "azurerm_image" "testdestination" { resource "azurerm_virtual_machine_scale_set" "testdestination" { name = "testdestination" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name upgrade_policy_mode = "Manual" sku { @@ -1479,7 +1506,7 @@ resource "azurerm_virtual_machine_scale_set" "testdestination" { ip_configuration { name = "TestIPConfiguration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id primary = true } } @@ -1491,7 +1518,7 @@ resource "azurerm_virtual_machine_scale_set" "testdestination" { } storage_profile_image_reference { - id = "${azurerm_image.testdestination.id}" + id = azurerm_image.testdestination.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, hostName, data.RandomInteger, data.RandomInteger, userName, password, data.RandomInteger, userName, password, data.RandomInteger) diff --git a/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go index c8265413d5c5e..9510faf3dcbb4 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go @@ -437,6 +437,10 @@ func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDisk_diskEncryptionSetDe location := "westus2" return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_client_config" "current" {} resource "azurerm_resource_group" "test" { @@ -456,7 +460,7 @@ resource "azurerm_key_vault" "test" { resource "azurerm_key_vault_access_policy" "service-principal" { key_vault_id = azurerm_key_vault.test.id tenant_id = data.azurerm_client_config.current.tenant_id - object_id = data.azurerm_client_config.current.service_principal_object_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", diff --git a/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go index ebae79a7d3d66..f7610e0a0828a 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go @@ -307,6 +307,10 @@ func testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDisk_diskEncryptionSetDepe location := "westus2" return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_client_config" "current" {} resource "azurerm_resource_group" "test" { @@ -326,7 +330,7 @@ resource "azurerm_key_vault" "test" { resource "azurerm_key_vault_access_policy" "service-principal" { key_vault_id = azurerm_key_vault.test.id tenant_id = data.azurerm_client_config.current.tenant_id - object_id = data.azurerm_client_config.current.service_principal_object_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", diff --git a/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_network_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_network_test.go index c5c17daa38132..48ebd33dd1324 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_network_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_network_test.go @@ -624,6 +624,10 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { func testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationGateway(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_other_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_other_test.go index 041785647d9d1..574711dd48d6d 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_other_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_other_test.go @@ -978,7 +978,7 @@ resource "azurerm_key_vault" "test" { access_policy { tenant_id = data.azurerm_client_config.current.tenant_id - object_id = data.azurerm_client_config.current.service_principal_object_id + object_id = data.azurerm_client_config.current.object_id certificate_permissions = [ "create", diff --git a/azurerm/internal/services/compute/tests/resource_arm_managed_disk_test.go b/azurerm/internal/services/compute/tests/resource_arm_managed_disk_test.go index 8ff810035dcbe..9bad68ae13112 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_managed_disk_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_managed_disk_test.go @@ -92,7 +92,7 @@ func TestAccAzureRMManagedDisk_import(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - //need to create a vm and then delete it so we can use the vhd to test import + // need to create a vm and then delete it so we can use the vhd to test import Config: testAccAzureRMVirtualMachine_basicLinuxMachine(data), Destroy: false, ExpectNonEmptyPlan: true, @@ -210,30 +210,6 @@ func TestAccAzureRMManagedDisk_encryption(t *testing.T) { }) } -func TestAccAzureRMManagedDisk_NonStandardCasing(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") - var d compute.Disk - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMManagedDiskDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMManagedDisk_nonStandardCasing(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), - ), - }, - { - Config: testAccAzureRMManagedDisk_nonStandardCasing(data), - PlanOnly: true, - ExpectNonEmptyPlan: false, - }, - }, - }) -} - func TestAccAzureRMManagedDisk_importEmpty_withZone(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk @@ -479,6 +455,10 @@ func testDeleteAzureRMVirtualMachine(resourceName string) resource.TestCheckFunc func testAccAzureRMManagedDisk_empty(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -486,8 +466,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "acctestd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = "1" @@ -506,9 +486,9 @@ func testAccAzureRMManagedDisk_requiresImport(data acceptance.TestData) string { %s resource "azurerm_managed_disk" "import" { - name = "${azurerm_managed_disk.test.name}" - location = "${azurerm_managed_disk.test.location}" - resource_group_name = "${azurerm_managed_disk.test.resource_group_name}" + name = azurerm_managed_disk.test.name + location = azurerm_managed_disk.test.location + resource_group_name = azurerm_managed_disk.test.resource_group_name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = "1" @@ -523,6 +503,10 @@ resource "azurerm_managed_disk" "import" { func testAccAzureRMManagedDisk_empty_withZone(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -530,8 +514,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "acctestd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = "1" @@ -547,6 +531,10 @@ resource "azurerm_managed_disk" "test" { func testAccAzureRMManagedDisk_import(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -566,7 +554,6 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } @@ -590,6 +577,10 @@ resource "azurerm_managed_disk" "test" { func testAccAzureRMManagedDisk_copy(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -597,8 +588,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "source" { name = "acctestd1-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = "1" @@ -611,11 +602,11 @@ resource "azurerm_managed_disk" "source" { resource "azurerm_managed_disk" "test" { name = "acctestd2-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Copy" - source_resource_id = "${azurerm_managed_disk.source.id}" + source_resource_id = azurerm_managed_disk.source.id disk_size_gb = "1" tags = { @@ -628,6 +619,10 @@ resource "azurerm_managed_disk" "test" { func testAccAzureRMManagedDisk_empty_updated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -635,8 +630,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "acctestd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Premium_LRS" create_option = "Empty" disk_size_gb = "2" @@ -648,31 +643,12 @@ resource "azurerm_managed_disk" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagedDisk_nonStandardCasing(data acceptance.TestData) string { +func testAccAzureRMManagedDisk_platformImage(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_managed_disk" "test" { - name = "acctestd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_type = "standard_lrs" - create_option = "Empty" - disk_size_gb = "1" - - tags = { - environment = "acctest" - cost-center = "ops" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMManagedDisk_platformImage(data acceptance.TestData) string { - return fmt.Sprintf(` data "azurerm_platform_image" "test" { location = "%s" publisher = "Canonical" @@ -687,11 +663,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "acctestd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name os_type = "Linux" create_option = "FromImage" - image_reference_id = "${data.azurerm_platform_image.test.id}" + image_reference_id = data.azurerm_platform_image.test.id storage_account_type = "Standard_LRS" } `, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -699,6 +675,10 @@ resource "azurerm_managed_disk" "test" { func testAccAzureRMManagedDisk_zeroGbFromPlatformImage(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_platform_image" "test" { location = "%s" publisher = "Canonical" @@ -713,12 +693,12 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "acctestd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name os_type = "Linux" create_option = "FromImage" disk_size_gb = "0" - image_reference_id = "${data.azurerm_platform_image.test.id}" + image_reference_id = data.azurerm_platform_image.test.id storage_account_type = "Standard_LRS" } `, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -726,6 +706,10 @@ resource "azurerm_managed_disk" "test" { func testAccAzureRMManagedDisk_encryption(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_client_config" "current" {} resource "azurerm_resource_group" "test" { @@ -745,7 +729,7 @@ resource "azurerm_key_vault" "test" { access_policy { tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + object_id = "${data.azurerm_client_config.current.object_id}" key_permissions = [ "create", @@ -817,6 +801,10 @@ resource "azurerm_managed_disk" "test" { func testAccAzureRMManagedDisk_create_withUltraSSD(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -824,8 +812,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "acctestd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "UltraSSD_LRS" create_option = "Empty" disk_size_gb = "4" @@ -843,6 +831,10 @@ resource "azurerm_managed_disk" "test" { func testAccAzureRMManagedDisk_update_withUltraSSD(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -850,8 +842,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "acctestd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "UltraSSD_LRS" create_option = "Empty" disk_size_gb = "4" @@ -873,9 +865,9 @@ func testAccAzureRMManagedDisk_import_withUltraSSD(data acceptance.TestData) str %s resource "azurerm_managed_disk" "import" { - name = "${azurerm_managed_disk.test.name}" - location = "${azurerm_managed_disk.test.location}" - resource_group_name = "${azurerm_managed_disk.test.resource_group_name}" + name = azurerm_managed_disk.test.name + location = azurerm_managed_disk.test.location + resource_group_name = azurerm_managed_disk.test.resource_group_name storage_account_type = "UltraSSD_LRS" create_option = "Empty" disk_size_gb = "4" @@ -896,6 +888,10 @@ func testAccAzureRMManagedDisk_diskEncryptionSetDependencies(data acceptance.Tes location := "westus2" return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_client_config" "current" {} resource "azurerm_resource_group" "test" { @@ -915,7 +911,7 @@ resource "azurerm_key_vault" "test" { resource "azurerm_key_vault_access_policy" "service-principal" { key_vault_id = azurerm_key_vault.test.id tenant_id = data.azurerm_client_config.current.tenant_id - object_id = data.azurerm_client_config.current.service_principal_object_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", @@ -1005,6 +1001,10 @@ resource "azurerm_managed_disk" "test" { func testAccAzureRMManagedDisk_managedDiskAttached(data acceptance.TestData, diskSize int) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%[2]s" @@ -1013,34 +1013,34 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%[1]d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_network_interface" "test" { name = "acctni-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } resource "azurerm_virtual_machine" "test" { name = "acctvm-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.test.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.test.id] vm_size = "Standard_F2" storage_image_reference { @@ -1070,16 +1070,16 @@ resource "azurerm_virtual_machine" "test" { resource "azurerm_managed_disk" "test" { name = "%[1]d-disk1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = %[3]d } resource "azurerm_virtual_machine_data_disk_attachment" "test" { - managed_disk_id = "${azurerm_managed_disk.test.id}" - virtual_machine_id = "${azurerm_virtual_machine.test.id}" + managed_disk_id = azurerm_managed_disk.test.id + virtual_machine_id = azurerm_virtual_machine.test.id lun = "0" caching = "None" } diff --git a/azurerm/internal/services/compute/tests/resource_arm_marketplace_agreement_test.go b/azurerm/internal/services/compute/tests/resource_arm_marketplace_agreement_test.go index 91319da1535ea..e5cb764796949 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_marketplace_agreement_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_marketplace_agreement_test.go @@ -184,6 +184,10 @@ func testCheckAzureRMMarketplaceAgreementDestroy(s *terraform.State) error { func testAccAzureRMMarketplaceAgreement_basicConfig() string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_marketplace_agreement" "test" { publisher = "barracudanetworks" offer = "waf" diff --git a/azurerm/internal/services/compute/tests/resource_arm_proximity_placement_group_test.go b/azurerm/internal/services/compute/tests/resource_arm_proximity_placement_group_test.go index 8fd5a54952653..534342b820a7b 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_proximity_placement_group_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_proximity_placement_group_test.go @@ -196,6 +196,10 @@ func testCheckAzureRMProximityPlacementGroupDestroy(s *terraform.State) error { func testAccProximityPlacementGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -203,8 +207,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_proximity_placement_group" "test" { name = "acctestPPG-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -215,15 +219,19 @@ func testAccProximityPlacementGroup_requiresImport(data acceptance.TestData) str %s resource "azurerm_proximity_placement_group" "import" { - name = "${azurerm_proximity_placement_group.test.name}" - location = "${azurerm_proximity_placement_group.test.location}" - resource_group_name = "${azurerm_proximity_placement_group.test.resource_group_name}" + name = azurerm_proximity_placement_group.test.name + location = azurerm_proximity_placement_group.test.location + resource_group_name = azurerm_proximity_placement_group.test.resource_group_name } `, template) } func testAccProximityPlacementGroup_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -231,8 +239,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_proximity_placement_group" "test" { name = "acctestPPG-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { environment = "Production" @@ -244,6 +252,10 @@ resource "azurerm_proximity_placement_group" "test" { func testAccProximityPlacementGroup_withUpdatedTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -251,8 +263,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_proximity_placement_group" "test" { name = "acctestPPG-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { environment = "staging" diff --git a/azurerm/internal/services/compute/tests/resource_arm_shared_image_gallery_test.go b/azurerm/internal/services/compute/tests/resource_arm_shared_image_gallery_test.go index 3d6e9eaeb6e77..158e8b431fa26 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_shared_image_gallery_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_shared_image_gallery_test.go @@ -142,6 +142,10 @@ func testCheckAzureRMSharedImageGalleryExists(resourceName string) resource.Test func testAccAzureRMSharedImageGallery_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -149,8 +153,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_shared_image_gallery" "test" { name = "acctestsig%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -160,15 +164,19 @@ func testAccAzureRMSharedImageGallery_requiresImport(data acceptance.TestData) s %s resource "azurerm_shared_image_gallery" "import" { - name = "${azurerm_shared_image_gallery.test.name}" - resource_group_name = "${azurerm_shared_image_gallery.test.resource_group_name}" - location = "${azurerm_shared_image_gallery.test.location}" + name = azurerm_shared_image_gallery.test.name + resource_group_name = azurerm_shared_image_gallery.test.resource_group_name + location = azurerm_shared_image_gallery.test.location } `, testAccAzureRMSharedImageGallery_basic(data)) } func testAccAzureRMSharedImageGallery_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -176,8 +184,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_shared_image_gallery" "test" { name = "acctestsig%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location description = "Shared images and things." tags = { diff --git a/azurerm/internal/services/compute/tests/resource_arm_shared_image_test.go b/azurerm/internal/services/compute/tests/resource_arm_shared_image_test.go index 0fa36eb427ccd..5854f0c4abfff 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_shared_image_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_shared_image_test.go @@ -140,6 +140,10 @@ func testCheckAzureRMSharedImageExists(resourceName string) resource.TestCheckFu func testAccAzureRMSharedImage_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -147,15 +151,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_shared_image_gallery" "test" { name = "acctestsig%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location } resource "azurerm_shared_image" "test" { name = "acctestimg%d" - gallery_name = "${azurerm_shared_image_gallery.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + gallery_name = azurerm_shared_image_gallery.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location os_type = "Linux" identifier { @@ -173,11 +177,11 @@ func testAccAzureRMSharedImage_requiresImport(data acceptance.TestData) string { %s resource "azurerm_shared_image" "import" { - name = "${azurerm_shared_image.test.name}" - gallery_name = "${azurerm_shared_image.test.gallery_name}" - resource_group_name = "${azurerm_shared_image.test.resource_group_name}" - location = "${azurerm_shared_image.test.location}" - os_type = "${azurerm_shared_image.test.os_type}" + name = azurerm_shared_image.test.name + gallery_name = azurerm_shared_image.test.gallery_name + resource_group_name = azurerm_shared_image.test.resource_group_name + location = azurerm_shared_image.test.location + os_type = azurerm_shared_image.test.os_type identifier { publisher = "AccTesPublisher%d" @@ -190,6 +194,10 @@ resource "azurerm_shared_image" "import" { func testAccAzureRMSharedImage_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -197,15 +205,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_shared_image_gallery" "test" { name = "acctestsig%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location } resource "azurerm_shared_image" "test" { name = "acctestimg%d" - gallery_name = "${azurerm_shared_image_gallery.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + gallery_name = azurerm_shared_image_gallery.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location os_type = "Linux" description = "Wubba lubba dub dub" eula = "Do you agree there's infinite Rick's and Infinite Morty's?" diff --git a/azurerm/internal/services/compute/tests/resource_arm_shared_image_version_test.go b/azurerm/internal/services/compute/tests/resource_arm_shared_image_version_test.go index cfc8fa8242f59..a70fed71c1aef 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_shared_image_version_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_shared_image_version_test.go @@ -245,15 +245,15 @@ func testAccAzureRMSharedImageVersion_provision(data acceptance.TestData, userna resource "azurerm_shared_image_gallery" "test" { name = "acctestsig%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location } resource "azurerm_shared_image" "test" { name = "acctestimg%d" - gallery_name = "${azurerm_shared_image_gallery.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + gallery_name = azurerm_shared_image_gallery.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location os_type = "Linux" identifier { @@ -272,14 +272,14 @@ func testAccAzureRMSharedImageVersion_imageVersion(data acceptance.TestData, use resource "azurerm_shared_image_version" "test" { name = "0.0.1" - gallery_name = "${azurerm_shared_image_gallery.test.name}" - image_name = "${azurerm_shared_image.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - managed_image_id = "${azurerm_image.test.id}" + gallery_name = azurerm_shared_image_gallery.test.name + image_name = azurerm_shared_image.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + managed_image_id = azurerm_image.test.id target_region { - name = "${azurerm_resource_group.test.location}" + name = azurerm_resource_group.test.location regional_replica_count = 1 } } @@ -293,14 +293,14 @@ func testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(data accept resource "azurerm_shared_image_version" "test" { name = "0.0.1" - gallery_name = "${azurerm_shared_image_gallery.test.name}" - image_name = "${azurerm_shared_image.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - managed_image_id = "${azurerm_image.test.id}" + gallery_name = azurerm_shared_image_gallery.test.name + image_name = azurerm_shared_image.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + managed_image_id = azurerm_image.test.id target_region { - name = "${azurerm_resource_group.test.location}" + name = azurerm_resource_group.test.location regional_replica_count = 1 storage_account_type = "%s" } @@ -313,15 +313,15 @@ func testAccAzureRMSharedImageVersion_requiresImport(data acceptance.TestData, u %s resource "azurerm_shared_image_version" "import" { - name = "${azurerm_shared_image_version.test.name}" - gallery_name = "${azurerm_shared_image_version.test.gallery_name}" - image_name = "${azurerm_shared_image_version.test.image_name}" - resource_group_name = "${azurerm_shared_image_version.test.resource_group_name}" - location = "${azurerm_shared_image_version.test.location}" - managed_image_id = "${azurerm_shared_image_version.test.managed_image_id}" + name = azurerm_shared_image_version.test.name + gallery_name = azurerm_shared_image_version.test.gallery_name + image_name = azurerm_shared_image_version.test.image_name + resource_group_name = azurerm_shared_image_version.test.resource_group_name + location = azurerm_shared_image_version.test.location + managed_image_id = azurerm_shared_image_version.test.managed_image_id target_region { - name = "${azurerm_resource_group.test.location}" + name = azurerm_resource_group.test.location regional_replica_count = 1 } } @@ -335,14 +335,14 @@ func testAccAzureRMSharedImageVersion_imageVersionUpdated(data acceptance.TestDa resource "azurerm_shared_image_version" "test" { name = "1234567890.1234567890.1234567890" - gallery_name = "${azurerm_shared_image_gallery.test.name}" - image_name = "${azurerm_shared_image.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - managed_image_id = "${azurerm_image.test.id}" + gallery_name = azurerm_shared_image_gallery.test.name + image_name = azurerm_shared_image.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + managed_image_id = azurerm_image.test.id target_region { - name = "${azurerm_resource_group.test.location}" + name = azurerm_resource_group.test.location regional_replica_count = 1 } diff --git a/azurerm/internal/services/compute/tests/resource_arm_snapshot_test.go b/azurerm/internal/services/compute/tests/resource_arm_snapshot_test.go index c4424d2c1de4c..cd07ca54b318a 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_snapshot_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_snapshot_test.go @@ -261,6 +261,10 @@ func testCheckAzureRMSnapshotExists(resourceName string) resource.TestCheckFunc func testAccAzureRMSnapshot_fromManagedDisk(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -268,8 +272,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "acctestmd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = "10" @@ -277,10 +281,10 @@ resource "azurerm_managed_disk" "test" { resource "azurerm_snapshot" "test" { name = "acctestss_%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name create_option = "Copy" - source_uri = "${azurerm_managed_disk.test.id}" + source_uri = azurerm_managed_disk.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } @@ -290,17 +294,21 @@ func testAccAzureRMSnapshot_requiresImport(data acceptance.TestData) string { %s resource "azurerm_snapshot" "import" { - name = "${azurerm_snapshot.test.name}" - location = "${azurerm_snapshot.test.location}" - resource_group_name = "${azurerm_snapshot.test.resource_group_name}" - create_option = "${azurerm_snapshot.test.create_option}" - source_uri = "${azurerm_snapshot.test.source_uri}" + name = azurerm_snapshot.test.name + location = azurerm_snapshot.test.location + resource_group_name = azurerm_snapshot.test.resource_group_name + create_option = azurerm_snapshot.test.create_option + source_uri = azurerm_snapshot.test.source_uri } `, testAccAzureRMSnapshot_fromManagedDisk(data)) } func testAccAzureRMSnapshot_fromManagedDiskUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -308,8 +316,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "acctestmd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = "10" @@ -317,10 +325,10 @@ resource "azurerm_managed_disk" "test" { resource "azurerm_snapshot" "test" { name = "acctestss_%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name create_option = "Copy" - source_uri = "${azurerm_managed_disk.test.id}" + source_uri = azurerm_managed_disk.test.id tags = { Hello = "World" @@ -331,6 +339,10 @@ resource "azurerm_snapshot" "test" { func testAccAzureRMSnapshot_encryption(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_client_config" "current" {} resource "azurerm_resource_group" "test" { @@ -359,7 +371,7 @@ resource "azurerm_key_vault" "test" { access_policy { tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + object_id = "${data.azurerm_client_config.current.object_id}" key_permissions = [ "create", @@ -426,6 +438,10 @@ resource "azurerm_snapshot" "test" { func testAccAzureRMSnapshot_extendingManagedDisk(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -433,8 +449,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "test" { name = "acctestmd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = "10" @@ -442,10 +458,10 @@ resource "azurerm_managed_disk" "test" { resource "azurerm_snapshot" "test" { name = "acctestss_%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name create_option = "Copy" - source_uri = "${azurerm_managed_disk.test.id}" + source_uri = azurerm_managed_disk.test.id disk_size_gb = "20" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) @@ -453,6 +469,10 @@ resource "azurerm_snapshot" "test" { func testAccAzureRMSnapshot_fromExistingSnapshot(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -460,8 +480,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_managed_disk" "original" { name = "acctestmd-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = "10" @@ -469,24 +489,28 @@ resource "azurerm_managed_disk" "original" { resource "azurerm_snapshot" "first" { name = "acctestss1_%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name create_option = "Copy" - source_uri = "${azurerm_managed_disk.original.id}" + source_uri = azurerm_managed_disk.original.id } resource "azurerm_snapshot" "second" { name = "acctestss2_%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name create_option = "Copy" - source_resource_id = "${azurerm_snapshot.first.id}" + source_resource_id = azurerm_snapshot.first.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMSnapshot_fromUnmanagedDisk(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -495,33 +519,33 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_network_interface" "test" { name = "acctestnic-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -532,16 +556,15 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } resource "azurerm_virtual_machine" "test" { name = "acctestvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.test.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.test.id] vm_size = "Standard_F2" delete_os_disk_on_termination = true @@ -576,11 +599,14 @@ resource "azurerm_virtual_machine" "test" { resource "azurerm_snapshot" "test" { name = "acctestss_%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name create_option = "Import" source_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" - depends_on = ["azurerm_virtual_machine", "test"] + depends_on = [ + azurerm_virtual_machine, + test, + ] } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_data_disk_attachment_test.go b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_data_disk_attachment_test.go index 68cd3b9999777..c58fdb10c1aba 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_data_disk_attachment_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_data_disk_attachment_test.go @@ -308,8 +308,8 @@ func testAccAzureRMVirtualMachineDataDiskAttachment_basic(data acceptance.TestDa %s resource "azurerm_virtual_machine_data_disk_attachment" "test" { - managed_disk_id = "${azurerm_managed_disk.test.id}" - virtual_machine_id = "${azurerm_virtual_machine.test.id}" + managed_disk_id = azurerm_managed_disk.test.id + virtual_machine_id = azurerm_virtual_machine.test.id lun = "0" caching = "None" } @@ -322,16 +322,20 @@ func testAccAzureRMVirtualMachineDataDiskAttachment_requiresImport(data acceptan %s resource "azurerm_virtual_machine_data_disk_attachment" "import" { - managed_disk_id = "${azurerm_virtual_machine_data_disk_attachment.test.managed_disk_id}" - virtual_machine_id = "${azurerm_virtual_machine_data_disk_attachment.test.virtual_machine_id}" - lun = "${azurerm_virtual_machine_data_disk_attachment.test.lun}" - caching = "${azurerm_virtual_machine_data_disk_attachment.test.caching}" + managed_disk_id = azurerm_virtual_machine_data_disk_attachment.test.managed_disk_id + virtual_machine_id = azurerm_virtual_machine_data_disk_attachment.test.virtual_machine_id + lun = azurerm_virtual_machine_data_disk_attachment.test.lun + caching = azurerm_virtual_machine_data_disk_attachment.test.caching } `, template) } func testAccAzureRMVirtualMachineDataDiskAttachment_managedServiceIdentity(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -340,34 +344,34 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.test.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.test.id] vm_size = "Standard_F2" storage_image_reference { @@ -401,16 +405,16 @@ resource "azurerm_virtual_machine" "test" { resource "azurerm_managed_disk" "test" { name = "%d-disk1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = 10 } resource "azurerm_virtual_machine_data_disk_attachment" "test" { - managed_disk_id = "${azurerm_managed_disk.test.id}" - virtual_machine_id = "${azurerm_virtual_machine.test.id}" + managed_disk_id = azurerm_managed_disk.test.id + virtual_machine_id = azurerm_virtual_machine.test.id lun = "0" caching = "None" } @@ -423,24 +427,24 @@ func testAccAzureRMVirtualMachineDataDiskAttachment_multipleDisks(data acceptanc %s resource "azurerm_virtual_machine_data_disk_attachment" "first" { - managed_disk_id = "${azurerm_managed_disk.test.id}" - virtual_machine_id = "${azurerm_virtual_machine.test.id}" + managed_disk_id = azurerm_managed_disk.test.id + virtual_machine_id = azurerm_virtual_machine.test.id lun = "10" caching = "None" } resource "azurerm_managed_disk" "second" { name = "%d-disk2" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = 10 } resource "azurerm_virtual_machine_data_disk_attachment" "second" { - managed_disk_id = "${azurerm_managed_disk.second.id}" - virtual_machine_id = "${azurerm_virtual_machine.test.id}" + managed_disk_id = azurerm_managed_disk.second.id + virtual_machine_id = azurerm_virtual_machine.test.id lun = "20" caching = "ReadOnly" } @@ -453,8 +457,8 @@ func testAccAzureRMVirtualMachineDataDiskAttachment_readOnly(data acceptance.Tes %s resource "azurerm_virtual_machine_data_disk_attachment" "test" { - managed_disk_id = "${azurerm_managed_disk.test.id}" - virtual_machine_id = "${azurerm_virtual_machine.test.id}" + managed_disk_id = azurerm_managed_disk.test.id + virtual_machine_id = azurerm_virtual_machine.test.id lun = "0" caching = "ReadOnly" } @@ -467,8 +471,8 @@ func testAccAzureRMVirtualMachineDataDiskAttachment_readWrite(data acceptance.Te %s resource "azurerm_virtual_machine_data_disk_attachment" "test" { - managed_disk_id = "${azurerm_managed_disk.test.id}" - virtual_machine_id = "${azurerm_virtual_machine.test.id}" + managed_disk_id = azurerm_managed_disk.test.id + virtual_machine_id = azurerm_virtual_machine.test.id lun = "0" caching = "ReadWrite" } @@ -477,6 +481,10 @@ resource "azurerm_virtual_machine_data_disk_attachment" "test" { func testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(data acceptance.TestData, enabled bool) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -485,34 +493,34 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.test.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.test.id] vm_size = "Standard_M64s" storage_image_reference { @@ -542,16 +550,16 @@ resource "azurerm_virtual_machine" "test" { resource "azurerm_managed_disk" "test" { name = "%d-disk1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Premium_LRS" create_option = "Empty" disk_size_gb = 10 } resource "azurerm_virtual_machine_data_disk_attachment" "test" { - managed_disk_id = "${azurerm_managed_disk.test.id}" - virtual_machine_id = "${azurerm_virtual_machine.test.id}" + managed_disk_id = azurerm_managed_disk.test.id + virtual_machine_id = azurerm_virtual_machine.test.id lun = "0" caching = "None" write_accelerator_enabled = %t @@ -561,6 +569,10 @@ resource "azurerm_virtual_machine_data_disk_attachment" "test" { func testAccAzureRMVirtualMachineDataDiskAttachment_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -569,34 +581,34 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_network_interface" "test" { name = "acctni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } resource "azurerm_virtual_machine" "test" { name = "acctvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.test.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.test.id] vm_size = "Standard_F2" storage_image_reference { @@ -626,8 +638,8 @@ resource "azurerm_virtual_machine" "test" { resource "azurerm_managed_disk" "test" { name = "%d-disk1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = 10 @@ -637,6 +649,10 @@ resource "azurerm_managed_disk" "test" { func testAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtensionPrep(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -744,16 +760,16 @@ func testAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtensionCompl resource "azurerm_managed_disk" "test" { name = "acctest%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = 10 } resource "azurerm_virtual_machine_data_disk_attachment" "test" { - managed_disk_id = "${azurerm_managed_disk.test.id}" - virtual_machine_id = "${azurerm_virtual_machine.test.id}" + managed_disk_id = azurerm_managed_disk.test.id + virtual_machine_id = azurerm_virtual_machine.test.id lun = "11" caching = "ReadWrite" } diff --git a/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_extension_test.go b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_extension_test.go index d409269fac98d..784cb33ec1f19 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_extension_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_extension_test.go @@ -11,6 +11,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" ) func TestAccAzureRMVirtualMachineExtension_basic(t *testing.T) { @@ -41,35 +42,6 @@ func TestAccAzureRMVirtualMachineExtension_basic(t *testing.T) { }) } -// TODO: Remove in 2.0 -func TestAccAzureRMVirtualMachineExtension_deprecated(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_virtual_machine_extension", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMVirtualMachineExtensionDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMVirtualMachineExtension_deprecated(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExtensionExists(data.ResourceName), - resource.TestMatchResourceAttr(data.ResourceName, "settings", regexp.MustCompile("hostname")), - ), - }, - data.ImportStep("protected_settings"), - { - Config: testAccAzureRMVirtualMachineExtension_deprecatedUpdate(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExtensionExists(data.ResourceName), - resource.TestMatchResourceAttr(data.ResourceName, "settings", regexp.MustCompile("whoami")), - ), - }, - data.ImportStep("protected_settings"), - }, - }) -} - func TestAccAzureRMVirtualMachineExtension_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -149,8 +121,12 @@ func testCheckAzureRMVirtualMachineExtensionExists(resourceName string) resource } name := rs.Primary.Attributes["name"] - vmName := rs.Primary.Attributes["virtual_machine_name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] + virtualMachineId, err := compute.ParseVirtualMachineID(rs.Primary.Attributes["virtual_machine_id"]) + if err != nil { + return fmt.Errorf("Error parsing Virtual Machine ID %q: %+v", virtualMachineId, err) + } + vmName := virtualMachineId.Name + resourceGroup := virtualMachineId.ResourceGroup resp, err := client.Get(ctx, resourceGroup, vmName, name, "") if err != nil { @@ -175,8 +151,12 @@ func testCheckAzureRMVirtualMachineExtensionDestroy(s *terraform.State) error { } name := rs.Primary.Attributes["name"] - vmName := rs.Primary.Attributes["virtual_machine_name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] + virtualMachineId, err := compute.ParseVirtualMachineID(rs.Primary.Attributes["virtual_machine_id"]) + if err != nil { + return fmt.Errorf("Error parsing Virtual Machine ID %q: %+v", virtualMachineId, err) + } + vmName := virtualMachineId.Name + resourceGroup := virtualMachineId.ResourceGroup resp, err := client.Get(ctx, resourceGroup, vmName, name, "") @@ -194,111 +174,10 @@ func testCheckAzureRMVirtualMachineExtensionDestroy(s *terraform.State) error { func testAccAzureRMVirtualMachineExtension_basic(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} - -resource "azurerm_network_interface" "test" { - name = "acctni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - } -} - -resource "azurerm_storage_account" "test" { - name = "accsa%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" - account_replication_type = "LRS" - - tags = { - environment = "staging" - } +provider "azurerm" { + features {} } -resource "azurerm_storage_container" "test" { - name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - container_access_type = "private" -} - -resource "azurerm_virtual_machine" "test" { - name = "acctvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_F2" - - storage_image_reference { - publisher = "Canonical" - offer = "UbuntuServer" - sku = "16.04-LTS" - version = "latest" - } - - storage_os_disk { - name = "myosdisk1" - vhd_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" - caching = "ReadWrite" - create_option = "FromImage" - } - - os_profile { - computer_name = "hostname%d" - admin_username = "testadmin" - admin_password = "Password1234!" - } - - os_profile_linux_config { - disable_password_authentication = false - } -} - -resource "azurerm_virtual_machine_extension" "test" { - name = "acctvme-%d" - virtual_machine_id = "${azurerm_virtual_machine.test.id}" - publisher = "Microsoft.Azure.Extensions" - type = "CustomScript" - type_handler_version = "2.0" - - settings = < 32767 { + errors = append(errors, fmt.Errorf( + "The `disk_size_gb` can only be between 0 and 32767")) + } + return warnings, errors +} + func validateDedicatedHostGroupName() func(i interface{}, k string) (warnings []string, errors []error) { return validation.StringMatch(regexp.MustCompile(`^[^_\W][\w-.]{0,78}[\w]$`), "") } diff --git a/azurerm/internal/services/compute/validation_test.go b/azurerm/internal/services/compute/validation_test.go index 0eb577a0b0f22..38990854633a8 100644 --- a/azurerm/internal/services/compute/validation_test.go +++ b/azurerm/internal/services/compute/validation_test.go @@ -149,7 +149,7 @@ func TestValidateDiskEncryptionSetName(t *testing.T) { expected: false, }, { - //basic example + // basic example input: "hello", expected: true, }, diff --git a/azurerm/internal/services/compute/windows_virtual_machine_resource.go b/azurerm/internal/services/compute/windows_virtual_machine_resource.go index 28324b4b26f12..2b2c8dd404b83 100644 --- a/azurerm/internal/services/compute/windows_virtual_machine_resource.go +++ b/azurerm/internal/services/compute/windows_virtual_machine_resource.go @@ -72,7 +72,7 @@ func resourceWindowsVirtualMachine() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, + ValidateFunc: validation.StringIsNotEmpty, }, "network_interface_ids": { @@ -90,7 +90,7 @@ func resourceWindowsVirtualMachine() *schema.Resource { "size": { Type: schema.TypeString, Required: true, - ValidateFunc: validate.NoEmptyStrings, + ValidateFunc: validation.StringIsNotEmpty, }, // Optional @@ -917,7 +917,7 @@ func resourceWindowsVirtualMachineUpdate(d *schema.ResourceData, meta interface{ func resourceWindowsVirtualMachineDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.VMClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() id, err := ParseVirtualMachineID(d.Id()) diff --git a/azurerm/internal/services/containers/data_source_kubernetes_cluster.go b/azurerm/internal/services/containers/data_source_kubernetes_cluster.go index f7d4902455875..32586415953dd 100644 --- a/azurerm/internal/services/containers/data_source_kubernetes_cluster.go +++ b/azurerm/internal/services/containers/data_source_kubernetes_cluster.go @@ -144,13 +144,6 @@ func dataSourceArmKubernetesCluster() *schema.Resource { }, }, - // TODO: remove this in a future version - "dns_prefix": { - Type: schema.TypeString, - Computed: true, - Deprecated: "This field is no longer returned from the Azure API", - }, - "vm_size": { Type: schema.TypeString, Computed: true, diff --git a/azurerm/internal/services/containers/kubernetes_nodepool.go b/azurerm/internal/services/containers/kubernetes_nodepool.go index eaa237fcd8b69..6fcc5d9838782 100644 --- a/azurerm/internal/services/containers/kubernetes_nodepool.go +++ b/azurerm/internal/services/containers/kubernetes_nodepool.go @@ -14,7 +14,7 @@ import ( func SchemaDefaultNodePool() *schema.Schema { return &schema.Schema{ Type: schema.TypeList, - Optional: true, + Required: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -142,11 +142,6 @@ func ConvertDefaultNodePoolToAgentPool(input *[]containerservice.ManagedClusterA func ExpandDefaultNodePool(d *schema.ResourceData) (*[]containerservice.ManagedClusterAgentPoolProfile, error) { input := d.Get("default_node_pool").([]interface{}) - // TODO: in 2.0 make this Required - // this exists to allow users to migrate to default_node_pool - if len(input) == 0 { - return nil, nil - } raw := input[0].(map[string]interface{}) enableAutoScaling := raw["enable_auto_scaling"].(bool) @@ -166,7 +161,7 @@ func ExpandDefaultNodePool(d *schema.ResourceData) (*[]containerservice.ManagedC // Windows agents can be configured via the separate node pool resource OsType: containerservice.Linux, - //// TODO: support these in time + // // TODO: support these in time // OrchestratorVersion: nil, // ScaleSetEvictionPolicy: "", // ScaleSetPriority: "", diff --git a/azurerm/internal/services/containers/registration.go b/azurerm/internal/services/containers/registration.go index b25375d4616fd..edb8f6fe732b3 100644 --- a/azurerm/internal/services/containers/registration.go +++ b/azurerm/internal/services/containers/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Container Services" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Container", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/containers/resource_arm_container_group.go b/azurerm/internal/services/containers/resource_arm_container_group.go index 2d376e60d2908..76b64aa84429b 100644 --- a/azurerm/internal/services/containers/resource_arm_container_group.go +++ b/azurerm/internal/services/containers/resource_arm_container_group.go @@ -239,33 +239,10 @@ func resourceArmContainerGroup() *schema.Resource { }, }, - "port": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Computed: true, - Deprecated: "Deprecated in favor of `ports`", - ValidateFunc: validate.PortNumber, - }, - - "protocol": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - Deprecated: "Deprecated in favor of `ports`", - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(containerinstance.TCP), - string(containerinstance.UDP), - }, true), - }, - "ports": { Type: schema.TypeSet, Optional: true, ForceNew: true, - Computed: true, Set: resourceArmContainerGroupPortsHash, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -273,7 +250,6 @@ func resourceArmContainerGroup() *schema.Resource { Type: schema.TypeInt, Optional: true, ForceNew: true, - Computed: true, ValidateFunc: validate.PortNumber, }, @@ -281,8 +257,7 @@ func resourceArmContainerGroup() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, - Computed: true, - //Default: string(containerinstance.TCP), restore in 2.0 + Default: string(containerinstance.TCP), ValidateFunc: validation.StringInSlice([]string{ string(containerinstance.TCP), string(containerinstance.UDP), @@ -311,14 +286,6 @@ func resourceArmContainerGroup() *schema.Resource { }, }, - "command": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - Deprecated: "Use `commands` instead.", - }, - "commands": { Type: schema.TypeList, Optional: true, @@ -782,26 +749,6 @@ func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstanc }) } container.Ports = &ports - } else { - if v := int32(data["port"].(int)); v != 0 { - ports := []containerinstance.ContainerPort{ - { - Port: &v, - }, - } - - port := containerinstance.Port{ - Port: &v, - } - - if v, ok := data["protocol"].(string); ok { - ports[0].Protocol = containerinstance.ContainerNetworkProtocol(v) - port.Protocol = containerinstance.ContainerGroupNetworkProtocol(v) - } - - container.Ports = &ports - containerGroupPorts = append(containerGroupPorts, port) - } } // Set both sensitive and non-secure environment variables @@ -834,13 +781,6 @@ func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstanc container.Command = &command } - if container.Command == nil { - if v := data["command"]; v != "" { - command := strings.Split(v.(string), " ") - container.Command = &command - } - } - if v, ok := data["volume"]; ok { volumeMounts, containerGroupVolumesPartial := expandContainerVolumes(v) container.VolumeMounts = volumeMounts @@ -1100,7 +1040,7 @@ func flattenContainerImageRegistryCredentials(d *schema.ResourceData, input *[]c } func flattenContainerGroupContainers(d *schema.ResourceData, containers *[]containerinstance.Container, ipAddress *containerinstance.IPAddress, containerGroupVolumes *[]containerinstance.Volume) []interface{} { - //map old container names to index so we can look up things up + // map old container names to index so we can look up things up nameIndexMap := map[string]int{} for i, c := range d.Get("container").([]interface{}) { cfg := c.(map[string]interface{}) @@ -1109,10 +1049,10 @@ func flattenContainerGroupContainers(d *schema.ResourceData, containers *[]conta containerCfg := make([]interface{}, 0, len(*containers)) for _, container := range *containers { - //TODO fix this crash point + // TODO fix this crash point name := *container.Name - //get index from name + // get index from name index := nameIndexMap[name] containerConfig := make(map[string]interface{}) @@ -1155,24 +1095,6 @@ func flattenContainerGroupContainers(d *schema.ResourceData, containers *[]conta ports = append(ports, port) } containerConfig["ports"] = schema.NewSet(resourceArmContainerGroupPortsHash, ports) - - //old deprecated code - containerPort := *(*cPorts)[0].Port - containerConfig["port"] = containerPort - // protocol isn't returned in container config, have to search in container group ports - protocol := "" - if ipAddress != nil { - if containerGroupPorts := ipAddress.Ports; containerGroupPorts != nil { - for _, cgPort := range *containerGroupPorts { - if *cgPort.Port == containerPort { - protocol = string(cgPort.Protocol) - } - } - } - } - if protocol != "" { - containerConfig["protocol"] = protocol - } } if container.EnvironmentVariables != nil { @@ -1189,7 +1111,6 @@ func flattenContainerGroupContainers(d *schema.ResourceData, containers *[]conta commands := make([]string, 0) if command := container.Command; command != nil { - containerConfig["command"] = strings.Join(*command, " ") commands = *command } containerConfig["commands"] = commands diff --git a/azurerm/internal/services/containers/resource_arm_container_registry.go b/azurerm/internal/services/containers/resource_arm_container_registry.go index 80500c2222976..3addd1c8b9100 100644 --- a/azurerm/internal/services/containers/resource_arm_container_registry.go +++ b/azurerm/internal/services/containers/resource_arm_container_registry.go @@ -88,27 +88,6 @@ func resourceArmContainerRegistry() *schema.Resource { Optional: true, }, - "storage_account": { - Type: schema.TypeList, - Optional: true, - Deprecated: "`storage_account` has been replaced by `storage_account_id`.", - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - }, - - "access_key": { - Type: schema.TypeString, - Required: true, - Sensitive: true, - }, - }, - }, - }, - "login_server": { Type: schema.TypeString, Computed: true, @@ -663,7 +642,7 @@ func flattenNetworkRuleSet(networkRuleSet *containerregistry.NetworkRuleSet) []i value := make(map[string]interface{}) value["action"] = string(ipRule.Action) - //When a /32 CIDR is passed as an ip rule, Azure will drop the /32 leading to the resource wanting to be re-created next run + // When a /32 CIDR is passed as an ip rule, Azure will drop the /32 leading to the resource wanting to be re-created next run if !strings.Contains(*ipRule.IPAddressOrRange, "/") { *ipRule.IPAddressOrRange += "/32" } diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go index 0d892bfa7d6b1..32a65ec4e6f7e 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go @@ -110,133 +110,6 @@ func resourceArmKubernetesCluster() *schema.Resource { "default_node_pool": SchemaDefaultNodePool(), - // TODO: remove in 2.0 - "agent_pool_profile": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Deprecated: "This has been replaced by `default_node_pool` and will be removed in version 2.0 of the AzureRM Provider", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.KubernetesAgentPoolName, - }, - - "type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: string(containerservice.AvailabilitySet), - ValidateFunc: validation.StringInSlice([]string{ - string(containerservice.AvailabilitySet), - string(containerservice.VirtualMachineScaleSets), - }, false), - }, - - "count": { - Type: schema.TypeInt, - Optional: true, - Default: 1, - ValidateFunc: validation.IntBetween(1, 100), - }, - - "max_count": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(1, 100), - }, - - "min_count": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(1, 100), - }, - - "enable_auto_scaling": { - Type: schema.TypeBool, - Optional: true, - }, - - "availability_zones": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - - // TODO: remove this field in the next major version - "dns_prefix": { - Type: schema.TypeString, - Computed: true, - Deprecated: "This field has been removed by Azure", - }, - - "fqdn": { - Type: schema.TypeString, - Computed: true, - Deprecated: "This field has been deprecated. Use the parent `fqdn` instead", - }, - - "vm_size": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringIsNotEmpty, - }, - - "os_disk_size_gb": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Computed: true, - ValidateFunc: validation.IntAtLeast(1), - }, - - "vnet_subnet_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - }, - - "os_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: string(containerservice.Linux), - ValidateFunc: validation.StringInSlice([]string{ - string(containerservice.Linux), - string(containerservice.Windows), - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, - - "max_pods": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - ForceNew: true, - }, - - "node_taints": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - - "enable_node_public_ip": { - Type: schema.TypeBool, - Optional: true, - }, - }, - }, - }, - "service_principal": { Type: schema.TypeList, Required: true, @@ -276,11 +149,9 @@ func resourceArmKubernetesCluster() *schema.Resource { Computed: true, }, - // TODO: remove Computed in 2.0 "enable_pod_security_policy": { Type: schema.TypeBool, Optional: true, - Computed: true, }, "identity": { @@ -682,17 +553,6 @@ func resourceArmKubernetesClusterCreate(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error expanding `default_node_pool`: %+v", err) } - // TODO: remove me in 2.0 - if agentProfiles == nil { - agentProfilesRaw := d.Get("agent_pool_profile").([]interface{}) - agentProfilesLegacy, err := expandKubernetesClusterAgentPoolProfiles(agentProfilesRaw, true) - if err != nil { - return err - } - - agentProfiles = &agentProfilesLegacy - } - addOnProfilesRaw := d.Get("addon_profile").([]interface{}) addonProfiles := ExpandKubernetesAddOnProfiles(addOnProfilesRaw) @@ -793,13 +653,10 @@ func resourceArmKubernetesClusterUpdate(d *schema.ResourceData, meta interface{} return err } - resourceGroup := id.ResourceGroup - name := id.Name - d.Partial(true) if d.HasChange("service_principal") { - log.Printf("[DEBUG] Updating the Service Principal for Kubernetes Cluster %q (Resource Group %q)..", name, resourceGroup) + log.Printf("[DEBUG] Updating the Service Principal for Kubernetes Cluster %q (Resource Group %q)..", id.Name, id.ResourceGroup) servicePrincipals := d.Get("service_principal").([]interface{}) servicePrincipalRaw := servicePrincipals[0].(map[string]interface{}) @@ -810,24 +667,24 @@ func resourceArmKubernetesClusterUpdate(d *schema.ResourceData, meta interface{} ClientID: utils.String(clientId), Secret: utils.String(clientSecret), } - future, err := clusterClient.ResetServicePrincipalProfile(ctx, resourceGroup, name, params) + future, err := clusterClient.ResetServicePrincipalProfile(ctx, id.ResourceGroup, id.Name, params) if err != nil { - return fmt.Errorf("Error updating Service Principal for Kubernetes Cluster %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error updating Service Principal for Kubernetes Cluster %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } if err = future.WaitForCompletionRef(ctx, clusterClient.Client); err != nil { - return fmt.Errorf("Error waiting for update of Service Principal for Kubernetes Cluster %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error waiting for update of Service Principal for Kubernetes Cluster %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } - log.Printf("[DEBUG] Updated the Service Principal for Kubernetes Cluster %q (Resource Group %q).", name, resourceGroup) + log.Printf("[DEBUG] Updated the Service Principal for Kubernetes Cluster %q (Resource Group %q).", id.Name, id.ResourceGroup) } // we need to conditionally update the cluster - existing, err := clusterClient.Get(ctx, resourceGroup, name) + existing, err := clusterClient.Get(ctx, id.ResourceGroup, id.Name) if err != nil { - return fmt.Errorf("Error retrieving existing Kubernetes Cluster %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error retrieving existing Kubernetes Cluster %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } if existing.ManagedClusterProperties == nil { - return fmt.Errorf("Error retrieving existing Kubernetes Cluster %q (Resource Group %q): `properties` was nil", name, resourceGroup) + return fmt.Errorf("Error retrieving existing Kubernetes Cluster %q (Resource Group %q): `properties` was nil", id.Name, id.ResourceGroup) } // since there's multiple reasons why we could be called into Update, we use this to only update if something's changed that's not SP/Version @@ -848,13 +705,13 @@ func resourceArmKubernetesClusterUpdate(d *schema.ResourceData, meta interface{} props.EnableRBAC = utils.Bool(rbacEnabled) log.Printf("[DEBUG] Updating the RBAC AAD profile") - future, err := clusterClient.ResetAADProfile(ctx, resourceGroup, name, *props.AadProfile) + future, err := clusterClient.ResetAADProfile(ctx, id.ResourceGroup, id.Name, *props.AadProfile) if err != nil { - return fmt.Errorf("Error updating Managed Kubernetes Cluster AAD Profile in cluster %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error updating Managed Kubernetes Cluster AAD Profile in cluster %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } if err = future.WaitForCompletionRef(ctx, clusterClient.Client); err != nil { - return fmt.Errorf("Error waiting for update of RBAC AAD profile of Managed Cluster %q (Resource Group %q):, %+v", name, resourceGroup, err) + return fmt.Errorf("Error waiting for update of RBAC AAD profile of Managed Cluster %q (Resource Group %q):, %+v", id.Name, id.ResourceGroup, err) } } else { updateCluster = true @@ -922,20 +779,20 @@ func resourceArmKubernetesClusterUpdate(d *schema.ResourceData, meta interface{} } if updateCluster { - log.Printf("[DEBUG] Updating the Kubernetes Cluster %q (Resource Group %q)..", name, resourceGroup) - future, err := clusterClient.CreateOrUpdate(ctx, resourceGroup, name, existing) + log.Printf("[DEBUG] Updating the Kubernetes Cluster %q (Resource Group %q)..", id.Name, id.ResourceGroup) + future, err := clusterClient.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, existing) if err != nil { - return fmt.Errorf("Error updating Managed Kubernetes Cluster %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error updating Managed Kubernetes Cluster %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } if err = future.WaitForCompletionRef(ctx, clusterClient.Client); err != nil { - return fmt.Errorf("Error waiting for update of Managed Kubernetes Cluster %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error waiting for update of Managed Kubernetes Cluster %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } - log.Printf("[DEBUG] Updated the Kubernetes Cluster %q (Resource Group %q)..", name, resourceGroup) + log.Printf("[DEBUG] Updated the Kubernetes Cluster %q (Resource Group %q)..", id.Name, id.ResourceGroup) } // update the node pool using the separate API - if d.HasChange("default_node_pool") || d.HasChange("agent_pool_profile") { + if d.HasChange("default_node_pool") { log.Printf("[DEBUG] Updating of Default Node Pool..") agentProfiles, err := ExpandDefaultNodePool(d) @@ -943,50 +800,39 @@ func resourceArmKubernetesClusterUpdate(d *schema.ResourceData, meta interface{} return fmt.Errorf("Error expanding `default_node_pool`: %+v", err) } - // TODO: remove me in 2.0 - if agentProfiles == nil { - agentProfilesRaw := d.Get("agent_pool_profile").([]interface{}) - agentProfilesLegacy, err := expandKubernetesClusterAgentPoolProfiles(agentProfilesRaw, false) - if err != nil { - return err - } - - agentProfiles = &agentProfilesLegacy - } - agentProfile := ConvertDefaultNodePoolToAgentPool(agentProfiles) - agentPool, err := nodePoolsClient.CreateOrUpdate(ctx, resourceGroup, name, *agentProfile.Name, agentProfile) + agentPool, err := nodePoolsClient.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, *agentProfile.Name, agentProfile) if err != nil { - return fmt.Errorf("Error updating Default Node Pool %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error updating Default Node Pool %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } if err := agentPool.WaitForCompletionRef(ctx, nodePoolsClient.Client); err != nil { - return fmt.Errorf("Error waiting for update of Default Node Pool %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error waiting for update of Default Node Pool %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } log.Printf("[DEBUG] Updated Default Node Pool.") } // then roll the version of Kubernetes if necessary if d.HasChange("kubernetes_version") { - existing, err = clusterClient.Get(ctx, resourceGroup, name) + existing, err = clusterClient.Get(ctx, id.ResourceGroup, id.Name) if err != nil { - return fmt.Errorf("Error retrieving existing Kubernetes Cluster %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error retrieving existing Kubernetes Cluster %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } if existing.ManagedClusterProperties == nil { - return fmt.Errorf("Error retrieving existing Kubernetes Cluster %q (Resource Group %q): `properties` was nil", name, resourceGroup) + return fmt.Errorf("Error retrieving existing Kubernetes Cluster %q (Resource Group %q): `properties` was nil", id.Name, id.ResourceGroup) } kubernetesVersion := d.Get("kubernetes_version").(string) log.Printf("[DEBUG] Upgrading the version of Kubernetes to %q..", kubernetesVersion) existing.ManagedClusterProperties.KubernetesVersion = utils.String(kubernetesVersion) - future, err := clusterClient.CreateOrUpdate(ctx, resourceGroup, name, existing) + future, err := clusterClient.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, existing) if err != nil { - return fmt.Errorf("Error updating Managed Kubernetes Cluster %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error updating Managed Kubernetes Cluster %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } if err = future.WaitForCompletionRef(ctx, clusterClient.Client); err != nil { - return fmt.Errorf("Error waiting for update of Managed Kubernetes Cluster %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error waiting for update of Managed Kubernetes Cluster %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } log.Printf("[DEBUG] Upgraded the version of Kubernetes to %q..", kubernetesVersion) @@ -1052,12 +898,6 @@ func resourceArmKubernetesClusterRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting `addon_profile`: %+v", err) } - // TODO: remove me in 2.0 - agentPoolProfiles := flattenKubernetesClusterAgentPoolProfiles(props.AgentPoolProfiles, resp.Fqdn) - if err := d.Set("agent_pool_profile", agentPoolProfiles); err != nil { - return fmt.Errorf("Error setting `agent_pool_profile`: %+v", err) - } - flattenedDefaultNodePool, err := FlattenDefaultNodePool(props.AgentPoolProfiles, d) if err != nil { return fmt.Errorf("Error flattening `default_node_pool`: %+v", err) @@ -1172,162 +1012,6 @@ func flattenKubernetesClusterAccessProfile(profile containerservice.ManagedClust return nil, []interface{}{} } -func expandKubernetesClusterAgentPoolProfiles(input []interface{}, isNewResource bool) ([]containerservice.ManagedClusterAgentPoolProfile, error) { - profiles := make([]containerservice.ManagedClusterAgentPoolProfile, 0) - - for _, v := range input { - config := v.(map[string]interface{}) - - name := config["name"].(string) - poolType := config["type"].(string) - count := int32(config["count"].(int)) - vmSize := config["vm_size"].(string) - osDiskSizeGB := int32(config["os_disk_size_gb"].(int)) - osType := config["os_type"].(string) - - profile := containerservice.ManagedClusterAgentPoolProfile{ - Name: utils.String(name), - Type: containerservice.AgentPoolType(poolType), - Count: utils.Int32(count), - VMSize: containerservice.VMSizeTypes(vmSize), - OsDiskSizeGB: utils.Int32(osDiskSizeGB), - OsType: containerservice.OSType(osType), - } - - if maxPods := int32(config["max_pods"].(int)); maxPods > 0 { - profile.MaxPods = utils.Int32(maxPods) - } - - vnetSubnetID := config["vnet_subnet_id"].(string) - if vnetSubnetID != "" { - profile.VnetSubnetID = utils.String(vnetSubnetID) - } - - if maxCount := int32(config["max_count"].(int)); maxCount > 0 { - profile.MaxCount = utils.Int32(maxCount) - } - - if minCount := int32(config["min_count"].(int)); minCount > 0 { - profile.MinCount = utils.Int32(minCount) - } - - if enableAutoScalingItf := config["enable_auto_scaling"]; enableAutoScalingItf != nil { - profile.EnableAutoScaling = utils.Bool(enableAutoScalingItf.(bool)) - - // Auto scaling will change the number of nodes, but the original count number should not be sent again. - // This avoid the cluster being resized after creation. - if *profile.EnableAutoScaling && !isNewResource { - profile.Count = nil - } - } - - if availabilityZones := utils.ExpandStringSlice(config["availability_zones"].([]interface{})); len(*availabilityZones) > 0 { - profile.AvailabilityZones = availabilityZones - } - - if *profile.EnableAutoScaling && (profile.MinCount == nil || profile.MaxCount == nil) { - return nil, fmt.Errorf("Can't create an AKS cluster with autoscaling enabled but not setting min_count or max_count") - } - - if nodeTaints := utils.ExpandStringSlice(config["node_taints"].([]interface{})); len(*nodeTaints) > 0 { - profile.NodeTaints = nodeTaints - } - - if enableNodePublicIP := config["enable_node_public_ip"]; enableNodePublicIP != nil { - profile.EnableNodePublicIP = utils.Bool(enableNodePublicIP.(bool)) - } - - profiles = append(profiles, profile) - } - - return profiles, nil -} - -func flattenKubernetesClusterAgentPoolProfiles(profiles *[]containerservice.ManagedClusterAgentPoolProfile, fqdn *string) []interface{} { - if profiles == nil { - return []interface{}{} - } - - agentPoolProfiles := make([]interface{}, 0) - - for _, profile := range *profiles { - count := 0 - if profile.Count != nil { - count = int(*profile.Count) - } - - enableAutoScaling := false - if profile.EnableAutoScaling != nil { - enableAutoScaling = *profile.EnableAutoScaling - } - - fqdnVal := "" - if fqdn != nil { - // temporarily persist the parent FQDN here until `fqdn` is removed from the `agent_pool_profile` - fqdnVal = *fqdn - } - - maxCount := 0 - if profile.MaxCount != nil { - maxCount = int(*profile.MaxCount) - } - - maxPods := 0 - if profile.MaxPods != nil { - maxPods = int(*profile.MaxPods) - } - - minCount := 0 - if profile.MinCount != nil { - minCount = int(*profile.MinCount) - } - - name := "" - if profile.Name != nil { - name = *profile.Name - } - - osDiskSizeGB := 0 - if profile.OsDiskSizeGB != nil { - osDiskSizeGB = int(*profile.OsDiskSizeGB) - } - - subnetId := "" - if profile.VnetSubnetID != nil { - subnetId = *profile.VnetSubnetID - } - - enableNodePublicIP := false - if profile.EnableNodePublicIP != nil { - enableNodePublicIP = *profile.EnableNodePublicIP - } - - agentPoolProfile := map[string]interface{}{ - "availability_zones": utils.FlattenStringSlice(profile.AvailabilityZones), - "count": count, - "enable_auto_scaling": enableAutoScaling, - "enable_node_public_ip": enableNodePublicIP, - "max_count": maxCount, - "max_pods": maxPods, - "min_count": minCount, - "name": name, - "node_taints": utils.FlattenStringSlice(profile.NodeTaints), - "os_disk_size_gb": osDiskSizeGB, - "os_type": string(profile.OsType), - "type": string(profile.Type), - "vm_size": string(profile.VMSize), - "vnet_subnet_id": subnetId, - - // TODO: remove in 2.0 - "fqdn": fqdnVal, - } - - agentPoolProfiles = append(agentPoolProfiles, agentPoolProfile) - } - - return agentPoolProfiles -} - func expandKubernetesClusterLinuxProfile(input []interface{}) *containerservice.LinuxProfile { if len(input) == 0 { return nil diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool.go index 805c9abb3c41b..a6b40c397f1c9 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool.go @@ -291,23 +291,20 @@ func resourceArmKubernetesClusterNodePoolUpdate(d *schema.ResourceData, meta int if err != nil { return err } - resourceGroup := id.ResourceGroup - clusterName := id.ClusterName - name := id.Name d.Partial(true) - log.Printf("[DEBUG] Retrieving existing Node Pool %q (Kubernetes Cluster %q / Resource Group %q)..", name, clusterName, resourceGroup) - existing, err := client.Get(ctx, resourceGroup, clusterName, name) + log.Printf("[DEBUG] Retrieving existing Node Pool %q (Kubernetes Cluster %q / Resource Group %q)..", id.Name, id.ClusterName, id.ResourceGroup) + existing, err := client.Get(ctx, id.ResourceGroup, id.ClusterName, id.Name) if err != nil { if utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("[DEBUG] Node Pool %q was not found in Managed Kubernetes Cluster %q / Resource Group %q!", name, clusterName, resourceGroup) + return fmt.Errorf("[DEBUG] Node Pool %q was not found in Managed Kubernetes Cluster %q / Resource Group %q!", id.Name, id.ClusterName, id.ResourceGroup) } - return fmt.Errorf("Error retrieving Node Pool %q (Managed Kubernetes Cluster %q / Resource Group %q): %+v", name, clusterName, resourceGroup, err) + return fmt.Errorf("Error retrieving Node Pool %q (Managed Kubernetes Cluster %q / Resource Group %q): %+v", id.Name, id.ClusterName, id.ResourceGroup, err) } if existing.ManagedClusterAgentPoolProfileProperties == nil { - return fmt.Errorf("Error retrieving Node Pool %q (Managed Kubernetes Cluster %q / Resource Group %q): `properties` was nil", name, clusterName, resourceGroup) + return fmt.Errorf("Error retrieving Node Pool %q (Managed Kubernetes Cluster %q / Resource Group %q): `properties` was nil", id.Name, id.ClusterName, id.ResourceGroup) } props := existing.ManagedClusterAgentPoolProfileProperties @@ -318,7 +315,7 @@ func resourceArmKubernetesClusterNodePoolUpdate(d *schema.ResourceData, meta int enableAutoScaling = *props.EnableAutoScaling } - log.Printf("[DEBUG] Determining delta for existing Node Pool %q (Kubernetes Cluster %q / Resource Group %q)..", name, clusterName, resourceGroup) + log.Printf("[DEBUG] Determining delta for existing Node Pool %q (Kubernetes Cluster %q / Resource Group %q)..", id.Name, id.ClusterName, id.ResourceGroup) // delta patching if d.HasChange("availability_zones") { @@ -378,15 +375,15 @@ func resourceArmKubernetesClusterNodePoolUpdate(d *schema.ResourceData, meta int return fmt.Errorf("`max_count` and `min_count` must be set to `0` when enable_auto_scaling is set to `false`") } - log.Printf("[DEBUG] Updating existing Node Pool %q (Kubernetes Cluster %q / Resource Group %q)..", name, clusterName, resourceGroup) + log.Printf("[DEBUG] Updating existing Node Pool %q (Kubernetes Cluster %q / Resource Group %q)..", id.Name, id.ClusterName, id.ResourceGroup) existing.ManagedClusterAgentPoolProfileProperties = props - future, err := client.CreateOrUpdate(ctx, resourceGroup, clusterName, name, existing) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.ClusterName, id.Name, existing) if err != nil { - return fmt.Errorf("Error updating Node Pool %q (Kubernetes Cluster %q / Resource Group %q): %+v", name, clusterName, resourceGroup, err) + return fmt.Errorf("Error updating Node Pool %q (Kubernetes Cluster %q / Resource Group %q): %+v", id.Name, id.ClusterName, id.ResourceGroup, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for update of Node Pool %q (Kubernetes Cluster %q / Resource Group %q): %+v", name, clusterName, resourceGroup, err) + return fmt.Errorf("Error waiting for update of Node Pool %q (Kubernetes Cluster %q / Resource Group %q): %+v", id.Name, id.ClusterName, id.ResourceGroup, err) } d.Partial(false) @@ -404,34 +401,31 @@ func resourceArmKubernetesClusterNodePoolRead(d *schema.ResourceData, meta inter if err != nil { return err } - resourceGroup := id.ResourceGroup - clusterName := id.ClusterName - name := id.Name // if the parent cluster doesn't exist then the node pool won't - cluster, err := clustersClient.Get(ctx, resourceGroup, clusterName) + cluster, err := clustersClient.Get(ctx, id.ResourceGroup, id.ClusterName) if err != nil { if utils.ResponseWasNotFound(cluster.Response) { - log.Printf("[DEBUG] Managed Kubernetes Cluster %q was not found in Resource Group %q - removing from state!", clusterName, resourceGroup) + log.Printf("[DEBUG] Managed Kubernetes Cluster %q was not found in Resource Group %q - removing from state!", id.ClusterName, id.ResourceGroup) d.SetId("") return nil } - return fmt.Errorf("Error retrieving Managed Kubernetes Cluster %q (Resource Group %q): %+v", clusterName, resourceGroup, err) + return fmt.Errorf("Error retrieving Managed Kubernetes Cluster %q (Resource Group %q): %+v", id.ClusterName, id.ResourceGroup, err) } - resp, err := poolsClient.Get(ctx, resourceGroup, clusterName, name) + resp, err := poolsClient.Get(ctx, id.ResourceGroup, id.ClusterName, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[DEBUG] Node Pool %q was not found in Managed Kubernetes Cluster %q / Resource Group %q - removing from state!", name, clusterName, resourceGroup) + log.Printf("[DEBUG] Node Pool %q was not found in Managed Kubernetes Cluster %q / Resource Group %q - removing from state!", id.Name, id.ClusterName, id.ResourceGroup) d.SetId("") return nil } - return fmt.Errorf("Error retrieving Node Pool %q (Managed Kubernetes Cluster %q / Resource Group %q): %+v", name, clusterName, resourceGroup, err) + return fmt.Errorf("Error retrieving Node Pool %q (Managed Kubernetes Cluster %q / Resource Group %q): %+v", id.Name, id.ClusterName, id.ResourceGroup, err) } - d.Set("name", name) + d.Set("name", id.Name) d.Set("kubernetes_cluster_id", cluster.ID) if props := resp.ManagedClusterAgentPoolProfileProperties; props != nil { diff --git a/azurerm/internal/services/containers/tests/data_source_container_registry_test.go b/azurerm/internal/services/containers/tests/data_source_container_registry_test.go index e109f2b05aa93..8edc95c78e4dd 100644 --- a/azurerm/internal/services/containers/tests/data_source_container_registry_test.go +++ b/azurerm/internal/services/containers/tests/data_source_container_registry_test.go @@ -35,8 +35,8 @@ func testAccDataSourceAzureRMContainerRegistry_basic(data acceptance.TestData) s %s data "azurerm_container_registry" "test" { - name = "${azurerm_container_registry.test.name}" - resource_group_name = "${azurerm_container_registry.test.resource_group_name}" + name = azurerm_container_registry.test.name + resource_group_name = azurerm_container_registry.test.resource_group_name } `, testAccAzureRMContainerRegistry_basicManaged(data, "Basic")) } diff --git a/azurerm/internal/services/containers/tests/data_source_kubernetes_cluster_test.go b/azurerm/internal/services/containers/tests/data_source_kubernetes_cluster_test.go index 1a4dc9810faf7..f0731084286f9 100644 --- a/azurerm/internal/services/containers/tests/data_source_kubernetes_cluster_test.go +++ b/azurerm/internal/services/containers/tests/data_source_kubernetes_cluster_test.go @@ -654,8 +654,8 @@ func testAccDataSourceAzureRMKubernetesCluster_basicConfig(data acceptance.TestD %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -666,8 +666,8 @@ func testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControlConfig(data %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, resource) } @@ -678,8 +678,8 @@ func testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(d %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, resource) } @@ -690,8 +690,8 @@ func testAccDataSourceAzureRMKubernetesCluster_internalNetworkConfig(data accept %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -702,8 +702,8 @@ func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureConfig(dat %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -714,8 +714,8 @@ func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPoli %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -726,8 +726,8 @@ func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyC %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -738,8 +738,8 @@ func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCompleteCo %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -750,8 +750,8 @@ func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPoli %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -762,8 +762,8 @@ func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyC %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -774,8 +774,8 @@ func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetConfig(d %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -786,8 +786,8 @@ func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetComplete %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -798,8 +798,8 @@ func testAccDataSourceAzureRMKubernetesCluster_addOnProfileOMSConfig(data accept %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -810,8 +810,8 @@ func testAccDataSourceAzureRMKubernetesCluster_addOnProfileKubeDashboardConfig(d %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -822,8 +822,8 @@ func testAccDataSourceAzureRMKubernetesCluster_addOnProfileAzurePolicyConfig(dat %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -834,8 +834,8 @@ func testAccDataSourceAzureRMKubernetesCluster_addOnProfileRoutingConfig(data ac %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -846,8 +846,8 @@ func testAccDataSourceAzureRMKubernetesCluster_autoScalingNoAvailabilityZonesCon %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -858,8 +858,8 @@ func testAccDataSourceAzureRMKubernetesCluster_autoScalingWithAvailabilityZonesC %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -870,8 +870,8 @@ func testAccDataSourceAzureRMKubernetesCluster_nodeTaintsConfig(data acceptance. %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } @@ -882,8 +882,8 @@ func testAccDataSourceAzureRMKubernetesCluster_enableNodePublicIPConfig(data acc %s data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" + name = azurerm_kubernetes_cluster.test.name + resource_group_name = azurerm_kubernetes_cluster.test.resource_group_name } `, r) } diff --git a/azurerm/internal/services/containers/tests/data_source_kubernetes_service_version_test.go b/azurerm/internal/services/containers/tests/data_source_kubernetes_service_version_test.go index 6ea37245bacc3..39cba73f787f3 100644 --- a/azurerm/internal/services/containers/tests/data_source_kubernetes_service_version_test.go +++ b/azurerm/internal/services/containers/tests/data_source_kubernetes_service_version_test.go @@ -76,6 +76,10 @@ func TestAccDataSourceAzureRMKubernetesServiceVersions_nopreview(t *testing.T) { func testAccDataSourceAzureRMKubernetesServiceVersions_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_kubernetes_service_versions" "test" { location = "%s" } @@ -84,6 +88,10 @@ data "azurerm_kubernetes_service_versions" "test" { func testAccDataSourceAzureRMKubernetesServiceVersions_filtered(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_kubernetes_service_versions" "test" { location = "%s" version_prefix = "1." @@ -93,6 +101,10 @@ data "azurerm_kubernetes_service_versions" "test" { func testAccDataSourceAzureRMKubernetesServiceVersions_nopreview(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_kubernetes_service_versions" "test" { location = "%s" include_preview = false diff --git a/azurerm/internal/services/containers/tests/resource_arm_container_group_test.go b/azurerm/internal/services/containers/tests/resource_arm_container_group_test.go index 8eb29403cb457..b39ee91dc88ff 100644 --- a/azurerm/internal/services/containers/tests/resource_arm_container_group_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_container_group_test.go @@ -128,7 +128,7 @@ func TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.1.server", "mine.acr.io"), resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.1.username", "acrusername"), resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.1.password", "acrpassword"), - resource.TestCheckResourceAttr(data.ResourceName, "container.0.port", "5443"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.ports.#", "1"), resource.TestCheckResourceAttr(data.ResourceName, "container.0.protocol", "UDP"), ), }, @@ -185,7 +185,7 @@ func TestAccAzureRMContainerGroup_linuxBasic(t *testing.T) { testCheckAzureRMContainerGroupExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "container.#", "1"), resource.TestCheckResourceAttr(data.ResourceName, "os_type", "Linux"), - resource.TestCheckResourceAttr(data.ResourceName, "container.0.port", "80"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.ports.#", "1"), ), }, data.ImportStep( @@ -264,7 +264,6 @@ func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) { testCheckAzureRMContainerGroupExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "container.#", "1"), resource.TestCheckResourceAttr(data.ResourceName, "container.0.ports.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "container.0.command", "/bin/bash -c ls"), resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.#", "3"), resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.0", "/bin/bash"), resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.1", "-c"), @@ -338,7 +337,7 @@ func TestAccAzureRMContainerGroup_virtualNetwork(t *testing.T) { resource.TestCheckNoResourceAttr(data.ResourceName, "identity"), resource.TestCheckResourceAttr(data.ResourceName, "container.#", "1"), resource.TestCheckResourceAttr(data.ResourceName, "os_type", "Linux"), - resource.TestCheckResourceAttr(data.ResourceName, "container.0.port", "80"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.ports.#", "1"), resource.TestCheckResourceAttr(data.ResourceName, "ip_address_type", "Private"), resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile_id"), ), @@ -383,7 +382,6 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { testCheckAzureRMContainerGroupExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "container.#", "1"), resource.TestCheckResourceAttr(data.ResourceName, "container.0.ports.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "container.0.command", "cmd.exe echo hi"), resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.#", "3"), resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.0", "cmd.exe"), resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.1", "echo"), @@ -435,6 +433,10 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { func testAccAzureRMContainerGroup_SystemAssignedIdentity(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -468,6 +470,10 @@ resource "azurerm_container_group" "test" { func testAccAzureRMContainerGroup_UserAssignedIdentity(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -509,6 +515,10 @@ resource "azurerm_container_group" "test" { func testAccAzureRMContainerGroup_MultipleAssignedIdentities(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -550,6 +560,10 @@ resource "azurerm_container_group" "test" { func testAccAzureRMContainerGroup_linuxBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -606,6 +620,10 @@ resource "azurerm_container_group" "import" { func testAccAzureRMContainerGroup_imageRegistryCredentials(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -613,18 +631,20 @@ resource "azurerm_resource_group" "test" { resource "azurerm_container_group" "test" { name = "acctestcontainergroup-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_address_type = "public" os_type = "Linux" container { - name = "hw" - image = "microsoft/aci-helloworld:latest" - cpu = "0.5" - memory = "0.5" - port = 5443 - protocol = "UDP" + name = "hw" + image = "microsoft/aci-helloworld:latest" + cpu = "0.5" + memory = "0.5" + ports { + port = 5443 + protocol = "UDP" + } } image_registry_credential { @@ -655,6 +675,10 @@ resource "azurerm_container_group" "test" { func testAccAzureRMContainerGroup_imageRegistryCredentialsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -662,8 +686,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_container_group" "test" { name = "acctestcontainergroup-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_address_type = "public" os_type = "Linux" @@ -700,6 +724,10 @@ resource "azurerm_container_group" "test" { func testAccAzureRMContainerGroup_logTypeUnset(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -707,15 +735,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_log_analytics_workspace" "test" { name = "acctestLAW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" } resource "azurerm_container_group" "test" { name = "acctestcontainergroup-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_address_type = "public" os_type = "Linux" @@ -724,13 +752,15 @@ resource "azurerm_container_group" "test" { image = "microsoft/aci-helloworld:latest" cpu = "0.5" memory = "0.5" - port = 80 + ports { + port = 80 + } } diagnostics { log_analytics { - workspace_id = "${azurerm_log_analytics_workspace.test.workspace_id}" - workspace_key = "${azurerm_log_analytics_workspace.test.primary_shared_key}" + workspace_id = azurerm_log_analytics_workspace.test.workspace_id + workspace_key = azurerm_log_analytics_workspace.test.primary_shared_key } } @@ -743,6 +773,10 @@ resource "azurerm_container_group" "test" { func testAccAzureRMContainerGroup_linuxBasicUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -750,8 +784,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_container_group" "test" { name = "acctestcontainergroup-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_address_type = "public" os_type = "Linux" @@ -787,6 +821,10 @@ resource "azurerm_container_group" "test" { func testAccAzureRMContainerGroup_virtualNetwork(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -794,15 +832,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "testvnet" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.1.0.0/16"] } resource "azurerm_subnet" "test" { name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.1.0.0/24" delegation { @@ -817,25 +855,25 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_profile" "test" { name = "testnetprofile" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name container_network_interface { name = "testcnic" ip_configuration { name = "testipconfig" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } } resource "azurerm_container_group" "test" { name = "acctestcontainergroup-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_address_type = "Private" - network_profile_id = "${azurerm_network_profile.test.id}" + network_profile_id = azurerm_network_profile.test.id os_type = "Linux" container { @@ -843,7 +881,9 @@ resource "azurerm_container_group" "test" { image = "microsoft/aci-helloworld:latest" cpu = "0.5" memory = "0.5" - port = 80 + ports { + port = 80 + } } tags = { @@ -855,6 +895,10 @@ resource "azurerm_container_group" "test" { func testAccAzureRMContainerGroup_windowsBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -862,8 +906,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_container_group" "test" { name = "acctestcontainergroup-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_address_type = "public" os_type = "windows" @@ -893,6 +937,10 @@ resource "azurerm_container_group" "test" { func testAccAzureRMContainerGroup_windowsComplete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -900,17 +948,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_log_analytics_workspace" "test" { name = "acctestLAW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" } resource "azurerm_log_analytics_solution" "test" { solution_name = "ContainerInsights" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" - workspace_name = "${azurerm_log_analytics_workspace.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + workspace_resource_id = azurerm_log_analytics_workspace.test.id + workspace_name = azurerm_log_analytics_workspace.test.name plan { publisher = "Microsoft" @@ -920,8 +968,8 @@ resource "azurerm_log_analytics_solution" "test" { resource "azurerm_container_group" "test" { name = "acctestcontainergroup-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_address_type = "public" dns_name_label = "acctestcontainergroup-%d" os_type = "windows" @@ -976,8 +1024,8 @@ resource "azurerm_container_group" "test" { diagnostics { log_analytics { - workspace_id = "${azurerm_log_analytics_workspace.test.workspace_id}" - workspace_key = "${azurerm_log_analytics_workspace.test.primary_shared_key}" + workspace_id = azurerm_log_analytics_workspace.test.workspace_id + workspace_key = azurerm_log_analytics_workspace.test.primary_shared_key log_type = "ContainerInsights" metadata = { @@ -995,6 +1043,10 @@ resource "azurerm_container_group" "test" { func testAccAzureRMContainerGroup_linuxComplete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/containers/tests/resource_arm_container_registry_test.go b/azurerm/internal/services/containers/tests/resource_arm_container_registry_test.go index 5a69ab399bf49..7c57b1abf2212 100644 --- a/azurerm/internal/services/containers/tests/resource_arm_container_registry_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_container_registry_test.go @@ -480,6 +480,10 @@ func testCheckAzureRMContainerRegistryGeoreplications(resourceName string, sku s func testAccAzureRMContainerRegistry_basic_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -487,8 +491,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_container_registry" "test" { name = "testacccr%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "Basic" # make sure network_rule_set is empty for basic SKU @@ -500,6 +504,10 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_basicManaged(data acceptance.TestData, sku string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -507,8 +515,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_container_registry" "test" { name = "testacccr%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "%s" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, sku) @@ -520,17 +528,20 @@ func testAccAzureRMContainerRegistry_requiresImport(data acceptance.TestData, sk %s resource "azurerm_container_registry" "import" { - name = "${azurerm_container_registry.test.name}" - resource_group_name = "${azurerm_container_registry.test.resource_group_name}" - location = "${azurerm_container_registry.test.location}" - sku = "${azurerm_container_registry.test.sku}" - + name = azurerm_container_registry.test.name + resource_group_name = azurerm_container_registry.test.resource_group_name + location = azurerm_container_registry.test.location + sku = azurerm_container_registry.test.sku } `, template) } func testAccAzureRMContainerRegistry_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -538,8 +549,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_container_registry" "test" { name = "testacccr%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location admin_enabled = false sku = "Basic" @@ -552,6 +563,10 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_completeUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -559,8 +574,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_container_registry" "test" { name = "testacccr%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location admin_enabled = true sku = "Basic" @@ -573,6 +588,10 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_geoReplication(data acceptance.TestData, sku string, georeplicationLocations string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -580,8 +599,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_container_registry" "test" { name = "testacccr%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "%s" georeplication_locations = ["%s"] } @@ -590,6 +609,10 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_geoReplicationUpdateWithNoLocation(data acceptance.TestData, sku string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -597,8 +620,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_container_registry" "test" { name = "testacccr%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "%s" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, sku) @@ -606,6 +629,10 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_geoReplicationUpdateWithNoLocation_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -613,8 +640,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_container_registry" "test" { name = "testacccr%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "Basic" # make sure network_rule_set is empty for basic SKU @@ -626,6 +653,10 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_networkAccessProfile_ip(data acceptance.TestData, sku string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%[2]s" @@ -633,8 +664,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_container_registry" "test" { name = "testAccCr%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "%[3]s" admin_enabled = false @@ -657,6 +688,10 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_networkAccessProfile_vnet(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%[2]s" @@ -664,15 +699,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "virtualNetwork1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" service_endpoints = ["Microsoft.ContainerRegistry"] @@ -680,8 +715,8 @@ resource "azurerm_subnet" "test" { resource "azurerm_container_registry" "test" { name = "testAccCr%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "Premium" admin_enabled = false @@ -695,7 +730,7 @@ resource "azurerm_container_registry" "test" { virtual_network { action = "Allow" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } } @@ -704,6 +739,10 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_networkAccessProfile_both(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%[2]s" @@ -711,15 +750,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "virtualNetwork1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" service_endpoints = ["Microsoft.ContainerRegistry"] @@ -727,8 +766,8 @@ resource "azurerm_subnet" "test" { resource "azurerm_container_registry" "test" { name = "testAccCr%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "Premium" admin_enabled = false @@ -742,7 +781,7 @@ resource "azurerm_container_registry" "test" { virtual_network { action = "Allow" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } } diff --git a/azurerm/internal/services/containers/tests/resource_arm_container_registry_webhook_test.go b/azurerm/internal/services/containers/tests/resource_arm_container_registry_webhook_test.go index 2b4899e20d6ed..f1abd7b037603 100644 --- a/azurerm/internal/services/containers/tests/resource_arm_container_registry_webhook_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_container_registry_webhook_test.go @@ -188,6 +188,10 @@ func TestAccAzureRMContainerRegistryWebhook_customHeaders(t *testing.T) { func testAccAzureRMContainerRegistryWebhook_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -217,6 +221,10 @@ resource "azurerm_container_registry_webhook" "test" { func testAccAzureRMContainerRegistryWebhook_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -250,6 +258,10 @@ resource "azurerm_container_registry_webhook" "test" { func testAccAzureRMContainerRegistryWebhook_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -284,6 +296,10 @@ resource "azurerm_container_registry_webhook" "test" { func testAccAzureRMContainerRegistryWebhook_actions(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -313,6 +329,10 @@ resource "azurerm_container_registry_webhook" "test" { func testAccAzureRMContainerRegistryWebhook_actionsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -343,6 +363,10 @@ resource "azurerm_container_registry_webhook" "test" { func testAccAzureRMContainerRegistryWebhook_status(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -374,6 +398,10 @@ resource "azurerm_container_registry_webhook" "test" { func testAccAzureRMContainerRegistryWebhook_statusUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -405,6 +433,10 @@ resource "azurerm_container_registry_webhook" "test" { func testAccAzureRMContainerRegistryWebhook_serviceUri(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -434,6 +466,10 @@ resource "azurerm_container_registry_webhook" "test" { func testAccAzureRMContainerRegistryWebhook_serviceUriUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -465,6 +501,10 @@ resource "azurerm_container_registry_webhook" "test" { func testAccAzureRMContainerRegistryWebhook_scope(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -496,6 +536,10 @@ resource "azurerm_container_registry_webhook" "test" { func testAccAzureRMContainerRegistryWebhook_scopeUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -527,6 +571,10 @@ resource "azurerm_container_registry_webhook" "test" { func testAccAzureRMContainerRegistryWebhook_customHeaders(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -560,6 +608,10 @@ resource "azurerm_container_registry_webhook" "test" { func testAccAzureRMContainerRegistryWebhook_customHeadersUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_addons_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_addons_test.go index 7ffd2a9f28443..ad2b7db65f201 100644 --- a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_addons_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_addons_test.go @@ -243,6 +243,10 @@ func testAccAzureRMKubernetesCluster_addonProfileRouting(t *testing.T) { func testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinuxConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -320,6 +324,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinuxDisabledConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -380,6 +388,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_addonProfileAzurePolicyConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -421,6 +433,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_addonProfileKubeDashboardConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -462,6 +478,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_addonProfileOMSConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -524,6 +544,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_addonProfileOMSDisabledConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -565,6 +589,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_addonProfileOMSScaleWithoutBlockConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -600,6 +628,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_addonProfileRoutingConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_auth_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_auth_test.go index e11d9a4870102..f46d2f1c7cab9 100644 --- a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_auth_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_auth_test.go @@ -246,6 +246,10 @@ func testAccAzureRMKubernetesCluster_updateRoleBaseAccessControlAAD(t *testing.T func testAccAzureRMKubernetesCluster_apiServerAuthorizedIPRangesConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -299,6 +303,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_enablePodSecurityPolicyConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -331,6 +339,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_managedClusterIdentityServicePrincipalConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -363,6 +375,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_roleBasedAccessControlConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -370,8 +386,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_kubernetes_cluster" "test" { name = "acctestaks%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name dns_prefix = "acctestaks%d" linux_profile { diff --git a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_legacy_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_legacy_test.go deleted file mode 100644 index a3a324b2552a9..0000000000000 --- a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_legacy_test.go +++ /dev/null @@ -1,123 +0,0 @@ -package tests - -import ( - "fmt" - "os" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -// NOTE: all of the tests in this file are for functionality which will be removed in 2.0 - -func TestAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySet(t *testing.T) { - checkIfShouldRunTestsIndividually(t) - testAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySet(t) -} - -func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySet(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySetConfig(data, clientId, clientSecret), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.type", "AvailabilitySet"), - ), - // since users are prompted to move to `default_node_pool` - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func TestAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSS(t *testing.T) { - checkIfShouldRunTestsIndividually(t) - testAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSS(t) -} - -func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSS(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSSConfig(data, clientId, clientSecret), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.type", "VirtualMachineScaleSets"), - ), - // since users are prompted to move to `default_node_pool` - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySetConfig(data acceptance.TestData, clientId string, clientSecret string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_kubernetes_cluster" "test" { - name = "acctestaks%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - dns_prefix = "acctestaks%d" - - agent_pool_profile { - name = "default" - count = 1 - vm_size = "Standard_DS2_v2" - } - - service_principal { - client_id = "%s" - client_secret = "%s" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) -} - -func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSSConfig(data acceptance.TestData, clientId string, clientSecret string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_kubernetes_cluster" "test" { - name = "acctestaks%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - dns_prefix = "acctestaks%d" - - agent_pool_profile { - name = "default" - count = 1 - type = "VirtualMachineScaleSets" - vm_size = "Standard_DS2_v2" - } - - service_principal { - client_id = "%s" - client_secret = "%s" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) -} diff --git a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_network_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_network_test.go index 1e40fe777f51c..6329ebdd9002d 100644 --- a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_network_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_network_test.go @@ -578,6 +578,10 @@ func testAccAzureRMKubernetesCluster_prefixedLoadBalancerProfile(t *testing.T) { func testAccAzureRMKubernetesCluster_advancedNetworkingConfig(data acceptance.TestData, clientId string, clientSecret string, location string, networkPlugin string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -595,11 +599,6 @@ resource "azurerm_subnet" "test" { resource_group_name = azurerm_resource_group.test.name virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.1.0.0/24" - - # TODO: remove in 2.0 - lifecycle { - ignore_changes = ["route_table_id"] - } } resource "azurerm_kubernetes_cluster" "test" { @@ -637,6 +636,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_advancedNetworkingCompleteConfig(data acceptance.TestData, clientId string, clientSecret string, location string, networkPlugin string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -667,11 +670,6 @@ resource "azurerm_subnet" "test" { resource_group_name = azurerm_resource_group.test.name virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.1.0.0/24" - - # TODO: remove in 2.0 - lifecycle { - ignore_changes = ["route_table_id"] - } } resource "azurerm_subnet_route_table_association" "test" { @@ -717,6 +715,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyConfig(data acceptance.TestData, clientId string, clientSecret string, location string, networkPlugin string, networkPolicy string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -772,6 +774,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyCompleteConfig(data acceptance.TestData, clientId string, clientSecret string, location string, networkPlugin string, networkPolicy string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -802,7 +808,6 @@ resource "azurerm_subnet" "test" { resource_group_name = azurerm_resource_group.test.name virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.1.0.0/24" - route_table_id = azurerm_route_table.test.id } resource "azurerm_subnet_route_table_association" "test" { @@ -849,6 +854,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_enableNodePublicIPConfig(data acceptance.TestData, clientId, clientSecret, location string, enabled bool) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -877,6 +886,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_internalNetworkConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -894,11 +907,6 @@ resource "azurerm_subnet" "test" { resource_group_name = azurerm_resource_group.test.name virtual_network_name = azurerm_virtual_network.test.name address_prefix = "172.0.2.0/24" - - # TODO: remove in 2.0 - lifecycle { - ignore_changes = ["route_table_id"] - } } resource "azurerm_kubernetes_cluster" "test" { @@ -933,6 +941,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_privateLinkConfig(data acceptance.TestData, clientId string, clientSecret string, location string, cdir string, enablePrivateLink bool) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -976,6 +988,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_standardLoadBalancerConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1032,6 +1048,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_standardLoadBalancerCompleteConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1062,7 +1082,6 @@ resource "azurerm_subnet" "test" { resource_group_name = azurerm_resource_group.test.name virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.1.0.0/24" - route_table_id = azurerm_route_table.test.id } resource "azurerm_subnet_route_table_association" "test" { @@ -1110,6 +1129,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_standardLoadBalancerProfileConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1169,6 +1192,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_standardLoadBalancerProfileCompleteConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1236,6 +1263,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_basicLoadBalancerProfileConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1295,6 +1326,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_conflictingLoadBalancerProfileConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1369,6 +1404,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_prefixedLoadBalancerProfileConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_node_pool_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_node_pool_test.go index 800c1bbbe403b..15e801160f746 100644 --- a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_node_pool_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_node_pool_test.go @@ -693,6 +693,10 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { func testAccAzureRMKubernetesClusterNodePool_availabilitySetConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -728,6 +732,9 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { func testAccAzureRMKubernetesClusterNodePool_availabilityZonesConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1022,6 +1029,10 @@ resource "azurerm_kubernetes_cluster_node_pool" "windows" { func testAccAzureRMKubernetesClusterNodePool_templateConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1049,6 +1060,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesClusterNodePool_templateVirtualNetworkConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1079,11 +1094,6 @@ resource "azurerm_subnet" "test" { resource_group_name = azurerm_resource_group.test.name virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.1.0.0/24" - - # TODO: remove in 2.0 - lifecycle { - ignore_changes = ["route_table_id"] - } } resource "azurerm_subnet_route_table_association" "test" { @@ -1114,6 +1124,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesClusterNodePool_templateWindowsConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_other_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_other_test.go index 51c16d42bf571..f5db975d285f2 100644 --- a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_other_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_other_test.go @@ -312,6 +312,10 @@ func testAccAzureRMKubernetesCluster_windowsProfile(t *testing.T) { func testAccAzureRMKubernetesCluster_basicAvailabilitySetConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -340,6 +344,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_basicVMSSConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -392,6 +400,10 @@ resource "azurerm_kubernetes_cluster" "import" { func testAccAzureRMKubernetesCluster_linuxProfileConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -427,6 +439,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_nodeTaintsConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -457,6 +473,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_nodeResourceGroupConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -485,6 +505,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_tagsConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -516,6 +540,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_tagsUpdatedConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -547,6 +575,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_upgradeConfig(data acceptance.TestData, clientId, clientSecret, version string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -583,6 +615,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_windowsProfileConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -590,8 +626,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_kubernetes_cluster" "test" { name = "acctestaks%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name dns_prefix = "acctestaks%d" linux_profile { diff --git a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_scaling_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_scaling_test.go index 2d1b1ee5d2abc..3d639aaa0c4df 100644 --- a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_scaling_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_scaling_test.go @@ -169,6 +169,10 @@ func testAccAzureRMKubernetesCluster_autoScalingWithAvailabilityZones(t *testing func testAccAzureRMKubernetesCluster_addAgentConfig(data acceptance.TestData, clientId, clientSecret, location string, numberOfAgents int) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -196,6 +200,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_autoscaleNodeCountUnsetConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -225,6 +233,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_autoscaleNoAvailabilityZonesConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -254,6 +266,10 @@ resource "azurerm_kubernetes_cluster" "test" { func testAccAzureRMKubernetesCluster_autoscaleWithAvailabilityZonesConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_test.go index 0b947d9648ce9..bee56efc903c3 100644 --- a/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_test.go @@ -37,10 +37,6 @@ func TestAccAzureRMKubernetes_all(t *testing.T) { "roleBasedAccessControl": testAccAzureRMKubernetesCluster_roleBasedAccessControl, "roleBasedAccessControlAAD": testAccAzureRMKubernetesCluster_roleBasedAccessControlAAD, }, - "legacy": { - "legacyAgentPoolProfileAvailabilitySet": testAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySet, - "legacyAgentPoolProfileVMSS": testAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSS, - }, "network": { "advancedNetworkingKubenet": testAccAzureRMKubernetesCluster_advancedNetworkingKubenet, "advancedNetworkingKubenetComplete": testAccAzureRMKubernetesCluster_advancedNetworkingKubenetComplete, diff --git a/azurerm/internal/services/cosmos/data_source_cosmos_db_account.go b/azurerm/internal/services/cosmos/data_source_cosmos_db_account.go index 43ddda9aa9296..15f202d0b0114 100644 --- a/azurerm/internal/services/cosmos/data_source_cosmos_db_account.go +++ b/azurerm/internal/services/cosmos/data_source_cosmos_db_account.go @@ -222,7 +222,7 @@ func dataSourceArmCosmosDbAccountRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting `consistency_policy`: %+v", err) } - //sort `geo_locations` by fail over priority + // sort `geo_locations` by fail over priority locations := make([]map[string]interface{}, len(*props.FailoverPolicies)) for _, l := range *props.FailoverPolicies { locations[*l.FailoverPriority] = map[string]interface{}{ diff --git a/azurerm/internal/services/cosmos/registration.go b/azurerm/internal/services/cosmos/registration.go index 97aff3a4de0e4..ad3a4ee361ca9 100644 --- a/azurerm/internal/services/cosmos/registration.go +++ b/azurerm/internal/services/cosmos/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "CosmosDB" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "CosmosDB (DocumentDB)", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account.go index 0bec359d958a8..19937b1af49ca 100644 --- a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account.go @@ -57,7 +57,7 @@ func resourceArmCosmosDbAccount() *schema.Resource { "resource_group_name": azure.SchemaResourceGroupName(), - //resource fields + // resource fields "offer_type": { Type: schema.TypeString, Required: true, @@ -131,43 +131,9 @@ func resourceArmCosmosDbAccount() *schema.Resource { }, }, - // this actually maps to the Location field in the API/SDK on create/update so has been renamed - // failover_policy is just the name of the field we get back from the API on a read - "failover_policy": { - Type: schema.TypeSet, - Optional: true, - Deprecated: "This field has been renamed to 'geo_location' to match Azure's usage", - ConflictsWith: []string{"geo_location"}, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - - "location": { - Type: schema.TypeString, - Required: true, - StateFunc: azure.NormalizeLocation, - DiffSuppressFunc: azure.SuppressLocationDiff, - }, - - "priority": { - Type: schema.TypeInt, - Required: true, - }, - }, - }, - Set: resourceAzureRMCosmosDBAccountFailoverPolicyHash, - }, - "geo_location": { - Type: schema.TypeSet, - //Required: true, //todo needs to be required when failover_policy is removed - Optional: true, - Computed: true, - ConflictsWith: []string{"failover_policy"}, + Type: schema.TypeSet, + Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -249,7 +215,7 @@ func resourceArmCosmosDbAccount() *schema.Resource { Default: false, }, - //computed + // computed "endpoint": { Type: schema.TypeString, Computed: true, @@ -349,21 +315,9 @@ func resourceArmCosmosDbAccountCreate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("CosmosDB Account %s already exists, please import the resource via terraform import", name) } - //hacky, todo fix up once deprecated field 'failover_policy' is removed - var geoLocations []documentdb.Location - if _, ok := d.GetOk("geo_location"); ok { - geoLocations, err = expandAzureRmCosmosDBAccountGeoLocations(name, d) - if err != nil { - return fmt.Errorf("Error expanding CosmosDB Account %q (Resource Group %q) geo locations: %+v", name, resourceGroup, err) - } - } else if _, ok := d.GetOk("failover_policy"); ok { - geoLocations, err = expandAzureRmCosmosDBAccountFailoverPolicy(name, d) - if err != nil { - return fmt.Errorf("Error expanding CosmosDB Account %q (Resource Group %q) failover_policy: %+v", name, resourceGroup, err) - } - } else { - //could be a CustomizeDiff?, but this is temporary - return fmt.Errorf("Neither `geo_location` or `failover_policy` is set for CosmosDB Account %s", name) + geoLocations, err := expandAzureRmCosmosDBAccountGeoLocations(name, d) + if err != nil { + return fmt.Errorf("Error expanding CosmosDB Account %q (Resource Group %q) geo locations: %+v", name, resourceGroup, err) } account := documentdb.DatabaseAccountCreateUpdateParameters{ @@ -416,7 +370,7 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{}) defer cancel() log.Printf("[INFO] preparing arguments for AzureRM Cosmos DB Account update.") - //move to function + // move to function name := d.Get("name").(string) location := d.Get("location").(string) resourceGroup := d.Get("resource_group_name").(string) @@ -429,25 +383,12 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{}) enableAutomaticFailover := d.Get("enable_automatic_failover").(bool) enableMultipleWriteLocations := d.Get("enable_multiple_write_locations").(bool) - //hacky, todo fix up once deprecated field 'failover_policy' is removed - var newLocations []documentdb.Location - var err error - if _, ok := d.GetOk("geo_location"); ok { - newLocations, err = expandAzureRmCosmosDBAccountGeoLocations(name, d) - if err != nil { - return fmt.Errorf("Error expanding CosmosDB Account %q (Resource Group %q) geo locations: %+v", name, resourceGroup, err) - } - } else if _, ok := d.GetOk("failover_policy"); ok { - newLocations, err = expandAzureRmCosmosDBAccountFailoverPolicy(name, d) - if err != nil { - return fmt.Errorf("Error expanding CosmosDB Account %q (Resource Group %q) failover_policy: %+v", name, resourceGroup, err) - } - } else { - //could be a CustomizeDiff?, but this is temporary - return fmt.Errorf("Neither `geo_location` or `failover_policy` is set for CosmosDB Account '%s'", name) + newLocations, err := expandAzureRmCosmosDBAccountGeoLocations(name, d) + if err != nil { + return fmt.Errorf("Error expanding CosmosDB Account %q (Resource Group %q) geo locations: %+v", name, resourceGroup, err) } - //get existing locations (if exists) + // get existing locations (if exists) resp, err := client.Get(ctx, resourceGroup, name) if err != nil { return fmt.Errorf("Error making Read request on AzureRM CosmosDB Account '%s': %s", name, err) @@ -466,8 +407,8 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{}) oldLocationsMap[azure.NormalizeLocation(*location.LocationName)] = location } - //cannot update properties and add/remove replication locations at the same time - //so first just update any changed properties + // cannot update properties and add/remove replication locations at the same time + // so first just update any changed properties account := documentdb.DatabaseAccountCreateUpdateParameters{ Location: utils.String(location), Kind: documentdb.DatabaseAccountKind(kind), @@ -489,7 +430,7 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error updating CosmosDB Account %q properties (Resource Group %q): %+v", name, resourceGroup, err) } - //determine if any locations have been renamed/priority reordered and remove them + // determine if any locations have been renamed/priority reordered and remove them removedOne := false for _, l := range newLocations { if ol, ok := oldLocationsMap[*l.LocationName]; ok { @@ -526,7 +467,7 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{}) } } - //add any new/renamed locations + // add any new/renamed locations account.DatabaseAccountCreateUpdateProperties.Locations = &newLocations upsertResponse, err := resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account, d) if err != nil { @@ -592,15 +533,9 @@ func resourceArmCosmosDbAccountRead(d *schema.ResourceData, meta interface{}) er if err = d.Set("consistency_policy", flattenAzureRmCosmosDBAccountConsistencyPolicy(resp.ConsistencyPolicy)); err != nil { return fmt.Errorf("Error setting CosmosDB Account %q `consistency_policy` (Resource Group %q): %+v", name, resourceGroup, err) } - if _, ok := d.GetOk("failover_policy"); ok { - if err = d.Set("failover_policy", flattenAzureRmCosmosDBAccountFailoverPolicy(resp.FailoverPolicies)); err != nil { - return fmt.Errorf("Error setting `failover_policy`: %+v", err) - } - } else { - //if failover policy isn't default to using geo_location - if err = d.Set("geo_location", flattenAzureRmCosmosDBAccountGeoLocations(d, resp)); err != nil { - return fmt.Errorf("Error setting `geo_location`: %+v", err) - } + + if err = d.Set("geo_location", flattenAzureRmCosmosDBAccountGeoLocations(d, resp)); err != nil { + return fmt.Errorf("Error setting `geo_location`: %+v", err) } if err = d.Set("capabilities", flattenAzureRmCosmosDBAccountCapabilities(resp.Capabilities)); err != nil { @@ -711,7 +646,7 @@ func resourceArmCosmosDbAccountDelete(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error issuing AzureRM delete request for CosmosDB Account '%s': %+v", name, err) } - //the SDK now will return a `WasNotFound` response even when still deleting + // the SDK now will return a `WasNotFound` response even when still deleting stateConf := &resource.StateChangeConf{ Pending: []string{"Deleting"}, Target: []string{"NotFound"}, @@ -747,7 +682,7 @@ func resourceArmCosmosDbAccountApiUpsert(client *documentdb.DatabaseAccountsClie return nil, fmt.Errorf("Error waiting for the CosmosDB Account %q (Resource Group %q) to finish creating/updating: %+v", name, resourceGroup, err) } - //if a replication location is added or removed it can take some time to provision + // if a replication location is added or removed it can take some time to provision stateConf := &resource.StateChangeConf{ Pending: []string{"Creating", "Updating", "Deleting", "Initializing"}, Target: []string{"Succeeded"}, @@ -762,7 +697,7 @@ func resourceArmCosmosDbAccountApiUpsert(client *documentdb.DatabaseAccountsClie status := "Succeeded" for _, l := range append(*resp.ReadLocations, *resp.WriteLocations...) { if status = *l.ProvisioningState; status == "Creating" || status == "Updating" || status == "Deleting" { - break //return the first non successful status. + break // return the first non successful status. } } @@ -831,7 +766,7 @@ func expandAzureRmCosmosDBAccountGeoLocations(databaseName string, d *schema.Res locations = append(locations, location) } - //TODO maybe this should be in a CustomizeDiff + // TODO maybe this should be in a CustomizeDiff // all priorities & locations must be unique byPriorities := make(map[int]interface{}, len(locations)) byName := make(map[string]interface{}, len(locations)) @@ -851,7 +786,7 @@ func expandAzureRmCosmosDBAccountGeoLocations(databaseName string, d *schema.Res byName[name] = location } - //and must have one of 0 priority + // and must have one of 0 priority if _, ok := byPriorities[0]; !ok { return nil, fmt.Errorf("There needs to be a `geo_location` with a failover_priority of 0") } @@ -859,54 +794,6 @@ func expandAzureRmCosmosDBAccountGeoLocations(databaseName string, d *schema.Res return locations, nil } -// todo remove when deprecated field `failover_policy` is -func expandAzureRmCosmosDBAccountFailoverPolicy(databaseName string, d *schema.ResourceData) ([]documentdb.Location, error) { - input := d.Get("failover_policy").(*schema.Set).List() - locations := make([]documentdb.Location, 0, len(input)) - - for _, configRaw := range input { - data := configRaw.(map[string]interface{}) - - locationName := azure.NormalizeLocation(data["location"].(string)) - id := fmt.Sprintf("%s-%s", databaseName, locationName) - failoverPriority := int32(data["priority"].(int)) - - location := documentdb.Location{ - ID: &id, - LocationName: &locationName, - FailoverPriority: &failoverPriority, - } - - locations = append(locations, location) - } - - containsWriteLocation := false - writeFailoverPriority := int32(0) - for _, location := range locations { - if *location.FailoverPriority == writeFailoverPriority { - containsWriteLocation = true - break - } - } - - // all priorities must be unique - locationIds := make(map[int]struct{}, len(locations)) - for _, location := range locations { - priority := int(*location.FailoverPriority) - if _, ok := locationIds[priority]; ok { - return nil, fmt.Errorf("Each Failover Policy needs to be unique") - } - - locationIds[priority] = struct{}{} - } - - if !containsWriteLocation { - return nil, fmt.Errorf("Failover Policy should contain a Write Location (Location '0')") - } - - return locations, nil -} - func expandAzureRmCosmosDBAccountCapabilities(d *schema.ResourceData) *[]documentdb.Capability { capabilities := d.Get("capabilities").(*schema.Set).List() s := make([]documentdb.Capability, 0) @@ -943,31 +830,12 @@ func flattenAzureRmCosmosDBAccountConsistencyPolicy(policy *documentdb.Consisten return []interface{}{result} } -// todo remove when failover_policy field is removed -func flattenAzureRmCosmosDBAccountFailoverPolicy(list *[]documentdb.FailoverPolicy) *schema.Set { - results := schema.Set{ - F: resourceAzureRMCosmosDBAccountFailoverPolicyHash, - } - - for _, i := range *list { - result := map[string]interface{}{ - "id": *i.ID, - "location": azure.NormalizeLocation(*i.LocationName), - "priority": int(*i.FailoverPriority), - } - - results.Add(result) - } - - return &results -} - func flattenAzureRmCosmosDBAccountGeoLocations(d *schema.ResourceData, account documentdb.DatabaseAccount) *schema.Set { locationSet := schema.Set{ F: resourceAzureRMCosmosDBAccountGeoLocationHash, } - //we need to propagate the `prefix` field so fetch existing + // we need to propagate the `prefix` field so fetch existing prefixMap := map[string]string{} if locations, ok := d.GetOk("geo_location"); ok { for _, lRaw := range locations.(*schema.Set).List() { @@ -984,7 +852,7 @@ func flattenAzureRmCosmosDBAccountGeoLocations(d *schema.ResourceData, account d "failover_priority": int(*l.FailoverPriority), } - //if id is not the default then it must be set via prefix + // if id is not the default then it must be set via prefix if id != resourceArmCosmosDbAccountGenerateDefaultId(d.Get("name").(string), lb["location"].(string)) { lb["prefix"] = id } @@ -1029,20 +897,6 @@ func flattenAzureRmCosmosDBAccountVirtualNetworkRules(rules *[]documentdb.Virtua return &results } -// todo remove once deprecated field `failover_policy` is removed -func resourceAzureRMCosmosDBAccountFailoverPolicyHash(v interface{}) int { - var buf bytes.Buffer - - if m, ok := v.(map[string]interface{}); ok { - location := azure.NormalizeLocation(m["location"].(string)) - priority := int32(m["priority"].(int)) - - buf.WriteString(fmt.Sprintf("%s-%d", location, priority)) - } - - return hashcode.String(buf.String()) -} - func resourceAzureRMCosmosDBAccountGeoLocationHash(v interface{}) int { var buf bytes.Buffer diff --git a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection.go index c1a1b7447f985..5b6cb44645ec2 100644 --- a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "strconv" - "strings" "time" "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" @@ -83,30 +82,6 @@ func resourceArmCosmosDbMongoCollection() *schema.Resource { Computed: true, ValidateFunc: validate.CosmosThroughput, }, - - "indexes": { - Type: schema.TypeSet, - Optional: true, - Deprecated: "Indexes are ignored unless they are the shared key so have been deprecated.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "key": { - Type: schema.TypeString, // this is a list in the SDK/API, however any more then a single value causes a 404 - Required: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - - "unique": { - Type: schema.TypeBool, - Optional: true, - Default: true, // portal defaults to true - }, - - // expire_after_seconds is only allowed on `_ts`: - // Unable to parse request payload due to the following reason: 'The 'expireAfterSeconds' option is supported on '_ts' field only. - }, - }, - }, }, } } @@ -146,7 +121,7 @@ func resourceArmCosmosDbMongoCollectionCreate(d *schema.ResourceData, meta inter MongoDBCollectionCreateUpdateProperties: &documentdb.MongoDBCollectionCreateUpdateProperties{ Resource: &documentdb.MongoDBCollectionResource{ ID: &name, - Indexes: expandCosmosMongoCollectionIndexes(d.Get("indexes"), ttl), + Indexes: expandCosmosMongoCollectionIndexes(ttl), }, Options: map[string]*string{}, }, @@ -206,7 +181,7 @@ func resourceArmCosmosDbMongoCollectionUpdate(d *schema.ResourceData, meta inter MongoDBCollectionCreateUpdateProperties: &documentdb.MongoDBCollectionCreateUpdateProperties{ Resource: &documentdb.MongoDBCollectionResource{ ID: &id.Collection, - Indexes: expandCosmosMongoCollectionIndexes(d.Get("indexes"), ttl), + Indexes: expandCosmosMongoCollectionIndexes(ttl), }, Options: map[string]*string{}, }, @@ -289,11 +264,7 @@ func resourceArmCosmosDbMongoCollectionRead(d *schema.ResourceData, meta interfa } if props.Indexes != nil { - indexes, ttl := flattenCosmosMongoCollectionIndexes(props.Indexes) - d.Set("default_ttl_seconds", ttl) - if err := d.Set("indexes", indexes); err != nil { - return fmt.Errorf("Error setting `indexes`: %+v", err) - } + d.Set("default_ttl_seconds", flattenCosmosMongoCollectionIndexes(props.Indexes)) } } @@ -336,21 +307,9 @@ func resourceArmCosmosDbMongoCollectionDelete(d *schema.ResourceData, meta inter return nil } -func expandCosmosMongoCollectionIndexes(input interface{}, defaultTtl *int) *[]documentdb.MongoIndex { +func expandCosmosMongoCollectionIndexes(defaultTtl *int) *[]documentdb.MongoIndex { outputs := make([]documentdb.MongoIndex, 0) - for _, i := range input.(*schema.Set).List() { - b := i.(map[string]interface{}) - outputs = append(outputs, documentdb.MongoIndex{ - Key: &documentdb.MongoIndexKeys{ - Keys: &[]string{b["key"].(string)}, - }, - Options: &documentdb.MongoIndexOptions{ - Unique: utils.Bool(b["unique"].(bool)), - }, - }) - } - if defaultTtl != nil { outputs = append(outputs, documentdb.MongoIndex{ Key: &documentdb.MongoIndexKeys{ @@ -365,37 +324,15 @@ func expandCosmosMongoCollectionIndexes(input interface{}, defaultTtl *int) *[]d return &outputs } -func flattenCosmosMongoCollectionIndexes(indexes *[]documentdb.MongoIndex) (*[]map[string]interface{}, *int) { - slice := make([]map[string]interface{}, 0) - +func flattenCosmosMongoCollectionIndexes(indexes *[]documentdb.MongoIndex) *int { var ttl int for _, i := range *indexes { if key := i.Key; key != nil { - m := map[string]interface{}{} var ttlInner int32 - if options := i.Options; options != nil { - if v := options.Unique; v != nil { - m["unique"] = *v - } else { - m["unique"] = false // todo required? API sends back nothing for false - } - - if v := options.ExpireAfterSeconds; v != nil { - ttlInner = *v - } - } - if keys := key.Keys; keys != nil && len(*keys) > 0 { k := (*keys)[0] - if !strings.HasPrefix(k, "_") && k != "DocumentDBDefaultIndex" { // lets ignore system properties? - m["key"] = k - - // only append indexes with a non system key - slice = append(slice, m) - } - if k == "_ts" { ttl = int(ttlInner) } @@ -403,5 +340,5 @@ func flattenCosmosMongoCollectionIndexes(indexes *[]documentdb.MongoIndex) (*[]m } } - return &slice, &ttl + return &ttl } diff --git a/azurerm/internal/services/cosmos/tests/data_source_cosmos_db_account_test.go b/azurerm/internal/services/cosmos/tests/data_source_cosmos_db_account_test.go index 74a762dd2bcd2..4260b2905ec76 100644 --- a/azurerm/internal/services/cosmos/tests/data_source_cosmos_db_account_test.go +++ b/azurerm/internal/services/cosmos/tests/data_source_cosmos_db_account_test.go @@ -54,8 +54,8 @@ func testAccDataSourceAzureRMCosmosDBAccount_basic(data acceptance.TestData) str %s data "azurerm_cosmosdb_account" "test" { - name = "${azurerm_cosmosdb_account.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_cosmosdb_account.test.name + resource_group_name = azurerm_resource_group.test.name } `, testAccAzureRMCosmosDBAccount_basic(data, documentdb.GlobalDocumentDB, documentdb.BoundedStaleness)) } @@ -65,8 +65,8 @@ func testAccDataSourceAzureRMCosmosDBAccount_complete(data acceptance.TestData) %s data "azurerm_cosmosdb_account" "test" { - name = "${azurerm_cosmosdb_account.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_cosmosdb_account.test.name + resource_group_name = azurerm_resource_group.test.name } `, testAccAzureRMCosmosDBAccount_complete(data, documentdb.GlobalDocumentDB, documentdb.BoundedStaleness)) } diff --git a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_failover_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_failover_test.go index 92cf8e8ad0643..c079273402a80 100644 --- a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_failover_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_failover_test.go @@ -138,6 +138,10 @@ func TestAccAzureRMCosmosDBAccount_failover_geoReplicated(t *testing.T) { func testAccAzureRMCosmosDBAccount_failover_boundedStaleness(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -145,17 +149,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_cosmosdb_account" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name offer_type = "Standard" consistency_policy { consistency_level = "BoundedStaleness" } - failover_policy { - location = "${azurerm_resource_group.test.location}" - priority = 0 + geo_location { + location = azurerm_resource_group.test.location + failover_priority = 0 } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -163,6 +167,10 @@ resource "azurerm_cosmosdb_account" "test" { func testAccAzureRMCosmosDBAccount_failover_boundedStalenessComplete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -170,8 +178,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_cosmosdb_account" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name offer_type = "Standard" consistency_policy { @@ -180,9 +188,9 @@ resource "azurerm_cosmosdb_account" "test" { max_staleness_prefix = 200 } - failover_policy { - location = "${azurerm_resource_group.test.location}" - priority = 0 + geo_location { + location = azurerm_resource_group.test.location + failover_priority = 0 } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -190,6 +198,10 @@ resource "azurerm_cosmosdb_account" "test" { func testAccAzureRMCosmosDBAccount_failover_eventualConsistency(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -197,17 +209,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_cosmosdb_account" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name offer_type = "Standard" consistency_policy { consistency_level = "Eventual" } - failover_policy { - location = "${azurerm_resource_group.test.location}" - priority = 0 + geo_location { + location = azurerm_resource_group.test.location + failover_priority = 0 } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -215,6 +227,10 @@ resource "azurerm_cosmosdb_account" "test" { func testAccAzureRMCosmosDBAccount_failover_session(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -222,17 +238,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_cosmosdb_account" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name offer_type = "Standard" consistency_policy { consistency_level = "Session" } - failover_policy { - location = "${azurerm_resource_group.test.location}" - priority = 0 + geo_location { + location = azurerm_resource_group.test.location + failover_priority = 0 } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -240,6 +256,10 @@ resource "azurerm_cosmosdb_account" "test" { func testAccAzureRMCosmosDBAccount_failover_mongoDB(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -247,8 +267,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_cosmosdb_account" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name kind = "MongoDB" offer_type = "Standard" @@ -256,9 +276,9 @@ resource "azurerm_cosmosdb_account" "test" { consistency_level = "BoundedStaleness" } - failover_policy { - location = "${azurerm_resource_group.test.location}" - priority = 0 + geo_location { + location = azurerm_resource_group.test.location + failover_priority = 0 } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -266,6 +286,10 @@ resource "azurerm_cosmosdb_account" "test" { func testAccAzureRMCosmosDBAccount_failover_strong(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -273,17 +297,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_cosmosdb_account" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name offer_type = "Standard" consistency_policy { consistency_level = "Strong" } - failover_policy { - location = "${azurerm_resource_group.test.location}" - priority = 0 + geo_location { + location = azurerm_resource_group.test.location + failover_priority = 0 } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -291,6 +315,10 @@ resource "azurerm_cosmosdb_account" "test" { func testAccAzureRMCosmosDBAccount_failover_geoReplicated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -298,8 +326,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_cosmosdb_account" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name offer_type = "Standard" consistency_policy { @@ -308,14 +336,14 @@ resource "azurerm_cosmosdb_account" "test" { max_staleness_prefix = 101101 } - failover_policy { - location = "${azurerm_resource_group.test.location}" - priority = 0 + geo_location { + location = azurerm_resource_group.test.location + failover_priority = 0 } - failover_policy { - location = "%s" - priority = 1 + geo_location { + location = "%s" + failover_priority = 1 } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary) diff --git a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_test.go index 1cf1b45825d57..976153d5688e7 100644 --- a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_test.go @@ -108,7 +108,7 @@ func TestAccAzureRMCosmosDBAccount_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDBAccount_basic(data, "", documentdb.Eventual), + Config: testAccAzureRMCosmosDBAccount_basic(data, "GlobalDocumentDB", documentdb.Eventual), Check: resource.ComposeAggregateTestCheckFunc( checkAccAzureRMCosmosDBAccount_basic(data, documentdb.Eventual, 1), ), @@ -241,7 +241,7 @@ func testAccAzureRMCosmosDBAccount_updateWith(t *testing.T, kind documentdb.Data { Config: testAccAzureRMCosmosDBAccount_basic(data, kind, documentdb.Eventual), Check: resource.ComposeAggregateTestCheckFunc( - //checkAccAzureRMCosmosDBAccount_basic(data, documentdb.Eventual, 1), + // checkAccAzureRMCosmosDBAccount_basic(data, documentdb.Eventual, 1), ), }, data.ImportStep(), @@ -402,6 +402,10 @@ func testCheckAzureRMCosmosDBAccountExists(resourceName string) resource.TestChe func testAccAzureRMCosmosDBAccount_basic(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-cosmos-%d" location = "%s" @@ -409,8 +413,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_cosmosdb_account" "test" { name = "acctest-ca-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name offer_type = "Standard" kind = "%s" @@ -419,7 +423,7 @@ resource "azurerm_cosmosdb_account" "test" { } geo_location { - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location failover_priority = 0 } } @@ -431,25 +435,29 @@ func testAccAzureRMCosmosDBAccount_requiresImport(data acceptance.TestData, cons %s resource "azurerm_cosmosdb_account" "import" { - name = "${azurerm_cosmosdb_account.test.name}" - location = "${azurerm_cosmosdb_account.test.location}" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - offer_type = "${azurerm_cosmosdb_account.test.offer_type}" + name = azurerm_cosmosdb_account.test.name + location = azurerm_cosmosdb_account.test.location + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + offer_type = azurerm_cosmosdb_account.test.offer_type consistency_policy { - consistency_level = "${azurerm_cosmosdb_account.consistency_policy.0.consistency_level}" + consistency_level = azurerm_cosmosdb_account.consistency_policy[0].consistency_level } geo_location { - location = "${azurerm_cosmosdb_account.geo_location.0.location}" - failover_priority = "${azurerm_cosmosdb_account.geo_location.0.location}" + location = azurerm_cosmosdb_account.geo_location[0].location + failover_priority = azurerm_cosmosdb_account.geo_location[0].location } } -`, testAccAzureRMCosmosDBAccount_basic(data, "", consistency)) +`, testAccAzureRMCosmosDBAccount_basic(data, "GlobalDocumentDB", consistency)) } func testAccAzureRMCosmosDBAccount_consistency(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel, interval, staleness int) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-cosmos-%d" location = "%s" @@ -457,8 +465,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_cosmosdb_account" "test" { name = "acctest-ca-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name offer_type = "Standard" kind = "%s" @@ -469,7 +477,7 @@ resource "azurerm_cosmosdb_account" "test" { } geo_location { - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location failover_priority = 0 } } @@ -478,6 +486,9 @@ resource "azurerm_cosmosdb_account" "test" { func testAccAzureRMCosmosDBAccount_completePreReqs(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} resource "azurerm_resource_group" "test" { name = "acctestRG-cosmos-%[1]d" @@ -486,24 +497,24 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctest-VNET-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location dns_servers = ["10.0.0.4", "10.0.0.5"] } resource "azurerm_subnet" "subnet1" { name = "acctest-SN1-%[1]d-1" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" service_endpoints = ["Microsoft.AzureCosmosDB"] } resource "azurerm_subnet" "subnet2" { name = "acctest-SN2-%[1]d-2" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" service_endpoints = ["Microsoft.AzureCosmosDB"] } @@ -512,35 +523,35 @@ resource "azurerm_subnet" "subnet2" { func testAccAzureRMCosmosDBAccount_complete(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) string { return fmt.Sprintf(` - %[1]s resource "azurerm_cosmosdb_account" "test" { name = "acctest-ca-%[2]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name offer_type = "Standard" kind = "%[3]s" consistency_policy { - consistency_level = "%[4]s" - max_staleness_prefix = 170000 + consistency_level = "%[4]s" + max_interval_in_seconds = 300 + max_staleness_prefix = 170000 } is_virtual_network_filter_enabled = true virtual_network_rule { - id = "${azurerm_subnet.subnet1.id}" + id = azurerm_subnet.subnet1.id } virtual_network_rule { - id = "${azurerm_subnet.subnet2.id}" + id = azurerm_subnet.subnet2.id } enable_multiple_write_locations = true geo_location { - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location failover_priority = 0 } @@ -560,13 +571,12 @@ resource "azurerm_cosmosdb_account" "test" { func testAccAzureRMCosmosDBAccount_completeUpdated(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) string { return fmt.Sprintf(` - %[1]s resource "azurerm_cosmosdb_account" "test" { name = "acctest-ca-%[2]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name offer_type = "Standard" kind = "%[3]s" @@ -578,13 +588,13 @@ resource "azurerm_cosmosdb_account" "test" { is_virtual_network_filter_enabled = true virtual_network_rule { - id = "${azurerm_subnet.subnet2.id}" + id = azurerm_subnet.subnet2.id } enable_multiple_write_locations = true geo_location { - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location failover_priority = 0 } @@ -610,6 +620,10 @@ func testAccAzureRMCosmosDBAccount_capabilities(data acceptance.TestData, kind d } return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-cosmos-%d" location = "%s" @@ -617,8 +631,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_cosmosdb_account" "test" { name = "acctest-ca-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name offer_type = "Standard" kind = "%s" @@ -629,7 +643,7 @@ resource "azurerm_cosmosdb_account" "test" { %s geo_location { - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location failover_priority = 0 } } diff --git a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_cassandra_keyspace_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_cassandra_keyspace_test.go index 32194cc66ab9e..03fbef53b7ecb 100644 --- a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_cassandra_keyspace_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_cassandra_keyspace_test.go @@ -142,8 +142,8 @@ func testAccAzureRMCosmosDbCassandraKeyspace_basic(data acceptance.TestData) str resource "azurerm_cosmosdb_cassandra_keyspace" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name } `, testAccAzureRMCosmosDBAccount_capabilities(data, documentdb.GlobalDocumentDB, []string{"EnableCassandra"}), data.RandomInteger) } @@ -154,8 +154,8 @@ func testAccAzureRMCosmosDbCassandraKeyspace_throughput(data acceptance.TestData resource "azurerm_cosmosdb_cassandra_keyspace" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name throughput = %[3]d } diff --git a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_gremlin_database_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_gremlin_database_test.go index 6034bda6d8d67..f9a3a478e12dc 100644 --- a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_gremlin_database_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_gremlin_database_test.go @@ -150,8 +150,8 @@ func testAccAzureRMCosmosGremlinDatabase_basic(data acceptance.TestData) string resource "azurerm_cosmosdb_gremlin_database" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name } `, testAccAzureRMCosmosDBAccount_capabilities(data, documentdb.GlobalDocumentDB, []string{"EnableGremlin"}), data.RandomInteger) } @@ -161,9 +161,9 @@ func testAccAzureRMCosmosDatabase_requiresImport(data acceptance.TestData) strin %s resource "azurerm_cosmosdb_gremlin_database" "import" { - name = "${azurerm_cosmosdb_database.test.name}" - resource_group_name = "${azurerm_cosmosdb_database.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_database.test.account_name}" + name = azurerm_cosmosdb_gremlin_database.test.name + resource_group_name = azurerm_cosmosdb_gremlin_database.test.resource_group_name + account_name = azurerm_cosmosdb_gremlin_database.test.account_name } `, testAccAzureRMCosmosGremlinDatabase_basic(data)) } @@ -174,8 +174,8 @@ func testAccAzureRMCosmosGremlinDatabase_complete(data acceptance.TestData, thro resource "azurerm_cosmosdb_gremlin_database" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name throughput = %[3]d } `, testAccAzureRMCosmosDBAccount_capabilities(data, documentdb.GlobalDocumentDB, []string{"EnableGremlin"}), data.RandomInteger, throughput) diff --git a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_gremlin_graph_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_gremlin_graph_test.go index d8256add53ce2..a5d0c669c979d 100644 --- a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_gremlin_graph_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_gremlin_graph_test.go @@ -189,9 +189,9 @@ func testAccAzureRMCosmosDbGremlinGraph_basic(data acceptance.TestData) string { resource "azurerm_cosmosdb_gremlin_graph" "test" { name = "acctest-CGRPC-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" - database_name = "${azurerm_cosmosdb_gremlin_database.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name + database_name = azurerm_cosmosdb_gremlin_database.test.name throughput = 400 index_policy { @@ -205,7 +205,6 @@ resource "azurerm_cosmosdb_gremlin_graph" "test" { mode = "LastWriterWins" conflict_resolution_path = "/_ts" } - } `, testAccAzureRMCosmosGremlinDatabase_basic(data), data.RandomInteger) } @@ -215,10 +214,22 @@ func testAccAzureRMCosmosDbGremlinGraph_requiresImport(data acceptance.TestData) %s resource "azurerm_cosmosdb_gremlin_graph" "import" { - name = "${azurerm_cosmosdb_gremlin_graph.test.name}" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" - database_name = "${azurerm_cosmosdb_gremlin_database.test.name}" + name = azurerm_cosmosdb_gremlin_graph.test.name + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name + database_name = azurerm_cosmosdb_gremlin_database.test.name + + index_policy { + automatic = true + indexing_mode = "Consistent" + included_paths = ["/*"] + excluded_paths = ["/\"_etag\"/?"] + } + + conflict_resolution_policy { + mode = "LastWriterWins" + conflict_resolution_path = "/_ts" + } } `, testAccAzureRMCosmosDbGremlinGraph_basic(data)) } @@ -229,9 +240,9 @@ func testAccAzureRMCosmosDbGremlinGraph_customConflictResolutionPolicy(data acce resource "azurerm_cosmosdb_gremlin_graph" "test" { name = "acctest-CGRPC-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" - database_name = "${azurerm_cosmosdb_gremlin_database.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name + database_name = azurerm_cosmosdb_gremlin_database.test.name throughput = 400 index_policy { @@ -255,9 +266,9 @@ func testAccAzureRMCosmosDbGremlinGraph_indexPolicy(data acceptance.TestData) st resource "azurerm_cosmosdb_gremlin_graph" "test" { name = "acctest-CGRPC-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" - database_name = "${azurerm_cosmosdb_gremlin_database.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name + database_name = azurerm_cosmosdb_gremlin_database.test.name throughput = 400 index_policy { @@ -279,9 +290,9 @@ func testAccAzureRMCosmosDbGremlinGraph_update(data acceptance.TestData, through resource "azurerm_cosmosdb_gremlin_graph" "test" { name = "acctest-CGRPC-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" - database_name = "${azurerm_cosmosdb_gremlin_database.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name + database_name = azurerm_cosmosdb_gremlin_database.test.name partition_key_path = "/test" throughput = %[3]d diff --git a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_collection_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_collection_test.go index 2e367f08ec700..0a84cb94d9e66 100644 --- a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_collection_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_collection_test.go @@ -185,9 +185,9 @@ func testAccAzureRMCosmosDbMongoCollection_basic(data acceptance.TestData) strin resource "azurerm_cosmosdb_mongo_collection" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_mongo_database.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_mongo_database.test.account_name}" - database_name = "${azurerm_cosmosdb_mongo_database.test.name}" + resource_group_name = azurerm_cosmosdb_mongo_database.test.resource_group_name + account_name = azurerm_cosmosdb_mongo_database.test.account_name + database_name = azurerm_cosmosdb_mongo_database.test.name } `, testAccAzureRMCosmosDbMongoDatabase_basic(data), data.RandomInteger) } @@ -198,9 +198,9 @@ func testAccAzureRMCosmosDbMongoCollection_complete(data acceptance.TestData) st resource "azurerm_cosmosdb_mongo_collection" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_mongo_database.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_mongo_database.test.account_name}" - database_name = "${azurerm_cosmosdb_mongo_database.test.name}" + resource_group_name = azurerm_cosmosdb_mongo_database.test.resource_group_name + account_name = azurerm_cosmosdb_mongo_database.test.account_name + database_name = azurerm_cosmosdb_mongo_database.test.name shard_key = "seven" default_ttl_seconds = 707 @@ -214,9 +214,9 @@ func testAccAzureRMCosmosDbMongoCollection_updated(data acceptance.TestData) str resource "azurerm_cosmosdb_mongo_collection" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_mongo_database.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_mongo_database.test.account_name}" - database_name = "${azurerm_cosmosdb_mongo_database.test.name}" + resource_group_name = azurerm_cosmosdb_mongo_database.test.resource_group_name + account_name = azurerm_cosmosdb_mongo_database.test.account_name + database_name = azurerm_cosmosdb_mongo_database.test.name shard_key = "seven" default_ttl_seconds = 70707 @@ -230,9 +230,9 @@ func testAccAzureRMCosmosDbMongoCollection_throughput(data acceptance.TestData, resource "azurerm_cosmosdb_mongo_collection" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_mongo_database.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_mongo_database.test.account_name}" - database_name = "${azurerm_cosmosdb_mongo_database.test.name}" + resource_group_name = azurerm_cosmosdb_mongo_database.test.resource_group_name + account_name = azurerm_cosmosdb_mongo_database.test.account_name + database_name = azurerm_cosmosdb_mongo_database.test.name throughput = %[3]d } diff --git a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_database_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_database_test.go index 82a211ed1025a..c01c01fc9b96e 100644 --- a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_database_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_database_test.go @@ -113,8 +113,8 @@ func testAccAzureRMCosmosDbMongoDatabase_basic(data acceptance.TestData) string resource "azurerm_cosmosdb_mongo_database" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name } `, testAccAzureRMCosmosDBAccount_basic(data, documentdb.MongoDB, documentdb.Strong), data.RandomInteger) } @@ -125,8 +125,8 @@ func testAccAzureRMCosmosDbMongoDatabase_complete(data acceptance.TestData) stri resource "azurerm_cosmosdb_mongo_database" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name throughput = 700 } `, testAccAzureRMCosmosDBAccount_basic(data, documentdb.MongoDB, documentdb.Strong), data.RandomInteger) diff --git a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_container_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_container_test.go index e2c796a3072b5..e7b4459653d79 100644 --- a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_container_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_container_test.go @@ -148,12 +148,10 @@ func testAccAzureRMCosmosDbSqlContainer_basic(data acceptance.TestData) string { resource "azurerm_cosmosdb_sql_container" "test" { name = "acctest-CSQLC-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" - database_name = "${azurerm_cosmosdb_sql_database.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name + database_name = azurerm_cosmosdb_sql_database.test.name } - - `, testAccAzureRMCosmosDbSqlDatabase_basic(data), data.RandomInteger) } @@ -163,9 +161,9 @@ func testAccAzureRMCosmosDbSqlContainer_complete(data acceptance.TestData) strin resource "azurerm_cosmosdb_sql_container" "test" { name = "acctest-CSQLC-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" - database_name = "${azurerm_cosmosdb_sql_database.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name + database_name = azurerm_cosmosdb_sql_database.test.name partition_key_path = "/definition/id" unique_key { paths = ["/definition/id1", "/definition/id2"] @@ -173,7 +171,6 @@ resource "azurerm_cosmosdb_sql_container" "test" { default_ttl = 500 throughput = 600 } - `, testAccAzureRMCosmosDbSqlDatabase_basic(data), data.RandomInteger) } @@ -183,9 +180,9 @@ func testAccAzureRMCosmosDbSqlContainer_update(data acceptance.TestData) string resource "azurerm_cosmosdb_sql_container" "test" { name = "acctest-CSQLC-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" - database_name = "${azurerm_cosmosdb_sql_database.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name + database_name = azurerm_cosmosdb_sql_database.test.name partition_key_path = "/definition/id" unique_key { paths = ["/definition/id1", "/definition/id2"] @@ -193,6 +190,5 @@ resource "azurerm_cosmosdb_sql_container" "test" { default_ttl = 1000 throughput = 400 } - `, testAccAzureRMCosmosDbSqlDatabase_basic(data), data.RandomInteger) } diff --git a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_database_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_database_test.go index e885ea5bd0261..b59fd9421b56d 100644 --- a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_database_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_database_test.go @@ -124,8 +124,8 @@ func testAccAzureRMCosmosDbSqlDatabase_basic(data acceptance.TestData) string { resource "azurerm_cosmosdb_sql_database" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name } `, testAccAzureRMCosmosDBAccount_basic(data, documentdb.GlobalDocumentDB, documentdb.Strong), data.RandomInteger) } @@ -136,8 +136,8 @@ func testAccAzureRMCosmosDbSqlDatabase_throughput(data acceptance.TestData, thro resource "azurerm_cosmosdb_sql_database" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name throughput = %[3]d } `, testAccAzureRMCosmosDBAccount_basic(data, documentdb.GlobalDocumentDB, documentdb.Strong), data.RandomInteger, throughput) diff --git a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_table_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_table_test.go index 942033cd47bd0..1bd2e3970e816 100644 --- a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_table_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_table_test.go @@ -124,8 +124,8 @@ func testAccAzureRMCosmosDbTable_basic(data acceptance.TestData) string { resource "azurerm_cosmosdb_table" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name } `, testAccAzureRMCosmosDBAccount_capabilities(data, documentdb.GlobalDocumentDB, []string{"EnableTable"}), data.RandomInteger) } @@ -136,8 +136,8 @@ func testAccAzureRMCosmosDbTable_throughput(data acceptance.TestData, throughput resource "azurerm_cosmosdb_table" "test" { name = "acctest-%[2]d" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - account_name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = azurerm_cosmosdb_account.test.resource_group_name + account_name = azurerm_cosmosdb_account.test.name throughput = %[3]d } `, testAccAzureRMCosmosDBAccount_capabilities(data, documentdb.GlobalDocumentDB, []string{"EnableTable"}), data.RandomInteger, throughput) diff --git a/azurerm/internal/services/databasemigration/client/client.go b/azurerm/internal/services/databasemigration/client/client.go new file mode 100644 index 0000000000000..90dba0b7f4943 --- /dev/null +++ b/azurerm/internal/services/databasemigration/client/client.go @@ -0,0 +1,24 @@ +package client + +import ( + "github.com/Azure/azure-sdk-for-go/services/datamigration/mgmt/2018-04-19/datamigration" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common" +) + +type Client struct { + ServicesClient *datamigration.ServicesClient + ProjectsClient *datamigration.ProjectsClient +} + +func NewClient(o *common.ClientOptions) *Client { + servicesClient := datamigration.NewServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&servicesClient.Client, o.ResourceManagerAuthorizer) + + projectsClient := datamigration.NewProjectsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&projectsClient.Client, o.ResourceManagerAuthorizer) + + return &Client{ + ServicesClient: &servicesClient, + ProjectsClient: &projectsClient, + } +} diff --git a/azurerm/internal/services/databasemigration/data_source_database_migration_project.go b/azurerm/internal/services/databasemigration/data_source_database_migration_project.go new file mode 100644 index 0000000000000..ad7aed0b92538 --- /dev/null +++ b/azurerm/internal/services/databasemigration/data_source_database_migration_project.go @@ -0,0 +1,91 @@ +package databasemigration + +import ( + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceArmDatabaseMigrationProject() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmDatabaseMigrationProjectRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validateDatabaseMigrationProjectName, + }, + + "service_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validateDatabaseMigrationServiceName, + }, + + "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + + "location": azure.SchemaLocationForDataSource(), + + "source_platform": { + Type: schema.TypeString, + Computed: true, + }, + + "target_platform": { + Type: schema.TypeString, + Computed: true, + }, + + "tags": tags.SchemaDataSource(), + }, + } +} + +func dataSourceArmDatabaseMigrationProjectRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DatabaseMigration.ProjectsClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + serviceName := d.Get("service_name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + resp, err := client.Get(ctx, resourceGroup, serviceName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error: Database Migration Project (Project Name %q / Service Name %q / Group Name %q) was not found", name, serviceName, resourceGroup) + } + return fmt.Errorf("Error reading Database Migration Project (Project Name %q / Service Name %q / Group Name %q): %+v", name, serviceName, resourceGroup, err) + } + + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("Cannot read Database Migration Project (Project Name %q / Service Name %q / Group Name %q) ID", name, serviceName, resourceGroup) + } + d.SetId(*resp.ID) + + d.Set("resource_group_name", resourceGroup) + + location := "" + if resp.Location != nil { + location = azure.NormalizeLocation(*resp.Location) + } + d.Set("location", location) + + if prop := resp.ProjectProperties; prop != nil { + d.Set("source_platform", string(prop.SourcePlatform)) + d.Set("target_platform", string(prop.TargetPlatform)) + } + + return nil +} diff --git a/azurerm/internal/services/databasemigration/data_source_database_migration_service.go b/azurerm/internal/services/databasemigration/data_source_database_migration_service.go new file mode 100644 index 0000000000000..0ea63e668a5b6 --- /dev/null +++ b/azurerm/internal/services/databasemigration/data_source_database_migration_service.go @@ -0,0 +1,84 @@ +package databasemigration + +import ( + "fmt" + "time" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceArmDatabaseMigrationService() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmDatabaseMigrationServiceRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validateDatabaseMigrationServiceName, + }, + + "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + + "location": azure.SchemaLocationForDataSource(), + + "subnet_id": { + Type: schema.TypeString, + Computed: true, + }, + + "sku_name": { + Type: schema.TypeString, + Computed: true, + }, + + "tags": tags.SchemaDataSource(), + }, + } +} + +func dataSourceArmDatabaseMigrationServiceRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DatabaseMigration.ServicesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + resourceGroup := d.Get("resource_group_name").(string) + name := d.Get("name").(string) + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error: Database Migration Service (Service Name %q / Group Name %q) was not found", name, resourceGroup) + } + return fmt.Errorf("Error reading Database Migration Service (Service Name %q / Group Name %q): %+v", name, resourceGroup, err) + } + + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("unexpected empty ID retrieved for Database Migration Service (Service Name %q / Group Name %q)", name, resourceGroup) + } + d.SetId(*resp.ID) + + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + d.Set("resource_group_name", resourceGroup) + d.Set("name", resp.Name) + if serviceProperties := resp.ServiceProperties; serviceProperties != nil { + d.Set("subnet_id", serviceProperties.VirtualSubnetID) + } + if resp.Sku != nil { + d.Set("sku_name", resp.Sku.Name) + } + + return tags.FlattenAndSet(d, resp.Tags) +} diff --git a/azurerm/internal/services/databasemigration/parse/datamigration_project.go b/azurerm/internal/services/databasemigration/parse/datamigration_project.go new file mode 100644 index 0000000000000..d047ab962f44d --- /dev/null +++ b/azurerm/internal/services/databasemigration/parse/datamigration_project.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DatabaseMigrationProjectId struct { + ResourceGroup string + Service string + Name string +} + +func DatabaseMigrationProjectID(input string) (*DatabaseMigrationProjectId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse Database Migration Project ID %q: %+v", input, err) + } + + project := DatabaseMigrationProjectId{ + ResourceGroup: id.ResourceGroup, + } + + if project.Service, err = id.PopSegment("services"); err != nil { + return nil, err + } + + if project.Name, err = id.PopSegment("projects"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &project, nil +} diff --git a/azurerm/internal/services/databasemigration/parse/datamigration_project_test.go b/azurerm/internal/services/databasemigration/parse/datamigration_project_test.go new file mode 100644 index 0000000000000..53b0505fd01c8 --- /dev/null +++ b/azurerm/internal/services/databasemigration/parse/datamigration_project_test.go @@ -0,0 +1,89 @@ +package parse + +import ( + "testing" +) + +func TestDatabaseMigrationProjectID(t *testing.T) { + testData := []struct { + Name string + Input string + Error bool + Expect *DatabaseMigrationProjectId + }{ + { + Name: "Empty", + Input: "", + Error: true, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Error: true, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Error: true, + }, + { + Name: "No Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Error: true, + }, + { + Name: "Missing service name", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/services", + Error: true, + }, + { + Name: "No Projects Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/services/service1", + Error: true, + }, + { + Name: "Missing project name", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/services/service1/projects", + Error: true, + }, + { + Name: "Service name", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Datamigration/services/service1/projects/project1", + Expect: &DatabaseMigrationProjectId{ + ResourceGroup: "resGroup1", + Service: "service1", + Name: "project1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Datamigration/Services/service1/projects/project1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := DatabaseMigrationProjectID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.ResourceGroup != v.Expect.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expect.ResourceGroup, actual.ResourceGroup) + } + + if actual.Service != v.Expect.Service { + t.Fatalf("Expected %q but got %q for Service", v.Expect.Service, actual.Service) + } + + if actual.Name != v.Expect.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name) + } + } +} diff --git a/azurerm/internal/services/databasemigration/parse/datamigration_service.go b/azurerm/internal/services/databasemigration/parse/datamigration_service.go new file mode 100644 index 0000000000000..afb7961865cdd --- /dev/null +++ b/azurerm/internal/services/databasemigration/parse/datamigration_service.go @@ -0,0 +1,33 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DatabaseMigrationServiceId struct { + ResourceGroup string + Name string +} + +func DatabaseMigrationServiceID(input string) (*DatabaseMigrationServiceId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse Database Migration Service ID %q: %+v", input, err) + } + + server := DatabaseMigrationServiceId{ + ResourceGroup: id.ResourceGroup, + } + + if server.Name, err = id.PopSegment("services"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &server, nil +} diff --git a/azurerm/internal/services/databasemigration/parse/datamigration_service_test.go b/azurerm/internal/services/databasemigration/parse/datamigration_service_test.go new file mode 100644 index 0000000000000..08b84daea08aa --- /dev/null +++ b/azurerm/internal/services/databasemigration/parse/datamigration_service_test.go @@ -0,0 +1,74 @@ +package parse + +import ( + "testing" +) + +func TestDatabaseMigrationServiceID(t *testing.T) { + testData := []struct { + Name string + Input string + Error bool + Expect *DatabaseMigrationServiceId + }{ + { + Name: "Empty", + Input: "", + Error: true, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Error: true, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Error: true, + }, + { + Name: "No Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Error: true, + }, + { + Name: "Missing service name", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/services", + Error: true, + }, + { + Name: "Service name", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Datamigration/services/service1", + Expect: &DatabaseMigrationServiceId{ + ResourceGroup: "resGroup1", + Name: "service1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Datamigration/Services/service1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := DatabaseMigrationServiceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.ResourceGroup != v.Expect.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expect.ResourceGroup, actual.ResourceGroup) + } + + if actual.Name != v.Expect.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name) + } + } +} diff --git a/azurerm/internal/services/databasemigration/registration.go b/azurerm/internal/services/databasemigration/registration.go new file mode 100644 index 0000000000000..7a2c32aae2a38 --- /dev/null +++ b/azurerm/internal/services/databasemigration/registration.go @@ -0,0 +1,37 @@ +package databasemigration + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +type Registration struct{} + +// Name is the name of this Service +func (r Registration) Name() string { + return "Database Migration" +} + +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Database Migration", + } +} + +// SupportedDataSources returns the supported Data Sources supported by this Service +func (r Registration) SupportedDataSources() map[string]*schema.Resource { + return map[string]*schema.Resource{ + "azurerm_database_migration_service": dataSourceArmDatabaseMigrationService(), + "azurerm_database_migration_project": dataSourceArmDatabaseMigrationProject(), + } +} + +// SupportedResources returns the supported Resources supported by this Service +func (r Registration) SupportedResources() map[string]*schema.Resource { + resources := map[string]*schema.Resource{ + "azurerm_database_migration_service": resourceArmDatabaseMigrationService(), + "azurerm_database_migration_project": resourceArmDatabaseMigrationProject(), + } + + return resources +} diff --git a/azurerm/internal/services/databasemigration/resource_arm_database_migration_project.go b/azurerm/internal/services/databasemigration/resource_arm_database_migration_project.go new file mode 100644 index 0000000000000..137ce4d6188ac --- /dev/null +++ b/azurerm/internal/services/databasemigration/resource_arm_database_migration_project.go @@ -0,0 +1,190 @@ +package databasemigration + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/datamigration/mgmt/2018-04-19/datamigration" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmDatabaseMigrationProject() *schema.Resource { + return &schema.Resource{ + Create: resourceArmDatabaseMigrationProjectCreateUpdate, + Read: resourceArmDatabaseMigrationProjectRead, + Update: resourceArmDatabaseMigrationProjectCreateUpdate, + Delete: resourceArmDatabaseMigrationProjectDelete, + + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DatabaseMigrationProjectID(id) + return err + }), + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateDatabaseMigrationProjectName, + }, + + "service_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateDatabaseMigrationServiceName, + }, + + "resource_group_name": azure.SchemaResourceGroupName(), + + "location": azure.SchemaLocation(), + + "source_platform": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + // Now that go sdk only export SQL as source platform type, we only allow it here. + string(datamigration.ProjectSourcePlatformSQL), + }, false), + }, + + "target_platform": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + // Now that go sdk only export SQL as source platform type, we only allow it here. + string(datamigration.ProjectTargetPlatformSQLDB), + }, false), + }, + + "tags": tags.Schema(), + }, + } +} + +func resourceArmDatabaseMigrationProjectCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DatabaseMigration.ProjectsClient + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + serviceName := d.Get("service_name").(string) + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + existing, err := client.Get(ctx, resourceGroup, serviceName, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for present of existing Database Migration Project (Project Name: %q / Service Name %q / Group Name %q): %+v", name, serviceName, resourceGroup, err) + } + } + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_database_migration_project", *existing.ID) + } + } + + location := azure.NormalizeLocation(d.Get("location").(string)) + sourcePlatform := d.Get("source_platform").(string) + targetPlatform := d.Get("target_platform").(string) + t := d.Get("tags").(map[string]interface{}) + + parameters := datamigration.Project{ + Location: utils.String(location), + ProjectProperties: &datamigration.ProjectProperties{ + SourcePlatform: datamigration.ProjectSourcePlatform(sourcePlatform), + TargetPlatform: datamigration.ProjectTargetPlatform(targetPlatform), + }, + Tags: tags.Expand(t), + } + + if _, err := client.CreateOrUpdate(ctx, parameters, resourceGroup, serviceName, name); err != nil { + return fmt.Errorf("Error creating Database Migration Project (Project Name %q / Service Name %q / Group Name %q): %+v", name, serviceName, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, serviceName, name) + if err != nil { + return fmt.Errorf("Error retrieving Database Migration Project (Project Name %q / Service Name %q / Group Name %q): %+v", name, serviceName, resourceGroup, err) + } + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("Cannot read Database Migration Project (Project Name %q / Service Name %q / Group Name %q) ID", name, serviceName, resourceGroup) + } + d.SetId(*resp.ID) + + return resourceArmDatabaseMigrationProjectRead(d, meta) +} + +func resourceArmDatabaseMigrationProjectRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DatabaseMigration.ProjectsClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.DatabaseMigrationProjectID(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.Service, id.Name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Database Migration Project %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading Database Migration Project (Project Name %q / Service Name %q / Group Name %q): %+v", id.Name, id.Service, id.ResourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("service_name", id.Service) + d.Set("resource_group_name", id.ResourceGroup) + + location := "" + if resp.Location != nil { + location = azure.NormalizeLocation(*resp.Location) + } + d.Set("location", location) + + if prop := resp.ProjectProperties; prop != nil { + d.Set("source_platform", string(prop.SourcePlatform)) + d.Set("target_platform", string(prop.TargetPlatform)) + } + + return tags.FlattenAndSet(d, resp.Tags) +} + +func resourceArmDatabaseMigrationProjectDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DatabaseMigration.ProjectsClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.DatabaseMigrationProjectID(d.Id()) + if err != nil { + return err + } + + deleteRunningTasks := false + if _, err := client.Delete(ctx, id.ResourceGroup, id.Service, id.Name, &deleteRunningTasks); err != nil { + return fmt.Errorf("Error deleting Database Migration Project (Project Name %q / Service Name %q / Group Name %q): %+v", id.Name, id.Service, id.ResourceGroup, err) + } + + return nil +} diff --git a/azurerm/internal/services/databasemigration/resource_arm_database_migration_service.go b/azurerm/internal/services/databasemigration/resource_arm_database_migration_service.go new file mode 100644 index 0000000000000..508cd93d0a4a1 --- /dev/null +++ b/azurerm/internal/services/databasemigration/resource_arm_database_migration_service.go @@ -0,0 +1,231 @@ +package databasemigration + +import ( + "fmt" + "log" + "time" + + "github.com/hashicorp/go-azure-helpers/response" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + + "github.com/Azure/azure-sdk-for-go/services/datamigration/mgmt/2018-04-19/datamigration" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmDatabaseMigrationService() *schema.Resource { + return &schema.Resource{ + Create: resourceArmDatabaseMigrationServiceCreate, + Read: resourceArmDatabaseMigrationServiceRead, + Update: resourceArmDatabaseMigrationServiceUpdate, + Delete: resourceArmDatabaseMigrationServiceDelete, + + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DatabaseMigrationServiceID(id) + return err + }), + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateDatabaseMigrationServiceName, + }, + + "location": azure.SchemaLocation(), + + "resource_group_name": azure.SchemaResourceGroupName(), + + "subnet_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, + }, + + "sku_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + // No const defined in go sdk, the literal listed below is derived from the response of listskus endpoint. + // See: https://docs.microsoft.com/en-us/rest/api/datamigration/resourceskus/listskus + "Premium_4vCores", + "Standard_1vCores", + "Standard_2vCores", + "Standard_4vCores", + }, false), + }, + + "tags": tags.Schema(), + }, + } +} + +func resourceArmDatabaseMigrationServiceCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DatabaseMigration.ServicesClient + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) + defer cancel() + + resourceGroup := d.Get("resource_group_name").(string) + name := d.Get("name").(string) + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + existing, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for present of existing Database Migration Service (Service Name %q / Group Name %q): %+v", name, resourceGroup, err) + } + } + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_database_migration_service", *existing.ID) + } + } + + skuName := d.Get("sku_name").(string) + subnetID := d.Get("subnet_id").(string) + location := azure.NormalizeLocation(d.Get("location").(string)) + + parameters := datamigration.Service{ + Location: utils.String(location), + ServiceProperties: &datamigration.ServiceProperties{ + VirtualSubnetID: utils.String(subnetID), + }, + Sku: &datamigration.ServiceSku{ + Name: utils.String(skuName), + }, + Kind: utils.String("Cloud"), // currently only "Cloud" is supported, hence hardcode here + } + if t, ok := d.GetOk("tags"); ok { + parameters.Tags = tags.Expand(t.(map[string]interface{})) + } + + future, err := client.CreateOrUpdate(ctx, parameters, resourceGroup, name) + if err != nil { + return fmt.Errorf("Error creating Database Migration Service (Service Name %q / Group Name %q): %+v", name, resourceGroup, err) + } + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for creation of Database Migration Service (Service Name %q / Group Name %q): %+v", name, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Error retrieving Database Migration Service (Service Name %q / Group Name %q): %+v", name, resourceGroup, err) + } + if resp.ID == nil { + return fmt.Errorf("Cannot read Database Migration Service (Service Name %q / Group Name %q) ID", name, resourceGroup) + } + d.SetId(*resp.ID) + + return resourceArmDatabaseMigrationServiceRead(d, meta) +} + +func resourceArmDatabaseMigrationServiceRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DatabaseMigration.ServicesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.DatabaseMigrationServiceID(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Database Migration Service %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading Database Migration Service (Service Name %q / Group Name %q): %+v", id.Name, id.ResourceGroup, err) + } + + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("unexpected empty ID retrieved for Database Migration Service (Service Name %q / Group Name %q)", id.Name, id.ResourceGroup) + } + d.SetId(*resp.ID) + + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + d.Set("resource_group_name", id.ResourceGroup) + d.Set("name", id.Name) + if serviceProperties := resp.ServiceProperties; serviceProperties != nil { + d.Set("subnet_id", serviceProperties.VirtualSubnetID) + } + if resp.Sku != nil { + d.Set("sku_name", resp.Sku.Name) + } + + return tags.FlattenAndSet(d, resp.Tags) +} + +func resourceArmDatabaseMigrationServiceUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DatabaseMigration.ServicesClient + ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.DatabaseMigrationServiceID(d.Id()) + if err != nil { + return err + } + + parameters := datamigration.Service{ + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), + } + + future, err := client.Update(ctx, parameters, id.ResourceGroup, id.Name) + if err != nil { + return fmt.Errorf("Error updating Database Migration Service (Service Name %q / Group Name %q): %+v", id.Name, id.ResourceGroup, err) + } + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for update of Database Migration Service (Service Name %q / Group Name %q): %+v", id.Name, id.ResourceGroup, err) + } + + return resourceArmDatabaseMigrationServiceRead(d, meta) +} + +func resourceArmDatabaseMigrationServiceDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DatabaseMigration.ServicesClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.DatabaseMigrationServiceID(d.Id()) + if err != nil { + return err + } + + // Always leave outstanding migration tasks untouched when deleting DMS. This is to avoid unexpectedly delete any tasks managed out of terraform. + toDeleteRunningTasks := false + future, err := client.Delete(ctx, id.ResourceGroup, id.Name, &toDeleteRunningTasks) + if err != nil { + if response.WasNotFound(future.Response()) { + return nil + } + return fmt.Errorf("Error deleting Database Migration Service (Service Name %q / Group Name %q): %+v", id.Name, id.ResourceGroup, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + if !response.WasNotFound(future.Response()) { + return fmt.Errorf("Error waiting for deleting Database Migration Service (Service Name %q / Group Name %q): %+v", id.Name, id.ResourceGroup, err) + } + } + + return nil +} diff --git a/azurerm/internal/services/databasemigration/tests/data_source_database_migration_project_test.go b/azurerm/internal/services/databasemigration/tests/data_source_database_migration_project_test.go new file mode 100644 index 0000000000000..cf3f20fcf62dc --- /dev/null +++ b/azurerm/internal/services/databasemigration/tests/data_source_database_migration_project_test.go @@ -0,0 +1,40 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMDatabaseMigrationProject_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_database_migration_project", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceDatabaseMigrationProject_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "source_platform", "SQL"), + resource.TestCheckResourceAttr(data.ResourceName, "target_platform", "SQLDB"), + ), + }, + }, + }) +} + +func testAccDataSourceDatabaseMigrationProject_basic(data acceptance.TestData) string { + config := testAccAzureRMDatabaseMigrationProject_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_database_migration_project" "test" { + name = azurerm_database_migration_project.test.name + service_name = azurerm_database_migration_project.test.service_name + resource_group_name = azurerm_database_migration_project.test.resource_group_name +} +`, config) +} diff --git a/azurerm/internal/services/databasemigration/tests/data_source_database_migration_service_test.go b/azurerm/internal/services/databasemigration/tests/data_source_database_migration_service_test.go new file mode 100644 index 0000000000000..c40a4d2b7b2a7 --- /dev/null +++ b/azurerm/internal/services/databasemigration/tests/data_source_database_migration_service_test.go @@ -0,0 +1,39 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMDatabaseMigrationService_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_database_migration_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceDatabaseMigrationService_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "Standard_1vCores"), + ), + }, + }, + }) +} + +func testAccDataSourceDatabaseMigrationService_basic(data acceptance.TestData) string { + config := testAccAzureRMDatabaseMigrationService_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_database_migration_service" "test" { + resource_group_name = "${azurerm_database_migration_service.test.resource_group_name}" + name = "${azurerm_database_migration_service.test.name}" +} +`, config) +} diff --git a/azurerm/internal/services/databasemigration/tests/resource_arm_database_migration_project_test.go b/azurerm/internal/services/databasemigration/tests/resource_arm_database_migration_project_test.go new file mode 100644 index 0000000000000..1324a9992fe6c --- /dev/null +++ b/azurerm/internal/services/databasemigration/tests/resource_arm_database_migration_project_test.go @@ -0,0 +1,216 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration/parse" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMDatabaseMigrationProject_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_database_migration_project", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDatabaseMigrationProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDatabaseMigrationProject_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDatabaseMigrationProjectExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "source_platform", "SQL"), + resource.TestCheckResourceAttr(data.ResourceName, "target_platform", "SQLDB"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMDatabaseMigrationProject_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_database_migration_project", "test") + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDatabaseMigrationProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDatabaseMigrationProject_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDatabaseMigrationProjectExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "source_platform", "SQL"), + resource.TestCheckResourceAttr(data.ResourceName, "target_platform", "SQLDB"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.name", "Test"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMDatabaseMigrationProject_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + + data := acceptance.BuildTestData(t, "azurerm_database_migration_project", "test") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDatabaseMigrationProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDatabaseMigrationProject_basic(data), + }, + data.RequiresImportErrorStep(testAccAzureRMDatabaseMigrationProject_requiresImport), + }, + }) +} + +func TestAccAzureRMDatabaseMigrationProject_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_database_migration_project", "test") + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDatabaseMigrationProjectDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDatabaseMigrationProject_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDatabaseMigrationProjectExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMDatabaseMigrationProject_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDatabaseMigrationProjectExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.name", "Test"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMDatabaseMigrationProject_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDatabaseMigrationProjectExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMDatabaseMigrationProjectExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Database Migration Project not found: %s", resourceName) + } + + id, err := parse.DatabaseMigrationProjectID(rs.Primary.ID) + if err != nil { + return err + } + + client := acceptance.AzureProvider.Meta().(*clients.Client).DatabaseMigration.ProjectsClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + if resp, err := client.Get(ctx, id.ResourceGroup, id.Service, id.Name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Database Migration Project (Project Name %q / Service Name %q / Group Name %q) does not exist", id.Name, id.Service, id.ResourceGroup) + } + return fmt.Errorf("Bad: Get on ProjectsClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMDatabaseMigrationProjectDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).DatabaseMigration.ProjectsClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_database_migration_project" { + continue + } + + id, err := parse.DatabaseMigrationProjectID(rs.Primary.ID) + if err != nil { + return err + } + + if resp, err := client.Get(ctx, id.ResourceGroup, id.Service, id.Name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on ProjectsClient: %+v", err) + } + } + + return nil + } + + return nil +} + +func testAccAzureRMDatabaseMigrationProject_basic(data acceptance.TestData) string { + template := testAccAzureRMDatabaseMigrationService_basic(data) + + return fmt.Sprintf(` +%s + +resource "azurerm_database_migration_project" "test" { + name = "acctestDbmsProject-%d" + service_name = azurerm_database_migration_service.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + source_platform = "SQL" + target_platform = "SQLDB" +} +`, template, data.RandomInteger) +} + +func testAccAzureRMDatabaseMigrationProject_complete(data acceptance.TestData) string { + template := testAccAzureRMDatabaseMigrationService_basic(data) + + return fmt.Sprintf(` +%s + +resource "azurerm_database_migration_project" "test" { + name = "acctestDbmsProject-%d" + service_name = azurerm_database_migration_service.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + source_platform = "SQL" + target_platform = "SQLDB" + tags = { + name = "Test" + } +} +`, template, data.RandomInteger) +} + +func testAccAzureRMDatabaseMigrationProject_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDatabaseMigrationProject_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_database_migration_project" "import" { + name = azurerm_database_migration_project.test.name + service_name = azurerm_database_migration_project.test.service_name + resource_group_name = azurerm_database_migration_project.test.resource_group_name + location = azurerm_database_migration_project.test.location + source_platform = azurerm_database_migration_project.test.source_platform + target_platform = azurerm_database_migration_project.test.target_platform +} +`, template) +} diff --git a/azurerm/internal/services/databasemigration/tests/resource_arm_database_migration_service_test.go b/azurerm/internal/services/databasemigration/tests/resource_arm_database_migration_service_test.go new file mode 100644 index 0000000000000..147c556529666 --- /dev/null +++ b/azurerm/internal/services/databasemigration/tests/resource_arm_database_migration_service_test.go @@ -0,0 +1,244 @@ +package azurerm + +import ( + "fmt" + "testing" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databasemigration/parse" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMDatabaseMigrationService_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_database_migration_service", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDatabaseMigrationServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDatabaseMigrationService_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDatabaseMigrationServiceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "Standard_1vCores"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMDatabaseMigrationService_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_database_migration_service", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDatabaseMigrationServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDatabaseMigrationService_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDatabaseMigrationServiceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "Standard_1vCores"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.name", "test"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMDatabaseMigrationService_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + + data := acceptance.BuildTestData(t, "azurerm_database_migration_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDatabaseMigrationServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDatabaseMigrationService_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDatabaseMigrationServiceExists(data.ResourceName), + ), + }, + data.RequiresImportErrorStep(testAccAzureRMDatabaseMigrationService_requiresImport), + }, + }) +} + +func TestAccAzureRMDatabaseMigrationService_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_database_migration_service", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDatabaseMigrationServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDatabaseMigrationService_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDatabaseMigrationServiceExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMDatabaseMigrationService_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDatabaseMigrationServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.name", "test"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMDatabaseMigrationService_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDatabaseMigrationServiceExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMDatabaseMigrationServiceExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Database Migration Service not found: %s", resourceName) + } + + id, err := parse.DatabaseMigrationServiceID(rs.Primary.ID) + if err != nil { + return err + } + + client := acceptance.AzureProvider.Meta().(*clients.Client).DatabaseMigration.ServicesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + if resp, err := client.Get(ctx, id.ResourceGroup, id.Name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Database Migration Service (Service Name %q / Group Name %q) does not exist", id.Name, id.ResourceGroup) + } + return fmt.Errorf("Bad: Get on ServicesClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMDatabaseMigrationServiceDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).DatabaseMigration.ServicesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_database_migration_service" { + continue + } + + id, err := parse.DatabaseMigrationServiceID(rs.Primary.ID) + if err != nil { + return err + } + + if resp, err := client.Get(ctx, id.ResourceGroup, id.Name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on ServicesClient: %+v", err) + } + } + + return nil + } + + return nil +} + +func testAccAzureRMDatabaseMigrationService_base(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-dbms-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctestVnet-dbms-%d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_subnet" "test" { + name = "acctestSubnet-dbms-%d" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.1.0/24" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMDatabaseMigrationService_basic(data acceptance.TestData) string { + template := testAccAzureRMDatabaseMigrationService_base(data) + + return fmt.Sprintf(` +%s + +resource "azurerm_database_migration_service" "test" { + name = "acctestDbms-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + subnet_id = azurerm_subnet.test.id + sku_name = "Standard_1vCores" +} +`, template, data.RandomInteger) +} + +func testAccAzureRMDatabaseMigrationService_complete(data acceptance.TestData) string { + template := testAccAzureRMDatabaseMigrationService_base(data) + + return fmt.Sprintf(` +%s + +resource "azurerm_database_migration_service" "test" { + name = "acctestDbms-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + subnet_id = azurerm_subnet.test.id + sku_name = "Standard_1vCores" + tags = { + name = "test" + } +} +`, template, data.RandomInteger) +} + +func testAccAzureRMDatabaseMigrationService_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDatabaseMigrationService_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_database_migration_service" "import" { + name = azurerm_database_migration_service.test.name + location = azurerm_database_migration_service.test.location + resource_group_name = azurerm_database_migration_service.test.resource_group_name + subnet_id = azurerm_database_migration_service.test.subnet_id + sku_name = azurerm_database_migration_service.test.sku_name +} +`, template) +} diff --git a/azurerm/internal/services/databasemigration/validation.go b/azurerm/internal/services/databasemigration/validation.go new file mode 100644 index 0000000000000..025529197cc59 --- /dev/null +++ b/azurerm/internal/services/databasemigration/validation.go @@ -0,0 +1,30 @@ +package databasemigration + +import ( + "fmt" + "regexp" +) + +func validateDatabaseMigrationServiceName(i interface{}, k string) ([]string, []error) { + v, ok := i.(string) + if !ok { + return nil, []error{fmt.Errorf("expected type of %q to be string", k)} + } + validName := regexp.MustCompile(`^[\d\w]+[\d\w\-_.]*$`) + if !validName.MatchString(v) { + return nil, []error{fmt.Errorf("invalid format of %q", k)} + } + return nil, nil +} + +func validateDatabaseMigrationProjectName(i interface{}, k string) ([]string, []error) { + v, ok := i.(string) + if !ok { + return nil, []error{fmt.Errorf("expected type of %q to be string", k)} + } + validName := regexp.MustCompile(`^[\d\w]+[\d\w\-_.]*$`) + if !validName.MatchString(v) { + return nil, []error{fmt.Errorf("invalid format of %q", k)} + } + return nil, nil +} diff --git a/azurerm/internal/services/databricks/registration.go b/azurerm/internal/services/databricks/registration.go index e68248aed3a24..e4fafb5d57eab 100644 --- a/azurerm/internal/services/databricks/registration.go +++ b/azurerm/internal/services/databricks/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "DataBricks" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Databricks", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{} diff --git a/azurerm/internal/services/databricks/resource_arm_databricks_workspace.go b/azurerm/internal/services/databricks/resource_arm_databricks_workspace.go index bdffef8b4005a..38a5a1a2d2c5c 100644 --- a/azurerm/internal/services/databricks/resource_arm_databricks_workspace.go +++ b/azurerm/internal/services/databricks/resource_arm_databricks_workspace.go @@ -149,7 +149,7 @@ func resourceArmDatabricksWorkspaceCreateUpdate(d *schema.ResourceData, meta int expandedTags := tags.Expand(t) if managedResourceGroupName == "" { - //no managed resource group name was provided, we use the default pattern + // no managed resource group name was provided, we use the default pattern log.Printf("[DEBUG][azurerm_databricks_workspace] no managed resource group id was provided, we use the default pattern.") managedResourceGroupID = fmt.Sprintf("/subscriptions/%s/resourceGroups/databricks-rg-%s", subscriptionID, resourceGroup) } else { diff --git a/azurerm/internal/services/databricks/tests/resource_arm_databricks_workspace_test.go b/azurerm/internal/services/databricks/tests/resource_arm_databricks_workspace_test.go index 65bd9fbb5ce8e..77e40a8f08479 100644 --- a/azurerm/internal/services/databricks/tests/resource_arm_databricks_workspace_test.go +++ b/azurerm/internal/services/databricks/tests/resource_arm_databricks_workspace_test.go @@ -246,6 +246,10 @@ func testCheckAzureRMDatabricksWorkspaceDestroy(s *terraform.State) error { func testAccAzureRMDatabricksWorkspace_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-db-%d" location = "%s" @@ -253,8 +257,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_databricks_workspace" "test" { name = "acctestDBW-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "standard" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -266,16 +270,20 @@ func testAccAzureRMDatabricksWorkspace_requiresImport(data acceptance.TestData) %s resource "azurerm_databricks_workspace" "import" { - name = "${azurerm_databricks_workspace.test.name}" - resource_group_name = "${azurerm_databricks_workspace.test.resource_group_name}" - location = "${azurerm_databricks_workspace.test.location}" - sku = "${azurerm_databricks_workspace.test.sku}" + name = azurerm_databricks_workspace.test.name + resource_group_name = azurerm_databricks_workspace.test.resource_group_name + location = azurerm_databricks_workspace.test.location + sku = azurerm_databricks_workspace.test.sku } `, template) } func testAccAzureRMDatabricksWorkspace_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-db-%[1]d" @@ -284,15 +292,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctest-vnet-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "public" { name = "acctest-sn-public-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" delegation { @@ -308,16 +316,12 @@ resource "azurerm_subnet" "public" { ] } } - - lifecycle { - ignore_changes = ["network_security_group_id"] - } } resource "azurerm_subnet" "private" { name = "acctest-sn-private-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" delegation { @@ -333,40 +337,36 @@ resource "azurerm_subnet" "private" { ] } } - - lifecycle { - ignore_changes = ["network_security_group_id"] - } } resource "azurerm_network_security_group" "nsg" { name = "acctest-nsg-private-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet_network_security_group_association" "public" { - subnet_id = "${azurerm_subnet.public.id}" - network_security_group_id = "${azurerm_network_security_group.nsg.id}" + subnet_id = azurerm_subnet.public.id + network_security_group_id = azurerm_network_security_group.nsg.id } resource "azurerm_subnet_network_security_group_association" "private" { - subnet_id = "${azurerm_subnet.private.id}" - network_security_group_id = "${azurerm_network_security_group.nsg.id}" + subnet_id = azurerm_subnet.private.id + network_security_group_id = azurerm_network_security_group.nsg.id } resource "azurerm_databricks_workspace" "test" { name = "acctestDBW-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "standard" managed_resource_group_name = "acctestRG-DBW-%[1]d-managed" custom_parameters { no_public_ip = true - public_subnet_name = "${azurerm_subnet.public.name}" - private_subnet_name = "${azurerm_subnet.private.name}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + public_subnet_name = azurerm_subnet.public.name + private_subnet_name = azurerm_subnet.private.name + virtual_network_id = azurerm_virtual_network.test.id } tags = { @@ -379,6 +379,10 @@ resource "azurerm_databricks_workspace" "test" { func testAccAzureRMDatabricksWorkspace_completeUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-db-%d" location = "%s" @@ -386,8 +390,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_databricks_workspace" "test" { name = "acctestDBW-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "standard" managed_resource_group_name = "acctestRG-DBW-%d-managed" diff --git a/azurerm/internal/services/datafactory/registration.go b/azurerm/internal/services/datafactory/registration.go index a47d4dd56da73..4f40b84445f68 100644 --- a/azurerm/internal/services/datafactory/registration.go +++ b/azurerm/internal/services/datafactory/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Data Factory" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Data Factory", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule.go index e6cd3e8d026a6..5f08bfa4ea0ce 100644 --- a/azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule.go @@ -63,7 +63,7 @@ func resourceArmDataFactoryTriggerSchedule() *schema.Resource { Optional: true, Computed: true, DiffSuppressFunc: suppress.RFC3339Time, - ValidateFunc: validate.RFC3339Time, //times in the past just start immediately + ValidateFunc: validation.IsRFC3339Time, // times in the past just start immediately }, // This time can only be represented in UTC. @@ -73,7 +73,7 @@ func resourceArmDataFactoryTriggerSchedule() *schema.Resource { Type: schema.TypeString, Optional: true, DiffSuppressFunc: suppress.RFC3339Time, - ValidateFunc: validate.RFC3339Time, //times in the past just start immediately + ValidateFunc: validation.IsRFC3339Time, // times in the past just start immediately }, "frequency": { @@ -154,14 +154,14 @@ func resourceArmDataFactoryTriggerScheduleCreateUpdate(d *schema.ResourceData, m } if v, ok := d.GetOk("start_time"); ok { - t, _ := time.Parse(time.RFC3339, v.(string)) //should be validated by the schema + t, _ := time.Parse(time.RFC3339, v.(string)) // should be validated by the schema props.Recurrence.StartTime = &date.Time{Time: t} } else { props.Recurrence.StartTime = &date.Time{Time: time.Now()} } if v, ok := d.GetOk("end_time"); ok { - t, _ := time.Parse(time.RFC3339, v.(string)) //should be validated by the schema + t, _ := time.Parse(time.RFC3339, v.(string)) // should be validated by the schema props.Recurrence.EndTime = &date.Time{Time: t} } diff --git a/azurerm/internal/services/datafactory/tests/data_source_data_factory_test.go b/azurerm/internal/services/datafactory/tests/data_source_data_factory_test.go index 293f3f96b5177..0b1016581281f 100644 --- a/azurerm/internal/services/datafactory/tests/data_source_data_factory_test.go +++ b/azurerm/internal/services/datafactory/tests/data_source_data_factory_test.go @@ -32,8 +32,8 @@ func testAccAzureRMDataFactoryDataSource_basic(data acceptance.TestData) string %s data "azurerm_data_factory" "test" { - name = "${azurerm_data_factory.test.name}" - resource_group_name = "${azurerm_data_factory.test.resource_group_name}" + name = azurerm_data_factory.test.name + resource_group_name = azurerm_data_factory.test.resource_group_name } `, config) } diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_mysql_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_mysql_test.go index 3d31c3f7a88ac..c21a6340f19eb 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_mysql_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_mysql_test.go @@ -126,6 +126,10 @@ func testCheckAzureRMDataFactoryDatasetMySQLDestroy(s *terraform.State) error { func testAccAzureRMDataFactoryDatasetMySQL_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -133,28 +137,32 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_mysql" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Server=test;Port=3306;Database=test;User=test;SSLMode=1;UseSystemTrustStore=0;Password=test" } resource "azurerm_data_factory_dataset_mysql" "test" { name = "acctestds%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" - linked_service_name = "${azurerm_data_factory_linked_service_mysql.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + linked_service_name = azurerm_data_factory_linked_service_mysql.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDataFactoryDatasetMySQL_update1(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -162,22 +170,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_mysql" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Server=test;Port=3306;Database=test;User=test;SSLMode=1;UseSystemTrustStore=0;Password=test" } resource "azurerm_data_factory_dataset_mysql" "test" { name = "acctestds%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" - linked_service_name = "${azurerm_data_factory_linked_service_mysql.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + linked_service_name = azurerm_data_factory_linked_service_mysql.test.name description = "test description" annotations = ["test1", "test2", "test3"] @@ -205,6 +213,10 @@ resource "azurerm_data_factory_dataset_mysql" "test" { func testAccAzureRMDataFactoryDatasetMySQL_update2(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -212,22 +224,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_mysql" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Server=test;Port=3306;Database=test;User=test;SSLMode=1;UseSystemTrustStore=0;Password=test" } resource "azurerm_data_factory_dataset_mysql" "test" { name = "acctestds%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" - linked_service_name = "${azurerm_data_factory_linked_service_mysql.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + linked_service_name = azurerm_data_factory_linked_service_mysql.test.name description = "test description 2" annotations = ["test1", "test2"] diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_postgresql_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_postgresql_test.go index 832c9cc240844..efa4ef87dc1de 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_postgresql_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_postgresql_test.go @@ -126,6 +126,10 @@ func testCheckAzureRMDataFactoryDatasetPostgreSQLDestroy(s *terraform.State) err func testAccAzureRMDataFactoryDatasetPostgreSQL_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -133,28 +137,32 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_postgresql" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Host=example;Port=5432;Database=example;UID=example;EncryptionMethod=0;Password=example" } resource "azurerm_data_factory_dataset_postgresql" "test" { name = "acctestds%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" - linked_service_name = "${azurerm_data_factory_linked_service_postgresql.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + linked_service_name = azurerm_data_factory_linked_service_postgresql.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDataFactoryDatasetPostgreSQL_update1(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -162,22 +170,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_postgresql" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Host=example;Port=5432;Database=example;UID=example;EncryptionMethod=0;Password=example" } resource "azurerm_data_factory_dataset_postgresql" "test" { name = "acctestds%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" - linked_service_name = "${azurerm_data_factory_linked_service_postgresql.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + linked_service_name = azurerm_data_factory_linked_service_postgresql.test.name description = "test description" annotations = ["test1", "test2", "test3"] @@ -205,6 +213,10 @@ resource "azurerm_data_factory_dataset_postgresql" "test" { func testAccAzureRMDataFactoryDatasetPostgreSQL_update2(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -212,22 +224,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_postgresql" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Host=example;Port=5432;Database=example;UID=example;EncryptionMethod=0;Password=example" } resource "azurerm_data_factory_dataset_postgresql" "test" { name = "acctestds%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" - linked_service_name = "${azurerm_data_factory_linked_service_postgresql.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + linked_service_name = azurerm_data_factory_linked_service_postgresql.test.name description = "test description 2" annotations = ["test1", "test2"] diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_sql_server_table_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_sql_server_table_test.go index dc31507646d8b..795d6ffcca720 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_sql_server_table_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_sql_server_table_test.go @@ -126,6 +126,10 @@ func testCheckAzureRMDataFactoryDatasetSQLServerTableDestroy(s *terraform.State) func testAccAzureRMDataFactoryDatasetSQLServerTable_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -133,28 +137,32 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_sql_server" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test" } resource "azurerm_data_factory_dataset_sql_server_table" "test" { name = "acctestds%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" - linked_service_name = "${azurerm_data_factory_linked_service_sql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + linked_service_name = azurerm_data_factory_linked_service_sql_server.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDataFactoryDatasetSQLServerTable_update1(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -162,22 +170,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_sql_server" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test" } resource "azurerm_data_factory_dataset_sql_server_table" "test" { name = "acctestds%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" - linked_service_name = "${azurerm_data_factory_linked_service_sql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + linked_service_name = azurerm_data_factory_linked_service_sql_server.test.name description = "test description" annotations = ["test1", "test2", "test3"] @@ -205,6 +213,10 @@ resource "azurerm_data_factory_dataset_sql_server_table" "test" { func testAccAzureRMDataFactoryDatasetSQLServerTable_update2(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -212,22 +224,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_sql_server" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test" } resource "azurerm_data_factory_dataset_sql_server_table" "test" { name = "acctestds%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" - linked_service_name = "${azurerm_data_factory_linked_service_sql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + linked_service_name = azurerm_data_factory_linked_service_sql_server.test.name description = "test description 2" annotations = ["test1", "test2"] diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_integration_runtime_managed_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_integration_runtime_managed_test.go index 97294b8264076..02be30c791af1 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_integration_runtime_managed_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_integration_runtime_managed_test.go @@ -101,6 +101,10 @@ func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_customSetupScript(t *tes func testAccAzureRMDataFactoryIntegrationRuntimeManaged_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -129,6 +133,10 @@ resource "azurerm_data_factory_integration_runtime_managed" "test" { func testAccAzureRMDataFactoryIntegrationRuntimeManaged_vnetIntegration(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -172,6 +180,10 @@ resource "azurerm_data_factory_integration_runtime_managed" "test" { func testAccAzureRMDataFactoryIntegrationRuntimeManaged_catalogInfo(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -212,6 +224,10 @@ resource "azurerm_data_factory_integration_runtime_managed" "test" { func testAccAzureRMDataFactoryIntegrationRuntimeManaged_customSetupScript(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go index ae4596366fda3..e86b754ddf604 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go @@ -124,6 +124,10 @@ func testCheckAzureRMDataFactoryLinkedServiceDataLakeStorageGen2Destroy(s *terra func testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -131,17 +135,18 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } -data "azurerm_client_config" "current" {} +data "azurerm_client_config" "current" { +} resource "azurerm_data_factory_linked_service_data_lake_storage_gen2" "test" { name = "acctestDataLake%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" - service_principal_id = "${data.azurerm_client_config.current.client_id}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + service_principal_id = data.azurerm_client_config.current.client_id service_principal_key = "testkey" tenant = "11111111-1111-1111-1111-111111111111" url = "https://test.azure.com" @@ -151,6 +156,10 @@ resource "azurerm_data_factory_linked_service_data_lake_storage_gen2" "test" { func testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_update1(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -158,17 +167,18 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } -data "azurerm_client_config" "current" {} +data "azurerm_client_config" "current" { +} resource "azurerm_data_factory_linked_service_data_lake_storage_gen2" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" - service_principal_id = "${data.azurerm_client_config.current.client_id}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + service_principal_id = data.azurerm_client_config.current.client_id service_principal_key = "testkey" tenant = "11111111-1111-1111-1111-111111111111" url = "https://test.azure.com" @@ -190,6 +200,10 @@ resource "azurerm_data_factory_linked_service_data_lake_storage_gen2" "test" { func testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_update2(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -197,17 +211,18 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } -data "azurerm_client_config" "current" {} +data "azurerm_client_config" "current" { +} resource "azurerm_data_factory_linked_service_data_lake_storage_gen2" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" - service_principal_id = "${data.azurerm_client_config.current.client_id}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + service_principal_id = data.azurerm_client_config.current.client_id service_principal_key = "testkey" tenant = "11111111-1111-1111-1111-111111111111" url = "https://test.azure.com" diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_mysql_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_mysql_test.go index 8f955e8a7d2ea..20d38d6b806dc 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_mysql_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_mysql_test.go @@ -124,6 +124,10 @@ func testCheckAzureRMDataFactoryLinkedServiceMySQLDestroy(s *terraform.State) er func testAccAzureRMDataFactoryLinkedServiceMySQL_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -131,14 +135,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_mysql" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Server=test;Port=3306;Database=test;User=test;SSLMode=1;UseSystemTrustStore=0;Password=test" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) @@ -146,6 +150,10 @@ resource "azurerm_data_factory_linked_service_mysql" "test" { func testAccAzureRMDataFactoryLinkedServiceMySQL_update1(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -153,14 +161,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_mysql" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Server=test;Port=3306;Database=test;User=test;SSLMode=1;UseSystemTrustStore=0;Password=test" annotations = ["test1", "test2", "test3"] description = "test description" @@ -180,6 +188,10 @@ resource "azurerm_data_factory_linked_service_mysql" "test" { func testAccAzureRMDataFactoryLinkedServiceMySQL_update2(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -187,14 +199,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_mysql" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Server=test;Port=3306;Database=test;User=test;SSLMode=1;UseSystemTrustStore=0;Password=test" annotations = ["test1", "test2"] description = "test description 2" diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_postgresql_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_postgresql_test.go index 8f235dc89e325..3a132da5576eb 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_postgresql_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_postgresql_test.go @@ -124,6 +124,10 @@ func testCheckAzureRMDataFactoryLinkedServicePostgreSQLDestroy(s *terraform.Stat func testAccAzureRMDataFactoryLinkedServicePostgreSQL_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -131,14 +135,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_postgresql" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Host=example;Port=5432;Database=example;UID=example;EncryptionMethod=0;Password=example" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) @@ -146,6 +150,10 @@ resource "azurerm_data_factory_linked_service_postgresql" "test" { func testAccAzureRMDataFactoryLinkedServicePostgreSQL_update1(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -153,14 +161,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_postgresql" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Host=example;Port=5432;Database=example;UID=example;EncryptionMethod=0;Password=example" annotations = ["test1", "test2", "test3"] description = "test description" @@ -180,6 +188,10 @@ resource "azurerm_data_factory_linked_service_postgresql" "test" { func testAccAzureRMDataFactoryLinkedServicePostgreSQL_update2(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -187,14 +199,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_postgresql" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Host=example;Port=5432;Database=example;UID=example;EncryptionMethod=0;Password=example" annotations = ["test1", "test2"] description = "test description 2" diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_sql_server_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_sql_server_test.go index c6719a36a9639..836f3d7f0d6ac 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_sql_server_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_sql_server_test.go @@ -107,6 +107,10 @@ func testCheckAzureRMDataFactoryLinkedServiceSQLServerDestroy(s *terraform.State func testAccAzureRMDataFactoryLinkedServiceSQLServer_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -114,14 +118,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_sql_server" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test" annotations = ["test1", "test2", "test3"] description = "test description" @@ -141,6 +145,10 @@ resource "azurerm_data_factory_linked_service_sql_server" "test" { func testAccAzureRMDataFactoryLinkedServiceSQLServer_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -148,14 +156,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_linked_service_sql_server" "test" { name = "acctestlssql%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test" annotations = ["test1", "test2"] description = "test description 2" diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_pipeline_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_pipeline_test.go index 6c2ef1a3d7552..e1f5574c534ba 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_pipeline_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_pipeline_test.go @@ -117,6 +117,10 @@ func testCheckAzureRMDataFactoryPipelineExists(resourceName string) resource.Tes func testAccAzureRMDataFactoryPipeline_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -124,20 +128,24 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdfv2%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_pipeline" "test" { name = "acctest%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDataFactoryPipeline_update1(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -145,14 +153,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdfv2%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_pipeline" "test" { name = "acctest%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name annotations = ["test1", "test2", "test3"] description = "test description" @@ -170,6 +178,10 @@ resource "azurerm_data_factory_pipeline" "test" { func testAccAzureRMDataFactoryPipeline_update2(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -177,14 +189,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdfv2%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_pipeline" "test" { name = "acctest%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name annotations = ["test1", "test2"] description = "test description2" diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_test.go index 2ed938a224b1d..b291d7b93f97d 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_test.go @@ -246,6 +246,10 @@ func testCheckAzureRMDataFactoryDestroy(s *terraform.State) error { func testAccAzureRMDataFactory_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -253,14 +257,18 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccAzureRMDataFactory_tags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -268,8 +276,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { environment = "production" @@ -280,6 +288,10 @@ resource "azurerm_data_factory" "test" { func testAccAzureRMDataFactory_tagsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -287,8 +299,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { environment = "production" @@ -300,6 +312,10 @@ resource "azurerm_data_factory" "test" { func testAccAzureRMDataFactory_identity(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -307,8 +323,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name identity { type = "SystemAssigned" @@ -319,6 +335,10 @@ resource "azurerm_data_factory" "test" { func testAccAzureRMDataFactory_github(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -326,8 +346,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name github_configuration { git_url = "https://github.com/terraform-providers/" @@ -342,6 +362,10 @@ resource "azurerm_data_factory" "test" { func testAccAzureRMDataFactory_githubUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -349,8 +373,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name github_configuration { git_url = "https://github.com/terraform-providers/" diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_trigger_schedule_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_trigger_schedule_test.go index e5dd552a267a4..c339052f51e14 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_trigger_schedule_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_trigger_schedule_test.go @@ -120,6 +120,10 @@ func testCheckAzureRMDataFactoryTriggerScheduleDestroy(s *terraform.State) error func testAccAzureRMDataFactoryTriggerSchedule_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -127,14 +131,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_pipeline" "test" { name = "acctest%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name parameters = { test = "testparameter" @@ -143,9 +147,9 @@ resource "azurerm_data_factory_pipeline" "test" { resource "azurerm_data_factory_trigger_schedule" "test" { name = "acctestdf%d" - data_factory_name = "${azurerm_data_factory.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - pipeline_name = "${azurerm_data_factory_pipeline.test.name}" + data_factory_name = azurerm_data_factory.test.name + resource_group_name = azurerm_resource_group.test.name + pipeline_name = azurerm_data_factory_pipeline.test.name annotations = ["test1", "test2", "test3"] } @@ -154,6 +158,10 @@ resource "azurerm_data_factory_trigger_schedule" "test" { func testAccAzureRMDataFactoryTriggerSchedule_update(data acceptance.TestData, endTime string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-datafactory-%d" location = "%s" @@ -161,14 +169,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_factory" "test" { name = "acctestdf%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_data_factory_pipeline" "test" { name = "acctest%d" - resource_group_name = "${azurerm_resource_group.test.name}" - data_factory_name = "${azurerm_data_factory.test.name}" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name parameters = { test = "testparameter" @@ -177,11 +185,11 @@ resource "azurerm_data_factory_pipeline" "test" { resource "azurerm_data_factory_trigger_schedule" "test" { name = "acctestDFTS%d" - data_factory_name = "${azurerm_data_factory.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - pipeline_name = "${azurerm_data_factory_pipeline.test.name}" + data_factory_name = azurerm_data_factory.test.name + resource_group_name = azurerm_resource_group.test.name + pipeline_name = azurerm_data_factory_pipeline.test.name - pipeline_parameters = "${azurerm_data_factory_pipeline.test.parameters}" + pipeline_parameters = azurerm_data_factory_pipeline.test.parameters annotations = ["test5"] frequency = "Day" interval = 5 diff --git a/azurerm/internal/services/datalake/registration.go b/azurerm/internal/services/datalake/registration.go index 94983780bea36..fda1870807390 100644 --- a/azurerm/internal/services/datalake/registration.go +++ b/azurerm/internal/services/datalake/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Data Lake" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Data Lake", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/datalake/tests/data_source_data_lake_store_test.go b/azurerm/internal/services/datalake/tests/data_source_data_lake_store_test.go index 681955502b3ee..8d54974f1d34c 100644 --- a/azurerm/internal/services/datalake/tests/data_source_data_lake_store_test.go +++ b/azurerm/internal/services/datalake/tests/data_source_data_lake_store_test.go @@ -47,6 +47,10 @@ func TestAccDataSourceAzureRMDataLakeStore_tier(t *testing.T) { func testAccDataSourceDataLakeStore_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -55,18 +59,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "unlikely23exst2acct%s" location = "%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } data "azurerm_data_lake_store" "test" { - name = "${azurerm_data_lake_store.test.name}" - resource_group_name = "${azurerm_data_lake_store.test.resource_group_name}" + name = azurerm_data_lake_store.test.name + resource_group_name = azurerm_data_lake_store.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.Locations.Primary) } func testAccDataSourceDataLakeStore_tier(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -76,7 +84,7 @@ resource "azurerm_data_lake_store" "test" { name = "unlikely23exst2acct%s" location = "%s" tier = "Commitment_1TB" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name tags = { hello = "world" @@ -84,8 +92,8 @@ resource "azurerm_data_lake_store" "test" { } data "azurerm_data_lake_store" "test" { - name = "${azurerm_data_lake_store.test.name}" - resource_group_name = "${azurerm_data_lake_store.test.resource_group_name}" + name = azurerm_data_lake_store.test.name + resource_group_name = azurerm_data_lake_store.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.Locations.Primary) } diff --git a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_account_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_account_test.go index 58fffcd2fb60f..192a0b9684a18 100644 --- a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_account_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_account_test.go @@ -168,10 +168,10 @@ func testAccAzureRMDataLakeAnalyticsAccount_basic(data acceptance.TestData) stri resource "azurerm_data_lake_analytics_account" "test" { name = "acctest%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location - default_store_account_name = "${azurerm_data_lake_store.test.name}" + default_store_account_name = azurerm_data_lake_store.test.name } `, template, strconv.Itoa(data.RandomInteger)[2:17]) } @@ -182,10 +182,10 @@ func testAccAzureRMDataLakeAnalyticsAccount_requiresImport(data acceptance.TestD %s resource "azurerm_data_lake_analytics_account" "import" { - name = "${azurerm_data_lake_analytics_account.test.name}" - resource_group_name = "${azurerm_data_lake_analytics_account.test.resource_group_name}" - location = "${azurerm_data_lake_analytics_account.test.location}" - default_store_account_name = "${azurerm_data_lake_analytics_account.test.default_store_account_name}" + name = azurerm_data_lake_analytics_account.test.name + resource_group_name = azurerm_data_lake_analytics_account.test.resource_group_name + location = azurerm_data_lake_analytics_account.test.location + default_store_account_name = azurerm_data_lake_analytics_account.test.default_store_account_name } `, template) } @@ -197,12 +197,12 @@ func testAccAzureRMDataLakeAnalyticsAccount_tier(data acceptance.TestData) strin resource "azurerm_data_lake_analytics_account" "test" { name = "acctest%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location tier = "Commitment_100AUHours" - default_store_account_name = "${azurerm_data_lake_store.test.name}" + default_store_account_name = azurerm_data_lake_store.test.name } `, template, strconv.Itoa(data.RandomInteger)[2:17]) } @@ -214,10 +214,10 @@ func testAccAzureRMDataLakeAnalyticsAccount_withTags(data acceptance.TestData) s resource "azurerm_data_lake_analytics_account" "test" { name = "acctest%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location - default_store_account_name = "${azurerm_data_lake_store.test.name}" + default_store_account_name = azurerm_data_lake_store.test.name tags = { environment = "Production" @@ -234,10 +234,10 @@ func testAccAzureRMDataLakeAnalyticsAccount_withTagsUpdate(data acceptance.TestD resource "azurerm_data_lake_analytics_account" "test" { name = "acctest%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location - default_store_account_name = "${azurerm_data_lake_store.test.name}" + default_store_account_name = azurerm_data_lake_store.test.name tags = { environment = "staging" diff --git a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_firewall_rule_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_firewall_rule_test.go index 23f836441f504..6d682e23e6b7b 100644 --- a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_firewall_rule_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_firewall_rule_test.go @@ -179,6 +179,10 @@ func testCheckAzureRMDataLakeAnalyticsFirewallRuleDestroy(s *terraform.State) er func testAccAzureRMDataLakeAnalyticsFirewallRule_basic(data acceptance.TestData, startIP, endIP string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%[2]s" @@ -186,22 +190,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "acctest%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location } resource "azurerm_data_lake_analytics_account" "test" { name = "acctest%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location - default_store_account_name = "${azurerm_data_lake_store.test.name}" + default_store_account_name = azurerm_data_lake_store.test.name } resource "azurerm_data_lake_analytics_firewall_rule" "test" { name = "acctest%[3]s" - account_name = "${azurerm_data_lake_analytics_account.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + account_name = azurerm_data_lake_analytics_account.test.name + resource_group_name = azurerm_resource_group.test.name start_ip_address = "%[4]s" end_ip_address = "%[5]s" } @@ -214,11 +218,11 @@ func testAccAzureRMDataLakeAnalyticsFirewallRule_requiresImport(data acceptance. %s resource "azurerm_data_lake_analytics_firewall_rule" "import" { - name = "${azurerm_data_lake_analytics_firewall_rule.test.name}" - account_name = "${azurerm_data_lake_analytics_firewall_rule.test.account_name}" - resource_group_name = "${azurerm_data_lake_analytics_firewall_rule.test.resource_group_name}" - start_ip_address = "${azurerm_data_lake_analytics_firewall_rule.test.start_ip_address}" - end_ip_address = "${azurerm_data_lake_analytics_firewall_rule.test.end_ip_address}" + name = azurerm_data_lake_analytics_firewall_rule.test.name + account_name = azurerm_data_lake_analytics_firewall_rule.test.account_name + resource_group_name = azurerm_data_lake_analytics_firewall_rule.test.resource_group_name + start_ip_address = azurerm_data_lake_analytics_firewall_rule.test.start_ip_address + end_ip_address = azurerm_data_lake_analytics_firewall_rule.test.end_ip_address } `, template) } diff --git a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_test.go index 37945eb54215b..4a5660e44e878 100644 --- a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_test.go @@ -63,10 +63,10 @@ func TestAccAzureRMDataLakeStoreFile_basic(t *testing.T) { func TestAccAzureRMDataLakeStoreFile_largefiles(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_data_lake_store_file", "test") - //"large" in this context is anything greater than 4 megabytes - largeSize := 12 * 1024 * 1024 //12 mb + // "large" in this context is anything greater than 4 megabytes + largeSize := 12 * 1024 * 1024 // 12 mb bytes := make([]byte, largeSize) - rand.Read(bytes) //fill with random data + rand.Read(bytes) // fill with random data tmpfile, err := ioutil.TempFile("", "azurerm-acc-datalake-file-large") if err != nil { @@ -180,6 +180,10 @@ func testCheckAzureRMDataLakeStoreFileDestroy(s *terraform.State) error { func testAccAzureRMDataLakeStoreFile_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -187,14 +191,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name location = "%s" firewall_state = "Disabled" } resource "azurerm_data_lake_store_file" "test" { remote_file_path = "/test/application_gateway_test.cer" - account_name = "${azurerm_data_lake_store.test.name}" + account_name = azurerm_data_lake_store.test.name local_file_path = "./testdata/application_gateway_test.cer" } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.Locations.Primary) @@ -202,6 +206,10 @@ resource "azurerm_data_lake_store_file" "test" { func testAccAzureRMDataLakeStoreFile_largefiles(data acceptance.TestData, file string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -209,14 +217,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name location = "%s" firewall_state = "Disabled" } resource "azurerm_data_lake_store_file" "test" { remote_file_path = "/test/testAccAzureRMDataLakeStoreFile_largefiles.bin" - account_name = "${azurerm_data_lake_store.test.name}" + account_name = azurerm_data_lake_store.test.name local_file_path = "%s" } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.Locations.Primary, file) @@ -228,8 +236,8 @@ func testAccAzureRMDataLakeStoreFile_requiresImport(data acceptance.TestData) st %s resource "azurerm_data_lake_store_file" "import" { - remote_file_path = "${azurerm_data_lake_store_file.test.remote_file_path}" - account_name = "${azurerm_data_lake_store_file.test.name}" + remote_file_path = azurerm_data_lake_store_file.test.remote_file_path + account_name = azurerm_data_lake_store_file.test.name local_file_path = "./testdata/application_gateway_test.cer" } `, template) diff --git a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_firewall_rule_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_firewall_rule_test.go index fef9389058b1e..d33ed68a7d921 100644 --- a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_firewall_rule_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_firewall_rule_test.go @@ -179,6 +179,10 @@ func testCheckAzureRMDataLakeStoreFirewallRuleDestroy(s *terraform.State) error func testAccAzureRMDataLakeStoreFirewallRule_basic(data acceptance.TestData, startIP, endIP string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -186,14 +190,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "acctest%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location } resource "azurerm_data_lake_store_firewall_rule" "test" { name = "acctest" - account_name = "${azurerm_data_lake_store.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + account_name = azurerm_data_lake_store.test.name + resource_group_name = azurerm_resource_group.test.name start_ip_address = "%s" end_ip_address = "%s" } @@ -206,11 +210,11 @@ func testAccAzureRMDataLakeStoreFirewallRule_requiresImport(data acceptance.Test %s resource "azurerm_data_lake_store_firewall_rule" "import" { - name = "${azurerm_data_lake_store_firewall_rule.test.name}" - account_name = "${azurerm_data_lake_store_firewall_rule.test.account_name}" - resource_group_name = "${azurerm_data_lake_store_firewall_rule.test.resource_group_name}" - start_ip_address = "${azurerm_data_lake_store_firewall_rule.test.start_ip_address}" - end_ip_address = "${azurerm_data_lake_store_firewall_rule.test.end_ip_address}" + name = azurerm_data_lake_store_firewall_rule.test.name + account_name = azurerm_data_lake_store_firewall_rule.test.account_name + resource_group_name = azurerm_data_lake_store_firewall_rule.test.resource_group_name + start_ip_address = azurerm_data_lake_store_firewall_rule.test.start_ip_address + end_ip_address = azurerm_data_lake_store_firewall_rule.test.end_ip_address } `, template) } diff --git a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_test.go index aac81c6f51e7e..b914a371eae82 100644 --- a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_test.go @@ -232,6 +232,10 @@ func testCheckAzureRMDataLakeStoreDestroy(s *terraform.State) error { func testAccAzureRMDataLakeStore_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -239,8 +243,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "acctest%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location } `, data.RandomInteger, data.Locations.Primary, strconv.Itoa(data.RandomInteger)[2:17]) } @@ -251,15 +255,19 @@ func testAccAzureRMDataLakeStore_requiresImport(data acceptance.TestData) string %s resource "azurerm_data_lake_store" "import" { - name = "${azurerm_data_lake_store.test.name}" - resource_group_name = "${azurerm_data_lake_store.test.resource_group_name}" - location = "${azurerm_data_lake_store.test.location}" + name = azurerm_data_lake_store.test.name + resource_group_name = azurerm_data_lake_store.test.resource_group_name + location = azurerm_data_lake_store.test.location } `, template) } func testAccAzureRMDataLakeStore_tier(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -267,8 +275,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "acctest%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location tier = "Commitment_1TB" } `, data.RandomInteger, data.Locations.Primary, strconv.Itoa(data.RandomInteger)[2:17]) @@ -276,6 +284,10 @@ resource "azurerm_data_lake_store" "test" { func testAccAzureRMDataLakeStore_encryptionDisabled(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -283,8 +295,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "acctest%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location encryption_state = "Disabled" } `, data.RandomInteger, data.Locations.Primary, strconv.Itoa(data.RandomInteger)[2:17]) @@ -292,6 +304,10 @@ resource "azurerm_data_lake_store" "test" { func testAccAzureRMDataLakeStore_firewall(data acceptance.TestData, firewallState string, firewallAllowAzureIPs string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -299,8 +315,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "acctest%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location firewall_state = "%s" firewall_allow_azure_ips = "%s" } @@ -309,6 +325,10 @@ resource "azurerm_data_lake_store" "test" { func testAccAzureRMDataLakeStore_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -316,8 +336,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "acctest%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location tags = { environment = "Production" @@ -329,6 +349,10 @@ resource "azurerm_data_lake_store" "test" { func testAccAzureRMDataLakeStore_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -336,8 +360,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "acctest%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location tags = { environment = "staging" diff --git a/azurerm/internal/services/devspace/registration.go b/azurerm/internal/services/devspace/registration.go index c40664b9c07f3..195ae43e43083 100644 --- a/azurerm/internal/services/devspace/registration.go +++ b/azurerm/internal/services/devspace/registration.go @@ -4,6 +4,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) +// TODO: this can be moved into Container + type Registration struct{} // Name is the name of this Service @@ -11,6 +13,13 @@ func (r Registration) Name() string { return "DevSpaces" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "DevSpace", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{} diff --git a/azurerm/internal/services/devspace/resource_arm_devspace_controller.go b/azurerm/internal/services/devspace/resource_arm_devspace_controller.go index 12b20d526e244..5bbfd9e51c0f6 100644 --- a/azurerm/internal/services/devspace/resource_arm_devspace_controller.go +++ b/azurerm/internal/services/devspace/resource_arm_devspace_controller.go @@ -53,43 +53,13 @@ func resourceArmDevSpaceController() *schema.Resource { "sku_name": { Type: schema.TypeString, - Optional: true, // required in 2.0 - Computed: true, // remove in 2.0 - //ForceNew: true, // uncomment in 2.0 - this should be fine as there is only 1 valid value - ConflictsWith: []string{"sku"}, + Required: true, + ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ "S1", }, false), }, - "sku": { - Type: schema.TypeList, - Optional: true, - //ForceNew: true, // uncomment in 2.0 - this should be fine as there is only 1 valid value - Computed: true, - ConflictsWith: []string{"sku_name"}, - Deprecated: "This property has been deprecated in favour of the 'sku_name' property and will be removed in version 2.0 of the provider", - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - "S1", - }, false), - }, - "tier": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - string(devspaces.Standard), - }, false), - }, - }, - }, - }, - "target_container_host_resource_id": { Type: schema.TypeString, Required: true, @@ -146,17 +116,9 @@ func resourceArmDevSpaceControllerCreate(d *schema.ResourceData, meta interface{ location := azure.NormalizeLocation(d.Get("location").(string)) t := d.Get("tags").(map[string]interface{}) - var sku *devspaces.Sku - if b, ok := d.GetOk("sku_name"); ok { - var err error - sku, err = expandControllerSkuName(b.(string)) - if err != nil { - return fmt.Errorf("error expanding sku_name for DevSpace Controller %s (Resource Group %q): %v", name, resourceGroup, err) - } - } else if _, ok := d.GetOk("sku"); ok { - sku = expandDevSpaceControllerSku(d) - } else { - return fmt.Errorf("One of `sku` or `sku_name` must be set for DevSpace Controller %q (Resource Group %q)", name, resourceGroup) + sku, err := expandControllerSkuName(d.Get("sku_name").(string)) + if err != nil { + return fmt.Errorf("error expanding `sku_name` for DevSpace Controller %s (Resource Group %q): %v", name, resourceGroup, err) } controller := devspaces.Controller{ @@ -250,10 +212,6 @@ func resourceArmDevSpaceControllerRead(d *schema.ResourceData, meta interface{}) d.Set("sku_name", sku.Name) } - if err := d.Set("sku", flattenDevSpaceControllerSku(resp.Sku)); err != nil { - return fmt.Errorf("Error flattenning `sku`: %+v", err) - } - if props := resp.ControllerProperties; props != nil { d.Set("host_suffix", props.HostSuffix) d.Set("data_plane_fqdn", props.DataPlaneFqdn) @@ -299,34 +257,3 @@ func expandControllerSkuName(skuName string) (*devspaces.Sku, error) { Tier: tier, }, nil } - -func expandDevSpaceControllerSku(d *schema.ResourceData) *devspaces.Sku { - if _, ok := d.GetOk("sku"); !ok { - return nil - } - - skuConfigs := d.Get("sku").([]interface{}) - skuConfig := skuConfigs[0].(map[string]interface{}) - skuName := skuConfig["name"].(string) - skuTier := devspaces.SkuTier(skuConfig["tier"].(string)) - - return &devspaces.Sku{ - Name: &skuName, - Tier: skuTier, - } -} - -func flattenDevSpaceControllerSku(skuObj *devspaces.Sku) []interface{} { - if skuObj == nil { - return []interface{}{} - } - - skuConfig := make(map[string]interface{}) - if skuObj.Name != nil { - skuConfig["name"] = *skuObj.Name - } - - skuConfig["tier"] = skuObj.Tier - - return []interface{}{skuConfig} -} diff --git a/azurerm/internal/services/devspace/tests/resource_arm_devspace_controller_test.go b/azurerm/internal/services/devspace/tests/resource_arm_devspace_controller_test.go index e0f0b48df240c..2fdff52451481 100644 --- a/azurerm/internal/services/devspace/tests/resource_arm_devspace_controller_test.go +++ b/azurerm/internal/services/devspace/tests/resource_arm_devspace_controller_test.go @@ -29,29 +29,6 @@ func TestAccAzureRMDevSpaceController_basic(t *testing.T) { Config: testAccAzureRMDevSpaceController_basic(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( testCheckAzureRMDevSpaceControllerExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "sku.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), - ), - }, - }, - }) -} - -func TestAccAzureRMDevSpaceController_basicOldSku(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_devspace_controller", "test") - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDevSpaceControllerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDevSpaceController_basicOldSku(data, clientId, clientSecret), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevSpaceControllerExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "sku.#", "1"), resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, @@ -150,51 +127,10 @@ func testCheckAzureRMDevSpaceControllerDestroy(s *terraform.State) error { func testAccAzureRMDevSpaceController_basic(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_kubernetes_cluster" "test" { - name = "acctestaks%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - dns_prefix = "acctestaks1" - - linux_profile { - admin_username = "acctestuser1" - - ssh_key { - key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt terraform@demo.tld" - } - } - - agent_pool_profile { - name = "default" - count = "1" - vm_size = "Standard_DS2_v2" - } - - service_principal { - client_id = "%s" - client_secret = "%s" - } -} - -resource "azurerm_devspace_controller" "test" { - name = "acctestdsc%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - target_container_host_resource_id = "${azurerm_kubernetes_cluster.test.id}" - target_container_host_credentials_base64 = "${base64encode(azurerm_kubernetes_cluster.test.kube_config_raw)}" - - sku_name = "S1" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, clientId, clientSecret, data.RandomInteger) -} - -func testAccAzureRMDevSpaceController_basicOldSku(data acceptance.TestData, clientId string, clientSecret string) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -214,10 +150,10 @@ resource "azurerm_kubernetes_cluster" "test" { } } - agent_pool_profile { - name = "default" - count = "1" - vm_size = "Standard_DS2_v2" + default_node_pool { + name = "default" + node_count = 1 + vm_size = "Standard_DS2_v2" } service_principal { @@ -228,15 +164,11 @@ resource "azurerm_kubernetes_cluster" "test" { resource "azurerm_devspace_controller" "test" { name = "acctestdsc%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - target_container_host_resource_id = "${azurerm_kubernetes_cluster.test.id}" - target_container_host_credentials_base64 = "${base64encode(azurerm_kubernetes_cluster.test.kube_config_raw)}" - - sku { - name = "S1" - tier = "Standard" - } + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + target_container_host_resource_id = azurerm_kubernetes_cluster.test.id + target_container_host_credentials_base64 = base64encode(azurerm_kubernetes_cluster.test.kube_config_raw) + sku_name = "S1" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, clientId, clientSecret, data.RandomInteger) } @@ -247,12 +179,12 @@ func testAccAzureRMDevSpaceController_requiresImport(data acceptance.TestData, c %s resource "azurerm_devspace_controller" "import" { - name = "${azurerm_devspace_controller.test.name}" - location = "${azurerm_devspace_controller.test.location}" - resource_group_name = "${azurerm_devspace_controller.test.resource_group_name}" - target_container_host_resource_id = "${azurerm_kubernetes_cluster.test.id}" - target_container_host_credentials_base64 = "${base64encode(azurerm_kubernetes_cluster.test.kube_config_raw)}" - sku_name = "${base64encode(azurerm_kubernetes_cluster.test.sku_name)}" + name = azurerm_devspace_controller.test.name + location = azurerm_devspace_controller.test.location + resource_group_name = azurerm_devspace_controller.test.resource_group_name + target_container_host_resource_id = azurerm_devspace_controller.test.target_container_host_resource_id + target_container_host_credentials_base64 = base64encode(azurerm_kubernetes_cluster.test.kube_config_raw) + sku_name = azurerm_devspace_controller.test.sku_name } `, template) } diff --git a/azurerm/internal/services/devtestlabs/registration.go b/azurerm/internal/services/devtestlabs/registration.go index c726d8eee79de..607fa7bc4d9f9 100644 --- a/azurerm/internal/services/devtestlabs/registration.go +++ b/azurerm/internal/services/devtestlabs/registration.go @@ -8,7 +8,14 @@ type Registration struct{} // Name is the name of this Service func (r Registration) Name() string { - return "DevTestLabs" + return "Dev Test" +} + +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Dev Test", + } } // SupportedDataSources returns the supported Data Sources supported by this Service diff --git a/azurerm/internal/services/devtestlabs/tests/data_source_dev_test_lab_test.go b/azurerm/internal/services/devtestlabs/tests/data_source_dev_test_lab_test.go index 3cc99acb9e869..4a37fda3ac5e9 100644 --- a/azurerm/internal/services/devtestlabs/tests/data_source_dev_test_lab_test.go +++ b/azurerm/internal/services/devtestlabs/tests/data_source_dev_test_lab_test.go @@ -47,6 +47,10 @@ func TestAccDataSourceAzureRMDevTestLab_complete(t *testing.T) { func testAccDataSourceDevTestLab_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -54,19 +58,23 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctestdtl%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } data "azurerm_dev_test_lab" "test" { - name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_dev_test_lab.test.resource_group_name}" + name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_dev_test_lab.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccDataSourceDevTestLab_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -74,8 +82,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctestdtl%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_type = "Standard" tags = { @@ -84,8 +92,8 @@ resource "azurerm_dev_test_lab" "test" { } data "azurerm_dev_test_lab" "test" { - name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_dev_test_lab.test.resource_group_name}" + name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_dev_test_lab.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/devtestlabs/tests/data_source_dev_test_virtual_network_test.go b/azurerm/internal/services/devtestlabs/tests/data_source_dev_test_virtual_network_test.go index bda37bf4a71f8..af8cfb7380a32 100644 --- a/azurerm/internal/services/devtestlabs/tests/data_source_dev_test_virtual_network_test.go +++ b/azurerm/internal/services/devtestlabs/tests/data_source_dev_test_virtual_network_test.go @@ -44,6 +44,10 @@ func TestAccDataSourceArmDevTestVirtualNetwork_basic(t *testing.T) { func testAccDataSourceArmDevTestVirtualNetwork_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -51,14 +55,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctestdtl%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dev_test_virtual_network" "test" { name = "acctestdtvn%d" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name subnet { use_public_ip_address = "Allow" @@ -67,11 +71,9 @@ resource "azurerm_dev_test_virtual_network" "test" { } data "azurerm_dev_test_virtual_network" "test" { - name = "${azurerm_dev_test_virtual_network.test.name}" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_dev_test_virtual_network.test.name + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name } - - `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_schedule_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_schedule_test.go index 4c216e4e8a221..870db269ba886 100644 --- a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_schedule_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_schedule_test.go @@ -159,6 +159,10 @@ func testCheckAzureRMDevTestLabScheduleDestroy(s *terraform.State) error { func testAccAzureRMDevTestLabSchedule_autoShutdownBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -166,23 +170,21 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctdtl-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dev_test_schedule" "test" { name = "LabVmsShutdown" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - lab_name = "${azurerm_dev_test_lab.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + lab_name = azurerm_dev_test_lab.test.name daily_recurrence { time = "0100" } time_zone_id = "India Standard Time" task_type = "LabVmsShutdownTask" notification_settings { - } tags = { @@ -194,6 +196,10 @@ resource "azurerm_dev_test_schedule" "test" { func testAccAzureRMDevTestLabSchedule_autoShutdownBasicUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -201,17 +207,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctdtl-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dev_test_schedule" "test" { name = "LabVmsShutdown" status = "Enabled" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - lab_name = "${azurerm_dev_test_lab.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + lab_name = azurerm_dev_test_lab.test.name daily_recurrence { time = "0900" } @@ -226,12 +231,15 @@ resource "azurerm_dev_test_schedule" "test" { environment = "Production" } } - `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccAzureRMDevTestLabSchedule_autoStartupBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -239,16 +247,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctdtl-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dev_test_schedule" "test" { name = "LabVmAutoStart" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - lab_name = "${azurerm_dev_test_lab.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + lab_name = azurerm_dev_test_lab.test.name weekly_recurrence { time = "1100" week_days = ["Monday", "Tuesday"] @@ -258,7 +265,6 @@ resource "azurerm_dev_test_schedule" "test" { task_type = "LabVmsStartupTask" notification_settings { - } tags = { @@ -270,6 +276,10 @@ resource "azurerm_dev_test_schedule" "test" { func testAccAzureRMDevTestLabSchedule_autoStartupBasicUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -277,16 +287,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctdtl-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dev_test_schedule" "test" { name = "LabVmAutoStart" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - lab_name = "${azurerm_dev_test_lab.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + lab_name = azurerm_dev_test_lab.test.name weekly_recurrence { time = "1000" week_days = ["Wednesday", "Thursday", "Friday"] @@ -296,7 +305,6 @@ resource "azurerm_dev_test_schedule" "test" { task_type = "LabVmsStartupTask" notification_settings { - } status = "Enabled" @@ -305,12 +313,15 @@ resource "azurerm_dev_test_schedule" "test" { environment = "Production" } } - `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccAzureRMDevTestLabSchedule_concurrent(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -318,16 +329,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctdtl-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dev_test_schedule" "test" { name = "LabVmAutoStart" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - lab_name = "${azurerm_dev_test_lab.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + lab_name = azurerm_dev_test_lab.test.name weekly_recurrence { time = "1100" week_days = ["Monday", "Tuesday"] @@ -337,7 +347,6 @@ resource "azurerm_dev_test_schedule" "test" { task_type = "LabVmsStartupTask" notification_settings { - } tags = { @@ -347,16 +356,15 @@ resource "azurerm_dev_test_schedule" "test" { resource "azurerm_dev_test_schedule" "test2" { name = "LabVmsShutdown" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - lab_name = "${azurerm_dev_test_lab.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + lab_name = azurerm_dev_test_lab.test.name daily_recurrence { time = "0100" } time_zone_id = "India Standard Time" task_type = "LabVmsShutdownTask" notification_settings { - } tags = { diff --git a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_test.go index 50fcfe88dd1c4..7af7e260ed3f7 100644 --- a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_test.go @@ -142,6 +142,10 @@ func testCheckAzureRMDevTestLabDestroy(s *terraform.State) error { func testAccAzureRMDevTestLab_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -149,8 +153,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctestdtl%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -161,15 +165,19 @@ func testAccAzureRMDevTestLab_requiresImport(data acceptance.TestData) string { %s resource "azurerm_dev_test_lab" "import" { - name = "${azurerm_dev_test_lab.test.name}" - location = "${azurerm_dev_test_lab.test.location}" - resource_group_name = "${azurerm_dev_test_lab.test.resource_group_name}" + name = azurerm_dev_test_lab.test.name + location = azurerm_dev_test_lab.test.location + resource_group_name = azurerm_dev_test_lab.test.resource_group_name } `, template) } func testAccAzureRMDevTestLab_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -177,8 +185,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctestdtl%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_type = "Standard" tags = { diff --git a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_linux_virtual_machine_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_linux_virtual_machine_test.go index 9144b97267d7b..86552e185863f 100644 --- a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_linux_virtual_machine_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_linux_virtual_machine_test.go @@ -214,14 +214,14 @@ func testAccAzureRMDevTestLinuxVirtualMachine_basic(data acceptance.TestData) st resource "azurerm_dev_test_linux_virtual_machine" "test" { name = "acctestvm-vm%d" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location size = "Standard_F2" username = "acct5stU5er" - password = "Pa$$w0rd1234!" - lab_virtual_network_id = "${azurerm_dev_test_virtual_network.test.id}" - lab_subnet_name = "${azurerm_dev_test_virtual_network.test.subnet.0.name}" + password = "Pa$w0rd1234!" + lab_virtual_network_id = azurerm_dev_test_virtual_network.test.id + lab_subnet_name = azurerm_dev_test_virtual_network.test.subnet[0].name storage_type = "Standard" gallery_image_reference { @@ -240,15 +240,15 @@ func testAccAzureRMDevTestLinuxVirtualMachine_requiresImport(data acceptance.Tes %s resource "azurerm_dev_test_linux_virtual_machine" "import" { - name = "${azurerm_dev_test_linux_virtual_machine.test.name}" - lab_name = "${azurerm_dev_test_linux_virtual_machine.test.lab_name}" - resource_group_name = "${azurerm_dev_test_linux_virtual_machine.test.resource_group_name}" - location = "${azurerm_dev_test_linux_virtual_machine.test.location}" - size = "${azurerm_dev_test_linux_virtual_machine.test.size}" + name = azurerm_dev_test_linux_virtual_machine.test.name + lab_name = azurerm_dev_test_linux_virtual_machine.test.lab_name + resource_group_name = azurerm_dev_test_linux_virtual_machine.test.resource_group_name + location = azurerm_dev_test_linux_virtual_machine.test.location + size = azurerm_dev_test_linux_virtual_machine.test.size username = "acct5stU5er" - password = "Pa$$w0rd1234!" - lab_virtual_network_id = "${azurerm_dev_test_virtual_network.test.id}" - lab_subnet_name = "${azurerm_dev_test_virtual_network.test.subnet.0.name}" + password = "Pa$w0rd1234!" + lab_virtual_network_id = azurerm_dev_test_virtual_network.test.id + lab_subnet_name = azurerm_dev_test_virtual_network.test.subnet[0].name storage_type = "Standard" gallery_image_reference { @@ -268,14 +268,14 @@ func testAccAzureRMDevTestLinuxVirtualMachine_basicSSH(data acceptance.TestData) resource "azurerm_dev_test_linux_virtual_machine" "test" { name = "acctestvm-vm%d" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location size = "Standard_F2" username = "acct5stU5er" ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCsTcryUl51Q2VSEHqDRNmceUFo55ZtcIwxl2QITbN1RREti5ml/VTytC0yeBOvnZA4x4CFpdw/lCDPk0yrH9Ei5vVkXmOrExdTlT3qI7YaAzj1tUVlBd4S6LX1F7y6VLActvdHuDDuXZXzCDd/97420jrDfWZqJMlUK/EmCE5ParCeHIRIvmBxcEnGfFIsw8xQZl0HphxWOtJil8qsUWSdMyCiJYYQpMoMliO99X40AUc4/AlsyPyT5ddbKk08YrZ+rKDVHF7o29rh4vi5MmHkVgVQHKiKybWlHq+b71gIAUQk9wrJxD+dqt4igrmDSpIjfjwnd+l5UIn5fJSO5DYV4YT/4hwK7OKmuo7OFHD0WyY5YnkYEMtFgzemnRBdE8ulcT60DQpVgRMXFWHvhyCWy0L6sgj1QWDZlLpvsIvNfHsyhKFMG1frLnMt/nP0+YCcfg+v1JYeCKjeoJxB8DWcRBsjzItY0CGmzP8UYZiYKl/2u+2TgFS5r7NWH11bxoUzjKdaa1NLw+ieA8GlBFfCbfWe6YVB9ggUte4VtYFMZGxOjS2bAiYtfgTKFJv+XqORAwExG6+G2eDxIDyo80/OA9IG7Xv/jwQr7D6KDjDuULFcN/iTxuttoKrHeYz1hf5ZQlBdllwJHYx6fK2g8kha6r2JIQKocvsAXiiONqSfw== hello@world.com" - lab_virtual_network_id = "${azurerm_dev_test_virtual_network.test.id}" - lab_subnet_name = "${azurerm_dev_test_virtual_network.test.subnet.0.name}" + lab_virtual_network_id = azurerm_dev_test_virtual_network.test.id + lab_subnet_name = azurerm_dev_test_virtual_network.test.subnet[0].name storage_type = "Standard" gallery_image_reference { @@ -295,15 +295,15 @@ func testAccAzureRMDevTestLinuxVirtualMachine_inboundNatRules(data acceptance.Te resource "azurerm_dev_test_linux_virtual_machine" "test" { name = "acctestvm-vm%d" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location size = "Standard_F2" username = "acct5stU5er" - password = "Pa$$w0rd1234!" + password = "Pa$w0rd1234!" disallow_public_ip_address = true - lab_virtual_network_id = "${azurerm_dev_test_virtual_network.test.id}" - lab_subnet_name = "${azurerm_dev_test_virtual_network.test.subnet.0.name}" + lab_virtual_network_id = azurerm_dev_test_virtual_network.test.id + lab_subnet_name = azurerm_dev_test_virtual_network.test.subnet[0].name storage_type = "Standard" gallery_image_reference { @@ -337,14 +337,14 @@ func testAccAzureRMDevTestLinuxVirtualMachine_storage(data acceptance.TestData, resource "azurerm_dev_test_linux_virtual_machine" "test" { name = "acctestvm-vm%d" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location size = "Standard_B1ms" username = "acct5stU5er" - password = "Pa$$w0rd1234!" - lab_virtual_network_id = "${azurerm_dev_test_virtual_network.test.id}" - lab_subnet_name = "${azurerm_dev_test_virtual_network.test.subnet.0.name}" + password = "Pa$w0rd1234!" + lab_virtual_network_id = azurerm_dev_test_virtual_network.test.id + lab_subnet_name = azurerm_dev_test_virtual_network.test.subnet[0].name storage_type = "%s" gallery_image_reference { @@ -359,6 +359,10 @@ resource "azurerm_dev_test_linux_virtual_machine" "test" { func testAccAzureRMDevTestLinuxVirtualMachine_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -366,14 +370,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctestdtl%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dev_test_virtual_network" "test" { name = "acctestdtvn%d" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name subnet { use_public_ip_address = "Allow" diff --git a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_policy_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_policy_test.go index 5e9fb2a800876..226d6e9adf15a 100644 --- a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_policy_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_policy_test.go @@ -142,6 +142,10 @@ func testCheckAzureRMDevTestPolicyDestroy(s *terraform.State) error { func testAccAzureRMDevTestPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -149,15 +153,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctestdtl%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dev_test_policy" "test" { name = "LabVmCount" policy_set_name = "default" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name threshold = "999" evaluator_type = "MaxValuePolicy" } @@ -170,10 +174,10 @@ func testAccAzureRMDevTestPolicy_requiresImport(data acceptance.TestData) string %s resource "azurerm_dev_test_policy" "import" { - name = "${azurerm_dev_test_policy.test.name}" + name = azurerm_dev_test_policy.test.name policy_set_name = "$[azurerm_dev_test_policy.test.policy_set_name}" - lab_name = "${azurerm_dev_test_policy.test.lab_name}" - resource_group_name = "${azurerm_dev_test_policy.test.resource_group_name}" + lab_name = azurerm_dev_test_policy.test.lab_name + resource_group_name = azurerm_dev_test_policy.test.resource_group_name threshold = "999" evaluator_type = "MaxValuePolicy" } @@ -182,6 +186,10 @@ resource "azurerm_dev_test_policy" "import" { func testAccAzureRMDevTestPolicy_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -189,15 +197,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctestdtl%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dev_test_policy" "test" { name = "LabVmCount" policy_set_name = "default" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name threshold = "999" evaluator_type = "MaxValuePolicy" description = "Aloha this is the max number of VM's'" diff --git a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_virtual_network_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_virtual_network_test.go index 871adfb707a95..650b3a94d5fd4 100644 --- a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_virtual_network_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_virtual_network_test.go @@ -171,6 +171,10 @@ func testCheckAzureRMDevTestVirtualNetworkDestroy(s *terraform.State) error { func testAccAzureRMDevTestVirtualNetwork_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -178,14 +182,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctestdtl%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dev_test_virtual_network" "test" { name = "acctestdtvn%d" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } @@ -196,15 +200,19 @@ func testAccAzureRMDevTestVirtualNetwork_requiresImport(data acceptance.TestData %s resource "azurerm_dev_test_virtual_network" "import" { - name = "${azurerm_dev_test_virtual_network.test.name}" - lab_name = "${azurerm_dev_test_virtual_network.test.lab_name}" - resource_group_name = "${azurerm_dev_test_virtual_network.test.resource_group_name}" + name = azurerm_dev_test_virtual_network.test.name + lab_name = azurerm_dev_test_virtual_network.test.lab_name + resource_group_name = azurerm_dev_test_virtual_network.test.resource_group_name } `, template) } func testAccAzureRMDevTestVirtualNetwork_subnets(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -212,14 +220,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctestdtl%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dev_test_virtual_network" "test" { name = "acctestdtvn%d" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name subnet { use_public_ip_address = "Deny" diff --git a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_windows_virtual_machine_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_windows_virtual_machine_test.go index 210c8bdd0865c..5d18357b9ea84 100644 --- a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_windows_virtual_machine_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_windows_virtual_machine_test.go @@ -188,14 +188,14 @@ func testAccAzureRMDevTestWindowsVirtualMachine_basic(data acceptance.TestData) resource "azurerm_dev_test_windows_virtual_machine" "test" { name = "acctestvm%d" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location size = "Standard_F2" username = "acct5stU5er" - password = "Pa$$w0rd1234!" - lab_virtual_network_id = "${azurerm_dev_test_virtual_network.test.id}" - lab_subnet_name = "${azurerm_dev_test_virtual_network.test.subnet.0.name}" + password = "Pa$w0rd1234!" + lab_virtual_network_id = azurerm_dev_test_virtual_network.test.id + lab_subnet_name = azurerm_dev_test_virtual_network.test.subnet[0].name storage_type = "Standard" gallery_image_reference { @@ -214,15 +214,15 @@ func testAccAzureRMDevTestWindowsVirtualMachine_requiresImport(data acceptance.T %s resource "azurerm_dev_test_windows_virtual_machine" "import" { - name = "${azurerm_dev_test_windows_virtual_machine.test.name}" - lab_name = "${azurerm_dev_test_windows_virtual_machine.test.lab_name}" - resource_group_name = "${azurerm_dev_test_windows_virtual_machine.test.resource_group_name}" - location = "${azurerm_dev_test_windows_virtual_machine.test.location}" - size = "${azurerm_dev_test_windows_virtual_machine.test.size}" + name = azurerm_dev_test_windows_virtual_machine.test.name + lab_name = azurerm_dev_test_windows_virtual_machine.test.lab_name + resource_group_name = azurerm_dev_test_windows_virtual_machine.test.resource_group_name + location = azurerm_dev_test_windows_virtual_machine.test.location + size = azurerm_dev_test_windows_virtual_machine.test.size username = "acct5stU5er" - password = "Pa$$w0rd1234!" - lab_virtual_network_id = "${azurerm_dev_test_virtual_network.test.id}" - lab_subnet_name = "${azurerm_dev_test_virtual_network.test.subnet.0.name}" + password = "Pa$w0rd1234!" + lab_virtual_network_id = azurerm_dev_test_virtual_network.test.id + lab_subnet_name = azurerm_dev_test_virtual_network.test.subnet[0].name storage_type = "Standard" gallery_image_reference { @@ -242,15 +242,15 @@ func testAccAzureRMDevTestWindowsVirtualMachine_inboundNatRules(data acceptance. resource "azurerm_dev_test_windows_virtual_machine" "test" { name = "acctestvm%d" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location size = "Standard_F2" username = "acct5stU5er" - password = "Pa$$w0rd1234!" + password = "Pa$w0rd1234!" disallow_public_ip_address = true - lab_virtual_network_id = "${azurerm_dev_test_virtual_network.test.id}" - lab_subnet_name = "${azurerm_dev_test_virtual_network.test.subnet.0.name}" + lab_virtual_network_id = azurerm_dev_test_virtual_network.test.id + lab_subnet_name = azurerm_dev_test_virtual_network.test.subnet[0].name storage_type = "Standard" gallery_image_reference { @@ -284,14 +284,14 @@ func testAccAzureRMDevTestWindowsVirtualMachine_storage(data acceptance.TestData resource "azurerm_dev_test_windows_virtual_machine" "test" { name = "acctestvm%d" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location size = "Standard_B1ms" username = "acct5stU5er" - password = "Pa$$w0rd1234!" - lab_virtual_network_id = "${azurerm_dev_test_virtual_network.test.id}" - lab_subnet_name = "${azurerm_dev_test_virtual_network.test.subnet.0.name}" + password = "Pa$w0rd1234!" + lab_virtual_network_id = azurerm_dev_test_virtual_network.test.id + lab_subnet_name = azurerm_dev_test_virtual_network.test.subnet[0].name storage_type = "%s" gallery_image_reference { @@ -306,6 +306,10 @@ resource "azurerm_dev_test_windows_virtual_machine" "test" { func testAccAzureRMDevTestWindowsVirtualMachine_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -313,14 +317,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dev_test_lab" "test" { name = "acctestdtl%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dev_test_virtual_network" "test" { name = "acctestdtvn%d" - lab_name = "${azurerm_dev_test_lab.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + lab_name = azurerm_dev_test_lab.test.name + resource_group_name = azurerm_resource_group.test.name subnet { use_public_ip_address = "Allow" diff --git a/azurerm/internal/services/dns/data_source_dns_zone.go b/azurerm/internal/services/dns/data_source_dns_zone.go index 79f38a81fc4b3..3c4586a34e8a4 100644 --- a/azurerm/internal/services/dns/data_source_dns_zone.go +++ b/azurerm/internal/services/dns/data_source_dns_zone.go @@ -51,24 +51,6 @@ func dataSourceArmDnsZone() *schema.Resource { Set: schema.HashString, }, - "zone_type": { - Type: schema.TypeString, - Computed: true, - Deprecated: "Private DNS Zones are now supported through a separate resource in Azure & Terraform", - }, - - "registration_virtual_network_ids": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - - "resolution_virtual_network_ids": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "tags": tags.SchemaDataSource(), }, } @@ -114,27 +96,6 @@ func dataSourceArmDnsZoneRead(d *schema.ResourceData, meta interface{}) error { if props := resp.ZoneProperties; props != nil { d.Set("number_of_record_sets", props.NumberOfRecordSets) d.Set("max_number_of_record_sets", props.MaxNumberOfRecordSets) - d.Set("zone_type", props.ZoneType) - - registrationVNets := make([]string, 0) - if rvns := props.RegistrationVirtualNetworks; rvns != nil { - for _, rvn := range *rvns { - registrationVNets = append(registrationVNets, *rvn.ID) - } - } - if err := d.Set("registration_virtual_network_ids", registrationVNets); err != nil { - return err - } - - resolutionVNets := make([]string, 0) - if rvns := props.ResolutionVirtualNetworks; rvns != nil { - for _, rvn := range *rvns { - resolutionVNets = append(resolutionVNets, *rvn.ID) - } - } - if err := d.Set("resolution_virtual_network_ids", resolutionVNets); err != nil { - return err - } nameServers := make([]string, 0) if ns := props.NameServers; ns != nil { diff --git a/azurerm/internal/services/dns/parse/dns_a_record.go b/azurerm/internal/services/dns/parse/dns_a_record.go new file mode 100644 index 0000000000000..dd85593c276ff --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_a_record.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DnsARecordId struct { + ResourceGroup string + ZoneName string + Name string +} + +func DnsARecordID(input string) (*DnsARecordId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse DNS A Record ID %q: %+v", input, err) + } + + record := DnsARecordId{ + ResourceGroup: id.ResourceGroup, + } + + if record.ZoneName, err = id.PopSegment("dnszones"); err != nil { + return nil, err + } + + if record.Name, err = id.PopSegment("A"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &record, nil +} diff --git a/azurerm/internal/services/dns/parse/dns_a_record_test.go b/azurerm/internal/services/dns/parse/dns_a_record_test.go new file mode 100644 index 0000000000000..cd48c1c806451 --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_a_record_test.go @@ -0,0 +1,86 @@ +package parse + +import ( + "testing" +) + +func TestDnsARecordId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *DnsARecordId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing DNS Zones Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/", + Expected: nil, + }, + { + Name: "DNS Zone ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1", + Expected: nil, + }, + { + Name: "Missing A Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/A/", + Expected: nil, + }, + { + Name: "DNS A Record ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/A/myrecord1", + Expected: &DnsARecordId{ + ResourceGroup: "resGroup1", + ZoneName: "zone1", + Name: "myrecord1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/a/myrecord1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := DnsARecordID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + if actual.ZoneName != v.Expected.ZoneName { + t.Fatalf("Expected %q but got %q for ZoneName", v.Expected.ZoneName, actual.ZoneName) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/dns/parse/dns_aaaa_record.go b/azurerm/internal/services/dns/parse/dns_aaaa_record.go new file mode 100644 index 0000000000000..e9b7b1bb10a3d --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_aaaa_record.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DnsAaaaRecordId struct { + ResourceGroup string + ZoneName string + Name string +} + +func DnsAaaaRecordID(input string) (*DnsAaaaRecordId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse DNS AAAA Record ID %q: %+v", input, err) + } + + record := DnsAaaaRecordId{ + ResourceGroup: id.ResourceGroup, + } + + if record.ZoneName, err = id.PopSegment("dnszones"); err != nil { + return nil, err + } + + if record.Name, err = id.PopSegment("AAAA"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &record, nil +} diff --git a/azurerm/internal/services/dns/parse/dns_aaaa_record_test.go b/azurerm/internal/services/dns/parse/dns_aaaa_record_test.go new file mode 100644 index 0000000000000..36dc9458b744f --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_aaaa_record_test.go @@ -0,0 +1,86 @@ +package parse + +import ( + "testing" +) + +func TestDnsAAAARecordId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *DnsAaaaRecordId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing DNS Zones Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/", + Expected: nil, + }, + { + Name: "DNS Zone ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1", + Expected: nil, + }, + { + Name: "Missing AAAA Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/AAAA/", + Expected: nil, + }, + { + Name: "DNS AAAA Record ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/AAAA/myrecord1", + Expected: &DnsAaaaRecordId{ + ResourceGroup: "resGroup1", + ZoneName: "zone1", + Name: "myrecord1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/aaaa/myrecord1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := DnsAaaaRecordID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + if actual.ZoneName != v.Expected.ZoneName { + t.Fatalf("Expected %q but got %q for ZoneName", v.Expected.ZoneName, actual.ZoneName) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/dns/parse/dns_caa_record.go b/azurerm/internal/services/dns/parse/dns_caa_record.go new file mode 100644 index 0000000000000..1ae6b4afc175f --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_caa_record.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DnsCaaRecordId struct { + ResourceGroup string + ZoneName string + Name string +} + +func DnsCaaRecordID(input string) (*DnsCaaRecordId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse DNS CAA Record ID %q: %+v", input, err) + } + + record := DnsCaaRecordId{ + ResourceGroup: id.ResourceGroup, + } + + if record.ZoneName, err = id.PopSegment("dnszones"); err != nil { + return nil, err + } + + if record.Name, err = id.PopSegment("CAA"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &record, nil +} diff --git a/azurerm/internal/services/dns/parse/dns_caa_record_test.go b/azurerm/internal/services/dns/parse/dns_caa_record_test.go new file mode 100644 index 0000000000000..0ee8c66689c73 --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_caa_record_test.go @@ -0,0 +1,86 @@ +package parse + +import ( + "testing" +) + +func TestDnsCaaRecordId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *DnsCaaRecordId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing DNS Zones Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/", + Expected: nil, + }, + { + Name: "DNS Zone ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1", + Expected: nil, + }, + { + Name: "Missing CAA Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/CAA/", + Expected: nil, + }, + { + Name: "DNS CAA Record ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/CAA/myrecord1", + Expected: &DnsCaaRecordId{ + ResourceGroup: "resGroup1", + ZoneName: "zone1", + Name: "myrecord1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/caa/myrecord1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := DnsCaaRecordID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + if actual.ZoneName != v.Expected.ZoneName { + t.Fatalf("Expected %q but got %q for ZoneName", v.Expected.ZoneName, actual.ZoneName) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/dns/parse/dns_cname_record.go b/azurerm/internal/services/dns/parse/dns_cname_record.go new file mode 100644 index 0000000000000..f43d8c4ff0dc2 --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_cname_record.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DnsCNameRecordId struct { + ResourceGroup string + ZoneName string + Name string +} + +func DnsCNameRecordID(input string) (*DnsCNameRecordId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse DNS CNAME Record ID %q: %+v", input, err) + } + + record := DnsCNameRecordId{ + ResourceGroup: id.ResourceGroup, + } + + if record.ZoneName, err = id.PopSegment("dnszones"); err != nil { + return nil, err + } + + if record.Name, err = id.PopSegment("CNAME"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &record, nil +} diff --git a/azurerm/internal/services/dns/parse/dns_cname_record_test.go b/azurerm/internal/services/dns/parse/dns_cname_record_test.go new file mode 100644 index 0000000000000..b0f4d55157b8f --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_cname_record_test.go @@ -0,0 +1,86 @@ +package parse + +import ( + "testing" +) + +func TestDnsCNameRecordId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *DnsCNameRecordId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing DNS Zones Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/", + Expected: nil, + }, + { + Name: "DNS Zone ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1", + Expected: nil, + }, + { + Name: "Missing CNAME Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/CNAME/", + Expected: nil, + }, + { + Name: "DNS CNAME Record ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/CNAME/myrecord1", + Expected: &DnsCNameRecordId{ + ResourceGroup: "resGroup1", + ZoneName: "zone1", + Name: "myrecord1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/cname/myrecord1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := DnsCNameRecordID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + if actual.ZoneName != v.Expected.ZoneName { + t.Fatalf("Expected %q but got %q for ZoneName", v.Expected.ZoneName, actual.ZoneName) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/dns/parse/dns_mx_record.go b/azurerm/internal/services/dns/parse/dns_mx_record.go new file mode 100644 index 0000000000000..17bb2798b541e --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_mx_record.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DnsMxRecordId struct { + ResourceGroup string + ZoneName string + Name string +} + +func DnsMxRecordID(input string) (*DnsMxRecordId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse DNS MX Record ID %q: %+v", input, err) + } + + record := DnsMxRecordId{ + ResourceGroup: id.ResourceGroup, + } + + if record.ZoneName, err = id.PopSegment("dnszones"); err != nil { + return nil, err + } + + if record.Name, err = id.PopSegment("MX"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &record, nil +} diff --git a/azurerm/internal/services/dns/parse/dns_mx_record_test.go b/azurerm/internal/services/dns/parse/dns_mx_record_test.go new file mode 100644 index 0000000000000..2b565b675c5dc --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_mx_record_test.go @@ -0,0 +1,86 @@ +package parse + +import ( + "testing" +) + +func TestDnsMxRecordId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *DnsMxRecordId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing DNS Zones Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/", + Expected: nil, + }, + { + Name: "DNS Zone ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1", + Expected: nil, + }, + { + Name: "Missing MX Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/MX/", + Expected: nil, + }, + { + Name: "DNS MX Record ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/MX/myrecord1", + Expected: &DnsMxRecordId{ + ResourceGroup: "resGroup1", + ZoneName: "zone1", + Name: "myrecord1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/mx/myrecord1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := DnsMxRecordID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + if actual.ZoneName != v.Expected.ZoneName { + t.Fatalf("Expected %q but got %q for ZoneName", v.Expected.ZoneName, actual.ZoneName) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/dns/parse/dns_ns_record.go b/azurerm/internal/services/dns/parse/dns_ns_record.go new file mode 100644 index 0000000000000..4bef6f9ea0b7b --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_ns_record.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DnsNsRecordId struct { + ResourceGroup string + ZoneName string + Name string +} + +func DnsNsRecordID(input string) (*DnsNsRecordId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse DNS NS Record ID %q: %+v", input, err) + } + + record := DnsNsRecordId{ + ResourceGroup: id.ResourceGroup, + } + + if record.ZoneName, err = id.PopSegment("dnszones"); err != nil { + return nil, err + } + + if record.Name, err = id.PopSegment("NS"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &record, nil +} diff --git a/azurerm/internal/services/dns/parse/dns_ns_record_test.go b/azurerm/internal/services/dns/parse/dns_ns_record_test.go new file mode 100644 index 0000000000000..35b2ce5c37f1b --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_ns_record_test.go @@ -0,0 +1,86 @@ +package parse + +import ( + "testing" +) + +func TestDnsNsRecordId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *DnsNsRecordId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing DNS Zones Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/", + Expected: nil, + }, + { + Name: "DNS Zone ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1", + Expected: nil, + }, + { + Name: "Missing NS Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/NS/", + Expected: nil, + }, + { + Name: "DNS NS Record ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/NS/myrecord1", + Expected: &DnsNsRecordId{ + ResourceGroup: "resGroup1", + ZoneName: "zone1", + Name: "myrecord1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/ns/myrecord1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := DnsNsRecordID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + if actual.ZoneName != v.Expected.ZoneName { + t.Fatalf("Expected %q but got %q for ZoneName", v.Expected.ZoneName, actual.ZoneName) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/dns/parse/dns_ptr_record.go b/azurerm/internal/services/dns/parse/dns_ptr_record.go new file mode 100644 index 0000000000000..0926b71e3890c --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_ptr_record.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DnsPtrRecordId struct { + ResourceGroup string + ZoneName string + Name string +} + +func DnsPtrRecordID(input string) (*DnsPtrRecordId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse DNS PTR Record ID %q: %+v", input, err) + } + + record := DnsPtrRecordId{ + ResourceGroup: id.ResourceGroup, + } + + if record.ZoneName, err = id.PopSegment("dnszones"); err != nil { + return nil, err + } + + if record.Name, err = id.PopSegment("PTR"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &record, nil +} diff --git a/azurerm/internal/services/dns/parse/dns_ptr_record_test.go b/azurerm/internal/services/dns/parse/dns_ptr_record_test.go new file mode 100644 index 0000000000000..7dfd262137177 --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_ptr_record_test.go @@ -0,0 +1,86 @@ +package parse + +import ( + "testing" +) + +func TestDnsPtrRecordId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *DnsPtrRecordId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing DNS Zones Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/", + Expected: nil, + }, + { + Name: "DNS Zone ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1", + Expected: nil, + }, + { + Name: "Missing PTR Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/PTR/", + Expected: nil, + }, + { + Name: "DNS PTR Record ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/PTR/myrecord1", + Expected: &DnsPtrRecordId{ + ResourceGroup: "resGroup1", + ZoneName: "zone1", + Name: "myrecord1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/ptr/myrecord1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := DnsPtrRecordID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + if actual.ZoneName != v.Expected.ZoneName { + t.Fatalf("Expected %q but got %q for ZoneName", v.Expected.ZoneName, actual.ZoneName) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/dns/parse/dns_srv_record.go b/azurerm/internal/services/dns/parse/dns_srv_record.go new file mode 100644 index 0000000000000..ec4d9802705c7 --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_srv_record.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DnsSrvRecordId struct { + ResourceGroup string + ZoneName string + Name string +} + +func DnsSrvRecordID(input string) (*DnsSrvRecordId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse DNS SRV Record ID %q: %+v", input, err) + } + + record := DnsSrvRecordId{ + ResourceGroup: id.ResourceGroup, + } + + if record.ZoneName, err = id.PopSegment("dnszones"); err != nil { + return nil, err + } + + if record.Name, err = id.PopSegment("SRV"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &record, nil +} diff --git a/azurerm/internal/services/dns/parse/dns_srv_record_test.go b/azurerm/internal/services/dns/parse/dns_srv_record_test.go new file mode 100644 index 0000000000000..00f6131a7c3a0 --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_srv_record_test.go @@ -0,0 +1,86 @@ +package parse + +import ( + "testing" +) + +func TestDnsSrvRecordId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *DnsSrvRecordId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing DNS Zones Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/", + Expected: nil, + }, + { + Name: "DNS Zone ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1", + Expected: nil, + }, + { + Name: "Missing SRV Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/SRV/", + Expected: nil, + }, + { + Name: "DNS SRV Record ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/SRV/myrecord1", + Expected: &DnsSrvRecordId{ + ResourceGroup: "resGroup1", + ZoneName: "zone1", + Name: "myrecord1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/srv/myrecord1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := DnsSrvRecordID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + if actual.ZoneName != v.Expected.ZoneName { + t.Fatalf("Expected %q but got %q for ZoneName", v.Expected.ZoneName, actual.ZoneName) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/dns/parse/dns_txt_record.go b/azurerm/internal/services/dns/parse/dns_txt_record.go new file mode 100644 index 0000000000000..dc4344ac78b9e --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_txt_record.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DnsTxtRecordId struct { + ResourceGroup string + ZoneName string + Name string +} + +func DnsTxtRecordID(input string) (*DnsTxtRecordId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse DNS TXT Record ID %q: %+v", input, err) + } + + record := DnsTxtRecordId{ + ResourceGroup: id.ResourceGroup, + } + + if record.ZoneName, err = id.PopSegment("dnszones"); err != nil { + return nil, err + } + + if record.Name, err = id.PopSegment("TXT"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &record, nil +} diff --git a/azurerm/internal/services/dns/parse/dns_txt_record_test.go b/azurerm/internal/services/dns/parse/dns_txt_record_test.go new file mode 100644 index 0000000000000..6c32e244024de --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_txt_record_test.go @@ -0,0 +1,86 @@ +package parse + +import ( + "testing" +) + +func TestDnsTxtRecordId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *DnsTxtRecordId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing DNS Zones Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/", + Expected: nil, + }, + { + Name: "DNS Zone ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1", + Expected: nil, + }, + { + Name: "Missing TXT Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/TXT/", + Expected: nil, + }, + { + Name: "DNS TXT Record ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/TXT/myrecord1", + Expected: &DnsTxtRecordId{ + ResourceGroup: "resGroup1", + ZoneName: "zone1", + Name: "myrecord1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1/txt/myrecord1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := DnsTxtRecordID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + if actual.ZoneName != v.Expected.ZoneName { + t.Fatalf("Expected %q but got %q for ZoneName", v.Expected.ZoneName, actual.ZoneName) + } + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/dns/parse/dns_zone.go b/azurerm/internal/services/dns/parse/dns_zone.go new file mode 100644 index 0000000000000..9d2fb359d068e --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_zone.go @@ -0,0 +1,33 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type DnsZoneId struct { + ResourceGroup string + Name string +} + +func DnsZoneID(input string) (*DnsZoneId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse DNS Zone ID %q: %+v", input, err) + } + + zone := DnsZoneId{ + ResourceGroup: id.ResourceGroup, + } + + if zone.Name, err = id.PopSegment("dnszones"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &zone, nil +} diff --git a/azurerm/internal/services/dns/parse/dns_zone_test.go b/azurerm/internal/services/dns/parse/dns_zone_test.go new file mode 100644 index 0000000000000..3d970377aa14e --- /dev/null +++ b/azurerm/internal/services/dns/parse/dns_zone_test.go @@ -0,0 +1,73 @@ +package parse + +import ( + "testing" +) + +func TestDnsZoneId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *DnsZoneId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing DNS Zones Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/", + Expected: nil, + }, + { + Name: "DNS Zone ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/dnszones/zone1", + Expected: &DnsZoneId{ + Name: "zone1", + ResourceGroup: "resGroup1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/Dnszones/zone1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := DnsZoneID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/dns/registration.go b/azurerm/internal/services/dns/registration.go index 1935a8f57175d..841f7e418f264 100644 --- a/azurerm/internal/services/dns/registration.go +++ b/azurerm/internal/services/dns/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "DNS" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "DNS", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/dns/resource_arm_dns_a_record.go b/azurerm/internal/services/dns/resource_arm_dns_a_record.go index a7a919eb49d27..a7798f49283a4 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_a_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_a_record.go @@ -11,7 +11,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -22,9 +24,6 @@ func resourceArmDnsARecord() *schema.Resource { Read: resourceArmDnsARecordRead, Update: resourceArmDnsARecordCreateUpdate, Delete: resourceArmDnsARecordDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -32,6 +31,10 @@ func resourceArmDnsARecord() *schema.Resource { Update: schema.DefaultTimeout(30 * time.Minute), Delete: schema.DefaultTimeout(30 * time.Minute), }, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DnsARecordID(id) + return err + }), Schema: map[string]*schema.Schema{ "name": { @@ -150,27 +153,24 @@ func resourceArmDnsARecordRead(d *schema.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsARecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["A"] - zoneName := id.Path["dnszones"] - - resp, err := dnsClient.Get(ctx, resGroup, zoneName, name, dns.A) + resp, err := dnsClient.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.A) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error reading DNS A record %s: %+v", name, err) + return fmt.Errorf("Error reading DNS A record %s: %+v", id.Name, err) } - d.Set("name", name) - d.Set("resource_group_name", resGroup) - d.Set("zone_name", zoneName) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("zone_name", id.ZoneName) + d.Set("fqdn", resp.Fqdn) d.Set("ttl", resp.TTL) @@ -192,18 +192,14 @@ func resourceArmDnsARecordDelete(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsARecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["A"] - zoneName := id.Path["dnszones"] - - resp, err := dnsClient.Delete(ctx, resGroup, zoneName, name, dns.A, "") + resp, err := dnsClient.Delete(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.A, "") if resp.StatusCode != http.StatusOK { - return fmt.Errorf("Error deleting DNS A Record %s: %+v", name, err) + return fmt.Errorf("Error deleting DNS A Record %s: %+v", id.Name, err) } return nil diff --git a/azurerm/internal/services/dns/resource_arm_dns_aaaa_record.go b/azurerm/internal/services/dns/resource_arm_dns_aaaa_record.go index 657bcfc287bb2..ba4788b3a33aa 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_aaaa_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_aaaa_record.go @@ -12,7 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -23,9 +25,6 @@ func resourceArmDnsAAAARecord() *schema.Resource { Read: resourceArmDnsAaaaRecordRead, Update: resourceArmDnsAaaaRecordCreateUpdate, Delete: resourceArmDnsAaaaRecordDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -34,6 +33,11 @@ func resourceArmDnsAAAARecord() *schema.Resource { Delete: schema.DefaultTimeout(30 * time.Minute), }, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DnsAaaaRecordID(id) + return err + }), + Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -152,27 +156,24 @@ func resourceArmDnsAaaaRecordRead(d *schema.ResourceData, meta interface{}) erro ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsAaaaRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["AAAA"] - zoneName := id.Path["dnszones"] - - resp, err := dnsClient.Get(ctx, resGroup, zoneName, name, dns.AAAA) + resp, err := dnsClient.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.AAAA) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error reading DNS AAAA record %s: %v", name, err) + return fmt.Errorf("Error reading DNS AAAA record %s: %v", id.Name, err) } - d.Set("name", name) - d.Set("resource_group_name", resGroup) - d.Set("zone_name", zoneName) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("zone_name", id.ZoneName) + d.Set("fqdn", resp.Fqdn) d.Set("ttl", resp.TTL) @@ -194,18 +195,14 @@ func resourceArmDnsAaaaRecordDelete(d *schema.ResourceData, meta interface{}) er ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsAaaaRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["AAAA"] - zoneName := id.Path["dnszones"] - - resp, err := dnsClient.Delete(ctx, resGroup, zoneName, name, dns.AAAA, "") + resp, err := dnsClient.Delete(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.AAAA, "") if resp.StatusCode != http.StatusOK { - return fmt.Errorf("Error deleting DNS AAAA Record %s: %+v", name, err) + return fmt.Errorf("Error deleting DNS AAAA Record %s: %+v", id.Name, err) } return nil diff --git a/azurerm/internal/services/dns/resource_arm_dns_caa_record.go b/azurerm/internal/services/dns/resource_arm_dns_caa_record.go index 65db838855bbc..7cf9ba5944bfd 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_caa_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_caa_record.go @@ -15,7 +15,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -26,9 +28,6 @@ func resourceArmDnsCaaRecord() *schema.Resource { Read: resourceArmDnsCaaRecordRead, Update: resourceArmDnsCaaRecordCreateUpdate, Delete: resourceArmDnsCaaRecordDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -37,6 +36,11 @@ func resourceArmDnsCaaRecord() *schema.Resource { Delete: schema.DefaultTimeout(30 * time.Minute), }, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DnsCaaRecordID(id) + return err + }), + Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -155,27 +159,24 @@ func resourceArmDnsCaaRecordRead(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsCaaRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["CAA"] - zoneName := id.Path["dnszones"] - - resp, err := client.Get(ctx, resGroup, zoneName, name, dns.CAA) + resp, err := client.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.CAA) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error reading DNS CAA record %s: %v", name, err) + return fmt.Errorf("Error reading DNS CAA record %s: %v", id.Name, err) } - d.Set("name", name) - d.Set("resource_group_name", resGroup) - d.Set("zone_name", zoneName) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("zone_name", id.ZoneName) + d.Set("ttl", resp.TTL) d.Set("fqdn", resp.Fqdn) @@ -190,18 +191,14 @@ func resourceArmDnsCaaRecordDelete(d *schema.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsCaaRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["CAA"] - zoneName := id.Path["dnszones"] - - resp, err := client.Delete(ctx, resGroup, zoneName, name, dns.CAA, "") + resp, err := client.Delete(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.CAA, "") if resp.StatusCode != http.StatusOK { - return fmt.Errorf("Error deleting DNS CAA Record %s: %+v", name, err) + return fmt.Errorf("Error deleting DNS CAA Record %s: %+v", id.Name, err) } return nil diff --git a/azurerm/internal/services/dns/resource_arm_dns_cname_record.go b/azurerm/internal/services/dns/resource_arm_dns_cname_record.go index 715bdc968812e..8ab073a76968a 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_cname_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_cname_record.go @@ -11,7 +11,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -22,9 +24,6 @@ func resourceArmDnsCNameRecord() *schema.Resource { Read: resourceArmDnsCNameRecordRead, Update: resourceArmDnsCNameRecordCreateUpdate, Delete: resourceArmDnsCNameRecordDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -33,6 +32,11 @@ func resourceArmDnsCNameRecord() *schema.Resource { Delete: schema.DefaultTimeout(30 * time.Minute), }, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DnsCNameRecordID(id) + return err + }), + Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -47,12 +51,6 @@ func resourceArmDnsCNameRecord() *schema.Resource { Required: true, }, - "records": { - Type: schema.TypeString, - Optional: true, - Removed: "Use `record` instead. This attribute will be removed in a future version", - }, - "record": { Type: schema.TypeString, Optional: true, @@ -73,7 +71,7 @@ func resourceArmDnsCNameRecord() *schema.Resource { Type: schema.TypeString, Optional: true, ValidateFunc: azure.ValidateResourceID, - ConflictsWith: []string{"records"}, + ConflictsWith: []string{"record"}, }, "tags": tags.Schema(), @@ -156,27 +154,24 @@ func resourceArmDnsCNameRecordRead(d *schema.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsCNameRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["CNAME"] - zoneName := id.Path["dnszones"] - - resp, err := dnsClient.Get(ctx, resGroup, zoneName, name, dns.CNAME) + resp, err := dnsClient.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.CNAME) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving CNAME Record %s (DNS Zone %q / Resource Group %q): %+v", name, zoneName, resGroup, err) + return fmt.Errorf("Error retrieving CNAME Record %s (DNS Zone %q / Resource Group %q): %+v", id.Name, id.ZoneName, id.ResourceGroup, err) } - d.Set("name", name) - d.Set("resource_group_name", resGroup) - d.Set("zone_name", zoneName) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("zone_name", id.ZoneName) + d.Set("fqdn", resp.Fqdn) d.Set("ttl", resp.TTL) @@ -202,18 +197,14 @@ func resourceArmDnsCNameRecordDelete(d *schema.ResourceData, meta interface{}) e ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsCNameRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["CNAME"] - zoneName := id.Path["dnszones"] - - resp, err := dnsClient.Delete(ctx, resGroup, zoneName, name, dns.CNAME, "") + resp, err := dnsClient.Delete(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.CNAME, "") if resp.StatusCode != http.StatusOK { - return fmt.Errorf("Error deleting CNAME Record %q (DNS Zone %q / Resource Group %q): %+v", name, zoneName, resGroup, err) + return fmt.Errorf("Error deleting CNAME Record %q (DNS Zone %q / Resource Group %q): %+v", id.Name, id.ZoneName, id.ResourceGroup, err) } return nil diff --git a/azurerm/internal/services/dns/resource_arm_dns_mx_record.go b/azurerm/internal/services/dns/resource_arm_dns_mx_record.go index 42f29f95d9878..a244b4c65eb9f 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_mx_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_mx_record.go @@ -14,7 +14,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -25,9 +27,6 @@ func resourceArmDnsMxRecord() *schema.Resource { Read: resourceArmDnsMxRecordRead, Update: resourceArmDnsMxRecordCreateUpdate, Delete: resourceArmDnsMxRecordDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -36,6 +35,11 @@ func resourceArmDnsMxRecord() *schema.Resource { Delete: schema.DefaultTimeout(30 * time.Minute), }, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DnsMxRecordID(id) + return err + }), + Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -143,27 +147,24 @@ func resourceArmDnsMxRecordRead(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsMxRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["MX"] - zoneName := id.Path["dnszones"] - - resp, err := client.Get(ctx, resGroup, zoneName, name, dns.MX) + resp, err := client.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.MX) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error reading DNS MX record %s: %v", name, err) + return fmt.Errorf("Error reading DNS MX record %s: %v", id.Name, err) } - d.Set("name", name) - d.Set("resource_group_name", resGroup) - d.Set("zone_name", zoneName) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("zone_name", id.ZoneName) + d.Set("ttl", resp.TTL) d.Set("fqdn", resp.Fqdn) @@ -178,18 +179,14 @@ func resourceArmDnsMxRecordDelete(d *schema.ResourceData, meta interface{}) erro ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsMxRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["MX"] - zoneName := id.Path["dnszones"] - - resp, err := client.Delete(ctx, resGroup, zoneName, name, dns.MX, "") + resp, err := client.Delete(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.MX, "") if resp.StatusCode != http.StatusOK { - return fmt.Errorf("Error deleting DNS MX Record %s: %+v", name, err) + return fmt.Errorf("Error deleting DNS MX Record %s: %+v", id.Name, err) } return nil diff --git a/azurerm/internal/services/dns/resource_arm_dns_ns_record.go b/azurerm/internal/services/dns/resource_arm_dns_ns_record.go index a1d5e37a85cb3..db47b9a0aa8e7 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_ns_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_ns_record.go @@ -11,20 +11,19 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func resourceArmDnsNsRecord() *schema.Resource { return &schema.Resource{ - Create: resourceArmDnsNsRecordCreateUpdate, + Create: resourceArmDnsNsRecordCreate, Read: resourceArmDnsNsRecordRead, - Update: resourceArmDnsNsRecordCreateUpdate, + Update: resourceArmDnsNsRecordUpdate, Delete: resourceArmDnsNsRecordDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -32,6 +31,10 @@ func resourceArmDnsNsRecord() *schema.Resource { Update: schema.DefaultTimeout(30 * time.Minute), Delete: schema.DefaultTimeout(30 * time.Minute), }, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DnsNsRecordID(id) + return err + }), Schema: map[string]*schema.Schema{ "name": { @@ -45,30 +48,14 @@ func resourceArmDnsNsRecord() *schema.Resource { "zone_name": { Type: schema.TypeString, Required: true, + ForceNew: true, }, "records": { - Type: schema.TypeList, - //TODO: add `Required: true` once we remove the `record` attribute - Optional: true, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - ConflictsWith: []string{"record"}, - }, - - "record": { - Type: schema.TypeSet, - Optional: true, - Computed: true, - Deprecated: "This field has been replaced by `records`", - ConflictsWith: []string{"records"}, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "nsdname": { - Type: schema.TypeString, - Required: true, - }, - }, + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{ + Type: schema.TypeString, }, }, @@ -87,16 +74,16 @@ func resourceArmDnsNsRecord() *schema.Resource { } } -func resourceArmDnsNsRecordCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceArmDnsNsRecordCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Dns.RecordSetsClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() name := d.Get("name").(string) resGroup := d.Get("resource_group_name").(string) zoneName := d.Get("zone_name").(string) - if features.ShouldResourcesBeImported() && d.IsNewResource() { + if features.ShouldResourcesBeImported() { existing, err := client.Get(ctx, resGroup, zoneName, name, dns.NS) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { @@ -112,19 +99,22 @@ func resourceArmDnsNsRecordCreateUpdate(d *schema.ResourceData, meta interface{} ttl := int64(d.Get("ttl").(int)) t := d.Get("tags").(map[string]interface{}) + recordsRaw := d.Get("records").([]interface{}) + records := expandAzureRmDnsNsRecords(recordsRaw) + parameters := dns.RecordSet{ Name: &name, RecordSetProperties: &dns.RecordSetProperties{ Metadata: tags.Expand(t), TTL: &ttl, - NsRecords: expandAzureRmDnsNsRecords(d), + NsRecords: records, }, } eTag := "" ifNoneMatch := "" // set to empty to allow updates to records after creation if _, err := client.CreateOrUpdate(ctx, resGroup, zoneName, name, dns.NS, parameters, eTag, ifNoneMatch); err != nil { - return fmt.Errorf("Error creating/updating DNS NS Record %q (Zone %q / Resource Group %q): %s", name, zoneName, resGroup, err) + return fmt.Errorf("Error creating DNS NS Record %q (Zone %q / Resource Group %q): %s", name, zoneName, resGroup, err) } resp, err := client.Get(ctx, resGroup, zoneName, name, dns.NS) @@ -141,9 +131,9 @@ func resourceArmDnsNsRecordCreateUpdate(d *schema.ResourceData, meta interface{} return resourceArmDnsNsRecordRead(d, meta) } -func resourceArmDnsNsRecordRead(d *schema.ResourceData, meta interface{}) error { - dnsClient := meta.(*clients.Client).Dns.RecordSetsClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) +func resourceArmDnsNsRecordUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Dns.RecordSetsClient + ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() id, err := azure.ParseAzureResourceID(d.Id()) @@ -155,28 +145,69 @@ func resourceArmDnsNsRecordRead(d *schema.ResourceData, meta interface{}) error name := id.Path["NS"] zoneName := id.Path["dnszones"] - resp, err := dnsClient.Get(ctx, resGroup, zoneName, name, dns.NS) + existing, err := client.Get(ctx, resGroup, zoneName, name, dns.NS) + if err != nil { + return fmt.Errorf("Error retrieving NS %q (DNS Zone %q / Resource Group %q): %+v", name, zoneName, resGroup, err) + } + + if existing.RecordSetProperties == nil { + return fmt.Errorf("Error retrieving NS %q (DNS Zone %q / Resource Group %q): `properties` was nil", name, zoneName, resGroup) + } + + if d.HasChange("records") { + recordsRaw := d.Get("records").([]interface{}) + records := expandAzureRmDnsNsRecords(recordsRaw) + existing.RecordSetProperties.NsRecords = records + } + + if d.HasChange("tags") { + t := d.Get("tags").(map[string]interface{}) + existing.RecordSetProperties.Metadata = tags.Expand(t) + } + + if d.HasChange("ttl") { + existing.RecordSetProperties.TTL = utils.Int64(int64(d.Get("ttl").(int))) + } + + eTag := "" + ifNoneMatch := "" // set to empty to allow updates to records after creation + if _, err := client.CreateOrUpdate(ctx, resGroup, zoneName, name, dns.NS, existing, eTag, ifNoneMatch); err != nil { + return fmt.Errorf("Error updating DNS NS Record %q (Zone %q / Resource Group %q): %s", name, zoneName, resGroup, err) + } + + return resourceArmDnsNsRecordRead(d, meta) +} + +func resourceArmDnsNsRecordRead(d *schema.ResourceData, meta interface{}) error { + dnsClient := meta.(*clients.Client).Dns.RecordSetsClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.DnsNsRecordID(d.Id()) + if err != nil { + return err + } + + resp, err := dnsClient.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.NS) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error reading DNS NS record %s: %+v", name, err) + return fmt.Errorf("Error reading DNS NS record %s: %+v", id.Name, err) } - d.Set("name", name) - d.Set("resource_group_name", resGroup) - d.Set("zone_name", zoneName) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("zone_name", id.ZoneName) + d.Set("ttl", resp.TTL) d.Set("fqdn", resp.Fqdn) - if err := d.Set("records", flattenAzureRmDnsNsRecords(resp.NsRecords)); err != nil { - return fmt.Errorf("Error settings `records`: %+v", err) - } - - //TODO: remove this once we remove the `record` attribute - if err := d.Set("record", flattenAzureRmDnsNsRecordsSet(resp.NsRecords)); err != nil { - return fmt.Errorf("Error settings `record`: %+v", err) + if props := resp.RecordSetProperties; props != nil { + if err := d.Set("records", flattenAzureRmDnsNsRecords(props.NsRecords)); err != nil { + return fmt.Errorf("Error settings `records`: %+v", err) + } } return tags.FlattenAndSet(d, resp.Metadata) @@ -187,80 +218,46 @@ func resourceArmDnsNsRecordDelete(d *schema.ResourceData, meta interface{}) erro ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsNsRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["NS"] - zoneName := id.Path["dnszones"] - - resp, err := dnsClient.Delete(ctx, resGroup, zoneName, name, dns.NS, "") + resp, err := dnsClient.Delete(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.NS, "") if resp.StatusCode != http.StatusOK { - return fmt.Errorf("Error deleting DNS NS Record %s: %+v", name, err) + return fmt.Errorf("Error deleting DNS NS Record %s: %+v", id.Name, err) } return nil } -//TODO: remove this once we remove the `record` attribute -func flattenAzureRmDnsNsRecordsSet(records *[]dns.NsRecord) []map[string]interface{} { - results := make([]map[string]interface{}, 0, len(*records)) - - if records != nil { - for _, record := range *records { - nsRecord := make(map[string]interface{}) - nsRecord["nsdname"] = *record.Nsdname - results = append(results, nsRecord) - } +func flattenAzureRmDnsNsRecords(records *[]dns.NsRecord) []interface{} { + if records == nil { + return []interface{}{} } - return results -} - -func flattenAzureRmDnsNsRecords(records *[]dns.NsRecord) []string { - results := make([]string, 0, len(*records)) - - if records != nil { - for _, record := range *records { - results = append(results, *record.Nsdname) + results := make([]interface{}, 0) + for _, record := range *records { + if record.Nsdname == nil { + continue } + + results = append(results, *record.Nsdname) } return results } -func expandAzureRmDnsNsRecords(d *schema.ResourceData) *[]dns.NsRecord { - var records []dns.NsRecord - - //TODO: remove this once we remove the `record` attribute - if d.HasChange("records") || !d.HasChange("record") { - recordStrings := d.Get("records").([]interface{}) - records = make([]dns.NsRecord, len(recordStrings)) - for i, v := range recordStrings { - record := v.(string) - - nsRecord := dns.NsRecord{ - Nsdname: &record, - } +func expandAzureRmDnsNsRecords(input []interface{}) *[]dns.NsRecord { + records := make([]dns.NsRecord, len(input)) + for i, v := range input { + record := v.(string) - records[i] = nsRecord - } - } else { - recordList := d.Get("record").(*schema.Set).List() - if len(recordList) != 0 { - records = make([]dns.NsRecord, len(recordList)) - for i, v := range recordList { - record := v.(map[string]interface{}) - nsdname := record["nsdname"].(string) - nsRecord := dns.NsRecord{ - Nsdname: &nsdname, - } - - records[i] = nsRecord - } + nsRecord := dns.NsRecord{ + Nsdname: &record, } + + records[i] = nsRecord } return &records } diff --git a/azurerm/internal/services/dns/resource_arm_dns_ptr_record.go b/azurerm/internal/services/dns/resource_arm_dns_ptr_record.go index 25272c1c2dd5e..8f85a76141542 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_ptr_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_ptr_record.go @@ -11,7 +11,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -22,9 +24,6 @@ func resourceArmDnsPtrRecord() *schema.Resource { Read: resourceArmDnsPtrRecordRead, Update: resourceArmDnsPtrRecordCreateUpdate, Delete: resourceArmDnsPtrRecordDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -33,6 +32,10 @@ func resourceArmDnsPtrRecord() *schema.Resource { Delete: schema.DefaultTimeout(30 * time.Minute), }, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DnsPtrRecordID(id) + return err + }), Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -128,28 +131,24 @@ func resourceArmDnsPtrRecordRead(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsPtrRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["PTR"] - zoneName := id.Path["dnszones"] - - resp, err := dnsClient.Get(ctx, resGroup, zoneName, name, dns.PTR) + resp, err := dnsClient.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.PTR) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error reading DNS PTR record %s: %+v", name, err) + return fmt.Errorf("Error reading DNS PTR record %s: %+v", id.Name, err) } - d.Set("name", name) - d.Set("resource_group_name", resGroup) - d.Set("zone_name", zoneName) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("zone_name", id.ZoneName) d.Set("ttl", resp.TTL) d.Set("fqdn", resp.Fqdn) @@ -165,22 +164,18 @@ func resourceArmDnsPtrRecordDelete(d *schema.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsPtrRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["PTR"] - zoneName := id.Path["dnszones"] - - resp, err := dnsClient.Delete(ctx, resGroup, zoneName, name, dns.PTR, "") + resp, err := dnsClient.Delete(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.PTR, "") if err != nil { if resp.StatusCode == http.StatusNotFound { return nil } - return fmt.Errorf("Error deleting DNS PTR Record %s: %+v", name, err) + return fmt.Errorf("Error deleting DNS PTR Record %s: %+v", id.Name, err) } return nil diff --git a/azurerm/internal/services/dns/resource_arm_dns_srv_record.go b/azurerm/internal/services/dns/resource_arm_dns_srv_record.go index d6f7749e37582..456afc758020e 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_srv_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_srv_record.go @@ -13,7 +13,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -24,9 +26,6 @@ func resourceArmDnsSrvRecord() *schema.Resource { Read: resourceArmDnsSrvRecordRead, Update: resourceArmDnsSrvRecordCreateUpdate, Delete: resourceArmDnsSrvRecordDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -34,7 +33,10 @@ func resourceArmDnsSrvRecord() *schema.Resource { Update: schema.DefaultTimeout(30 * time.Minute), Delete: schema.DefaultTimeout(30 * time.Minute), }, - + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DnsSrvRecordID(id) + return err + }), Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -152,27 +154,23 @@ func resourceArmDnsSrvRecordRead(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsSrvRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["SRV"] - zoneName := id.Path["dnszones"] - - resp, err := client.Get(ctx, resGroup, zoneName, name, dns.SRV) + resp, err := client.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.SRV) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error reading DNS SRV record %s: %v", name, err) + return fmt.Errorf("Error reading DNS SRV record %s: %v", id.Name, err) } - d.Set("name", name) - d.Set("resource_group_name", resGroup) - d.Set("zone_name", zoneName) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("zone_name", id.ZoneName) d.Set("ttl", resp.TTL) d.Set("fqdn", resp.Fqdn) @@ -187,18 +185,14 @@ func resourceArmDnsSrvRecordDelete(d *schema.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsSrvRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["SRV"] - zoneName := id.Path["dnszones"] - - resp, err := client.Delete(ctx, resGroup, zoneName, name, dns.SRV, "") + resp, err := client.Delete(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.SRV, "") if resp.StatusCode != http.StatusOK { - return fmt.Errorf("Error deleting DNS SRV Record %s: %+v", name, err) + return fmt.Errorf("Error deleting DNS SRV Record %s: %+v", id.Name, err) } return nil diff --git a/azurerm/internal/services/dns/resource_arm_dns_txt_record.go b/azurerm/internal/services/dns/resource_arm_dns_txt_record.go index abf1e2eaae9c5..7a7f7a0c01ff4 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_txt_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_txt_record.go @@ -3,15 +3,19 @@ package dns import ( "fmt" "net/http" + "strings" "time" "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -22,9 +26,6 @@ func resourceArmDnsTxtRecord() *schema.Resource { Read: resourceArmDnsTxtRecordRead, Update: resourceArmDnsTxtRecordCreateUpdate, Delete: resourceArmDnsTxtRecordDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -32,7 +33,10 @@ func resourceArmDnsTxtRecord() *schema.Resource { Update: schema.DefaultTimeout(30 * time.Minute), Delete: schema.DefaultTimeout(30 * time.Minute), }, - + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DnsTxtRecordID(id) + return err + }), Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -53,8 +57,9 @@ func resourceArmDnsTxtRecord() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "value": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringLenBetween(1, 1024), }, }, }, @@ -134,27 +139,23 @@ func resourceArmDnsTxtRecordRead(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsTxtRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["TXT"] - zoneName := id.Path["dnszones"] - - resp, err := client.Get(ctx, resGroup, zoneName, name, dns.TXT) + resp, err := client.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.TXT) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error reading DNS TXT record %s: %+v", name, err) + return fmt.Errorf("Error reading DNS TXT record %s: %+v", id.Name, err) } - d.Set("name", name) - d.Set("resource_group_name", resGroup) - d.Set("zone_name", zoneName) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("zone_name", id.ZoneName) d.Set("ttl", resp.TTL) d.Set("fqdn", resp.Fqdn) @@ -169,18 +170,14 @@ func resourceArmDnsTxtRecordDelete(d *schema.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsTxtRecordID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["TXT"] - zoneName := id.Path["dnszones"] - - resp, err := client.Delete(ctx, resGroup, zoneName, name, dns.TXT, "") + resp, err := client.Delete(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.TXT, "") if resp.StatusCode != http.StatusOK { - return fmt.Errorf("Error deleting DNS TXT Record %s: %+v", name, err) + return fmt.Errorf("Error deleting DNS TXT Record %s: %+v", id.Name, err) } return nil @@ -194,7 +191,7 @@ func flattenAzureRmDnsTxtRecords(records *[]dns.TxtRecord) []map[string]interfac txtRecord := make(map[string]interface{}) if v := record.Value; v != nil { - value := (*v)[0] + value := strings.Join(*v, "") txtRecord["value"] = value } @@ -209,9 +206,17 @@ func expandAzureRmDnsTxtRecords(d *schema.ResourceData) *[]dns.TxtRecord { recordStrings := d.Get("record").(*schema.Set).List() records := make([]dns.TxtRecord, len(recordStrings)) + segmentLen := 254 for i, v := range recordStrings { record := v.(map[string]interface{}) - value := []string{record["value"].(string)} + v := record["value"].(string) + + var value []string + for len(v) > segmentLen { + value = append(value, v[:segmentLen]) + v = v[segmentLen:] + } + value = append(value, v) txtRecord := dns.TxtRecord{ Value: &value, diff --git a/azurerm/internal/services/dns/resource_arm_dns_zone.go b/azurerm/internal/services/dns/resource_arm_dns_zone.go index 8cbc72e5a3b8b..58258a85f94f5 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_zone.go +++ b/azurerm/internal/services/dns/resource_arm_dns_zone.go @@ -7,12 +7,13 @@ import ( "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -23,9 +24,6 @@ func resourceArmDnsZone() *schema.Resource { Read: resourceArmDnsZoneRead, Update: resourceArmDnsZoneCreateUpdate, Delete: resourceArmDnsZoneDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -34,6 +32,10 @@ func resourceArmDnsZone() *schema.Resource { Delete: schema.DefaultTimeout(30 * time.Minute), }, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.DnsZoneID(id) + return err + }), Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, @@ -60,29 +62,6 @@ func resourceArmDnsZone() *schema.Resource { Set: schema.HashString, }, - "zone_type": { - Type: schema.TypeString, - Default: string(dns.Public), - Optional: true, - Deprecated: "Use the `azurerm_private_dns_zone` resource instead.", - ValidateFunc: validation.StringInSlice([]string{ - string(dns.Private), - string(dns.Public), - }, false), - }, - - "registration_virtual_network_ids": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - - "resolution_virtual_network_ids": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "tags": tags.Schema(), }, } @@ -110,26 +89,16 @@ func resourceArmDnsZoneCreateUpdate(d *schema.ResourceData, meta interface{}) er } location := "global" - zoneType := d.Get("zone_type").(string) t := d.Get("tags").(map[string]interface{}) - registrationVirtualNetworkIds := expandDnsZoneRegistrationVirtualNetworkIds(d) - resolutionVirtualNetworkIds := expandDnsZoneResolutionVirtualNetworkIds(d) - parameters := dns.Zone{ Location: &location, Tags: tags.Expand(t), - ZoneProperties: &dns.ZoneProperties{ - ZoneType: dns.ZoneType(zoneType), - RegistrationVirtualNetworks: registrationVirtualNetworkIds, - ResolutionVirtualNetworks: resolutionVirtualNetworkIds, - }, } etag := "" ifNoneMatch := "" // set to empty to allow updates to records after creation - _, err := client.CreateOrUpdate(ctx, resGroup, name, parameters, etag, ifNoneMatch) - if err != nil { + if _, err := client.CreateOrUpdate(ctx, resGroup, name, parameters, etag, ifNoneMatch); err != nil { return fmt.Errorf("Error creating/updating DNS Zone %q (Resource Group %q): %s", name, resGroup, err) } @@ -152,38 +121,25 @@ func resourceArmDnsZoneRead(d *schema.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsZoneID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["dnszones"] - - resp, err := zonesClient.Get(ctx, resGroup, name) + resp, err := zonesClient.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error reading DNS Zone %q (Resource Group %q): %+v", name, resGroup, err) + return fmt.Errorf("Error reading DNS Zone %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } - d.Set("name", name) - d.Set("resource_group_name", resGroup) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("number_of_record_sets", resp.NumberOfRecordSets) d.Set("max_number_of_record_sets", resp.MaxNumberOfRecordSets) - d.Set("zone_type", resp.ZoneType) - - registrationVirtualNetworks := flattenDnsZoneRegistrationVirtualNetworkIDs(resp.RegistrationVirtualNetworks) - if err := d.Set("registration_virtual_network_ids", registrationVirtualNetworks); err != nil { - return err - } - - resolutionVirtualNetworks := flattenDnsZoneResolutionVirtualNetworkIDs(resp.ResolutionVirtualNetworks) - if err := d.Set("resolution_virtual_network_ids", resolutionVirtualNetworks); err != nil { - return err - } nameServers := make([]string, 0) if s := resp.NameServers; s != nil { @@ -201,81 +157,26 @@ func resourceArmDnsZoneDelete(d *schema.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.DnsZoneID(d.Id()) if err != nil { return err } - resGroup := id.ResourceGroup - name := id.Path["dnszones"] - etag := "" - future, err := client.Delete(ctx, resGroup, name, etag) + future, err := client.Delete(ctx, id.ResourceGroup, id.Name, etag) if err != nil { if response.WasNotFound(future.Response()) { return nil } - return fmt.Errorf("Error deleting DNS zone %s (resource group %s): %+v", name, resGroup, err) + return fmt.Errorf("Error deleting DNS zone %s (resource group %s): %+v", id.Name, id.ResourceGroup, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { if response.WasNotFound(future.Response()) { return nil } - return fmt.Errorf("Error deleting DNS zone %s (resource group %s): %+v", name, resGroup, err) + return fmt.Errorf("Error deleting DNS zone %s (resource group %s): %+v", id.Name, id.ResourceGroup, err) } return nil } - -func expandDnsZoneResolutionVirtualNetworkIds(d *schema.ResourceData) *[]dns.SubResource { - resolutionVirtualNetworks := d.Get("resolution_virtual_network_ids").([]interface{}) - - resolutionVNetSubResources := make([]dns.SubResource, 0, len(resolutionVirtualNetworks)) - for _, rvn := range resolutionVirtualNetworks { - id := rvn.(string) - resolutionVNetSubResources = append(resolutionVNetSubResources, dns.SubResource{ - ID: &id, - }) - } - - return &resolutionVNetSubResources -} - -func flattenDnsZoneRegistrationVirtualNetworkIDs(input *[]dns.SubResource) []string { - registrationVirtualNetworks := make([]string, 0) - - if input != nil { - for _, rvn := range *input { - registrationVirtualNetworks = append(registrationVirtualNetworks, *rvn.ID) - } - } - - return registrationVirtualNetworks -} - -func expandDnsZoneRegistrationVirtualNetworkIds(d *schema.ResourceData) *[]dns.SubResource { - registrationVirtualNetworks := d.Get("registration_virtual_network_ids").([]interface{}) - - registrationVNetSubResources := make([]dns.SubResource, 0) - for _, rvn := range registrationVirtualNetworks { - id := rvn.(string) - registrationVNetSubResources = append(registrationVNetSubResources, dns.SubResource{ - ID: &id, - }) - } - - return ®istrationVNetSubResources -} - -func flattenDnsZoneResolutionVirtualNetworkIDs(input *[]dns.SubResource) []string { - resolutionVirtualNetworks := make([]string, 0) - - if input != nil { - for _, rvn := range *input { - resolutionVirtualNetworks = append(resolutionVirtualNetworks, *rvn.ID) - } - } - - return resolutionVirtualNetworks -} diff --git a/azurerm/internal/services/dns/tests/data_source_dns_zone_test.go b/azurerm/internal/services/dns/tests/data_source_dns_zone_test.go index 044cbeacf9bb7..94e5127124b76 100644 --- a/azurerm/internal/services/dns/tests/data_source_dns_zone_test.go +++ b/azurerm/internal/services/dns/tests/data_source_dns_zone_test.go @@ -66,6 +66,10 @@ func TestAccDataSourceAzureRMDNSZone_withoutResourceGroupName(t *testing.T) { func testAccDataSourceDNSZone_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -73,18 +77,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } data "azurerm_dns_zone" "test" { - name = "${azurerm_dns_zone.test.name}" - resource_group_name = "${azurerm_dns_zone.test.resource_group_name}" + name = azurerm_dns_zone.test.name + resource_group_name = azurerm_dns_zone.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccDataSourceDNSZone_tags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -92,7 +100,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name tags = { hello = "world" @@ -100,14 +108,18 @@ resource "azurerm_dns_zone" "test" { } data "azurerm_dns_zone" "test" { - name = "${azurerm_dns_zone.test.name}" - resource_group_name = "${azurerm_dns_zone.test.resource_group_name}" + name = azurerm_dns_zone.test.name + resource_group_name = azurerm_dns_zone.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccDataSourceDNSZone_onlyName(data acceptance.TestData, resourceGroupName string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "%s" location = "%s" @@ -115,11 +127,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } data "azurerm_dns_zone" "test" { - name = "${azurerm_dns_zone.test.name}" + name = azurerm_dns_zone.test.name } `, resourceGroupName, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/dns/tests/resource_arm_dns_a_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_a_record_test.go index 81d1c015abb51..9ef2a14927660 100644 --- a/azurerm/internal/services/dns/tests/resource_arm_dns_a_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_a_record_test.go @@ -11,6 +11,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" ) func TestAccAzureRMDnsARecord_basic(t *testing.T) { @@ -163,7 +164,7 @@ func TestAccAzureRMDnsARecord_RecordsToAlias(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMDnsARecordExists(data.ResourceName), resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName, "id"), - resource.TestCheckNoResourceAttr(data.ResourceName, "records"), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "0"), ), }, data.ImportStep(), @@ -211,20 +212,18 @@ func testCheckAzureRMDnsARecordExists(resourceName string) resource.TestCheckFun return fmt.Errorf("Not found: %s", resourceName) } - aName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for DNS A record: %s", aName) + id, err := parse.DnsARecordID(rs.Primary.ID) + if err != nil { + return err } - resp, err := conn.Get(ctx, resourceGroup, zoneName, aName, dns.A) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.A) if err != nil { return fmt.Errorf("Bad: Get A RecordSet: %+v", err) } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: DNS A record %s (resource group: %s) does not exist", aName, resourceGroup) + return fmt.Errorf("Bad: DNS A record %s (resource group: %s) does not exist", id.Name, id.ResourceGroup) } return nil @@ -240,11 +239,11 @@ func testCheckAzureRMDnsARecordDestroy(s *terraform.State) error { continue } - aName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := conn.Get(ctx, resourceGroup, zoneName, aName, dns.A) + id, err := parse.DnsARecordID(rs.Primary.ID) + if err != nil { + return err + } + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.A) if err != nil { if resp.StatusCode == http.StatusNotFound { @@ -262,6 +261,10 @@ func testCheckAzureRMDnsARecordDestroy(s *terraform.State) error { func testAccAzureRMDnsARecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -269,13 +272,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_a_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["1.2.3.4", "1.2.4.5"] } @@ -288,9 +291,9 @@ func testAccAzureRMDnsARecord_requiresImport(data acceptance.TestData) string { %s resource "azurerm_dns_a_record" "import" { - name = "${azurerm_dns_a_record.test.name}" - resource_group_name = "${azurerm_dns_a_record.test.resource_group_name}" - zone_name = "${azurerm_dns_a_record.test.zone_name}" + name = azurerm_dns_a_record.test.name + resource_group_name = azurerm_dns_a_record.test.resource_group_name + zone_name = azurerm_dns_a_record.test.zone_name ttl = 300 records = ["1.2.3.4", "1.2.4.5"] } @@ -299,6 +302,10 @@ resource "azurerm_dns_a_record" "import" { func testAccAzureRMDnsARecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -306,13 +313,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_a_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["1.2.3.4", "1.2.4.5", "1.2.3.7"] } @@ -321,6 +328,10 @@ resource "azurerm_dns_a_record" "test" { func testAccAzureRMDnsARecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -328,13 +339,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_a_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["1.2.3.4", "1.2.4.5"] @@ -348,6 +359,10 @@ resource "azurerm_dns_a_record" "test" { func testAccAzureRMDnsARecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -355,13 +370,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_a_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["1.2.3.4", "1.2.4.5"] @@ -374,6 +389,10 @@ resource "azurerm_dns_a_record" "test" { func testAccAzureRMDnsARecord_withAlias(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -381,29 +400,33 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_public_ip" "test" { name = "mypublicip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" ip_version = "IPv4" } resource "azurerm_dns_a_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 - target_resource_id = "${azurerm_public_ip.test.id}" + target_resource_id = azurerm_public_ip.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDnsARecord_withAliasUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -411,29 +434,33 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_public_ip" "test2" { name = "mypublicip%d2" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" ip_version = "IPv4" } resource "azurerm_dns_a_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 - target_resource_id = "${azurerm_public_ip.test2.id}" + target_resource_id = azurerm_public_ip.test2.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDnsARecord_AliasToRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -441,29 +468,33 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_public_ip" "test" { name = "mypublicip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" ip_version = "IPv4" } resource "azurerm_dns_a_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 - target_resource_id = "${azurerm_public_ip.test.id}" + target_resource_id = azurerm_public_ip.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDnsARecord_AliasToRecordsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -471,13 +502,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_a_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["1.2.3.4", "1.2.4.5"] } diff --git a/azurerm/internal/services/dns/tests/resource_arm_dns_aaaa_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_aaaa_record_test.go index a06dcc54a05e9..24319099ec7b2 100644 --- a/azurerm/internal/services/dns/tests/resource_arm_dns_aaaa_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_aaaa_record_test.go @@ -11,6 +11,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" ) func TestAccAzureRMDnsAAAARecord_basic(t *testing.T) { @@ -238,20 +239,18 @@ func testCheckAzureRMDnsAaaaRecordExists(resourceName string) resource.TestCheck return fmt.Errorf("Not found: %s", resourceName) } - aaaaName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for DNS AAAA record: %s", aaaaName) + id, err := parse.DnsAaaaRecordID(rs.Primary.ID) + if err != nil { + return err } - resp, err := conn.Get(ctx, resourceGroup, zoneName, aaaaName, dns.AAAA) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.AAAA) if err != nil { return fmt.Errorf("Bad: Get AAAA RecordSet: %+v", err) } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: DNS AAAA record %s (resource group: %s) does not exist", aaaaName, resourceGroup) + return fmt.Errorf("Bad: DNS AAAA record %s (resource group: %s) does not exist", id.Name, id.ResourceGroup) } return nil @@ -267,11 +266,11 @@ func testCheckAzureRMDnsAaaaRecordDestroy(s *terraform.State) error { continue } - aaaaName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := conn.Get(ctx, resourceGroup, zoneName, aaaaName, dns.AAAA) + id, err := parse.DnsAaaaRecordID(rs.Primary.ID) + if err != nil { + return err + } + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.AAAA) if err != nil { if resp.StatusCode == http.StatusNotFound { @@ -289,6 +288,10 @@ func testCheckAzureRMDnsAaaaRecordDestroy(s *terraform.State) error { func testAccAzureRMDnsAAAARecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -296,13 +299,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_aaaa_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["2607:f8b0:4009:1803::1005", "2607:f8b0:4009:1803::1006"] } @@ -315,9 +318,9 @@ func testAccAzureRMDnsAAAARecord_requiresImport(data acceptance.TestData) string %s resource "azurerm_dns_aaaa_record" "import" { - name = "${azurerm_dns_aaaa_record.test.name}" - resource_group_name = "${azurerm_dns_aaaa_record.test.resource_group_name}" - zone_name = "${azurerm_dns_aaaa_record.test.zone_name}" + name = azurerm_dns_aaaa_record.test.name + resource_group_name = azurerm_dns_aaaa_record.test.resource_group_name + zone_name = azurerm_dns_aaaa_record.test.zone_name ttl = 300 records = ["2607:f8b0:4009:1803::1005", "2607:f8b0:4009:1803::1006"] } @@ -326,6 +329,10 @@ resource "azurerm_dns_aaaa_record" "import" { func testAccAzureRMDnsAAAARecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -333,13 +340,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_aaaa_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["2607:f8b0:4009:1803::1005", "2607:f8b0:4009:1803::1006", "::1"] } @@ -348,6 +355,10 @@ resource "azurerm_dns_aaaa_record" "test" { func testAccAzureRMDnsAAAARecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -355,13 +366,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_aaaa_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["2607:f8b0:4009:1803::1005", "2607:f8b0:4009:1803::1006"] @@ -375,6 +386,10 @@ resource "azurerm_dns_aaaa_record" "test" { func testAccAzureRMDnsAAAARecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -382,13 +397,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_aaaa_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["2607:f8b0:4009:1803::1005", "2607:f8b0:4009:1803::1006"] @@ -401,6 +416,10 @@ resource "azurerm_dns_aaaa_record" "test" { func testAccAzureRMDnsAAAARecord_withAlias(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -408,29 +427,33 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_public_ip" "test" { name = "mypublicip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" ip_version = "IPv6" } resource "azurerm_dns_aaaa_record" "test" { name = "myaaaarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 - target_resource_id = "${azurerm_public_ip.test.id}" + target_resource_id = azurerm_public_ip.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDnsAAAARecord_withAliasUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -438,29 +461,33 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_public_ip" "test2" { name = "mypublicip%d2" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" ip_version = "IPv6" } resource "azurerm_dns_aaaa_record" "test" { name = "myaaaarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 - target_resource_id = "${azurerm_public_ip.test2.id}" + target_resource_id = azurerm_public_ip.test2.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDnsAaaaRecord_AliasToRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -468,29 +495,33 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_public_ip" "test" { name = "mypublicip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" ip_version = "IPv6" } resource "azurerm_dns_aaaa_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 - target_resource_id = "${azurerm_public_ip.test.id}" + target_resource_id = azurerm_public_ip.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDnsAaaaRecord_AliasToRecordsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -498,13 +529,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_aaaa_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["3a62:353:8885:293c:a218:45cc:9ee9:4e27", "3a62:353:8885:293c:a218:45cc:9ee9:4e28"] } @@ -513,6 +544,10 @@ resource "azurerm_dns_aaaa_record" "test" { func testAccAzureRMDnsAAAARecord_uncompressed(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -520,13 +555,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_aaaa_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["2607:f8b0:4005:0800:0000:0000:0000:1003", "2201:1234:1234::1"] } diff --git a/azurerm/internal/services/dns/tests/resource_arm_dns_caa_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_caa_record_test.go index 72adf5d97c830..2fd30199c8531 100644 --- a/azurerm/internal/services/dns/tests/resource_arm_dns_caa_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_caa_record_test.go @@ -11,6 +11,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" ) func TestAccAzureRMDnsCaaRecord_basic(t *testing.T) { @@ -124,20 +125,18 @@ func testCheckAzureRMDnsCaaRecordExists(resourceName string) resource.TestCheckF return fmt.Errorf("Not found: %s", resourceName) } - caaName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for DNS CAA record: %s", caaName) + id, err := parse.DnsCaaRecordID(rs.Primary.ID) + if err != nil { + return err } - resp, err := conn.Get(ctx, resourceGroup, zoneName, caaName, dns.CAA) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.CAA) if err != nil { return fmt.Errorf("Bad: Get CAA RecordSet: %+v", err) } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: DNS CAA record %s (resource group: %s) does not exist", caaName, resourceGroup) + return fmt.Errorf("Bad: DNS CAA record %s (resource group: %s) does not exist", id.Name, id.ResourceGroup) } return nil @@ -153,11 +152,11 @@ func testCheckAzureRMDnsCaaRecordDestroy(s *terraform.State) error { continue } - caaName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := conn.Get(ctx, resourceGroup, zoneName, caaName, dns.CAA) + id, err := parse.DnsCaaRecordID(rs.Primary.ID) + if err != nil { + return err + } + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.CAA) if err != nil { if resp.StatusCode == http.StatusNotFound { @@ -175,6 +174,10 @@ func testCheckAzureRMDnsCaaRecordDestroy(s *terraform.State) error { func testAccAzureRMDnsCaaRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -182,13 +185,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_caa_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -224,9 +227,9 @@ func testAccAzureRMDnsCaaRecord_requiresImport(data acceptance.TestData) string %s resource "azurerm_dns_caa_record" "import" { - name = "${azurerm_dns_caa_record.test.name}" - resource_group_name = "${azurerm_dns_caa_record.test.resource_group_name}" - zone_name = "${azurerm_dns_caa_record.test.zone_name}" + name = azurerm_dns_caa_record.test.name + resource_group_name = azurerm_dns_caa_record.test.resource_group_name + zone_name = azurerm_dns_caa_record.test.zone_name ttl = 300 record { @@ -258,6 +261,10 @@ resource "azurerm_dns_caa_record" "import" { func testAccAzureRMDnsCaaRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -265,13 +272,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_caa_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -309,6 +316,10 @@ resource "azurerm_dns_caa_record" "test" { func testAccAzureRMDnsCaaRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -316,13 +327,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_caa_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -347,6 +358,10 @@ resource "azurerm_dns_caa_record" "test" { func testAccAzureRMDnsCaaRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -354,13 +369,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_caa_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { diff --git a/azurerm/internal/services/dns/tests/resource_arm_dns_cname_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_cname_record_test.go index 3e33c95bdcfe1..2064f9d4dd3b1 100644 --- a/azurerm/internal/services/dns/tests/resource_arm_dns_cname_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_cname_record_test.go @@ -11,6 +11,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" ) func TestAccAzureRMDnsCNameRecord_basic(t *testing.T) { @@ -180,7 +181,7 @@ func TestAccAzureRMDnsCNameRecord_RecordToAlias(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMDnsCNameRecordExists(data.ResourceName), resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName, "id"), - resource.TestCheckNoResourceAttr(data.ResourceName, "record"), + resource.TestCheckResourceAttr(data.ResourceName, "record", ""), ), }, data.ImportStep(), @@ -208,7 +209,7 @@ func TestAccAzureRMDnsCNameRecord_AliasToRecord(t *testing.T) { Config: testAccAzureRMDnsCNameRecord_AliasToRecordUpdate(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMDnsCNameRecordExists(data.ResourceName), - resource.TestCheckNoResourceAttr(data.ResourceName, "target_resource_id"), + resource.TestCheckResourceAttr(data.ResourceName, "target_resource_id", ""), ), }, data.ImportStep(), @@ -227,20 +228,18 @@ func testCheckAzureRMDnsCNameRecordExists(resourceName string) resource.TestChec return fmt.Errorf("Not found: %s", resourceName) } - cnameName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for DNS CNAME record: %s", cnameName) + id, err := parse.DnsCNameRecordID(rs.Primary.ID) + if err != nil { + return err } - resp, err := conn.Get(ctx, resourceGroup, zoneName, cnameName, dns.CNAME) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.CNAME) if err != nil { return fmt.Errorf("Bad: Get CNAME RecordSet: %v", err) } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: DNS CNAME record %s (resource group: %s) does not exist", cnameName, resourceGroup) + return fmt.Errorf("Bad: DNS CNAME record %s (resource group: %s) does not exist", id.Name, id.ResourceGroup) } return nil @@ -256,11 +255,12 @@ func testCheckAzureRMDnsCNameRecordDestroy(s *terraform.State) error { continue } - cnameName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] + id, err := parse.DnsCNameRecordID(rs.Primary.ID) + if err != nil { + return err + } - resp, err := conn.Get(ctx, resourceGroup, zoneName, cnameName, dns.CNAME) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.CNAME) if err != nil { if resp.StatusCode == http.StatusNotFound { @@ -278,6 +278,10 @@ func testCheckAzureRMDnsCNameRecordDestroy(s *terraform.State) error { func testAccAzureRMDnsCNameRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -285,13 +289,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_cname_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record = "contoso.com" } @@ -304,9 +308,9 @@ func testAccAzureRMDnsCNameRecord_requiresImport(data acceptance.TestData) strin %s resource "azurerm_dns_cname_record" "import" { - name = "${azurerm_dns_cname_record.test.name}" - resource_group_name = "${azurerm_dns_cname_record.test.resource_group_name}" - zone_name = "${azurerm_dns_cname_record.test.zone_name}" + name = azurerm_dns_cname_record.test.name + resource_group_name = azurerm_dns_cname_record.test.resource_group_name + zone_name = azurerm_dns_cname_record.test.zone_name ttl = 300 record = "contoso.com" } @@ -315,6 +319,10 @@ resource "azurerm_dns_cname_record" "import" { func testAccAzureRMDnsCNameRecord_subdomain(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -322,13 +330,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_cname_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record = "test.contoso.com" } @@ -337,6 +345,10 @@ resource "azurerm_dns_cname_record" "test" { func testAccAzureRMDnsCNameRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -344,13 +356,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_cname_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record = "contoso.co.uk" } @@ -359,6 +371,10 @@ resource "azurerm_dns_cname_record" "test" { func testAccAzureRMDnsCNameRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -366,13 +382,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_cname_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record = "contoso.com" @@ -386,6 +402,10 @@ resource "azurerm_dns_cname_record" "test" { func testAccAzureRMDnsCNameRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -393,13 +413,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_cname_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record = "contoso.com" @@ -412,6 +432,10 @@ resource "azurerm_dns_cname_record" "test" { func testAccAzureRMDnsCNameRecord_withAlias(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -419,29 +443,33 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_cname_record" "target" { name = "mycnametarget%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record = "contoso.com" } resource "azurerm_dns_cname_record" "test" { name = "mycnamerecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 - target_resource_id = "${azurerm_dns_cname_record.target.id}" + target_resource_id = azurerm_dns_cname_record.target.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDnsCNameRecord_withAliasUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -449,29 +477,33 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_cname_record" "target2" { name = "mycnametarget%d2" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record = "contoso.co.uk" } resource "azurerm_dns_cname_record" "test" { name = "mycnamerecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 - target_resource_id = "${azurerm_dns_cname_record.target2.id}" + target_resource_id = azurerm_dns_cname_record.target2.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDnsCNameRecord_AliasToRecord(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -479,29 +511,33 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_cname_record" "target2" { name = "mycnametarget%d2" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record = "contoso.co.uk" } resource "azurerm_dns_cname_record" "test" { name = "mycnamerecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 - target_resource_id = "${azurerm_dns_cname_record.target2.id}" + target_resource_id = azurerm_dns_cname_record.target2.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDnsCNameRecord_AliasToRecordUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -509,13 +545,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_cname_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record = "1.2.3.4" } diff --git a/azurerm/internal/services/dns/tests/resource_arm_dns_mx_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_mx_record_test.go index 0587fe54c99b8..ed50ae861a36c 100644 --- a/azurerm/internal/services/dns/tests/resource_arm_dns_mx_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_mx_record_test.go @@ -11,6 +11,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" ) func TestAccAzureRMDnsMxRecord_basic(t *testing.T) { @@ -144,20 +145,18 @@ func testCheckAzureRMDnsMxRecordExists(resourceName string) resource.TestCheckFu return fmt.Errorf("Not found: %s", resourceName) } - mxName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for DNS MX record: %s", mxName) + id, err := parse.DnsMxRecordID(rs.Primary.ID) + if err != nil { + return err } - resp, err := conn.Get(ctx, resourceGroup, zoneName, mxName, dns.MX) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.MX) if err != nil { return fmt.Errorf("Bad: Get MX RecordSet: %+v", err) } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: DNS MX record %s (resource group: %s) does not exist", mxName, resourceGroup) + return fmt.Errorf("Bad: DNS MX record %s (resource group: %s) does not exist", id.Name, id.ResourceGroup) } return nil @@ -173,11 +172,12 @@ func testCheckAzureRMDnsMxRecordDestroy(s *terraform.State) error { continue } - mxName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] + id, err := parse.DnsMxRecordID(rs.Primary.ID) + if err != nil { + return err + } - resp, err := conn.Get(ctx, resourceGroup, zoneName, mxName, dns.MX) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.MX) if err != nil { if resp.StatusCode == http.StatusNotFound { @@ -195,6 +195,10 @@ func testCheckAzureRMDnsMxRecordDestroy(s *terraform.State) error { func testAccAzureRMDnsMxRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -202,13 +206,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_mx_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -226,6 +230,10 @@ resource "azurerm_dns_mx_record" "test" { func testAccAzureRMDnsMxRecord_rootrecord(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -233,12 +241,12 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_mx_record" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -260,9 +268,9 @@ func testAccAzureRMDnsMxRecord_requiresImport(data acceptance.TestData) string { %s resource "azurerm_dns_mx_record" "import" { - name = "${azurerm_dns_mx_record.test.name}" - resource_group_name = "${azurerm_dns_mx_record.test.resource_group_name}" - zone_name = "${azurerm_dns_mx_record.test.zone_name}" + name = azurerm_dns_mx_record.test.name + resource_group_name = azurerm_dns_mx_record.test.resource_group_name + zone_name = azurerm_dns_mx_record.test.zone_name ttl = 300 record { @@ -280,6 +288,10 @@ resource "azurerm_dns_mx_record" "import" { func testAccAzureRMDnsMxRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -287,13 +299,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_mx_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -316,6 +328,10 @@ resource "azurerm_dns_mx_record" "test" { func testAccAzureRMDnsMxRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -323,13 +339,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_mx_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -352,6 +368,10 @@ resource "azurerm_dns_mx_record" "test" { func testAccAzureRMDnsMxRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -359,13 +379,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_mx_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { diff --git a/azurerm/internal/services/dns/tests/resource_arm_dns_ns_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_ns_record_test.go index f35992c2e2596..e4c4ae47ad5e6 100644 --- a/azurerm/internal/services/dns/tests/resource_arm_dns_ns_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_ns_record_test.go @@ -11,27 +11,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" ) -//TODO: remove this once we remove the `record` attribute -func TestAccAzureRMDnsNsRecord_deprecatedBasic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDnsNsRecordDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDnsNsRecord_deprecatedBasic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(data.ResourceName), - ), - }, - }, - }) -} - func TestAccAzureRMDnsNsRecord_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") @@ -79,33 +61,6 @@ func TestAccAzureRMDnsNsRecord_requiresImport(t *testing.T) { }) } -//TODO: remove this once we remove the `record` attribute -func TestAccAzureRMDnsNsRecord_deprecatedUpdateRecords(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDnsNsRecordDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDnsNsRecord_deprecatedBasic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "record.#", "2"), - ), - }, - { - Config: testAccAzureRMDnsNsRecord_deprecatedUpdateRecords(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "record.#", "3"), - ), - }, - }, - }) -} - func TestAccAzureRMDnsNsRecord_updateRecords(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") @@ -132,60 +87,6 @@ func TestAccAzureRMDnsNsRecord_updateRecords(t *testing.T) { }) } -//TODO: remove this once we remove the `record` attribute -func TestAccAzureRMDnsNsRecord_deprecatedChangeRecordToRecords(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDnsNsRecordDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDnsNsRecord_deprecatedBasic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), - ), - }, - { - Config: testAccAzureRMDnsNsRecord_deprecatedBasicNewRecords(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), - ), - }, - }, - }) -} - -//TODO: remove this once we remove the `record` attribute -func TestAccAzureRMDnsNsRecord_deprecatedWithTags(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDnsNsRecordDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDnsNsRecord_deprecatedWithTags(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), - ), - }, - { - Config: testAccAzureRMDnsNsRecord_deprecatedWithTagsUpdate(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - ), - }, - }, - }) -} - func TestAccAzureRMDnsNsRecord_withTags(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") @@ -224,20 +125,18 @@ func testCheckAzureRMDnsNsRecordExists(resourceName string) resource.TestCheckFu return fmt.Errorf("Not found: %s", resourceName) } - nsName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for DNS NS record: %s", nsName) + id, err := parse.DnsNsRecordID(rs.Primary.ID) + if err != nil { + return err } - resp, err := conn.Get(ctx, resourceGroup, zoneName, nsName, dns.NS) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.NS) if err != nil { return fmt.Errorf("Bad: Get DNS NS Record: %+v", err) } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: DNS NS record %s (resource group: %s) does not exist", nsName, resourceGroup) + return fmt.Errorf("Bad: DNS NS record %s (resource group: %s) does not exist", id.Name, id.ResourceGroup) } return nil @@ -253,11 +152,12 @@ func testCheckAzureRMDnsNsRecordDestroy(s *terraform.State) error { continue } - nsName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] + id, err := parse.DnsNsRecordID(rs.Primary.ID) + if err != nil { + return err + } - resp, err := conn.Get(ctx, resourceGroup, zoneName, nsName, dns.NS) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.NS) if err != nil { return nil @@ -273,6 +173,10 @@ func testCheckAzureRMDnsNsRecordDestroy(s *terraform.State) error { func testAccAzureRMDnsNsRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -280,13 +184,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_ns_record" "test" { name = "mynsrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["ns1.contoso.com", "ns2.contoso.com"] @@ -300,9 +204,9 @@ func testAccAzureRMDnsNsRecord_requiresImport(data acceptance.TestData) string { %s resource "azurerm_dns_ns_record" "import" { - name = "${azurerm_dns_ns_record.test.name}" - resource_group_name = "${azurerm_dns_ns_record.test.resource_group_name}" - zone_name = "${azurerm_dns_ns_record.test.zone_name}" + name = azurerm_dns_ns_record.test.name + resource_group_name = azurerm_dns_ns_record.test.resource_group_name + zone_name = azurerm_dns_ns_record.test.zone_name ttl = 300 records = ["ns1.contoso.com", "ns2.contoso.com"] @@ -310,86 +214,12 @@ resource "azurerm_dns_ns_record" "import" { `, template) } -//TODO: remove this once we remove the `record` attribute -func testAccAzureRMDnsNsRecord_deprecatedBasic(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_dns_zone" "test" { - name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_dns_ns_record" "test" { - name = "mynsrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" - ttl = 300 - - record { - nsdname = "ns1.contoso.com" - } - - record { - nsdname = "ns2.contoso.com" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} - -//TODO: remove this once we remove the `record` attribute -func testAccAzureRMDnsNsRecord_deprecatedBasicNewRecords(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_dns_zone" "test" { - name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_dns_ns_record" "test" { - name = "mynsrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" - ttl = 300 - - records = ["ns2.contoso.com", "ns1.contoso.com"] -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} - func testAccAzureRMDnsNsRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_dns_zone" "test" { - name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_dns_ns_record" "test" { - name = "mynsrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" - ttl = 300 - - records = ["ns1.contoso.com", "ns2.contoso.com", "ns3.contoso.com"] -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} - -//TODO: remove this once we remove the `record` attribute -func testAccAzureRMDnsNsRecord_deprecatedUpdateRecords(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -397,61 +227,26 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_ns_record" "test" { name = "mynsrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 - record { - nsdname = "ns1.contoso.com" - } - - record { - nsdname = "ns2.contoso.com" - } - - record { - nsdname = "ns3.contoso.com" - } + records = ["ns1.contoso.com", "ns2.contoso.com", "ns3.contoso.com"] } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testAccAzureRMDnsNsRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_dns_zone" "test" { - name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_dns_ns_record" "test" { - name = "mynsrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" - ttl = 300 - - records = ["ns1.contoso.com", "ns2.contoso.com"] - - tags = { - environment = "Production" - cost_center = "MSFT" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} - -//TODO: remove this once we remove the `record` attribute -func testAccAzureRMDnsNsRecord_deprecatedWithTags(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -459,22 +254,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_ns_record" "test" { name = "mynsrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 - record { - nsdname = "ns1.contoso.com" - } - - record { - nsdname = "ns2.contoso.com" - } + records = ["ns1.contoso.com", "ns2.contoso.com"] tags = { environment = "Production" @@ -486,34 +275,10 @@ resource "azurerm_dns_ns_record" "test" { func testAccAzureRMDnsNsRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_dns_zone" "test" { - name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" +provider "azurerm" { + features {} } -resource "azurerm_dns_ns_record" "test" { - name = "mynsrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" - ttl = 300 - - records = ["ns1.contoso.com", "ns2.contoso.com"] - - tags = { - environment = "staging" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} - -//TODO: remove this once we remove the `record` attribute -func testAccAzureRMDnsNsRecord_deprecatedWithTagsUpdate(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -521,22 +286,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_ns_record" "test" { name = "mynsrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 - record { - nsdname = "ns1.contoso.com" - } - - record { - nsdname = "ns2.contoso.com" - } + records = ["ns1.contoso.com", "ns2.contoso.com"] tags = { environment = "staging" diff --git a/azurerm/internal/services/dns/tests/resource_arm_dns_ptr_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_ptr_record_test.go index db31482bf55b0..cb0b7abc65e1c 100644 --- a/azurerm/internal/services/dns/tests/resource_arm_dns_ptr_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_ptr_record_test.go @@ -11,6 +11,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" ) func TestAccAzureRMDnsPtrRecord_basic(t *testing.T) { @@ -126,20 +127,18 @@ func testCheckAzureRMDnsPtrRecordExists(resourceName string) resource.TestCheckF return fmt.Errorf("Not found: %s", resourceName) } - ptrName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for DNS PTR record: %s", ptrName) + id, err := parse.DnsPtrRecordID(rs.Primary.ID) + if err != nil { + return err } - resp, err := conn.Get(ctx, resourceGroup, zoneName, ptrName, dns.PTR) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.PTR) if err != nil { return fmt.Errorf("Bad: Get PTR RecordSet: %+v", err) } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: DNS PTR record %s (resource group: %s) does not exist", ptrName, resourceGroup) + return fmt.Errorf("Bad: DNS PTR record %s (resource group: %s) does not exist", id.Name, id.ResourceGroup) } return nil @@ -155,11 +154,12 @@ func testCheckAzureRMDnsPtrRecordDestroy(s *terraform.State) error { continue } - ptrName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] + id, err := parse.DnsPtrRecordID(rs.Primary.ID) + if err != nil { + return err + } - resp, err := conn.Get(ctx, resourceGroup, zoneName, ptrName, dns.PTR) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.PTR) if err != nil { if resp.StatusCode == http.StatusNotFound { @@ -177,6 +177,10 @@ func testCheckAzureRMDnsPtrRecordDestroy(s *terraform.State) error { func testAccAzureRMDnsPtrRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -184,13 +188,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_ptr_record" "test" { name = "testptrrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["hashicorp.com", "microsoft.com"] } @@ -203,9 +207,9 @@ func testAccAzureRMDnsPtrRecord_requiresImport(data acceptance.TestData) string %s resource "azurerm_dns_ptr_record" "import" { - name = "${azurerm_dns_ptr_record.test.name}" - resource_group_name = "${azurerm_dns_ptr_record.test.resource_group_name}" - zone_name = "${azurerm_dns_ptr_record.test.zone_name}" + name = azurerm_dns_ptr_record.test.name + resource_group_name = azurerm_dns_ptr_record.test.resource_group_name + zone_name = azurerm_dns_ptr_record.test.zone_name ttl = 300 records = ["hashicorp.com", "microsoft.com"] } @@ -214,6 +218,10 @@ resource "azurerm_dns_ptr_record" "import" { func testAccAzureRMDnsPtrRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -221,13 +229,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_ptr_record" "test" { name = "testptrrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["hashicorp.com", "microsoft.com", "reddit.com"] } @@ -236,6 +244,10 @@ resource "azurerm_dns_ptr_record" "test" { func testAccAzureRMDnsPtrRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -243,13 +255,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_ptr_record" "test" { name = "testptrrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["hashicorp.com", "microsoft.com"] @@ -263,6 +275,10 @@ resource "azurerm_dns_ptr_record" "test" { func testAccAzureRMDnsPtrRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -270,13 +286,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_ptr_record" "test" { name = "testptrrecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 records = ["hashicorp.com", "microsoft.com"] diff --git a/azurerm/internal/services/dns/tests/resource_arm_dns_srv_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_srv_record_test.go index 0e10c85b932d2..cb53fa399f4b7 100644 --- a/azurerm/internal/services/dns/tests/resource_arm_dns_srv_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_srv_record_test.go @@ -11,6 +11,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" ) func TestAccAzureRMDnsSrvRecord_basic(t *testing.T) { @@ -124,20 +125,18 @@ func testCheckAzureRMDnsSrvRecordExists(resourceName string) resource.TestCheckF return fmt.Errorf("Not found: %s", resourceName) } - srvName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for DNS SRV record: %s", srvName) + id, err := parse.DnsSrvRecordID(rs.Primary.ID) + if err != nil { + return err } - resp, err := conn.Get(ctx, resourceGroup, zoneName, srvName, dns.SRV) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.SRV) if err != nil { return fmt.Errorf("Bad: Get SRV RecordSet: %+v", err) } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: DNS SRV record %s (resource group: %s) does not exist", srvName, resourceGroup) + return fmt.Errorf("Bad: DNS SRV record %s (resource group: %s) does not exist", id.Name, id.ResourceGroup) } return nil @@ -153,11 +152,12 @@ func testCheckAzureRMDnsSrvRecordDestroy(s *terraform.State) error { continue } - srvName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] + id, err := parse.DnsSrvRecordID(rs.Primary.ID) + if err != nil { + return err + } - resp, err := conn.Get(ctx, resourceGroup, zoneName, srvName, dns.SRV) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.SRV) if err != nil { if resp.StatusCode == http.StatusNotFound { @@ -175,6 +175,10 @@ func testCheckAzureRMDnsSrvRecordDestroy(s *terraform.State) error { func testAccAzureRMDnsSrvRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -182,13 +186,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_srv_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -214,9 +218,9 @@ func testAccAzureRMDnsSrvRecord_requiresImport(data acceptance.TestData) string %s resource "azurerm_dns_srv_record" "import" { - name = "${azurerm_dns_srv_record.test.name}" - resource_group_name = "${azurerm_dns_srv_record.test.resource_group_name}" - zone_name = "${azurerm_dns_srv_record.test.zone_name}" + name = azurerm_dns_srv_record.test.name + resource_group_name = azurerm_dns_srv_record.test.resource_group_name + zone_name = azurerm_dns_srv_record.test.zone_name ttl = 300 record { @@ -238,6 +242,10 @@ resource "azurerm_dns_srv_record" "import" { func testAccAzureRMDnsSrvRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -245,13 +253,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_srv_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -280,6 +288,10 @@ resource "azurerm_dns_srv_record" "test" { func testAccAzureRMDnsSrvRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -287,13 +299,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_srv_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -320,6 +332,10 @@ resource "azurerm_dns_srv_record" "test" { func testAccAzureRMDnsSrvRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -327,13 +343,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_srv_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { diff --git a/azurerm/internal/services/dns/tests/resource_arm_dns_txt_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_txt_record_test.go index 8bf2d3301d002..42acb69644fa6 100644 --- a/azurerm/internal/services/dns/tests/resource_arm_dns_txt_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_txt_record_test.go @@ -11,6 +11,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" ) func TestAccAzureRMDnsTxtRecord_basic(t *testing.T) { @@ -124,20 +125,18 @@ func testCheckAzureRMDnsTxtRecordExists(resourceName string) resource.TestCheckF return fmt.Errorf("Not found: %s", resourceName) } - txtName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for DNS TXT record: %s", txtName) + id, err := parse.DnsTxtRecordID(rs.Primary.ID) + if err != nil { + return err } - resp, err := conn.Get(ctx, resourceGroup, zoneName, txtName, dns.TXT) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.TXT) if err != nil { return fmt.Errorf("Bad: Get TXT RecordSet: %+v", err) } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: DNS TXT record %s (resource group: %s) does not exist", txtName, resourceGroup) + return fmt.Errorf("Bad: DNS TXT record %s (resource group: %s) does not exist", id.Name, id.ResourceGroup) } return nil @@ -153,11 +152,12 @@ func testCheckAzureRMDnsTxtRecordDestroy(s *terraform.State) error { continue } - txtName := rs.Primary.Attributes["name"] - zoneName := rs.Primary.Attributes["zone_name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] + id, err := parse.DnsTxtRecordID(rs.Primary.ID) + if err != nil { + return err + } - resp, err := conn.Get(ctx, resourceGroup, zoneName, txtName, dns.TXT) + resp, err := conn.Get(ctx, id.ResourceGroup, id.ZoneName, id.Name, dns.TXT) if err != nil { if resp.StatusCode == http.StatusNotFound { @@ -175,6 +175,10 @@ func testCheckAzureRMDnsTxtRecordDestroy(s *terraform.State) error { func testAccAzureRMDnsTxtRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -182,13 +186,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_txt_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -196,7 +200,7 @@ resource "azurerm_dns_txt_record" "test" { } record { - value = "Another test txt string" + value = "A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......" } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) @@ -208,9 +212,9 @@ func testAccAzureRMDnsTxtRecord_requiresImport(data acceptance.TestData) string %s resource "azurerm_dns_txt_record" "import" { - name = "${azurerm_dns_txt_record.test.name}" - resource_group_name = "${azurerm_dns_txt_record.test.resource_group_name}" - zone_name = "${azurerm_dns_txt_record.test.zone_name}" + name = azurerm_dns_txt_record.test.name + resource_group_name = azurerm_dns_txt_record.test.resource_group_name + zone_name = azurerm_dns_txt_record.test.zone_name ttl = 300 record { @@ -218,7 +222,7 @@ resource "azurerm_dns_txt_record" "import" { } record { - value = "Another test txt string" + value = "A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......" } } `, template) @@ -226,6 +230,10 @@ resource "azurerm_dns_txt_record" "import" { func testAccAzureRMDnsTxtRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -233,13 +241,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_txt_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -247,7 +255,7 @@ resource "azurerm_dns_txt_record" "test" { } record { - value = "Another test txt string" + value = "A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......A long text......" } record { @@ -259,6 +267,10 @@ resource "azurerm_dns_txt_record" "test" { func testAccAzureRMDnsTxtRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -266,13 +278,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_txt_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { @@ -293,6 +305,10 @@ resource "azurerm_dns_txt_record" "test" { func testAccAzureRMDnsTxtRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -300,13 +316,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_dns_txt_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_dns_zone.test.name ttl = 300 record { diff --git a/azurerm/internal/services/dns/tests/resource_arm_dns_zone_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_zone_test.go index 0d935db321d62..0fb4bc6081850 100644 --- a/azurerm/internal/services/dns/tests/resource_arm_dns_zone_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_zone_test.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/dns/parse" ) func TestAccAzureRMDnsZone_basic(t *testing.T) { @@ -58,25 +59,6 @@ func TestAccAzureRMDnsZone_requiresImport(t *testing.T) { }) } -func TestAccAzureRMDnsZone_withVNets(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_dns_zone", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDnsZoneDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDnsZone_withVNets(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsZoneExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - func TestAccAzureRMDnsZone_withTags(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_dns_zone", "test") @@ -115,19 +97,18 @@ func testCheckAzureRMDnsZoneExists(resourceName string) resource.TestCheckFunc { return fmt.Errorf("Not found: %s", resourceName) } - zoneName := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for DNS zone: %s", zoneName) + id, err := parse.DnsZoneID(rs.Primary.ID) + if err != nil { + return err } - resp, err := client.Get(ctx, resourceGroup, zoneName) + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { return fmt.Errorf("Bad: Get DNS zone: %+v", err) } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: DNS zone %s (resource group: %s) does not exist", zoneName, resourceGroup) + return fmt.Errorf("Bad: DNS zone %s (resource group: %s) does not exist", id.Name, id.ResourceGroup) } return nil @@ -143,10 +124,12 @@ func testCheckAzureRMDnsZoneDestroy(s *terraform.State) error { continue } - zoneName := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] + id, err := parse.DnsZoneID(rs.Primary.ID) + if err != nil { + return err + } - resp, err := conn.Get(ctx, resourceGroup, zoneName) + resp, err := conn.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if resp.StatusCode == http.StatusNotFound { return nil @@ -163,6 +146,10 @@ func testCheckAzureRMDnsZoneDestroy(s *terraform.State) error { func testAccAzureRMDnsZone_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -170,7 +157,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -181,38 +168,18 @@ func testAccAzureRMDnsZone_requiresImport(data acceptance.TestData) string { %s resource "azurerm_dns_zone" "import" { - name = "${azurerm_dns_zone.test.name}" - resource_group_name = "${azurerm_dns_zone.test.resource_group_name}" + name = azurerm_dns_zone.test.name + resource_group_name = azurerm_dns_zone.test.resource_group_name } `, template) } -func testAccAzureRMDnsZone_withVNets(data acceptance.TestData) string { +func testAccAzureRMDnsZone_withTags(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG_%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvnet%d" - location = "%s" - resource_group_name = "${azurerm_resource_group.test.name}" - address_space = ["10.0.0.0/16"] - dns_servers = ["168.63.129.16"] -} - -resource "azurerm_dns_zone" "test" { - name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_type = "Private" - registration_virtual_network_ids = ["${azurerm_virtual_network.test.id}"] -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +provider "azurerm" { + features {} } -func testAccAzureRMDnsZone_withTags(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -220,7 +187,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name tags = { environment = "Production" @@ -232,6 +199,10 @@ resource "azurerm_dns_zone" "test" { func testAccAzureRMDnsZone_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -239,7 +210,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name tags = { environment = "staging" diff --git a/azurerm/internal/services/eventgrid/registration.go b/azurerm/internal/services/eventgrid/registration.go index 5896b3ecbc6bf..f1b2feda1dc8b 100644 --- a/azurerm/internal/services/eventgrid/registration.go +++ b/azurerm/internal/services/eventgrid/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "EventGrid" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Messaging", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription.go b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription.go index 0babcb0a6644a..e78ec1676ce0c 100644 --- a/azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription.go +++ b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription.go @@ -296,22 +296,20 @@ func resourceArmEventGridEventSubscriptionRead(d *schema.ResourceData, meta inte if err != nil { return err } - scope := id.Scope - name := id.Name - resp, err := client.Get(ctx, scope, name) + resp, err := client.Get(ctx, id.Scope, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[WARN] EventGrid Event Subscription '%s' was not found (resource group '%s')", name, scope) + log.Printf("[WARN] EventGrid Event Subscription '%s' was not found (resource group '%s')", id.Name, id.Scope) d.SetId("") return nil } - return fmt.Errorf("Error making Read request on EventGrid Event Subscription '%s': %+v", name, err) + return fmt.Errorf("Error making Read request on EventGrid Event Subscription '%s': %+v", id.Name, err) } d.Set("name", resp.Name) - d.Set("scope", scope) + d.Set("scope", id.Scope) if props := resp.EventSubscriptionProperties; props != nil { d.Set("event_delivery_schema", string(props.EventDeliverySchema)) @@ -322,52 +320,52 @@ func resourceArmEventGridEventSubscriptionRead(d *schema.ResourceData, meta inte if storageQueueEndpoint, ok := props.Destination.AsStorageQueueEventSubscriptionDestination(); ok { if err := d.Set("storage_queue_endpoint", flattenEventGridEventSubscriptionStorageQueueEndpoint(storageQueueEndpoint)); err != nil { - return fmt.Errorf("Error setting `storage_queue_endpoint` for EventGrid Event Subscription %q (Scope %q): %s", name, scope, err) + return fmt.Errorf("Error setting `storage_queue_endpoint` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err) } } if eventHubEndpoint, ok := props.Destination.AsEventHubEventSubscriptionDestination(); ok { if err := d.Set("eventhub_endpoint", flattenEventGridEventSubscriptionEventHubEndpoint(eventHubEndpoint)); err != nil { - return fmt.Errorf("Error setting `eventhub_endpoint` for EventGrid Event Subscription %q (Scope %q): %s", name, scope, err) + return fmt.Errorf("Error setting `eventhub_endpoint` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err) } } if hybridConnectionEndpoint, ok := props.Destination.AsHybridConnectionEventSubscriptionDestination(); ok { if err := d.Set("hybrid_connection_endpoint", flattenEventGridEventSubscriptionHybridConnectionEndpoint(hybridConnectionEndpoint)); err != nil { - return fmt.Errorf("Error setting `hybrid_connection_endpoint` for EventGrid Event Subscription %q (Scope %q): %s", name, scope, err) + return fmt.Errorf("Error setting `hybrid_connection_endpoint` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err) } } if _, ok := props.Destination.AsWebHookEventSubscriptionDestination(); ok { - fullURL, err := client.GetFullURL(ctx, scope, name) + fullURL, err := client.GetFullURL(ctx, id.Scope, id.Name) if err != nil { - return fmt.Errorf("Error making Read request on EventGrid Event Subscription full URL '%s': %+v", name, err) + return fmt.Errorf("Error making Read request on EventGrid Event Subscription full URL '%s': %+v", id.Name, err) } if err := d.Set("webhook_endpoint", flattenEventGridEventSubscriptionWebhookEndpoint(&fullURL)); err != nil { - return fmt.Errorf("Error setting `webhook_endpoint` for EventGrid Event Subscription %q (Scope %q): %s", name, scope, err) + return fmt.Errorf("Error setting `webhook_endpoint` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err) } } if filter := props.Filter; filter != nil { d.Set("included_event_types", filter.IncludedEventTypes) if err := d.Set("subject_filter", flattenEventGridEventSubscriptionSubjectFilter(filter)); err != nil { - return fmt.Errorf("Error setting `subject_filter` for EventGrid Event Subscription %q (Scope %q): %s", name, scope, err) + return fmt.Errorf("Error setting `subject_filter` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err) } } if props.DeadLetterDestination != nil { if storageBlobDeadLetterDestination, ok := props.DeadLetterDestination.AsStorageBlobDeadLetterDestination(); ok { if err := d.Set("storage_blob_dead_letter_destination", flattenEventGridEventSubscriptionStorageBlobDeadLetterDestination(storageBlobDeadLetterDestination)); err != nil { - return fmt.Errorf("Error setting `storage_blob_dead_letter_destination` for EventGrid Event Subscription %q (Scope %q): %s", name, scope, err) + return fmt.Errorf("Error setting `storage_blob_dead_letter_destination` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err) } } } if retryPolicy := props.RetryPolicy; retryPolicy != nil { if err := d.Set("retry_policy", flattenEventGridEventSubscriptionRetryPolicy(retryPolicy)); err != nil { - return fmt.Errorf("Error setting `retry_policy` for EventGrid Event Subscription %q (Scope %q): %s", name, scope, err) + return fmt.Errorf("Error setting `retry_policy` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err) } } if err := d.Set("labels", props.Labels); err != nil { - return fmt.Errorf("Error setting `labels` for EventGrid Event Subscription %q (Scope %q): %s", name, scope, err) + return fmt.Errorf("Error setting `labels` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err) } } @@ -383,22 +381,20 @@ func resourceArmEventGridEventSubscriptionDelete(d *schema.ResourceData, meta in if err != nil { return err } - scope := id.Scope - name := id.Name - future, err := client.Delete(ctx, scope, name) + future, err := client.Delete(ctx, id.Scope, id.Name) if err != nil { if response.WasNotFound(future.Response()) { return nil } - return fmt.Errorf("Error deleting Event Grid Event Subscription %q: %+v", name, err) + return fmt.Errorf("Error deleting Event Grid Event Subscription %q: %+v", id.Name, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { if response.WasNotFound(future.Response()) { return nil } - return fmt.Errorf("Error deleting Event Grid Event Subscription %q: %+v", name, err) + return fmt.Errorf("Error deleting Event Grid Event Subscription %q: %+v", id.Name, err) } return nil diff --git a/azurerm/internal/services/eventgrid/tests/data_source_eventgrid_topic_test.go b/azurerm/internal/services/eventgrid/tests/data_source_eventgrid_topic_test.go index b28f944049320..ddfe6b24e22a1 100644 --- a/azurerm/internal/services/eventgrid/tests/data_source_eventgrid_topic_test.go +++ b/azurerm/internal/services/eventgrid/tests/data_source_eventgrid_topic_test.go @@ -34,8 +34,8 @@ func testAccDataSourceAzureRMEventGridTopic_basic(data acceptance.TestData) stri %s data "azurerm_eventgrid_topic" "test" { - name = "${azurerm_eventgrid_topic.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_eventgrid_topic.test.name + resource_group_name = azurerm_resource_group.test.name } `, template) } diff --git a/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_domain_test.go b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_domain_test.go index b78b9519fae43..3dd1e68cfccc6 100644 --- a/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_domain_test.go +++ b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_domain_test.go @@ -139,6 +139,10 @@ func testCheckAzureRMEventGridDomainExists(resourceName string) resource.TestChe func testAccAzureRMEventGridDomain_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -146,14 +150,18 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventgrid_domain" "test" { name = "acctesteg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccAzureRMEventGridDomain_mapping(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -161,8 +169,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventgrid_domain" "test" { name = "acctesteg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name input_schema = "CustomEventSchema" @@ -181,6 +189,10 @@ resource "azurerm_eventgrid_domain" "test" { func testAccAzureRMEventGridDomain_basicWithTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -188,8 +200,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventgrid_domain" "test" { name = "acctesteg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { "foo" = "bar" diff --git a/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_event_subscription_test.go b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_event_subscription_test.go index 166b6e6aa10e4..434804e88195e 100644 --- a/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_event_subscription_test.go +++ b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_event_subscription_test.go @@ -177,6 +177,10 @@ func testCheckAzureRMEventGridEventSubscriptionExists(resourceName string) resou func testAccAzureRMEventGridEventSubscription_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -202,7 +206,6 @@ resource "azurerm_storage_queue" "test" { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } @@ -244,6 +247,10 @@ resource "azurerm_eventgrid_event_subscription" "test" { func testAccAzureRMEventGridEventSubscription_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -251,8 +258,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestacc%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -263,23 +270,20 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_queue" "test" { name = "mysamplequeue-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name } resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } resource "azurerm_storage_blob" "test" { name = "herpderp1.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name type = "page" size = 5120 @@ -287,16 +291,16 @@ resource "azurerm_storage_blob" "test" { resource "azurerm_eventgrid_event_subscription" "test" { name = "acctesteg-%d" - scope = "${azurerm_resource_group.test.id}" + scope = azurerm_resource_group.test.id storage_queue_endpoint { - storage_account_id = "${azurerm_storage_account.test.id}" - queue_name = "${azurerm_storage_queue.test.name}" + storage_account_id = azurerm_storage_account.test.id + queue_name = azurerm_storage_queue.test.name } storage_blob_dead_letter_destination { - storage_account_id = "${azurerm_storage_account.test.id}" - storage_blob_container_name = "${azurerm_storage_container.test.name}" + storage_account_id = azurerm_storage_account.test.id + storage_blob_container_name = azurerm_storage_container.test.name } retry_policy { @@ -317,6 +321,10 @@ resource "azurerm_eventgrid_event_subscription" "test" { func testAccAzureRMEventGridEventSubscription_eventhub(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -324,26 +332,26 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Basic" } resource "azurerm_eventhub" "test" { name = "acctesteventhub-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name partition_count = 2 message_retention = 1 } resource "azurerm_eventgrid_event_subscription" "test" { name = "acctesteg-%d" - scope = "${azurerm_resource_group.test.id}" + scope = azurerm_resource_group.test.id event_delivery_schema = "CloudEventV01Schema" eventhub_endpoint { - eventhub_id = "${azurerm_eventhub.test.id}" + eventhub_id = azurerm_eventhub.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -351,6 +359,10 @@ resource "azurerm_eventgrid_event_subscription" "test" { func testAccAzureRMEventGridEventSubscription_filter(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_topic_test.go b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_topic_test.go index 04af0f761fb46..5e33ace9f23d3 100644 --- a/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_topic_test.go +++ b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_topic_test.go @@ -150,6 +150,10 @@ func testAccAzureRMEventGridTopic_basic(data acceptance.TestData) string { // currently only supported in "West Central US" & "West US 2" location := "westus2" return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -157,8 +161,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventgrid_topic" "test" { name = "acctesteg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, location, data.RandomInteger) } @@ -169,9 +173,9 @@ func testAccAzureRMEventGridTopic_requiresImport(data acceptance.TestData) strin %s resource "azurerm_eventgrid_topic" "import" { - name = "${azurerm_eventgrid_topic.test.name}" - location = "${azurerm_eventgrid_topic.test.location}" - resource_group_name = "${azurerm_eventgrid_topic.test.resource_group_name}" + name = azurerm_eventgrid_topic.test.name + location = azurerm_eventgrid_topic.test.location + resource_group_name = azurerm_eventgrid_topic.test.resource_group_name } `, template) } @@ -180,6 +184,10 @@ func testAccAzureRMEventGridTopic_basicWithTags(data acceptance.TestData) string // currently only supported in "West Central US" & "West US 2" location := "westus2" return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -187,8 +195,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventgrid_topic" "test" { name = "acctesteg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { "foo" = "bar" diff --git a/azurerm/internal/services/eventhub/data_source_eventhub_authorization_rule.go b/azurerm/internal/services/eventhub/data_source_eventhub_authorization_rule.go new file mode 100644 index 0000000000000..79e64fe3b6f65 --- /dev/null +++ b/azurerm/internal/services/eventhub/data_source_eventhub_authorization_rule.go @@ -0,0 +1,108 @@ +package eventhub + +import ( + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceEventHubAuthorizationRule() *schema.Resource { + return &schema.Resource{ + Read: dataSourceEventHubAuthorizationRuleRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: azure.EventHubAuthorizationRuleSchemaFrom(map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: azure.ValidateEventHubAuthorizationRuleName(), + }, + + "namespace_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: azure.ValidateEventHubNamespaceName(), + }, + + "eventhub_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: azure.ValidateEventHubName(), + }, + + "primary_key": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_key": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "primary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + + "location": azure.SchemaLocationForDataSource(), + }), + } +} + +func dataSourceEventHubAuthorizationRuleRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Eventhub.EventHubsClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + eventHubName := d.Get("eventhub_name").(string) + namespaceName := d.Get("namespace_name").(string) + + resp, err := client.GetAuthorizationRule(ctx, resourceGroup, namespaceName, eventHubName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error: EventHub Authorization Rule %q (Resource Group %q) was not found", name, resourceGroup) + } + return fmt.Errorf("Error: EventHub Authorization Rule %s: %+v", name, err) + } + + d.SetId(*resp.ID) + + d.Set("name", name) + d.Set("eventhub_name", eventHubName) + d.Set("namespace_name", namespaceName) + d.Set("resource_group_name", resourceGroup) + + 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("secondary_key", keysResp.SecondaryKey) + d.Set("primary_connection_string", keysResp.PrimaryConnectionString) + d.Set("secondary_connection_string", keysResp.SecondaryConnectionString) + + return nil +} diff --git a/azurerm/internal/services/eventhub/registration.go b/azurerm/internal/services/eventhub/registration.go index 330cd1b2f89de..864c7bf8159de 100644 --- a/azurerm/internal/services/eventhub/registration.go +++ b/azurerm/internal/services/eventhub/registration.go @@ -11,9 +11,17 @@ func (r Registration) Name() string { return "EventHub" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Messaging", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ + "azurerm_eventhub_authorization_rule": dataSourceEventHubAuthorizationRule(), "azurerm_eventhub_consumer_group": dataSourceEventHubConsumerGroup(), "azurerm_eventhub_namespace": dataSourceEventHubNamespace(), "azurerm_eventhub_namespace_authorization_rule": dataSourceEventHubNamespaceAuthorizationRule(), diff --git a/azurerm/internal/services/eventhub/resource_arm_eventhub.go b/azurerm/internal/services/eventhub/resource_arm_eventhub.go index a16f9b115fcde..9c123649a3fe1 100644 --- a/azurerm/internal/services/eventhub/resource_arm_eventhub.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub.go @@ -52,9 +52,6 @@ func resourceArmEventHub() *schema.Resource { "resource_group_name": azure.SchemaResourceGroupName(), - // TODO: remove me in the next major version - "location": azure.SchemaLocationDeprecated(), - "partition_count": { Type: schema.TypeInt, Required: true, diff --git a/azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule.go index 6c96f669d2a8b..8fcf45bc0cf5b 100644 --- a/azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule.go @@ -57,8 +57,6 @@ func resourceArmEventHubAuthorizationRule() *schema.Resource { }, "resource_group_name": azure.SchemaResourceGroupName(), - - "location": azure.SchemaLocationDeprecated(), }), CustomizeDiff: azure.EventHubAuthorizationRuleCustomizeDiff, diff --git a/azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group.go index 6553378d42005..75d32d0fa6c81 100644 --- a/azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group.go @@ -57,8 +57,6 @@ func resourceArmEventHubConsumerGroup() *schema.Resource { "resource_group_name": azure.SchemaResourceGroupName(), - "location": azure.SchemaLocationDeprecated(), - "user_metadata": { Type: schema.TypeString, Optional: true, diff --git a/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace.go index 75ae45576d158..5ae3bbfa2af61 100644 --- a/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace.go @@ -78,13 +78,6 @@ func resourceArmEventHubNamespace() *schema.Resource { Default: false, }, - "kafka_enabled": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - Deprecated: "This field is now automatically set depending on the SKU used - as such it's no longer used and will be removed in 2.0 of the Azure Provider", - }, - "maximum_throughput_units": { Type: schema.TypeInt, Optional: true, @@ -110,9 +103,11 @@ func resourceArmEventHubNamespace() *schema.Resource { }, false), }, + // 128 limit per https://docs.microsoft.com/azure/event-hubs/event-hubs-quotas "virtual_network_rule": { Type: schema.TypeList, Optional: true, + MaxItems: 128, ConfigMode: schema.SchemaConfigModeAttr, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -134,10 +129,11 @@ func resourceArmEventHubNamespace() *schema.Resource { }, }, + // 128 limit per https://docs.microsoft.com/azure/event-hubs/event-hubs-quotas "ip_rule": { Type: schema.TypeList, Optional: true, - MaxItems: 1, + MaxItems: 128, ConfigMode: schema.SchemaConfigModeAttr, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -314,9 +310,6 @@ func resourceArmEventHubNamespaceRead(d *schema.ResourceData, meta interface{}) if props := resp.EHNamespaceProperties; props != nil { d.Set("auto_inflate_enabled", props.IsAutoInflateEnabled) d.Set("maximum_throughput_units", int(*props.MaximumThroughputUnits)) - - // TODO: remove me in 2.0 - d.Set("kafka_enabled", props.KafkaEnabled) } ruleset, err := client.GetNetworkRuleSet(ctx, resGroup, name) diff --git a/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule.go index 662320cb9b97d..7ae9a036c6c56 100644 --- a/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule.go @@ -50,8 +50,6 @@ func resourceArmEventHubNamespaceAuthorizationRule() *schema.Resource { }, "resource_group_name": azure.SchemaResourceGroupName(), - - "location": azure.SchemaLocationDeprecated(), }), CustomizeDiff: azure.EventHubAuthorizationRuleCustomizeDiff, @@ -117,7 +115,7 @@ func resourceArmEventHubNamespaceAuthorizationRuleRead(d *schema.ResourceData, m return err } - name := id.Path["AuthorizationRules"] //this is different then eventhub where its authorizationRules + name := id.Path["AuthorizationRules"] // this is different then eventhub where its authorizationRules resourceGroup := id.ResourceGroup namespaceName := id.Path["namespaces"] @@ -164,7 +162,7 @@ func resourceArmEventHubNamespaceAuthorizationRuleDelete(d *schema.ResourceData, return err } - name := id.Path["AuthorizationRules"] //this is different then eventhub where its authorizationRules + name := id.Path["AuthorizationRules"] // this is different then eventhub where its authorizationRules resourceGroup := id.ResourceGroup namespaceName := id.Path["namespaces"] diff --git a/azurerm/internal/services/eventhub/tests/data_source_eventhub_authorization_rule_test.go b/azurerm/internal/services/eventhub/tests/data_source_eventhub_authorization_rule_test.go new file mode 100644 index 0000000000000..b6691fc114d76 --- /dev/null +++ b/azurerm/internal/services/eventhub/tests/data_source_eventhub_authorization_rule_test.go @@ -0,0 +1,48 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMEventHubAuthorizationRule(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_eventhub_authorization_rule", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMEventHubAuthorizationRule_base(data, true, true, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "eventhub_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMEventHubAuthorizationRule_base(data acceptance.TestData, listen, send, manage bool) string { + template := testAccAzureRMEventHubAuthorizationRule_base(data, listen, send, manage) + return fmt.Sprintf(` +%s + +data "azurerm_eventhub_authorization_rule" "test" { + name = azurerm_eventhub_authorization_rule.test.name + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name +} +`, template) +} diff --git a/azurerm/internal/services/eventhub/tests/data_source_eventhub_consumer_group_test.go b/azurerm/internal/services/eventhub/tests/data_source_eventhub_consumer_group_test.go index 41196836c4aa6..3802cf8da05da 100644 --- a/azurerm/internal/services/eventhub/tests/data_source_eventhub_consumer_group_test.go +++ b/azurerm/internal/services/eventhub/tests/data_source_eventhub_consumer_group_test.go @@ -29,6 +29,10 @@ func TestAccDataSourceAzureRMEventHubConsumerGroup_complete(t *testing.T) { func testAccDataSourceAzureRMEventHubConsumerGroup_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -36,32 +40,32 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + 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}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name partition_count = 2 message_retention = 7 } resource "azurerm_eventhub_consumer_group" "test" { name = "acctesteventhubcg-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - eventhub_name = "${azurerm_eventhub.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name user_metadata = "some-meta-data" } data "azurerm_eventhub_consumer_group" "test" { - name = "${azurerm_eventhub_consumer_group.test.name}" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - eventhub_name = "${azurerm_eventhub.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_eventhub_consumer_group.test.name + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/eventhub/tests/data_source_eventhub_namespace_authorization_rule_test.go b/azurerm/internal/services/eventhub/tests/data_source_eventhub_namespace_authorization_rule_test.go index 2a747b4756681..e6737abb76a04 100644 --- a/azurerm/internal/services/eventhub/tests/data_source_eventhub_namespace_authorization_rule_test.go +++ b/azurerm/internal/services/eventhub/tests/data_source_eventhub_namespace_authorization_rule_test.go @@ -25,6 +25,10 @@ func TestAccDataSourceAzureRMEventHubNamespaceAuthorizationRule_basic(t *testing func testAccDataSourceEventHubNamespaceAuthorizationRule_basic(data acceptance.TestData, listen, send, manage bool) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%[1]d" location = "%[2]s" @@ -32,16 +36,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctest-EHN-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + 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-EHN-AR%[1]d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name listen = %[3]t send = %[4]t @@ -49,9 +53,9 @@ resource "azurerm_eventhub_namespace_authorization_rule" "test" { } data "azurerm_eventhub_namespace_authorization_rule" "test" { - name = "${azurerm_eventhub_namespace_authorization_rule.test.name}" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_eventhub_namespace_authorization_rule.test.name + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, listen, send, manage) } diff --git a/azurerm/internal/services/eventhub/tests/data_source_eventhub_namespace_test.go b/azurerm/internal/services/eventhub/tests/data_source_eventhub_namespace_test.go index 70480fb0f4477..97a171726f4a3 100644 --- a/azurerm/internal/services/eventhub/tests/data_source_eventhub_namespace_test.go +++ b/azurerm/internal/services/eventhub/tests/data_source_eventhub_namespace_test.go @@ -47,6 +47,10 @@ func TestAccDataSourceAzureRMEventHubNamespace_complete(t *testing.T) { func testAccDataSourceEventHubNamespace_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -54,20 +58,24 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Basic" } data "azurerm_eventhub_namespace" "test" { - name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_eventhub_namespace.test.resource_group_name}" + name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_eventhub_namespace.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccDataSourceEventHubNamespace_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -75,8 +83,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" capacity = "2" auto_inflate_enabled = true @@ -84,8 +92,8 @@ resource "azurerm_eventhub_namespace" "test" { } data "azurerm_eventhub_namespace" "test" { - name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_eventhub_namespace.test.resource_group_name}" + name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_eventhub_namespace.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_authorization_rule_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_authorization_rule_test.go index 1d3ecbeb62dad..4307ddc42aabf 100644 --- a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_authorization_rule_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_authorization_rule_test.go @@ -181,6 +181,10 @@ func testCheckAzureRMEventHubAuthorizationRuleExists(resourceName string) resour func testAccAzureRMEventHubAuthorizationRule_base(data acceptance.TestData, listen, send, manage bool) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%[2]s" @@ -188,16 +192,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub" "test" { name = "acctesteventhub-%[1]d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name partition_count = 2 message_retention = 1 @@ -205,9 +209,9 @@ resource "azurerm_eventhub" "test" { resource "azurerm_eventhub_authorization_rule" "test" { 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}" + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name listen = %[3]t send = %[4]t @@ -222,13 +226,13 @@ func testAccAzureRMEventHubAuthorizationRule_requiresImport(data acceptance.Test %s resource "azurerm_eventhub_authorization_rule" "import" { - name = "${azurerm_eventhub_authorization_rule.test.name}" - namespace_name = "${azurerm_eventhub_authorization_rule.test.namespace_name}" - eventhub_name = "${azurerm_eventhub_authorization_rule.test.eventhub_name}" - resource_group_name = "${azurerm_eventhub_authorization_rule.test.resource_group_name}" - listen = "${azurerm_eventhub_authorization_rule.test.listen}" - send = "${azurerm_eventhub_authorization_rule.test.send}" - manage = "${azurerm_eventhub_authorization_rule.test.manage}" + name = azurerm_eventhub_authorization_rule.test.name + namespace_name = azurerm_eventhub_authorization_rule.test.namespace_name + eventhub_name = azurerm_eventhub_authorization_rule.test.eventhub_name + resource_group_name = azurerm_eventhub_authorization_rule.test.resource_group_name + listen = azurerm_eventhub_authorization_rule.test.listen + send = azurerm_eventhub_authorization_rule.test.send + manage = azurerm_eventhub_authorization_rule.test.manage } `, template) } diff --git a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_consumer_group_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_consumer_group_test.go index 48e790717242b..303756af8d15f 100644 --- a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_consumer_group_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_consumer_group_test.go @@ -164,6 +164,10 @@ func testCheckAzureRMEventHubConsumerGroupExists(resourceName string) resource.T func testAccAzureRMEventHubConsumerGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -171,24 +175,24 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + 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}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name partition_count = 2 message_retention = 7 } resource "azurerm_eventhub_consumer_group" "test" { name = "acctesteventhubcg-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - eventhub_name = "${azurerm_eventhub.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } @@ -199,16 +203,20 @@ func testAccAzureRMEventHubConsumerGroup_requiresImport(data acceptance.TestData %s resource "azurerm_eventhub_consumer_group" "import" { - name = "${azurerm_eventhub_consumer_group.test.name}" - namespace_name = "${azurerm_eventhub_consumer_group.test.namespace_name}" - eventhub_name = "${azurerm_eventhub_consumer_group.test.eventhub_name}" - resource_group_name = "${azurerm_eventhub_consumer_group.test.resource_group_name}" + name = azurerm_eventhub_consumer_group.test.name + namespace_name = azurerm_eventhub_consumer_group.test.namespace_name + eventhub_name = azurerm_eventhub_consumer_group.test.eventhub_name + resource_group_name = azurerm_eventhub_consumer_group.test.resource_group_name } `, template) } func testAccAzureRMEventHubConsumerGroup_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -216,24 +224,24 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + 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}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name partition_count = 2 message_retention = 7 } resource "azurerm_eventhub_consumer_group" "test" { name = "acctesteventhubcg-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - eventhub_name = "${azurerm_eventhub.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name user_metadata = "some-meta-data" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) diff --git a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_authorization_rule_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_authorization_rule_test.go index d82e9e238fb6a..08399d6cad933 100644 --- a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_authorization_rule_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_authorization_rule_test.go @@ -178,6 +178,10 @@ func testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(resourceName strin func testAccAzureRMEventHubNamespaceAuthorizationRule_base(data acceptance.TestData, listen, send, manage bool) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%[1]d" location = "%[2]s" @@ -185,16 +189,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctest-EHN-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + 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-EHN-AR%[1]d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name listen = %[3]t send = %[4]t @@ -209,12 +213,12 @@ func testAccAzureRMEventHubNamespaceAuthorizationRule_requiresImport(data accept %s resource "azurerm_eventhub_namespace_authorization_rule" "import" { - name = "${azurerm_eventhub_namespace_authorization_rule.test.name}" - namespace_name = "${azurerm_eventhub_namespace_authorization_rule.test.namespace_name}" - resource_group_name = "${azurerm_eventhub_namespace_authorization_rule.test.resource_group_name}" - listen = "${azurerm_eventhub_namespace_authorization_rule.test.listen}" - send = "${azurerm_eventhub_namespace_authorization_rule.test.send}" - manage = "${azurerm_eventhub_namespace_authorization_rule.test.manage}" + name = azurerm_eventhub_namespace_authorization_rule.test.name + namespace_name = azurerm_eventhub_namespace_authorization_rule.test.namespace_name + resource_group_name = azurerm_eventhub_namespace_authorization_rule.test.resource_group_name + listen = azurerm_eventhub_namespace_authorization_rule.test.listen + send = azurerm_eventhub_namespace_authorization_rule.test.send + manage = azurerm_eventhub_namespace_authorization_rule.test.manage } `, template) } diff --git a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_disaster_recovery_config_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_disaster_recovery_config_test.go index 29dfffc7657a3..0cd015495693b 100644 --- a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_disaster_recovery_config_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_disaster_recovery_config_test.go @@ -135,6 +135,10 @@ func testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(resourceName func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%[1]d" location = "%[2]s" @@ -142,30 +146,33 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "testa" { name = "acctest-EHN-%[1]d-a" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub_namespace" "testb" { name = "acctest-EHN-%[1]d-b" location = "%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" { name = "acctest-EHN-DRC-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - namespace_name = "${azurerm_eventhub_namespace.testa.name}" - partner_namespace_id = "${azurerm_eventhub_namespace.testb.id}" + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_eventhub_namespace.testa.name + partner_namespace_id = azurerm_eventhub_namespace.testb.id } - `, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) } func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%[1]d" location = "%[2]s" @@ -173,31 +180,34 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "testa" { name = "acctest-EHN-%[1]d-a" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub_namespace" "testb" { name = "acctest-EHN-%[1]d-b" location = "%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" { name = "${azurerm_eventhub_namespace.testa.name}-111" - resource_group_name = "${azurerm_resource_group.test.name}" - namespace_name = "${azurerm_eventhub_namespace.testa.name}" - partner_namespace_id = "${azurerm_eventhub_namespace.testb.id}" + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_eventhub_namespace.testa.name + partner_namespace_id = azurerm_eventhub_namespace.testb.id alternate_name = "acctest-EHN-DRC-%[1]d-alt" } - `, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) } func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%[1]d" location = "%[2]s" @@ -205,37 +215,40 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "testa" { name = "acctest-EHN-%[1]d-a" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub_namespace" "testb" { name = "acctest-EHN-%[1]d-b" location = "%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub_namespace" "testc" { name = "acctest-EHN-%[1]d-c" location = "%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" { name = "acctest-EHN-DRC-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - namespace_name = "${azurerm_eventhub_namespace.testa.name}" - partner_namespace_id = "${azurerm_eventhub_namespace.testc.id}" + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_eventhub_namespace.testa.name + partner_namespace_id = azurerm_eventhub_namespace.testc.id } - `, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) } func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated_removed(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%[1]d" location = "%[2]s" @@ -243,22 +256,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "testa" { name = "acctest-EHN-%[1]d-a" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub_namespace" "testb" { name = "acctest-EHN-%[1]d-b" location = "%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub_namespace" "testc" { name = "acctest-EHN-%[1]d-c" location = "%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } `, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) diff --git a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_test.go index 6a7a18f915390..8d2b11374b134 100644 --- a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_test.go @@ -116,6 +116,27 @@ func TestAccAzureRMEventHubNamespace_networkrule_vnet(t *testing.T) { }) } +func TestAccAzureRMEventHubNamespace_networkruleVnetIpRule(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMEventHubNamespace_networkruleVnetIpRule(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_rulesets.0.virtual_network_rule.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rulesets.0.ip_rule.#", "2"), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMEventHubNamespace_readDefaultKeys(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") @@ -381,6 +402,10 @@ func testCheckAzureRMEventHubNamespaceExists(resourceName string) resource.TestC func testAccAzureRMEventHubNamespace_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -388,8 +413,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Basic" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -401,16 +426,20 @@ func testAccAzureRMEventHubNamespace_requiresImport(data acceptance.TestData) st %s resource "azurerm_eventhub_namespace" "import" { - name = "${azurerm_eventhub_namespace.test.name}" - location = "${azurerm_eventhub_namespace.test.location}" - resource_group_name = "${azurerm_eventhub_namespace.test.resource_group_name}" - sku = "${azurerm_eventhub_namespace.test.sku}" + name = azurerm_eventhub_namespace.test.name + location = azurerm_eventhub_namespace.test.location + resource_group_name = azurerm_eventhub_namespace.test.resource_group_name + sku = azurerm_eventhub_namespace.test.sku } `, template) } func testAccAzureRMEventHubNamespace_standard(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -418,8 +447,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" capacity = "2" } @@ -428,6 +457,10 @@ resource "azurerm_eventhub_namespace" "test" { func testAccAzureRMEventHubNamespace_networkrule_iprule(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -435,8 +468,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" capacity = "2" @@ -452,6 +485,10 @@ resource "azurerm_eventhub_namespace" "test" { func testAccAzureRMEventHubNamespace_networkrule_vnet(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%[2]s" @@ -460,28 +497,28 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%[1]d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" capacity = "2" network_rulesets { default_action = "Deny" virtual_network_rule { - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id ignore_missing_virtual_network_service_endpoint = true } @@ -490,8 +527,83 @@ resource "azurerm_eventhub_namespace" "test" { `, data.RandomInteger, data.Locations.Primary) } +func testAccAzureRMEventHubNamespace_networkruleVnetIpRule(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[1]d" + location = "%[2]s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn1-%[1]d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_subnet" "test" { + name = "acctsub1-%[1]d" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.1.0/24" + service_endpoints = ["Microsoft.EventHub"] +} + +resource "azurerm_virtual_network" "test2" { + name = "acctvn2-%[1]d" + address_space = ["10.1.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_subnet" "test2" { + name = "acctsub2-%[1]d" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test2.name + address_prefix = "10.1.1.0/24" + service_endpoints = ["Microsoft.EventHub"] +} + +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" + capacity = "2" + + network_rulesets { + default_action = "Deny" + + virtual_network_rule { + subnet_id = azurerm_subnet.test.id + } + + virtual_network_rule { + subnet_id = azurerm_subnet.test2.id + } + + ip_rule { + ip_mask = "10.0.1.0/24" + } + + ip_rule { + ip_mask = "10.1.1.0/24" + } + } +} +`, data.RandomInteger, data.Locations.Primary) +} + func testAccAzureRMEventHubNamespaceNonStandardCasing(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -499,8 +611,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "basic" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -508,6 +620,10 @@ resource "azurerm_eventhub_namespace" "test" { func testAccAzureRMEventHubNamespace_maximumThroughputUnits(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -515,8 +631,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" capacity = "2" auto_inflate_enabled = true @@ -527,6 +643,10 @@ resource "azurerm_eventhub_namespace" "test" { func testAccAzureRMEventHubNamespace_basicWithTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -534,8 +654,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Basic" tags = { @@ -547,6 +667,10 @@ resource "azurerm_eventhub_namespace" "test" { func testAccAzureRMEventHubNamespace_capacity(data acceptance.TestData, capacity int) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -554,8 +678,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Basic" capacity = %d } @@ -564,6 +688,10 @@ resource "azurerm_eventhub_namespace" "test" { func testAccAzureRMEventHubNamespace_maximumThroughputUnitsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -571,8 +699,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" capacity = 1 auto_inflate_enabled = true @@ -583,6 +711,10 @@ resource "azurerm_eventhub_namespace" "test" { func testAccAzureRMEventHubNamespace_autoInfalteDisabledWithAutoInflateUnits(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -590,8 +722,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" capacity = 1 auto_inflate_enabled = false diff --git a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_test.go index bdd3e5ec21dd2..0e6aa4ff5d1f3 100644 --- a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_test.go @@ -415,6 +415,10 @@ func testCheckAzureRMEventHubExists(resourceName string) resource.TestCheckFunc func testAccAzureRMEventHub_basic(data acceptance.TestData, partitionCount int) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%d" location = "%s" @@ -422,15 +426,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Basic" } resource "azurerm_eventhub" "test" { name = "acctesteventhub-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name partition_count = %d message_retention = 1 } @@ -443,17 +447,21 @@ func testAccAzureRMEventHub_requiresImport(data acceptance.TestData) string { %s resource "azurerm_eventhub" "import" { - name = "${azurerm_eventhub.test.name}" - namespace_name = "${azurerm_eventhub.test.namespace_name}" - resource_group_name = "${azurerm_eventhub.test.resource_group_name}" - partition_count = "${azurerm_eventhub.test.partition_count}" - message_retention = "${azurerm_eventhub.test.message_retention}" + name = azurerm_eventhub.test.name + namespace_name = azurerm_eventhub.test.namespace_name + resource_group_name = azurerm_eventhub.test.resource_group_name + partition_count = azurerm_eventhub.test.partition_count + message_retention = azurerm_eventhub.test.message_retention } `, template) } func testAccAzureRMEventHub_partitionCountUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%d" location = "%s" @@ -461,15 +469,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Basic" } resource "azurerm_eventhub" "test" { name = "acctesteventhub-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name partition_count = 10 message_retention = 1 } @@ -478,6 +486,10 @@ resource "azurerm_eventhub" "test" { func testAccAzureRMEventHub_standard(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%d" location = "%s" @@ -485,15 +497,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctest-EHN-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub" "test" { name = "acctest-EH-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name partition_count = 2 message_retention = 7 } @@ -503,6 +515,10 @@ resource "azurerm_eventhub" "test" { func testAccAzureRMEventHub_captureDescription(data acceptance.TestData, enabled bool) string { enabledString := strconv.FormatBool(enabled) return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%d" location = "%s" @@ -510,30 +526,29 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "acctest" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } resource "azurerm_eventhub_namespace" "test" { name = "acctest-EHN%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub" "test" { name = "acctest-EH%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name partition_count = 2 message_retention = 7 @@ -547,8 +562,8 @@ resource "azurerm_eventhub" "test" { destination { name = "EventHubArchive.AzureBlockBlob" archive_name_format = "Prod_{EventHub}/{Namespace}\\{PartitionId}_{Year}_{Month}/{Day}/{Hour}/{Minute}/{Second}" - blob_container_name = "${azurerm_storage_container.test.name}" - storage_account_id = "${azurerm_storage_account.test.id}" + blob_container_name = azurerm_storage_container.test.name + storage_account_id = azurerm_storage_account.test.id } } } @@ -557,6 +572,10 @@ resource "azurerm_eventhub" "test" { func testAccAzureRMEventHub_messageRetentionUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%d" location = "%s" @@ -564,15 +583,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctest-EHN-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_eventhub" "test" { name = "acctest-EH-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name partition_count = 2 message_retention = 5 } diff --git a/azurerm/internal/services/frontdoor/registration.go b/azurerm/internal/services/frontdoor/registration.go index 57231cd3b9c0e..bccd7cc0fd546 100644 --- a/azurerm/internal/services/frontdoor/registration.go +++ b/azurerm/internal/services/frontdoor/registration.go @@ -4,6 +4,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) +// TODO: move this to the network one + type Registration struct{} // Name is the name of this Service @@ -11,6 +13,13 @@ func (r Registration) Name() string { return "FrontDoor" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Network", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{} diff --git a/azurerm/internal/services/frontdoor/resource_arm_frontdoor.go b/azurerm/internal/services/frontdoor/resource_arm_frontdoor.go index 2af4efdfb7df6..b8348e880534a 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_frontdoor.go +++ b/azurerm/internal/services/frontdoor/resource_arm_frontdoor.go @@ -3,6 +3,7 @@ package frontdoor import ( "fmt" "log" + "strings" "time" "github.com/Azure/azure-sdk-for-go/services/frontdoor/mgmt/2019-11-01/frontdoor" @@ -175,7 +176,7 @@ func resourceArmFrontDoor() *schema.Resource { "cache_enabled": { Type: schema.TypeBool, Optional: true, - Default: true, + Default: false, }, "cache_use_dynamic_compression": { Type: schema.TypeBool, @@ -185,26 +186,25 @@ func resourceArmFrontDoor() *schema.Resource { "cache_query_parameter_strip_directive": { Type: schema.TypeString, Optional: true, + Default: string(frontdoor.StripAll), ValidateFunc: validation.StringInSlice([]string{ string(frontdoor.StripAll), string(frontdoor.StripNone), }, false), - Default: string(frontdoor.StripNone), }, "custom_forwarding_path": { Type: schema.TypeString, Optional: true, }, - // TODO: In 2.0 Switch default value from MatchRequest to HTTPSOnly #4627 "forwarding_protocol": { Type: schema.TypeString, Optional: true, + Default: string(frontdoor.HTTPSOnly), ValidateFunc: validation.StringInSlice([]string{ string(frontdoor.HTTPOnly), string(frontdoor.HTTPSOnly), string(frontdoor.MatchRequest), }, false), - Default: string(frontdoor.MatchRequest), }, }, }, @@ -262,6 +262,11 @@ func resourceArmFrontDoor() *schema.Resource { Required: true, ValidateFunc: ValidateBackendPoolRoutingRuleName, }, + "enabled": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, "path": { Type: schema.TypeString, Optional: true, @@ -270,11 +275,20 @@ func resourceArmFrontDoor() *schema.Resource { "protocol": { Type: schema.TypeString, Optional: true, + Default: string(frontdoor.HTTP), ValidateFunc: validation.StringInSlice([]string{ string(frontdoor.HTTP), string(frontdoor.HTTPS), }, false), - Default: string(frontdoor.HTTP), + }, + "probe_method": { + Type: schema.TypeString, + Optional: true, + Default: string(frontdoor.GET), + ValidateFunc: validation.StringInSlice([]string{ + string(frontdoor.GET), + string(frontdoor.HEAD), + }, false), }, "interval_in_seconds": { Type: schema.TypeInt, @@ -319,14 +333,14 @@ func resourceArmFrontDoor() *schema.Resource { "weight": { Type: schema.TypeInt, Optional: true, - ValidateFunc: validation.IntBetween(1, 1000), Default: 50, + ValidateFunc: validation.IntBetween(1, 1000), }, "priority": { Type: schema.TypeInt, Optional: true, - ValidateFunc: validation.IntBetween(1, 5), Default: 1, + ValidateFunc: validation.IntBetween(1, 5), }, "host_header": { Type: schema.TypeString, @@ -402,11 +416,11 @@ func resourceArmFrontDoor() *schema.Resource { "certificate_source": { Type: schema.TypeString, Optional: true, + Default: string(frontdoor.CertificateSourceFrontDoor), ValidateFunc: validation.StringInSlice([]string{ string(frontdoor.CertificateSourceAzureKeyVault), string(frontdoor.CertificateSourceFrontDoor), }, false), - Default: string(frontdoor.CertificateSourceFrontDoor), }, "minimum_tls_version": { Type: schema.TypeString, @@ -485,6 +499,7 @@ func resourceArmFrontDoorCreateUpdate(d *schema.ResourceData, meta interface{}) frontendEndpoints := d.Get("frontend_endpoint").([]interface{}) backendPoolsSettings := d.Get("enforce_backend_pools_certificate_name_check").(bool) enabledState := d.Get("load_balancer_enabled").(bool) + t := d.Get("tags").(map[string]interface{}) frontDoorParameters := frontdoor.FrontDoor{ @@ -863,6 +878,12 @@ func expandArmFrontDoorHealthProbeSettingsModel(input []interface{}, frontDoorPa protocol := v["protocol"].(string) intervalInSeconds := int32(v["interval_in_seconds"].(int)) name := v["name"].(string) + enabled := v["enabled"].(bool) + + healthProbeEnabled := frontdoor.HealthProbeEnabledEnabled + if !enabled { + healthProbeEnabled = frontdoor.HealthProbeEnabledDisabled + } result := frontdoor.HealthProbeSettingsModel{ ID: utils.String(frontDoorPath + "/HealthProbeSettings/" + name), @@ -871,6 +892,8 @@ func expandArmFrontDoorHealthProbeSettingsModel(input []interface{}, frontDoorPa IntervalInSeconds: utils.Int32(intervalInSeconds), Path: utils.String(path), Protocol: frontdoor.Protocol(protocol), + HealthProbeMethod: frontdoor.HealthProbeMethod(v["probe_method"].(string)), + EnabledState: healthProbeEnabled, }, } @@ -1077,7 +1100,7 @@ func expandArmFrontDoorForwardingConfiguration(input []interface{}, frontDoorPat if cacheQueryParameterStripDirective == "" { // Set Default Value for strip directive is not in the key slice and cache is enabled - cacheQueryParameterStripDirective = string(frontdoor.StripNone) + cacheQueryParameterStripDirective = string(frontdoor.StripAll) } forwardingConfiguration.CacheConfiguration = &frontdoor.CacheConfiguration{ @@ -1277,12 +1300,13 @@ func flattenArmFrontDoorFrontendEndpoint(d *schema.ResourceData, input *[]frontd } func flattenArmFrontDoorHealthProbeSettingsModel(input *[]frontdoor.HealthProbeSettingsModel) []interface{} { + results := make([]interface{}, 0) if input == nil { - return make([]interface{}, 0) + return results } - result := make(map[string]interface{}) for _, v := range *input { + result := make(map[string]interface{}) if id := v.ID; id != nil { result["id"] = *id } @@ -1296,21 +1320,31 @@ func flattenArmFrontDoorHealthProbeSettingsModel(input *[]frontdoor.HealthProbeS if path := properties.Path; path != nil { result["path"] = *path } + if healthProbeMethod := properties.HealthProbeMethod; healthProbeMethod != "" { + // I have to upper this as the frontdoor.GET and frondoor.HEAD types are uppercased + // but Azure stores them in the resource as pascal cased (e.g. "Get" and "Head") + result["probe_method"] = strings.ToUpper(string(healthProbeMethod)) + } + if enabled := properties.EnabledState; enabled != "" { + result["enabled"] = (enabled == frontdoor.HealthProbeEnabledEnabled) + } result["protocol"] = string(properties.Protocol) } + + results = append(results, result) } - return []interface{}{result} + return results } func flattenArmFrontDoorLoadBalancingSettingsModel(input *[]frontdoor.LoadBalancingSettingsModel) []interface{} { + results := make([]interface{}, 0) if input == nil { - return make([]interface{}, 0) + return results } - result := make(map[string]interface{}) - for _, v := range *input { + result := make(map[string]interface{}) if id := v.ID; id != nil { result["id"] = *id } @@ -1328,8 +1362,11 @@ func flattenArmFrontDoorLoadBalancingSettingsModel(input *[]frontdoor.LoadBalanc result["successful_samples_required"] = *successfulSamplesRequired } } + + results = append(results, result) } - return []interface{}{result} + + return results } func flattenArmFrontDoorRoutingRule(input *[]frontdoor.RoutingRule, oldBlocks interface{}) []interface{} { @@ -1388,22 +1425,24 @@ func flattenArmFrontDoorRoutingRule(input *[]frontdoor.RoutingRule, oldBlocks in if stripDirective := cacheConfiguration.QueryParameterStripDirective; stripDirective != "" { c["cache_query_parameter_strip_directive"] = string(stripDirective) } else { - c["cache_query_parameter_strip_directive"] = string(frontdoor.StripNone) + // Default value if not set + c["cache_query_parameter_strip_directive"] = string(frontdoor.StripAll) } if dynamicCompression := cacheConfiguration.DynamicCompression; dynamicCompression != "" { c["cache_use_dynamic_compression"] = bool(string(dynamicCompression) == string(frontdoor.DynamicCompressionEnabledEnabled)) } } else { + // if the cache is disabled, set the default values or revert to what they were in the previous plan c["cache_enabled"] = false + c["cache_query_parameter_strip_directive"] = string(frontdoor.StripAll) if name != nil { - //get `forwarding_configuration` + // get `forwarding_configuration` if o, ok := oldByName[*name]; ok { ofcs := o["forwarding_configuration"].([]interface{}) if len(ofcs) > 0 { ofc := ofcs[0].(map[string]interface{}) - c["cache_query_parameter_strip_directive"] = ofc["cache_query_parameter_strip_directive"] c["cache_use_dynamic_compression"] = ofc["cache_use_dynamic_compression"] } diff --git a/azurerm/internal/services/frontdoor/resource_arm_frontdoor_firewall_policy.go b/azurerm/internal/services/frontdoor/resource_arm_frontdoor_firewall_policy.go index 218d1c1e23b92..2337cf55cee7c 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_frontdoor_firewall_policy.go +++ b/azurerm/internal/services/frontdoor/resource_arm_frontdoor_firewall_policy.go @@ -41,7 +41,7 @@ func resourceArmFrontDoorFirewallPolicy() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, + ValidateFunc: ValidateFrontDoorWAFName, }, "location": azure.SchemaLocationForDataSource(), diff --git a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go index 4f87a37e1de42..fb0cc3e425cac 100644 --- a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go +++ b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go @@ -9,9 +9,94 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/frontdoor" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) +func TestAccAzureRMFrontDoorFirewallPolicy_validateName(t *testing.T) { + cases := []struct { + Name string + Input string + ExpectError bool + }{ + { + Name: "Empty String", + Input: "", + ExpectError: true, + }, + { + Name: "Starst with Numeric", + Input: "1WellThisIsAllWrong", + ExpectError: true, + }, + { + Name: "Has Spaces", + Input: "What part of no spaces do you not understand", + ExpectError: true, + }, + { + Name: "Has Hyphens", + Input: "What-part-of-no-hyphens-do-you-not-understand", + ExpectError: true, + }, + { + Name: "Special Characters", + Input: "WellArn`tTheseSpecialCharacters?!", + ExpectError: true, + }, + { + Name: "Mixed Case Alpha and Numeric", + Input: "ThisNameIsAPerfectlyFine1", + ExpectError: false, + }, + { + Name: "Too Long", + Input: "OhMyLordyThisNameIsWayToLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog", + ExpectError: true, + }, + { + Name: "Max Length", + Input: "NowThisNameIsThePerfectLengthForAFrontdoorFireWallPolicyDontYouThinkAnyLongerWouldBeJustWayToLoooooooooooooooooooongDontYouThink", + ExpectError: false, + }, + { + Name: "Minimum Length Upper", + Input: "A", + ExpectError: false, + }, + { + Name: "Minimum Length Lower", + Input: "a", + ExpectError: false, + }, + { + Name: "Mixed Case Alpha no Numeric", + Input: "LookMomNoNumbers", + ExpectError: false, + }, + { + Name: "All Upper Alpha with Numeric", + Input: "OU812", + ExpectError: false, + }, + { + Name: "All lower no Numeric", + Input: "heythisisalllowercase", + ExpectError: false, + }, + } + + for _, tc := range cases { + _, errors := frontdoor.ValidateFrontDoorWAFName(tc.Input, tc.Name) + + hasError := len(errors) > 0 + + if tc.ExpectError && !hasError { + t.Fatalf("Expected the FrontDoor WAF Name to trigger a validation error for '%s'", tc.Name) + } + } +} + func TestAccAzureRMFrontDoorFirewallPolicy_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_frontdoor_firewall_policy", "test") resource.ParallelTest(t, resource.TestCase{ @@ -187,6 +272,10 @@ func testCheckAzureRMFrontDoorFirewallPolicyAttrNotExists(name string, attribute func testAccAzureRMFrontDoorFirewallPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "testaccRG-%d" location = "%s" @@ -216,6 +305,10 @@ func testAccAzureRMFrontDoorFirewallPolicy_update(data acceptance.TestData, upda return testAccAzureRMFrontDoorFirewallPolicy_updated(data) } return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "testaccRG-%d" location = "%s" @@ -272,6 +365,10 @@ resource "azurerm_frontdoor_firewall_policy" "test" { func testAccAzureRMFrontDoorFirewallPolicy_updated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "testaccRG-%d" location = "%[2]s" diff --git a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go index f288ee6a68276..dc6d15add6ba5 100644 --- a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go +++ b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go @@ -23,6 +23,16 @@ func TestAccAzureRMFrontDoor_basic(t *testing.T) { Config: testAccAzureRMFrontDoor_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMFrontDoorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backend_pool_health_probe.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "backend_pool_health_probe.0.probe_method", "GET"), + ), + }, + { + Config: testAccAzureRMFrontDoor_basicDisabled(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMFrontDoorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backend_pool_health_probe.0.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "backend_pool_health_probe.0.probe_method", "HEAD"), ), }, data.ImportStep(), @@ -85,6 +95,28 @@ func TestAccAzureRMFrontDoor_update(t *testing.T) { }) } +func TestAccAzureRMFrontDoor_multiplePools(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_frontdoor", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMFrontDoorDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMFrontDoor_multiplePools(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMFrontDoorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backend_pool.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "backend_pool_health_probe.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "backend_pool_load_balancing.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.#", "2"), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMFrontDoor_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_frontdoor", "test") resource.ParallelTest(t, resource.TestCase{ @@ -134,7 +166,7 @@ func TestAccAzureRMFrontDoor_EnableDisableCache(t *testing.T) { testCheckAzureRMFrontDoorExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_enabled", "true"), resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_use_dynamic_compression", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", "StripNone"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", "StripAll"), ), }, { @@ -143,7 +175,7 @@ func TestAccAzureRMFrontDoor_EnableDisableCache(t *testing.T) { testCheckAzureRMFrontDoorExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_enabled", "false"), resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_use_dynamic_compression", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", "StripNone"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", "StripAll"), ), }, { @@ -152,7 +184,7 @@ func TestAccAzureRMFrontDoor_EnableDisableCache(t *testing.T) { testCheckAzureRMFrontDoorExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_enabled", "true"), resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_use_dynamic_compression", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", "StripNone"), + resource.TestCheckResourceAttr(data.ResourceName, "routing_rule.0.forwarding_configuration.0.cache_query_parameter_strip_directive", "StripAll"), ), }, data.ImportStep(), @@ -240,8 +272,12 @@ func testCheckAzureRMFrontDoorDestroy(s *terraform.State) error { func testAccAzureRMFrontDoor_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestRG-frontdoor-%d" location = "%s" } @@ -253,7 +289,7 @@ locals { } resource "azurerm_frontdoor" "test" { - name = "acctestfd-%d" + name = "acctest-FD-%d" location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name enforce_backend_pools_certificate_name_check = false @@ -292,7 +328,74 @@ resource "azurerm_frontdoor" "test" { frontend_endpoint { name = local.endpoint_name - host_name = "acctestfd-%d.azurefd.net" + host_name = "acctest-FD-%d.azurefd.net" + custom_https_provisioning_enabled = false + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMFrontDoor_basicDisabled(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-frontdoor-%d" + location = "%s" +} + +locals { + backend_name = "backend-bing" + endpoint_name = "frontend-endpoint" + health_probe_name = "health-probe" + load_balancing_name = "load-balancing-setting" +} + +resource "azurerm_frontdoor" "test" { + name = "acctest-FD-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + enforce_backend_pools_certificate_name_check = false + + routing_rule { + name = "routing-rule" + accepted_protocols = ["Http", "Https"] + patterns_to_match = ["/*"] + frontend_endpoints = [local.endpoint_name] + forwarding_configuration { + forwarding_protocol = "MatchRequest" + backend_pool_name = local.backend_name + } + } + + backend_pool_load_balancing { + name = local.load_balancing_name + } + + backend_pool_health_probe { + name = local.health_probe_name + enabled = false + probe_method = "HEAD" + } + + backend_pool { + name = local.backend_name + backend { + host_header = "www.bing.com" + address = "www.bing.com" + http_port = 80 + https_port = 443 + } + + load_balancing_name = local.load_balancing_name + health_probe_name = local.health_probe_name + } + + frontend_endpoint { + name = local.endpoint_name + host_name = "acctest-FD-%d.azurefd.net" custom_https_provisioning_enabled = false } } @@ -344,7 +447,7 @@ resource "azurerm_frontdoor" "import" { frontend_endpoint { name = local.endpoint_name - host_name = "acctestfd-%d.azurefd.net" + host_name = "acctest-FD-%d.azurefd.net" custom_https_provisioning_enabled = false } } @@ -353,8 +456,12 @@ resource "azurerm_frontdoor" "import" { func testAccAzureRMFrontDoor_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestRG-frontdoor-%d" location = "%s" } @@ -366,7 +473,7 @@ locals { } resource "azurerm_frontdoor" "test" { - name = "acctestfd-%d" + name = "acctest-FD-%d" location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name enforce_backend_pools_certificate_name_check = false @@ -405,7 +512,7 @@ resource "azurerm_frontdoor" "test" { frontend_endpoint { name = local.endpoint_name - host_name = "acctestfd-%d.azurefd.net" + host_name = "acctest-FD-%d.azurefd.net" custom_https_provisioning_enabled = false } } @@ -414,8 +521,12 @@ resource "azurerm_frontdoor" "test" { func testAccAzureRMFrontDoor_waf(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestRG-frontdoor-%d" location = "%s" } @@ -433,7 +544,7 @@ resource "azurerm_frontdoor_firewall_policy" "test" { } resource "azurerm_frontdoor" "test" { - name = "acctestfd-%d" + name = "acctest-FD-%d" location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name enforce_backend_pools_certificate_name_check = false @@ -472,7 +583,7 @@ resource "azurerm_frontdoor" "test" { frontend_endpoint { name = local.endpoint_name - host_name = "acctestfd-%d.azurefd.net" + host_name = "acctest-FD-%d.azurefd.net" custom_https_provisioning_enabled = false web_application_firewall_policy_link_id = azurerm_frontdoor_firewall_policy.test.id } @@ -482,8 +593,12 @@ resource "azurerm_frontdoor" "test" { func testAccAzureRMFrontDoor_DisableCache(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestRG-frontdoor-%d" location = "%s" } @@ -495,7 +610,7 @@ locals { } resource "azurerm_frontdoor" "test" { - name = "acctestfd-%d" + name = "acctest-FD-%d" location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name enforce_backend_pools_certificate_name_check = false @@ -508,7 +623,6 @@ resource "azurerm_frontdoor" "test" { forwarding_configuration { forwarding_protocol = "MatchRequest" backend_pool_name = local.backend_name - cache_enabled = false } } @@ -535,7 +649,7 @@ resource "azurerm_frontdoor" "test" { frontend_endpoint { name = local.endpoint_name - host_name = "acctestfd-%d.azurefd.net" + host_name = "acctest-FD-%d.azurefd.net" custom_https_provisioning_enabled = false } } @@ -544,8 +658,12 @@ resource "azurerm_frontdoor" "test" { func testAccAzureRMFrontDoor_EnableCache(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestRG-frontdoor-%d" location = "%s" } @@ -557,7 +675,7 @@ locals { } resource "azurerm_frontdoor" "test" { - name = "acctestfd-%d" + name = "acctest-FD-%d" location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name enforce_backend_pools_certificate_name_check = false @@ -571,6 +689,7 @@ resource "azurerm_frontdoor" "test" { forwarding_configuration { forwarding_protocol = "MatchRequest" backend_pool_name = local.backend_name + cache_enabled = true } } @@ -597,7 +716,7 @@ resource "azurerm_frontdoor" "test" { frontend_endpoint { name = local.endpoint_name - host_name = "acctestfd-%d.azurefd.net" + host_name = "acctest-FD-%d.azurefd.net" custom_https_provisioning_enabled = false } } @@ -606,8 +725,12 @@ resource "azurerm_frontdoor" "test" { func testAccAzureRMFrontDoor_CustomHttpsEnabled(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestRG-frontdoor-%d" location = "%s" } @@ -619,7 +742,7 @@ locals { } resource "azurerm_frontdoor" "test" { - name = "acctestfd-%d" + name = "acctest-FD-%d" location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name enforce_backend_pools_certificate_name_check = false @@ -659,7 +782,7 @@ resource "azurerm_frontdoor" "test" { frontend_endpoint { name = local.endpoint_name - host_name = "acctestfd-%d.azurefd.net" + host_name = "acctest-FD-%d.azurefd.net" custom_https_provisioning_enabled = true custom_https_configuration { certificate_source = "FrontDoor" @@ -671,8 +794,12 @@ resource "azurerm_frontdoor" "test" { func testAccAzureRMFrontDoor_CustomHttpsDisabled(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctestRG-frontdoor-%d" location = "%s" } @@ -684,7 +811,7 @@ locals { } resource "azurerm_frontdoor" "test" { - name = "acctestfd-%d" + name = "acctest-FD-%d" location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name enforce_backend_pools_certificate_name_check = false @@ -724,9 +851,121 @@ resource "azurerm_frontdoor" "test" { frontend_endpoint { name = local.endpoint_name - host_name = "acctestfd-%d.azurefd.net" + host_name = "acctest-FD-%d.azurefd.net" custom_https_provisioning_enabled = false } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } + +func testAccAzureRMFrontDoor_multiplePools(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-frontdoor-%[1]d" + location = "%s" +} + +resource "azurerm_frontdoor" "test" { + name = "acctest-FD-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + enforce_backend_pools_certificate_name_check = false + + frontend_endpoint { + name = "acctest-FD-%[1]d-default-FE" + host_name = "acctest-FD-%[1]d.azurefd.net" + custom_https_provisioning_enabled = false + } + + # --- Pool 1 + + routing_rule { + name = "acctest-FD-%[1]d-bing-RR" + accepted_protocols = ["Https"] + patterns_to_match = ["/poolBing/*"] + frontend_endpoints = ["acctest-FD-%[1]d-default-FE"] + + forwarding_configuration { + forwarding_protocol = "MatchRequest" + backend_pool_name = "acctest-FD-%[1]d-pool-bing" + cache_enabled = true + } + } + + backend_pool_load_balancing { + name = "acctest-FD-%[1]d-bing-LB" + additional_latency_milliseconds = 0 + sample_size = 4 + successful_samples_required = 2 + } + + backend_pool_health_probe { + name = "acctest-FD-%[1]d-bing-HP" + protocol = "Https" + enabled = true + probe_method = "HEAD" + } + + backend_pool { + name = "acctest-FD-%[1]d-pool-bing" + load_balancing_name = "acctest-FD-%[1]d-bing-LB" + health_probe_name = "acctest-FD-%[1]d-bing-HP" + + backend { + host_header = "bing.com" + address = "bing.com" + http_port = 80 + https_port = 443 + weight = 75 + enabled = true + } + } + + # --- Pool 2 + + routing_rule { + name = "acctest-FD-%[1]d-google-RR" + accepted_protocols = ["Https"] + patterns_to_match = ["/poolGoogle/*"] + frontend_endpoints = ["acctest-FD-%[1]d-default-FE"] + + forwarding_configuration { + forwarding_protocol = "MatchRequest" + backend_pool_name = "acctest-FD-%[1]d-pool-google" + cache_enabled = true + } + } + + backend_pool_load_balancing { + name = "acctest-FD-%[1]d-google-LB" + additional_latency_milliseconds = 0 + sample_size = 4 + successful_samples_required = 2 + } + + backend_pool_health_probe { + name = "acctest-FD-%[1]d-google-HP" + protocol = "Https" + } + + backend_pool { + name = "acctest-FD-%[1]d-pool-google" + load_balancing_name = "acctest-FD-%[1]d-google-LB" + health_probe_name = "acctest-FD-%[1]d-google-HP" + + backend { + host_header = "google.com" + address = "google.com" + http_port = 80 + https_port = 443 + weight = 75 + enabled = true + } + } +} +`, data.RandomInteger, data.Locations.Primary) +} diff --git a/azurerm/internal/services/frontdoor/validate.go b/azurerm/internal/services/frontdoor/validate.go index 0a78075a9d85e..872bd54f09ae9 100644 --- a/azurerm/internal/services/frontdoor/validate.go +++ b/azurerm/internal/services/frontdoor/validate.go @@ -15,6 +15,14 @@ func ValidateFrontDoorName(i interface{}, k string) (_ []string, errors []error) return nil, errors } +func ValidateFrontDoorWAFName(i interface{}, k string) (_ []string, errors []error) { + if m, regexErrs := validate.RegExHelper(i, k, `(^[a-zA-Z])([\da-zA-Z]{0,127})$`); !m { + errors = append(regexErrs, fmt.Errorf(`%q must be between 1 and 128 characters in length, must begin with a letter and may only contain letters and numbers.`, k)) + } + + return nil, errors +} + func ValidateBackendPoolRoutingRuleName(i interface{}, k string) (_ []string, errors []error) { if m, regexErrs := validate.RegExHelper(i, k, `(^[\da-zA-Z])([-\da-zA-Z]{1,88})([\da-zA-Z]$)`); !m { errors = append(regexErrs, fmt.Errorf(`%q must be between 1 and 90 characters in length and begin with a letter or number, end with a letter or number and may contain only letters, numbers or hyphens.`, k)) diff --git a/azurerm/internal/services/hdinsight/registration.go b/azurerm/internal/services/hdinsight/registration.go index 7dade4b97802f..91804ab3788c6 100644 --- a/azurerm/internal/services/hdinsight/registration.go +++ b/azurerm/internal/services/hdinsight/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "HDInsight" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "HDInsight", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/hdinsight/tests/data_source_hdinsight_cluster_test.go b/azurerm/internal/services/hdinsight/tests/data_source_hdinsight_cluster_test.go index 48070e77d440e..76d2bb6cef8b8 100644 --- a/azurerm/internal/services/hdinsight/tests/data_source_hdinsight_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/data_source_hdinsight_cluster_test.go @@ -175,8 +175,8 @@ func testAccDataSourceHDInsightCluster_hadoop(data acceptance.TestData) string { %s data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_hadoop_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_hadoop_cluster.test.resource_group_name}" + name = azurerm_hdinsight_hadoop_cluster.test.name + resource_group_name = azurerm_hdinsight_hadoop_cluster.test.resource_group_name } `, template) } @@ -187,8 +187,8 @@ func testAccDataSourceHDInsightCluster_hbase(data acceptance.TestData) string { %s data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_hbase_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_hbase_cluster.test.resource_group_name}" + name = azurerm_hdinsight_hbase_cluster.test.name + resource_group_name = azurerm_hdinsight_hbase_cluster.test.resource_group_name } `, template) } @@ -199,8 +199,8 @@ func testAccDataSourceHDInsightCluster_interactiveQuery(data acceptance.TestData %s data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_interactive_query_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_interactive_query_cluster.test.resource_group_name}" + name = azurerm_hdinsight_interactive_query_cluster.test.name + resource_group_name = azurerm_hdinsight_interactive_query_cluster.test.resource_group_name } `, template) } @@ -211,8 +211,8 @@ func testAccDataSourceHDInsightCluster_kafka(data acceptance.TestData) string { %s data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_kafka_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_kafka_cluster.test.resource_group_name}" + name = azurerm_hdinsight_kafka_cluster.test.name + resource_group_name = azurerm_hdinsight_kafka_cluster.test.resource_group_name } `, template) } @@ -223,8 +223,8 @@ func testAccDataSourceHDInsightCluster_mlServices(data acceptance.TestData) stri %s data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_ml_services_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_ml_services_cluster.test.resource_group_name}" + name = azurerm_hdinsight_ml_services_cluster.test.name + resource_group_name = azurerm_hdinsight_ml_services_cluster.test.resource_group_name } `, template) } @@ -235,8 +235,8 @@ func testAccDataSourceHDInsightCluster_rserver(data acceptance.TestData) string %s data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_rserver_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_rserver_cluster.test.resource_group_name}" + name = azurerm_hdinsight_rserver_cluster.test.name + resource_group_name = azurerm_hdinsight_rserver_cluster.test.resource_group_name } `, template) } @@ -247,8 +247,8 @@ func testAccDataSourceHDInsightCluster_spark(data acceptance.TestData) string { %s data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_spark_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_spark_cluster.test.resource_group_name}" + name = azurerm_hdinsight_spark_cluster.test.name + resource_group_name = azurerm_hdinsight_spark_cluster.test.resource_group_name } `, template) } @@ -259,8 +259,8 @@ func testAccDataSourceHDInsightCluster_storm(data acceptance.TestData) string { %s data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_storm_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_storm_cluster.test.resource_group_name}" + name = azurerm_hdinsight_storm_cluster.test.name + resource_group_name = azurerm_hdinsight_storm_cluster.test.resource_group_name } `, template) } diff --git a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hadoop_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hadoop_cluster_test.go index 066e8b0b61a03..6ed62031cf9cc 100644 --- a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hadoop_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hadoop_cluster_test.go @@ -326,8 +326,8 @@ func testAccAzureRMHDInsightHadoopCluster_basic(data acceptance.TestData) string resource "azurerm_hdinsight_hadoop_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -342,8 +342,8 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -377,15 +377,91 @@ func testAccAzureRMHDInsightHadoopCluster_requiresImport(data acceptance.TestDat %s resource "azurerm_hdinsight_hadoop_cluster" "import" { - name = "${azurerm_hdinsight_hadoop_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_hadoop_cluster.test.resource_group_name}" - location = "${azurerm_hdinsight_hadoop_cluster.test.location}" - cluster_version = "${azurerm_hdinsight_hadoop_cluster.test.cluster_version}" - tier = "${azurerm_hdinsight_hadoop_cluster.test.tier}" - component_version = "${azurerm_hdinsight_hadoop_cluster.test.component_version}" - gateway = "${azurerm_hdinsight_hadoop_cluster.test.gateway}" - storage_account = "${azurerm_hdinsight_hadoop_cluster.test.storage_account}" - roles = "${azurerm_hdinsight_hadoop_cluster.test.roles}" + name = azurerm_hdinsight_hadoop_cluster.test.name + resource_group_name = azurerm_hdinsight_hadoop_cluster.test.resource_group_name + location = azurerm_hdinsight_hadoop_cluster.test.location + cluster_version = azurerm_hdinsight_hadoop_cluster.test.cluster_version + tier = azurerm_hdinsight_hadoop_cluster.test.tier + dynamic "component_version" { + for_each = azurerm_hdinsight_hadoop_cluster.test.component_version + content { + hadoop = component_version.value.hadoop + } + } + dynamic "gateway" { + for_each = azurerm_hdinsight_hadoop_cluster.test.gateway + content { + enabled = gateway.value.enabled + password = gateway.value.password + username = gateway.value.username + } + } + dynamic "storage_account" { + for_each = azurerm_hdinsight_hadoop_cluster.test.storage_account + content { + is_default = storage_account.value.is_default + storage_account_key = storage_account.value.storage_account_key + storage_container_id = storage_account.value.storage_container_id + } + } + dynamic "roles" { + for_each = azurerm_hdinsight_hadoop_cluster.test.roles + content { + dynamic "edge_node" { + for_each = lookup(roles.value, "edge_node", []) + content { + target_instance_count = edge_node.value.target_instance_count + vm_size = edge_node.value.vm_size + + dynamic "install_script_action" { + for_each = lookup(edge_node.value, "install_script_action", []) + content { + name = install_script_action.value.name + uri = install_script_action.value.uri + } + } + } + } + + dynamic "head_node" { + for_each = lookup(roles.value, "head_node", []) + content { + password = lookup(head_node.value, "password", null) + ssh_keys = lookup(head_node.value, "ssh_keys", null) + subnet_id = lookup(head_node.value, "subnet_id", null) + username = head_node.value.username + virtual_network_id = lookup(head_node.value, "virtual_network_id", null) + vm_size = head_node.value.vm_size + } + } + + dynamic "worker_node" { + for_each = lookup(roles.value, "worker_node", []) + content { + min_instance_count = lookup(worker_node.value, "min_instance_count", null) + password = lookup(worker_node.value, "password", null) + ssh_keys = lookup(worker_node.value, "ssh_keys", null) + subnet_id = lookup(worker_node.value, "subnet_id", null) + target_instance_count = worker_node.value.target_instance_count + username = worker_node.value.username + virtual_network_id = lookup(worker_node.value, "virtual_network_id", null) + vm_size = worker_node.value.vm_size + } + } + + dynamic "zookeeper_node" { + for_each = lookup(roles.value, "zookeeper_node", []) + content { + password = lookup(zookeeper_node.value, "password", null) + ssh_keys = lookup(zookeeper_node.value, "ssh_keys", null) + subnet_id = lookup(zookeeper_node.value, "subnet_id", null) + username = zookeeper_node.value.username + virtual_network_id = lookup(zookeeper_node.value, "virtual_network_id", null) + vm_size = zookeeper_node.value.vm_size + } + } + } + } } `, template) } @@ -401,8 +477,8 @@ variable "ssh_key" { resource "azurerm_hdinsight_hadoop_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -417,8 +493,8 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -426,20 +502,20 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { head_node { vm_size = "Standard_D3_v2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } worker_node { vm_size = "Standard_D4_v2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] target_instance_count = 3 } zookeeper_node { vm_size = "Standard_D3_v2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } } } @@ -453,8 +529,8 @@ func testAccAzureRMHDInsightHadoopCluster_updated(data acceptance.TestData) stri resource "azurerm_hdinsight_hadoop_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -469,8 +545,8 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -510,21 +586,21 @@ func testAccAzureRMHDInsightHadoopCluster_virtualNetwork(data acceptance.TestDat resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_hadoop_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -539,8 +615,8 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -549,8 +625,8 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { vm_size = "Standard_D3_v2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -558,16 +634,16 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_D3_v2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } } @@ -582,21 +658,21 @@ func testAccAzureRMHDInsightHadoopCluster_complete(data acceptance.TestData) str resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_hadoop_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -611,8 +687,8 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -621,8 +697,8 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { vm_size = "Standard_D3_v2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -630,16 +706,16 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_D3_v2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } @@ -657,8 +733,8 @@ func testAccAzureRMHDInsightHadoopCluster_edgeNodeBasic(data acceptance.TestData resource "azurerm_hdinsight_hadoop_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -673,8 +749,8 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -829,6 +905,10 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { func testAccAzureRMHDInsightHadoopCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -836,23 +916,26 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "acctest" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } - `, data.RandomInteger, data.Locations.Primary, data.RandomString) } func testAccAzureRMHDInsightHadoopCluster_gen2template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hbase_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hbase_cluster_test.go index d7e4fb404ff09..9161a77a692ef 100644 --- a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hbase_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hbase_cluster_test.go @@ -212,8 +212,8 @@ func testAccAzureRMHDInsightHBaseCluster_basic(data acceptance.TestData) string resource "azurerm_hdinsight_hbase_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -228,8 +228,8 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -316,15 +316,75 @@ func testAccAzureRMHDInsightHBaseCluster_requiresImport(data acceptance.TestData %s resource "azurerm_hdinsight_hbase_cluster" "import" { - name = "${azurerm_hdinsight_hbase_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_hbase_cluster.test.resource_group_name}" - location = "${azurerm_hdinsight_hbase_cluster.test.location}" - cluster_version = "${azurerm_hdinsight_hbase_cluster.test.cluster_version}" - tier = "${azurerm_hdinsight_hbase_cluster.test.tier}" - component_version = "${azurerm_hdinsight_hbase_cluster.test.component_version}" - gateway = "${azurerm_hdinsight_hbase_cluster.test.gateway}" - storage_account = "${azurerm_hdinsight_hbase_cluster.test.storage_account}" - roles = "${azurerm_hdinsight_hbase_cluster.test.roles}" + name = azurerm_hdinsight_hbase_cluster.test.name + resource_group_name = azurerm_hdinsight_hbase_cluster.test.resource_group_name + location = azurerm_hdinsight_hbase_cluster.test.location + cluster_version = azurerm_hdinsight_hbase_cluster.test.cluster_version + tier = azurerm_hdinsight_hbase_cluster.test.tier + dynamic "component_version" { + for_each = azurerm_hdinsight_hbase_cluster.test.component_version + content { + hbase = component_version.value.hbase + } + } + dynamic "gateway" { + for_each = azurerm_hdinsight_hbase_cluster.test.gateway + content { + enabled = gateway.value.enabled + password = gateway.value.password + username = gateway.value.username + } + } + dynamic "storage_account" { + for_each = azurerm_hdinsight_hbase_cluster.test.storage_account + content { + is_default = storage_account.value.is_default + storage_account_key = storage_account.value.storage_account_key + storage_container_id = storage_account.value.storage_container_id + } + } + dynamic "roles" { + for_each = azurerm_hdinsight_hbase_cluster.test.roles + content { + dynamic "head_node" { + for_each = lookup(roles.value, "head_node", []) + content { + password = lookup(head_node.value, "password", null) + ssh_keys = lookup(head_node.value, "ssh_keys", null) + subnet_id = lookup(head_node.value, "subnet_id", null) + username = head_node.value.username + virtual_network_id = lookup(head_node.value, "virtual_network_id", null) + vm_size = head_node.value.vm_size + } + } + + dynamic "worker_node" { + for_each = lookup(roles.value, "worker_node", []) + content { + min_instance_count = lookup(worker_node.value, "min_instance_count", null) + password = lookup(worker_node.value, "password", null) + ssh_keys = lookup(worker_node.value, "ssh_keys", null) + subnet_id = lookup(worker_node.value, "subnet_id", null) + target_instance_count = worker_node.value.target_instance_count + username = worker_node.value.username + virtual_network_id = lookup(worker_node.value, "virtual_network_id", null) + vm_size = worker_node.value.vm_size + } + } + + dynamic "zookeeper_node" { + for_each = lookup(roles.value, "zookeeper_node", []) + content { + password = lookup(zookeeper_node.value, "password", null) + ssh_keys = lookup(zookeeper_node.value, "ssh_keys", null) + subnet_id = lookup(zookeeper_node.value, "subnet_id", null) + username = zookeeper_node.value.username + virtual_network_id = lookup(zookeeper_node.value, "virtual_network_id", null) + vm_size = zookeeper_node.value.vm_size + } + } + } + } } `, template) } @@ -340,8 +400,8 @@ variable "ssh_key" { resource "azurerm_hdinsight_hbase_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -356,8 +416,8 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -365,20 +425,20 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { head_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } worker_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] target_instance_count = 3 } zookeeper_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } } } @@ -392,8 +452,8 @@ func testAccAzureRMHDInsightHBaseCluster_updated(data acceptance.TestData) strin resource "azurerm_hdinsight_hbase_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -408,8 +468,8 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -449,21 +509,21 @@ func testAccAzureRMHDInsightHBaseCluster_virtualNetwork(data acceptance.TestData resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_hbase_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -478,8 +538,8 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -488,8 +548,8 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -497,16 +557,16 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } } @@ -521,21 +581,21 @@ func testAccAzureRMHDInsightHBaseCluster_complete(data acceptance.TestData) stri resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_hbase_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -550,8 +610,8 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -560,8 +620,8 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -569,16 +629,16 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } @@ -591,6 +651,10 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { func testAccAzureRMHDInsightHBaseCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -598,16 +662,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "acctest" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } `, data.RandomInteger, data.Locations.Primary, data.RandomString) @@ -615,6 +678,10 @@ resource "azurerm_storage_container" "test" { func testAccAzureRMHDInsightHBaseCluster_gen2template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_interactive_query_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_interactive_query_cluster_test.go index 80adb0a0e264a..2335ceb6f2e71 100644 --- a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_interactive_query_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_interactive_query_cluster_test.go @@ -212,8 +212,8 @@ func testAccAzureRMHDInsightInteractiveQueryCluster_basic(data acceptance.TestDa resource "azurerm_hdinsight_interactive_query_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -228,8 +228,8 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -318,15 +318,75 @@ func testAccAzureRMHDInsightInteractiveQueryCluster_requiresImport(data acceptan %s resource "azurerm_hdinsight_interactive_query_cluster" "import" { - name = "${azurerm_hdinsight_interactive_query_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_interactive_query_cluster.test.resource_group_name}" - location = "${azurerm_hdinsight_interactive_query_cluster.test.location}" - cluster_version = "${azurerm_hdinsight_interactive_query_cluster.test.cluster_version}" - tier = "${azurerm_hdinsight_interactive_query_cluster.test.tier}" - component_version = "${azurerm_hdinsight_interactive_query_cluster.test.component_version}" - gateway = "${azurerm_hdinsight_interactive_query_cluster.test.gateway}" - storage_account = "${azurerm_hdinsight_interactive_query_cluster.test.storage_account}" - roles = "${azurerm_hdinsight_interactive_query_cluster.test.roles}" + name = azurerm_hdinsight_interactive_query_cluster.test.name + resource_group_name = azurerm_hdinsight_interactive_query_cluster.test.resource_group_name + location = azurerm_hdinsight_interactive_query_cluster.test.location + cluster_version = azurerm_hdinsight_interactive_query_cluster.test.cluster_version + tier = azurerm_hdinsight_interactive_query_cluster.test.tier + dynamic "component_version" { + for_each = azurerm_hdinsight_interactive_query_cluster.test.component_version + content { + interactive_hive = component_version.value.interactive_hive + } + } + dynamic "gateway" { + for_each = azurerm_hdinsight_interactive_query_cluster.test.gateway + content { + enabled = gateway.value.enabled + password = gateway.value.password + username = gateway.value.username + } + } + dynamic "storage_account" { + for_each = azurerm_hdinsight_interactive_query_cluster.test.storage_account + content { + is_default = storage_account.value.is_default + storage_account_key = storage_account.value.storage_account_key + storage_container_id = storage_account.value.storage_container_id + } + } + dynamic "roles" { + for_each = azurerm_hdinsight_interactive_query_cluster.test.roles + content { + dynamic "head_node" { + for_each = lookup(roles.value, "head_node", []) + content { + password = lookup(head_node.value, "password", null) + ssh_keys = lookup(head_node.value, "ssh_keys", null) + subnet_id = lookup(head_node.value, "subnet_id", null) + username = head_node.value.username + virtual_network_id = lookup(head_node.value, "virtual_network_id", null) + vm_size = head_node.value.vm_size + } + } + + dynamic "worker_node" { + for_each = lookup(roles.value, "worker_node", []) + content { + min_instance_count = lookup(worker_node.value, "min_instance_count", null) + password = lookup(worker_node.value, "password", null) + ssh_keys = lookup(worker_node.value, "ssh_keys", null) + subnet_id = lookup(worker_node.value, "subnet_id", null) + target_instance_count = worker_node.value.target_instance_count + username = worker_node.value.username + virtual_network_id = lookup(worker_node.value, "virtual_network_id", null) + vm_size = worker_node.value.vm_size + } + } + + dynamic "zookeeper_node" { + for_each = lookup(roles.value, "zookeeper_node", []) + content { + password = lookup(zookeeper_node.value, "password", null) + ssh_keys = lookup(zookeeper_node.value, "ssh_keys", null) + subnet_id = lookup(zookeeper_node.value, "subnet_id", null) + username = zookeeper_node.value.username + virtual_network_id = lookup(zookeeper_node.value, "virtual_network_id", null) + vm_size = zookeeper_node.value.vm_size + } + } + } + } } `, template) } @@ -342,8 +402,8 @@ variable "ssh_key" { resource "azurerm_hdinsight_interactive_query_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -358,8 +418,8 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -367,20 +427,20 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { head_node { vm_size = "Standard_D13_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } worker_node { vm_size = "Standard_D14_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] target_instance_count = 3 } zookeeper_node { vm_size = "Standard_A4_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } } } @@ -394,8 +454,8 @@ func testAccAzureRMHDInsightInteractiveQueryCluster_updated(data acceptance.Test resource "azurerm_hdinsight_interactive_query_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -410,8 +470,8 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -451,21 +511,21 @@ func testAccAzureRMHDInsightInteractiveQueryCluster_virtualNetwork(data acceptan resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_interactive_query_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -480,8 +540,8 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -490,8 +550,8 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { vm_size = "Standard_D13_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -499,16 +559,16 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_A4_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } } @@ -523,21 +583,21 @@ func testAccAzureRMHDInsightInteractiveQueryCluster_complete(data acceptance.Tes resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_interactive_query_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -552,8 +612,8 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -562,8 +622,8 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { vm_size = "Standard_D13_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -571,16 +631,16 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_A4_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } @@ -593,6 +653,10 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { func testAccAzureRMHDInsightInteractiveQueryCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -600,16 +664,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "acctest" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } `, data.RandomInteger, data.Locations.Primary, data.RandomString) @@ -617,6 +680,10 @@ resource "azurerm_storage_container" "test" { func testAccAzureRMHDInsightInteractiveQueryCluster_gen2template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_kafka_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_kafka_cluster_test.go index be933e1545c95..7ee5536c1aef4 100644 --- a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_kafka_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_kafka_cluster_test.go @@ -215,8 +215,8 @@ func testAccAzureRMHDInsightKafkaCluster_basic(data acceptance.TestData) string resource "azurerm_hdinsight_kafka_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -231,8 +231,8 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -323,15 +323,76 @@ func testAccAzureRMHDInsightKafkaCluster_requiresImport(data acceptance.TestData %s resource "azurerm_hdinsight_kafka_cluster" "import" { - name = "${azurerm_hdinsight_kafka_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_kafka_cluster.test.resource_group_name}" - location = "${azurerm_hdinsight_kafka_cluster.test.location}" - cluster_version = "${azurerm_hdinsight_kafka_cluster.test.cluster_version}" - tier = "${azurerm_hdinsight_kafka_cluster.test.tier}" - component_version = "${azurerm_hdinsight_kafka_cluster.test.component_version}" - gateway = "${azurerm_hdinsight_kafka_cluster.test.gateway}" - storage_account = "${azurerm_hdinsight_kafka_cluster.test.storage_account}" - roles = "${azurerm_hdinsight_kafka_cluster.test.roles}" + name = azurerm_hdinsight_kafka_cluster.test.name + resource_group_name = azurerm_hdinsight_kafka_cluster.test.resource_group_name + location = azurerm_hdinsight_kafka_cluster.test.location + cluster_version = azurerm_hdinsight_kafka_cluster.test.cluster_version + tier = azurerm_hdinsight_kafka_cluster.test.tier + dynamic "component_version" { + for_each = azurerm_hdinsight_kafka_cluster.test.component_version + content { + kafka = component_version.value.kafka + } + } + dynamic "gateway" { + for_each = azurerm_hdinsight_kafka_cluster.test.gateway + content { + enabled = gateway.value.enabled + password = gateway.value.password + username = gateway.value.username + } + } + dynamic "storage_account" { + for_each = azurerm_hdinsight_kafka_cluster.test.storage_account + content { + is_default = storage_account.value.is_default + storage_account_key = storage_account.value.storage_account_key + storage_container_id = storage_account.value.storage_container_id + } + } + dynamic "roles" { + for_each = azurerm_hdinsight_kafka_cluster.test.roles + content { + dynamic "head_node" { + for_each = lookup(roles.value, "head_node", []) + content { + password = lookup(head_node.value, "password", null) + ssh_keys = lookup(head_node.value, "ssh_keys", null) + subnet_id = lookup(head_node.value, "subnet_id", null) + username = head_node.value.username + virtual_network_id = lookup(head_node.value, "virtual_network_id", null) + vm_size = head_node.value.vm_size + } + } + + dynamic "worker_node" { + for_each = lookup(roles.value, "worker_node", []) + content { + min_instance_count = lookup(worker_node.value, "min_instance_count", null) + number_of_disks_per_node = worker_node.value.number_of_disks_per_node + password = lookup(worker_node.value, "password", null) + ssh_keys = lookup(worker_node.value, "ssh_keys", null) + subnet_id = lookup(worker_node.value, "subnet_id", null) + target_instance_count = worker_node.value.target_instance_count + username = worker_node.value.username + virtual_network_id = lookup(worker_node.value, "virtual_network_id", null) + vm_size = worker_node.value.vm_size + } + } + + dynamic "zookeeper_node" { + for_each = lookup(roles.value, "zookeeper_node", []) + content { + password = lookup(zookeeper_node.value, "password", null) + ssh_keys = lookup(zookeeper_node.value, "ssh_keys", null) + subnet_id = lookup(zookeeper_node.value, "subnet_id", null) + username = zookeeper_node.value.username + virtual_network_id = lookup(zookeeper_node.value, "virtual_network_id", null) + vm_size = zookeeper_node.value.vm_size + } + } + } + } } `, template) } @@ -347,8 +408,8 @@ variable "ssh_key" { resource "azurerm_hdinsight_kafka_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -363,8 +424,8 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -372,13 +433,13 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { head_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } worker_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] target_instance_count = 3 number_of_disks_per_node = 2 } @@ -386,7 +447,7 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { zookeeper_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } } } @@ -400,8 +461,8 @@ func testAccAzureRMHDInsightKafkaCluster_updated(data acceptance.TestData) strin resource "azurerm_hdinsight_kafka_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -416,8 +477,8 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -458,21 +519,21 @@ func testAccAzureRMHDInsightKafkaCluster_virtualNetwork(data acceptance.TestData resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_kafka_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -487,8 +548,8 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -497,8 +558,8 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -507,16 +568,16 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { password = "AccTestvdSC4daf986!" target_instance_count = 3 number_of_disks_per_node = 2 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } } @@ -531,21 +592,21 @@ func testAccAzureRMHDInsightKafkaCluster_complete(data acceptance.TestData) stri resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_kafka_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -560,8 +621,8 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -570,8 +631,8 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -580,16 +641,16 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { password = "AccTestvdSC4daf986!" target_instance_count = 3 number_of_disks_per_node = 2 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } @@ -602,6 +663,10 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { func testAccAzureRMHDInsightKafkaCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -609,16 +674,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "acctest" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } `, data.RandomInteger, data.Locations.Primary, data.RandomString) @@ -626,6 +690,10 @@ resource "azurerm_storage_container" "test" { func testAccAzureRMHDInsightKafkaCluster_gen2template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_ml_services_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_ml_services_cluster_test.go index 983ff39f5a4aa..6cadca6d29bde 100644 --- a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_ml_services_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_ml_services_cluster_test.go @@ -205,8 +205,8 @@ func testAccAzureRMHDInsightMLServicesCluster_basic(data acceptance.TestData) st resource "azurerm_hdinsight_ml_services_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" rstudio = true @@ -218,8 +218,8 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -259,14 +259,81 @@ func testAccAzureRMHDInsightMLServicesCluster_requiresImport(data acceptance.Tes %s resource "azurerm_hdinsight_ml_services_cluster" "import" { - name = "${azurerm_hdinsight_ml_services_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_ml_services_cluster.test.resource_group_name}" - location = "${azurerm_hdinsight_ml_services_cluster.test.location}" - cluster_version = "${azurerm_hdinsight_ml_services_cluster.test.cluster_version}" - tier = "${azurerm_hdinsight_ml_services_cluster.test.tier}" - gateway = "${azurerm_hdinsight_ml_services_cluster.test.gateway}" - storage_account = "${azurerm_hdinsight_ml_services_cluster.test.storage_account}" - roles = "${azurerm_hdinsight_ml_services_cluster.test.roles}" + name = azurerm_hdinsight_ml_services_cluster.test.name + resource_group_name = azurerm_hdinsight_ml_services_cluster.test.resource_group_name + location = azurerm_hdinsight_ml_services_cluster.test.location + cluster_version = azurerm_hdinsight_ml_services_cluster.test.cluster_version + tier = azurerm_hdinsight_ml_services_cluster.test.tier + dynamic "gateway" { + for_each = azurerm_hdinsight_ml_services_cluster.test.gateway + content { + enabled = gateway.value.enabled + password = gateway.value.password + username = gateway.value.username + } + } + dynamic "storage_account" { + for_each = azurerm_hdinsight_ml_services_cluster.test.storage_account + content { + is_default = storage_account.value.is_default + storage_account_key = storage_account.value.storage_account_key + storage_container_id = storage_account.value.storage_container_id + } + } + dynamic "roles" { + for_each = azurerm_hdinsight_ml_services_cluster.test.roles + content { + dynamic "edge_node" { + for_each = lookup(roles.value, "edge_node", []) + content { + password = lookup(edge_node.value, "password", null) + ssh_keys = lookup(edge_node.value, "ssh_keys", null) + subnet_id = lookup(edge_node.value, "subnet_id", null) + username = edge_node.value.username + virtual_network_id = lookup(edge_node.value, "virtual_network_id", null) + vm_size = edge_node.value.vm_size + } + } + + dynamic "head_node" { + for_each = lookup(roles.value, "head_node", []) + content { + password = lookup(head_node.value, "password", null) + ssh_keys = lookup(head_node.value, "ssh_keys", null) + subnet_id = lookup(head_node.value, "subnet_id", null) + username = head_node.value.username + virtual_network_id = lookup(head_node.value, "virtual_network_id", null) + vm_size = head_node.value.vm_size + } + } + + dynamic "worker_node" { + for_each = lookup(roles.value, "worker_node", []) + content { + min_instance_count = lookup(worker_node.value, "min_instance_count", null) + password = lookup(worker_node.value, "password", null) + ssh_keys = lookup(worker_node.value, "ssh_keys", null) + subnet_id = lookup(worker_node.value, "subnet_id", null) + target_instance_count = worker_node.value.target_instance_count + username = worker_node.value.username + virtual_network_id = lookup(worker_node.value, "virtual_network_id", null) + vm_size = worker_node.value.vm_size + } + } + + dynamic "zookeeper_node" { + for_each = lookup(roles.value, "zookeeper_node", []) + content { + password = lookup(zookeeper_node.value, "password", null) + ssh_keys = lookup(zookeeper_node.value, "ssh_keys", null) + subnet_id = lookup(zookeeper_node.value, "subnet_id", null) + username = zookeeper_node.value.username + virtual_network_id = lookup(zookeeper_node.value, "virtual_network_id", null) + vm_size = zookeeper_node.value.vm_size + } + } + } + } } `, template) } @@ -282,8 +349,8 @@ variable "ssh_key" { resource "azurerm_hdinsight_ml_services_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" rstudio = true @@ -295,8 +362,8 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -304,26 +371,26 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { head_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } worker_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] target_instance_count = 3 } zookeeper_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } edge_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } } } @@ -337,8 +404,8 @@ func testAccAzureRMHDInsightMLServicesCluster_updated(data acceptance.TestData) resource "azurerm_hdinsight_ml_services_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" rstudio = true @@ -350,8 +417,8 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -397,21 +464,21 @@ func testAccAzureRMHDInsightMLServicesCluster_virtualNetwork(data acceptance.Tes resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_ml_services_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" rstudio = true @@ -423,8 +490,8 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -433,8 +500,8 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -442,24 +509,24 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } edge_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } } @@ -474,21 +541,21 @@ func testAccAzureRMHDInsightMLServicesCluster_complete(data acceptance.TestData) resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_ml_services_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" rstudio = true @@ -500,8 +567,8 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -510,8 +577,8 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -519,24 +586,24 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } edge_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } @@ -549,6 +616,10 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { func testAccAzureRMHDInsightMLServicesCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -556,16 +627,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "acctest" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } `, data.RandomInteger, data.Locations.Primary, data.RandomString) diff --git a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_rserver_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_rserver_cluster_test.go index 5d4818cb076ed..a1f18f58a2b32 100644 --- a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_rserver_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_rserver_cluster_test.go @@ -205,8 +205,8 @@ func testAccAzureRMHDInsightRServerCluster_basic(data acceptance.TestData) strin resource "azurerm_hdinsight_rserver_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" rstudio = true @@ -218,8 +218,8 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -259,14 +259,81 @@ func testAccAzureRMHDInsightRServerCluster_requiresImport(data acceptance.TestDa %s resource "azurerm_hdinsight_rserver_cluster" "import" { - name = "${azurerm_hdinsight_rserver_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_rserver_cluster.test.resource_group_name}" - location = "${azurerm_hdinsight_rserver_cluster.test.location}" - cluster_version = "${azurerm_hdinsight_rserver_cluster.test.cluster_version}" - tier = "${azurerm_hdinsight_rserver_cluster.test.tier}" - gateway = "${azurerm_hdinsight_rserver_cluster.test.gateway}" - storage_account = "${azurerm_hdinsight_rserver_cluster.test.storage_account}" - roles = "${azurerm_hdinsight_rserver_cluster.test.roles}" + name = azurerm_hdinsight_rserver_cluster.test.name + resource_group_name = azurerm_hdinsight_rserver_cluster.test.resource_group_name + location = azurerm_hdinsight_rserver_cluster.test.location + cluster_version = azurerm_hdinsight_rserver_cluster.test.cluster_version + tier = azurerm_hdinsight_rserver_cluster.test.tier + dynamic "gateway" { + for_each = azurerm_hdinsight_rserver_cluster.test.gateway + content { + enabled = gateway.value.enabled + password = gateway.value.password + username = gateway.value.username + } + } + dynamic "storage_account" { + for_each = azurerm_hdinsight_rserver_cluster.test.storage_account + content { + is_default = storage_account.value.is_default + storage_account_key = storage_account.value.storage_account_key + storage_container_id = storage_account.value.storage_container_id + } + } + dynamic "roles" { + for_each = azurerm_hdinsight_rserver_cluster.test.roles + content { + dynamic "edge_node" { + for_each = lookup(roles.value, "edge_node", []) + content { + password = lookup(edge_node.value, "password", null) + ssh_keys = lookup(edge_node.value, "ssh_keys", null) + subnet_id = lookup(edge_node.value, "subnet_id", null) + username = edge_node.value.username + virtual_network_id = lookup(edge_node.value, "virtual_network_id", null) + vm_size = edge_node.value.vm_size + } + } + + dynamic "head_node" { + for_each = lookup(roles.value, "head_node", []) + content { + password = lookup(head_node.value, "password", null) + ssh_keys = lookup(head_node.value, "ssh_keys", null) + subnet_id = lookup(head_node.value, "subnet_id", null) + username = head_node.value.username + virtual_network_id = lookup(head_node.value, "virtual_network_id", null) + vm_size = head_node.value.vm_size + } + } + + dynamic "worker_node" { + for_each = lookup(roles.value, "worker_node", []) + content { + min_instance_count = lookup(worker_node.value, "min_instance_count", null) + password = lookup(worker_node.value, "password", null) + ssh_keys = lookup(worker_node.value, "ssh_keys", null) + subnet_id = lookup(worker_node.value, "subnet_id", null) + target_instance_count = worker_node.value.target_instance_count + username = worker_node.value.username + virtual_network_id = lookup(worker_node.value, "virtual_network_id", null) + vm_size = worker_node.value.vm_size + } + } + + dynamic "zookeeper_node" { + for_each = lookup(roles.value, "zookeeper_node", []) + content { + password = lookup(zookeeper_node.value, "password", null) + ssh_keys = lookup(zookeeper_node.value, "ssh_keys", null) + subnet_id = lookup(zookeeper_node.value, "subnet_id", null) + username = zookeeper_node.value.username + virtual_network_id = lookup(zookeeper_node.value, "virtual_network_id", null) + vm_size = zookeeper_node.value.vm_size + } + } + } + } } `, template) } @@ -282,8 +349,8 @@ variable "ssh_key" { resource "azurerm_hdinsight_rserver_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" rstudio = true @@ -295,8 +362,8 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -304,26 +371,26 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { head_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } worker_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] target_instance_count = 3 } zookeeper_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } edge_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } } } @@ -337,8 +404,8 @@ func testAccAzureRMHDInsightRServerCluster_updated(data acceptance.TestData) str resource "azurerm_hdinsight_rserver_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" rstudio = true @@ -350,8 +417,8 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -397,21 +464,21 @@ func testAccAzureRMHDInsightRServerCluster_virtualNetwork(data acceptance.TestDa resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_rserver_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" rstudio = true @@ -423,8 +490,8 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -433,8 +500,8 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -442,24 +509,24 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } edge_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } } @@ -474,21 +541,21 @@ func testAccAzureRMHDInsightRServerCluster_complete(data acceptance.TestData) st resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_rserver_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" rstudio = true @@ -500,8 +567,8 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -510,8 +577,8 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -519,24 +586,24 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } edge_node { vm_size = "Standard_D3_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } @@ -549,6 +616,10 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { func testAccAzureRMHDInsightRServerCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -556,16 +627,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "acctest" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } `, data.RandomInteger, data.Locations.Primary, data.RandomString) diff --git a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_spark_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_spark_cluster_test.go index 0e16380f7599b..b1d0782f797e5 100644 --- a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_spark_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_spark_cluster_test.go @@ -212,8 +212,8 @@ func testAccAzureRMHDInsightSparkCluster_basic(data acceptance.TestData) string resource "azurerm_hdinsight_spark_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -228,8 +228,8 @@ resource "azurerm_hdinsight_spark_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -318,15 +318,75 @@ func testAccAzureRMHDInsightSparkCluster_requiresImport(data acceptance.TestData %s resource "azurerm_hdinsight_spark_cluster" "import" { - name = "${azurerm_hdinsight_spark_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_spark_cluster.test.resource_group_name}" - location = "${azurerm_hdinsight_spark_cluster.test.location}" - cluster_version = "${azurerm_hdinsight_spark_cluster.test.cluster_version}" - tier = "${azurerm_hdinsight_spark_cluster.test.tier}" - component_version = "${azurerm_hdinsight_spark_cluster.test.component_version}" - gateway = "${azurerm_hdinsight_spark_cluster.test.gateway}" - storage_account = "${azurerm_hdinsight_spark_cluster.test.storage_account}" - roles = "${azurerm_hdinsight_spark_cluster.test.roles}" + name = azurerm_hdinsight_spark_cluster.test.name + resource_group_name = azurerm_hdinsight_spark_cluster.test.resource_group_name + location = azurerm_hdinsight_spark_cluster.test.location + cluster_version = azurerm_hdinsight_spark_cluster.test.cluster_version + tier = azurerm_hdinsight_spark_cluster.test.tier + dynamic "component_version" { + for_each = azurerm_hdinsight_spark_cluster.test.component_version + content { + spark = component_version.value.spark + } + } + dynamic "gateway" { + for_each = azurerm_hdinsight_spark_cluster.test.gateway + content { + enabled = gateway.value.enabled + password = gateway.value.password + username = gateway.value.username + } + } + dynamic "storage_account" { + for_each = azurerm_hdinsight_spark_cluster.test.storage_account + content { + is_default = storage_account.value.is_default + storage_account_key = storage_account.value.storage_account_key + storage_container_id = storage_account.value.storage_container_id + } + } + dynamic "roles" { + for_each = azurerm_hdinsight_spark_cluster.test.roles + content { + dynamic "head_node" { + for_each = lookup(roles.value, "head_node", []) + content { + password = lookup(head_node.value, "password", null) + ssh_keys = lookup(head_node.value, "ssh_keys", null) + subnet_id = lookup(head_node.value, "subnet_id", null) + username = head_node.value.username + virtual_network_id = lookup(head_node.value, "virtual_network_id", null) + vm_size = head_node.value.vm_size + } + } + + dynamic "worker_node" { + for_each = lookup(roles.value, "worker_node", []) + content { + min_instance_count = lookup(worker_node.value, "min_instance_count", null) + password = lookup(worker_node.value, "password", null) + ssh_keys = lookup(worker_node.value, "ssh_keys", null) + subnet_id = lookup(worker_node.value, "subnet_id", null) + target_instance_count = worker_node.value.target_instance_count + username = worker_node.value.username + virtual_network_id = lookup(worker_node.value, "virtual_network_id", null) + vm_size = worker_node.value.vm_size + } + } + + dynamic "zookeeper_node" { + for_each = lookup(roles.value, "zookeeper_node", []) + content { + password = lookup(zookeeper_node.value, "password", null) + ssh_keys = lookup(zookeeper_node.value, "ssh_keys", null) + subnet_id = lookup(zookeeper_node.value, "subnet_id", null) + username = zookeeper_node.value.username + virtual_network_id = lookup(zookeeper_node.value, "virtual_network_id", null) + vm_size = zookeeper_node.value.vm_size + } + } + } + } } `, template) } @@ -342,8 +402,8 @@ variable "ssh_key" { resource "azurerm_hdinsight_spark_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -358,8 +418,8 @@ resource "azurerm_hdinsight_spark_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -367,20 +427,20 @@ resource "azurerm_hdinsight_spark_cluster" "test" { head_node { vm_size = "Standard_A4_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } worker_node { vm_size = "Standard_A4_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] target_instance_count = 3 } zookeeper_node { vm_size = "Medium" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } } } @@ -394,8 +454,8 @@ func testAccAzureRMHDInsightSparkCluster_updated(data acceptance.TestData) strin resource "azurerm_hdinsight_spark_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -410,8 +470,8 @@ resource "azurerm_hdinsight_spark_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -451,21 +511,21 @@ func testAccAzureRMHDInsightSparkCluster_virtualNetwork(data acceptance.TestData resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_spark_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -480,8 +540,8 @@ resource "azurerm_hdinsight_spark_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -490,8 +550,8 @@ resource "azurerm_hdinsight_spark_cluster" "test" { vm_size = "Standard_A4_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -499,16 +559,16 @@ resource "azurerm_hdinsight_spark_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Medium" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } } @@ -523,21 +583,21 @@ func testAccAzureRMHDInsightSparkCluster_complete(data acceptance.TestData) stri resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_spark_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -552,8 +612,8 @@ resource "azurerm_hdinsight_spark_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -562,8 +622,8 @@ resource "azurerm_hdinsight_spark_cluster" "test" { vm_size = "Standard_A4_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -571,16 +631,16 @@ resource "azurerm_hdinsight_spark_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Medium" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } @@ -593,6 +653,10 @@ resource "azurerm_hdinsight_spark_cluster" "test" { func testAccAzureRMHDInsightSparkCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -600,16 +664,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "acctest" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } `, data.RandomInteger, data.Locations.Primary, data.RandomString) @@ -617,6 +680,10 @@ resource "azurerm_storage_container" "test" { func testAccAzureRMHDInsightSparkCluster_gen2template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_storm_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_storm_cluster_test.go index 1e80c779ac03d..26adc1d1b5a15 100644 --- a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_storm_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_storm_cluster_test.go @@ -187,8 +187,8 @@ func testAccAzureRMHDInsightStormCluster_basic(data acceptance.TestData) string resource "azurerm_hdinsight_storm_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -203,8 +203,8 @@ resource "azurerm_hdinsight_storm_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -238,15 +238,75 @@ func testAccAzureRMHDInsightStormCluster_requiresImport(data acceptance.TestData %s resource "azurerm_hdinsight_storm_cluster" "import" { - name = "${azurerm_hdinsight_storm_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_storm_cluster.test.resource_group_name}" - location = "${azurerm_hdinsight_storm_cluster.test.location}" - cluster_version = "${azurerm_hdinsight_storm_cluster.test.cluster_version}" - tier = "${azurerm_hdinsight_storm_cluster.test.tier}" - component_version = "${azurerm_hdinsight_storm_cluster.test.component_version}" - gateway = "${azurerm_hdinsight_storm_cluster.test.gateway}" - storage_account = "${azurerm_hdinsight_storm_cluster.test.storage_account}" - roles = "${azurerm_hdinsight_storm_cluster.test.roles}" + name = azurerm_hdinsight_storm_cluster.test.name + resource_group_name = azurerm_hdinsight_storm_cluster.test.resource_group_name + location = azurerm_hdinsight_storm_cluster.test.location + cluster_version = azurerm_hdinsight_storm_cluster.test.cluster_version + tier = azurerm_hdinsight_storm_cluster.test.tier + dynamic "component_version" { + for_each = azurerm_hdinsight_storm_cluster.test.component_version + content { + storm = component_version.value.storm + } + } + dynamic "gateway" { + for_each = azurerm_hdinsight_storm_cluster.test.gateway + content { + enabled = gateway.value.enabled + password = gateway.value.password + username = gateway.value.username + } + } + dynamic "storage_account" { + for_each = azurerm_hdinsight_storm_cluster.test.storage_account + content { + is_default = storage_account.value.is_default + storage_account_key = storage_account.value.storage_account_key + storage_container_id = storage_account.value.storage_container_id + } + } + dynamic "roles" { + for_each = azurerm_hdinsight_storm_cluster.test.roles + content { + dynamic "head_node" { + for_each = lookup(roles.value, "head_node", []) + content { + password = lookup(head_node.value, "password", null) + ssh_keys = lookup(head_node.value, "ssh_keys", null) + subnet_id = lookup(head_node.value, "subnet_id", null) + username = head_node.value.username + virtual_network_id = lookup(head_node.value, "virtual_network_id", null) + vm_size = head_node.value.vm_size + } + } + + dynamic "worker_node" { + for_each = lookup(roles.value, "worker_node", []) + content { + min_instance_count = lookup(worker_node.value, "min_instance_count", null) + password = lookup(worker_node.value, "password", null) + ssh_keys = lookup(worker_node.value, "ssh_keys", null) + subnet_id = lookup(worker_node.value, "subnet_id", null) + target_instance_count = worker_node.value.target_instance_count + username = worker_node.value.username + virtual_network_id = lookup(worker_node.value, "virtual_network_id", null) + vm_size = worker_node.value.vm_size + } + } + + dynamic "zookeeper_node" { + for_each = lookup(roles.value, "zookeeper_node", []) + content { + password = lookup(zookeeper_node.value, "password", null) + ssh_keys = lookup(zookeeper_node.value, "ssh_keys", null) + subnet_id = lookup(zookeeper_node.value, "subnet_id", null) + username = zookeeper_node.value.username + virtual_network_id = lookup(zookeeper_node.value, "virtual_network_id", null) + vm_size = zookeeper_node.value.vm_size + } + } + } + } } `, template) } @@ -262,8 +322,8 @@ variable "ssh_key" { resource "azurerm_hdinsight_storm_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -278,8 +338,8 @@ resource "azurerm_hdinsight_storm_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -287,20 +347,20 @@ resource "azurerm_hdinsight_storm_cluster" "test" { head_node { vm_size = "Standard_A4_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } worker_node { vm_size = "Standard_A4_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] target_instance_count = 3 } zookeeper_node { vm_size = "Standard_A4_V2" username = "acctestusrvm" - ssh_keys = ["${var.ssh_key}"] + ssh_keys = [var.ssh_key] } } } @@ -314,8 +374,8 @@ func testAccAzureRMHDInsightStormCluster_updated(data acceptance.TestData) strin resource "azurerm_hdinsight_storm_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -330,8 +390,8 @@ resource "azurerm_hdinsight_storm_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -371,21 +431,21 @@ func testAccAzureRMHDInsightStormCluster_virtualNetwork(data acceptance.TestData resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_storm_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -400,8 +460,8 @@ resource "azurerm_hdinsight_storm_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -410,8 +470,8 @@ resource "azurerm_hdinsight_storm_cluster" "test" { vm_size = "Standard_A4_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -419,16 +479,16 @@ resource "azurerm_hdinsight_storm_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_A4_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } } @@ -443,21 +503,21 @@ func testAccAzureRMHDInsightStormCluster_complete(data acceptance.TestData) stri resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_hdinsight_storm_cluster" "test" { name = "acctesthdi-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location cluster_version = "3.6" tier = "Standard" @@ -472,8 +532,8 @@ resource "azurerm_hdinsight_storm_cluster" "test" { } storage_account { - storage_container_id = "${azurerm_storage_container.test.id}" - storage_account_key = "${azurerm_storage_account.test.primary_access_key}" + storage_container_id = azurerm_storage_container.test.id + storage_account_key = azurerm_storage_account.test.primary_access_key is_default = true } @@ -482,8 +542,8 @@ resource "azurerm_hdinsight_storm_cluster" "test" { vm_size = "Standard_A4_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } worker_node { @@ -491,16 +551,16 @@ resource "azurerm_hdinsight_storm_cluster" "test" { username = "acctestusrvm" password = "AccTestvdSC4daf986!" target_instance_count = 3 - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } zookeeper_node { vm_size = "Standard_A4_V2" username = "acctestusrvm" password = "AccTestvdSC4daf986!" - subnet_id = "${azurerm_subnet.test.id}" - virtual_network_id = "${azurerm_virtual_network.test.id}" + subnet_id = azurerm_subnet.test.id + virtual_network_id = azurerm_virtual_network.test.id } } @@ -513,6 +573,10 @@ resource "azurerm_hdinsight_storm_cluster" "test" { func testAccAzureRMHDInsightStormCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -520,16 +584,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "acctest" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } `, data.RandomInteger, data.Locations.Primary, data.RandomString) diff --git a/azurerm/internal/services/healthcare/registration.go b/azurerm/internal/services/healthcare/registration.go index 19171d82ada96..d1f842d84a380 100644 --- a/azurerm/internal/services/healthcare/registration.go +++ b/azurerm/internal/services/healthcare/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Health Care" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Healthcare", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/healthcare/tests/data_source_healthcare_service_test.go b/azurerm/internal/services/healthcare/tests/data_source_healthcare_service_test.go index 180f45f720d2c..146a6a023b620 100644 --- a/azurerm/internal/services/healthcare/tests/data_source_healthcare_service_test.go +++ b/azurerm/internal/services/healthcare/tests/data_source_healthcare_service_test.go @@ -36,9 +36,9 @@ func testAccAzureRMDataSourceHealthcareService_basic(data acceptance.TestData) s %s data "azurerm_healthcare_service" "test" { - name = "${azurerm_healthcare_service.test.name}" - resource_group_name = "${azurerm_healthcare_service.test.resource_group_name}" - location = "${azurerm_resource_group.test.location}" + name = azurerm_healthcare_service.test.name + resource_group_name = azurerm_healthcare_service.test.resource_group_name + location = azurerm_resource_group.test.location } `, resource) } diff --git a/azurerm/internal/services/healthcare/tests/resource_arm_healthcare_service_test.go b/azurerm/internal/services/healthcare/tests/resource_arm_healthcare_service_test.go index 662a6ce55ea2c..6537bd4ba65c0 100644 --- a/azurerm/internal/services/healthcare/tests/resource_arm_healthcare_service_test.go +++ b/azurerm/internal/services/healthcare/tests/resource_arm_healthcare_service_test.go @@ -135,7 +135,12 @@ func testAccAzureRMHealthCareService_basic(data acceptance.TestData) string { location := "westus2" return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-health-%d" @@ -144,14 +149,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_healthcare_service" "test" { name = "testacc%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name access_policy_object_ids = [ - "${data.azurerm_client_config.current.service_principal_object_id}", + data.azurerm_client_config.current.object_id, ] } -`, data.RandomInteger, location, data.RandomIntOfLength(17)) //name can only be 24 chars long +`, data.RandomInteger, location, data.RandomIntOfLength(17)) // name can only be 24 chars long } func testAccAzureRMHealthCareService_requiresImport(data acceptance.TestData) string { @@ -165,7 +170,7 @@ resource "azurerm_healthcare_service" "import" { resource_group_name = azurerm_healthcare_service.test.resource_group_name access_policy_object_ids = [ - "${data.azurerm_client_config.current.service_principal_object_id}", + "${data.azurerm_client_config.current.object_id}", ] } `, template) @@ -176,7 +181,12 @@ func testAccAzureRMHealthCareService_complete(data acceptance.TestData) string { location := "westus2" return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-health-%d" @@ -185,8 +195,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_healthcare_service" "test" { name = "testacc%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { environment = "production" @@ -194,7 +204,7 @@ resource "azurerm_healthcare_service" "test" { } access_policy_object_ids = [ - "${data.azurerm_client_config.current.service_principal_object_id}", + data.azurerm_client_config.current.object_id, ] authentication_configuration { @@ -211,5 +221,5 @@ resource "azurerm_healthcare_service" "test" { allow_credentials = true } } -`, data.RandomInteger, location, data.RandomIntOfLength(17)) //name can only be 24 chars long +`, data.RandomInteger, location, data.RandomIntOfLength(17)) // name can only be 24 chars long } diff --git a/azurerm/internal/services/iotcentral/client/client.go b/azurerm/internal/services/iotcentral/client/client.go new file mode 100644 index 0000000000000..5bd0b54bbd3b9 --- /dev/null +++ b/azurerm/internal/services/iotcentral/client/client.go @@ -0,0 +1,18 @@ +package client + +import ( + "github.com/Azure/azure-sdk-for-go/services/iotcentral/mgmt/2018-09-01/iotcentral" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common" +) + +type Client struct { + AppsClient *iotcentral.AppsClient +} + +func NewClient(o *common.ClientOptions) *Client { + AppsClient := iotcentral.NewAppsClient(o.SubscriptionId) + o.ConfigureClient(&AppsClient.Client, o.ResourceManagerAuthorizer) + return &Client{ + AppsClient: &AppsClient, + } +} diff --git a/azurerm/internal/services/iotcentral/parse/iotcentral_application.go b/azurerm/internal/services/iotcentral/parse/iotcentral_application.go new file mode 100644 index 0000000000000..5cce5e047314d --- /dev/null +++ b/azurerm/internal/services/iotcentral/parse/iotcentral_application.go @@ -0,0 +1,33 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type IoTCentralApplicationId struct { + ResourceGroup string + Name string +} + +func IoTCentralApplicationID(input string) (*IoTCentralApplicationId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse IoT Central Application ID %q: %+v", input, err) + } + + server := IoTCentralApplicationId{ + ResourceGroup: id.ResourceGroup, + } + + if server.Name, err = id.PopSegment("IoTApps"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &server, nil +} diff --git a/azurerm/internal/services/iotcentral/parse/iotcentral_application_test.go b/azurerm/internal/services/iotcentral/parse/iotcentral_application_test.go new file mode 100644 index 0000000000000..eb7e27b0dc60f --- /dev/null +++ b/azurerm/internal/services/iotcentral/parse/iotcentral_application_test.go @@ -0,0 +1,73 @@ +package parse + +import ( + "testing" +) + +func TestIotCentralApplicationID(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *IoTCentralApplicationId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing IoT Central Application Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/IoTApps/", + Expected: nil, + }, + { + Name: "IoT Central Application ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/IoTApps/App1", + Expected: &IoTCentralApplicationId{ + Name: "App1", + ResourceGroup: "resGroup1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.IoTCentral/IotApps/App1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := IoTCentralApplicationID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/iotcentral/registration.go b/azurerm/internal/services/iotcentral/registration.go new file mode 100644 index 0000000000000..bfa321dcd032c --- /dev/null +++ b/azurerm/internal/services/iotcentral/registration.go @@ -0,0 +1,31 @@ +package iotcentral + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +type Registration struct{} + +// Name is the name of this Service +func (r Registration) Name() string { + return "IoT Central" +} + +// SupportedDataSources returns the supported Data Sources supported by this Service +func (r Registration) SupportedDataSources() map[string]*schema.Resource { + return map[string]*schema.Resource{} +} + +// SupportedResources returns the supported Resources supported by this Service +func (r Registration) SupportedResources() map[string]*schema.Resource { + return map[string]*schema.Resource{ + "azurerm_iotcentral_application": resourceArmIotCentralApplication(), + } +} + +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "IoT Central", + } +} diff --git a/azurerm/internal/services/iotcentral/resource_arm_iotcentral_application.go b/azurerm/internal/services/iotcentral/resource_arm_iotcentral_application.go new file mode 100644 index 0000000000000..1005c97956ccb --- /dev/null +++ b/azurerm/internal/services/iotcentral/resource_arm_iotcentral_application.go @@ -0,0 +1,267 @@ +package iotcentral + +import ( + "fmt" + "time" + + "github.com/Azure/azure-sdk-for-go/services/iotcentral/mgmt/2018-09-01/iotcentral" + "github.com/hashicorp/go-azure-helpers/response" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iotcentral/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iotcentral/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmIotCentralApplication() *schema.Resource { + return &schema.Resource{ + Create: resourceArmIotCentralAppCreate, + Read: resourceArmIotCentralAppRead, + Update: resourceArmIotCentralAppUpdate, + Delete: resourceArmIotCentralAppDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.IotCentralAppName, + }, + + "location": azure.SchemaLocation(), + + "resource_group_name": azure.SchemaResourceGroupName(), + + "sub_domain": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.IotCentralAppSubdomain, + }, + + "display_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validate.IotCentralAppDisplayName, + }, + + "sku": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + string(iotcentral.F1), + string(iotcentral.S1), + string(iotcentral.ST1), + string(iotcentral.ST2), + }, true), + Default: iotcentral.ST1, + }, + "template": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validate.IotCentralAppTemplateName, + }, + + "tags": tags.Schema(), + }, + } +} + +func resourceArmIotCentralAppCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).IoTCentral.AppsClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + if features.ShouldResourcesBeImported() { + existing, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing IoT Central Application %q (Resource Group %q): %+v", name, resourceGroup, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_iotcentral_application", *existing.ID) + } + } + + resp, err := client.CheckNameAvailability(ctx, iotcentral.OperationInputs{ + Name: utils.String(name), + }) + if err != nil { + return fmt.Errorf("Error happened on check name availability. %q (Group Name %q). Error: %+v", name, resourceGroup, err) + } + if !*resp.NameAvailable { + return fmt.Errorf("Resource name not available. name: %s, Reason: %q, Message %q", name, *resp.Reason, *resp.Message) + } + + displayName := d.Get("display_name").(string) + if displayName == "" { + displayName = name + } + + subdomain := d.Get("sub_domain").(string) + template := d.Get("template").(string) + location := d.Get("location").(string) + app := iotcentral.App{ + AppProperties: &iotcentral.AppProperties{ + DisplayName: &displayName, + Subdomain: &subdomain, + Template: &template, + }, + Sku: &iotcentral.AppSkuInfo{ + Name: iotcentral.AppSku(d.Get("sku").(string)), + }, + Location: &location, + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), + } + + future, err := client.CreateOrUpdate(ctx, resourceGroup, name, app) + if err != nil { + return fmt.Errorf("Error creating Iot Central Application. %v", err) + } + + if err = future.Future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for creating IoT Central Application %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + response, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Error retrieving IoT Central Application %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if response.ID == nil || *response.ID == "" { + return fmt.Errorf("Error creating IoT Central Application %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.SetId(*response.ID) + return resourceArmIotCentralAppRead(d, meta) +} + +func resourceArmIotCentralAppUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).IoTCentral.AppsClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.IoTCentralApplicationID(d.Id()) + if err != nil { + return err + } + + displayName := d.Get("display_name").(string) + if displayName == "" { + displayName = id.Name + } + + subdomain := d.Get("sub_domain").(string) + template := d.Get("template").(string) + appPatch := iotcentral.AppPatch{ + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), + AppProperties: &iotcentral.AppProperties{ + DisplayName: &displayName, + Subdomain: &subdomain, + Template: &template, + }, + } + future, err := client.Update(ctx, id.ResourceGroup, id.Name, appPatch) + if err != nil { + return fmt.Errorf("Error update Iot Central Application %q (Resource Group %q). %+v", id.Name, id.ResourceGroup, err) + } + + if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for the completion of update Iot Central Application %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + if err != nil { + return fmt.Errorf("Error retrieving IoT Central Application %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + } + + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("Cannot read IoT Central Application %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + } + + d.SetId(*resp.ID) + return resourceArmIotCentralAppRead(d, meta) +} + +func resourceArmIotCentralAppRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).IoTCentral.AppsClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.IoTCentralApplicationID(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + return fmt.Errorf("Error retrieving IoT Central Application %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", id.ResourceGroup) + + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + if err := d.Set("sku", resp.Sku.Name); err != nil { + return fmt.Errorf("Error setting `sku`: %+v", err) + } + + if props := resp.AppProperties; props != nil { + d.Set("sub_domain", props.Subdomain) + d.Set("display_name", props.DisplayName) + d.Set("template", props.Template) + } + + return tags.FlattenAndSet(d, resp.Tags) +} + +func resourceArmIotCentralAppDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).IoTCentral.AppsClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.IoTCentralApplicationID(d.Id()) + if err != nil { + return err + } + resp, err := client.Delete(ctx, id.ResourceGroup, id.Name) + if err != nil { + if !response.WasNotFound(resp.Response()) { + return fmt.Errorf("Error delete Iot Central Application %q (Resource Group %q). %+v", id.Name, id.ResourceGroup, err) + } + } + + if err := resp.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error delete Iot Central Application %q Resource Group %q). %+v", id.Name, id.ResourceGroup, err) + } + return nil +} diff --git a/azurerm/internal/services/iotcentral/tests/resource_arm_iotcentral_application_test.go b/azurerm/internal/services/iotcentral/tests/resource_arm_iotcentral_application_test.go new file mode 100644 index 0000000000000..faa77523145f2 --- /dev/null +++ b/azurerm/internal/services/iotcentral/tests/resource_arm_iotcentral_application_test.go @@ -0,0 +1,245 @@ +package tests + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" +) + +func TestAccAzureRMIoTCentralApplication_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_iotcentral_application", "test") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMIotCentralApplicationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMIotCentralApplication_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMIotCentralApplicationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "ST1"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMIoTCentralApplication_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_iotcentral_application", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMIotCentralApplicationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMIotCentralApplication_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMIotCentralApplicationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "template", "iotc-default@1.0.0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "Test"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMIoTCentralApplication_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_iotcentral_application", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMIotCentralApplicationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMIotCentralApplication_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMIotCentralApplicationExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMIotCentralApplication_update(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMIotCentralApplicationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "ST1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "Test"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMIoTCentralApplication_requiresImportErrorStep(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + + data := acceptance.BuildTestData(t, "azurerm_iotcentral_application", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMIotCentralApplicationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMIotCentralApplication_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMIotCentralApplicationExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMIotCentralApplication_requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_iotcentral_application"), + }, + }, + }) +} + +func testCheckAzureRMIotCentralApplicationExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + appName := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for IoT Central Application: %s", appName) + } + + client := acceptance.AzureProvider.Meta().(*clients.Client).IoTCentral.AppsClient + resp, err := client.Get(ctx, resourceGroup, appName) + if err != nil { + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: IoT Central Application %q (Resource Group %q) does not exist", appName, resourceGroup) + } + + return fmt.Errorf("Bad: Get IoT Central Application: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMIotCentralApplicationDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).IoTCentral.AppsClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_iotcentral_application" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + if resp, err := client.Get(ctx, resourceGroup, name); err != nil { + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Bad: Get IoT Central Application: %+v", err) + } + } + } + return nil +} + +func testAccAzureRMIotCentralApplication_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[1]d" + location = "%[2]s" +} + +resource "azurerm_iotcentral_application" "test" { + name = "acctest-iotcentralapp-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sub_domain = "acctest-iotcentralapp-%[1]d" + sku = "ST1" +} +`, data.RandomInteger, data.Locations.Primary) +} + +func testAccAzureRMIotCentralApplication_complete(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[2]d" + location = "%[1]s" +} + +resource "azurerm_iotcentral_application" "test" { + name = "acctest-iotcentralapp-%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sub_domain = "acctest-iotcentralapp-%[2]d" + display_name = "acctest-iotcentralapp-%[2]d" + sku = "ST1" + template = "iotc-default@1.0.0" + tags = { + ENV = "Test" + } +} +`, data.Locations.Primary, data.RandomInteger) +} + +func testAccAzureRMIotCentralApplication_update(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[2]d" + location = "%[1]s" +} + +resource "azurerm_iotcentral_application" "test" { + name = "acctest-iotcentralapp-%[2]d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + sub_domain = "acctest-iotcentralapp-%[2]d" + display_name = "acctest-iotcentralapp-%[2]d" + sku = "ST1" + tags = { + + ENV = "Test" + } +} +`, data.Locations.Primary, data.RandomInteger) +} + +func testAccAzureRMIotCentralApplication_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotCentralApplication_basic(data) + return fmt.Sprintf(` +%s +resource "azurerm_iotcentral_application" "import" { + name = azurerm_iotcentral_application.test.name + resource_group_name = azurerm_iotcentral_application.test.resource_group_name + location = azurerm_iotcentral_application.test.location + sub_domain = azurerm_iotcentral_application.test.sub_domain + display_name = azurerm_iotcentral_application.test.display_name + sku = "ST1" +} +`, template) +} diff --git a/azurerm/internal/services/iotcentral/validate/iotcentral_app.go b/azurerm/internal/services/iotcentral/validate/iotcentral_app.go new file mode 100644 index 0000000000000..bfda4ecb46bf1 --- /dev/null +++ b/azurerm/internal/services/iotcentral/validate/iotcentral_app.go @@ -0,0 +1,44 @@ +package validate + +import ( + "fmt" + "regexp" +) + +func IotCentralAppName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + + // Portal: The value must contain only alphanumeric characters or the following: - + if matched := regexp.MustCompile(`^[a-z\d][a-z\d-]{0,61}[a-z\d]$`).Match([]byte(value)); !matched { + errors = append(errors, fmt.Errorf("test: %s, %q may only contain alphanumeric characters and dashes, length between 2-63", k, v)) + } + return warnings, errors +} + +func IotCentralAppSubdomain(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + + // Portal: The value must contain only alphanumeric characters or the following: - + if matched := regexp.MustCompile(`^[a-z\d][a-z\d-]{0,61}[a-z\d]$`).Match([]byte(value)); !matched { + errors = append(errors, fmt.Errorf("test: %s, %q may only contain alphanumeric characters and dashes, length between 2-63", k, v)) + } + return warnings, errors +} + +func IotCentralAppDisplayName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + + if matched := regexp.MustCompile(`^.{1,200}$`).Match([]byte(value)); !matched { + errors = append(errors, fmt.Errorf("test: %s, %q length should between 1~200", k, v)) + } + return warnings, errors +} + +func IotCentralAppTemplateName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + + if matched := regexp.MustCompile(`^.{1,50}$`).Match([]byte(value)); !matched { + errors = append(errors, fmt.Errorf("test: %s, %q length should between 1~50", k, v)) + } + return warnings, errors +} diff --git a/azurerm/internal/services/iotcentral/validate/iotcentral_app_test.go b/azurerm/internal/services/iotcentral/validate/iotcentral_app_test.go new file mode 100644 index 0000000000000..f9ce1cc36bdb8 --- /dev/null +++ b/azurerm/internal/services/iotcentral/validate/iotcentral_app_test.go @@ -0,0 +1,468 @@ +package validate + +import ( + "testing" +) + +func TestIotCentralAppName(t *testing.T) { + testData := []struct { + Value string + Error bool + }{ + { + Value: "a1", + Error: false, + }, + { + Value: "11", + Error: false, + }, + { + Value: "1a", + Error: false, + }, + { + Value: "aa", + Error: false, + }, + { + Value: "1-1", + Error: false, + }, + { + Value: "aaa-aa", + Error: false, + }, + { + Value: "a--a-aa", + Error: false, + }, + { + Value: "a1-1", + Error: false, + }, + { + Value: "a1-a", + Error: false, + }, + { + Value: "1a-1", + Error: false, + }, + { + Value: "1a-a-1-2", + Error: false, + }, + { + Value: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde", + Error: false, + }, + { + Value: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde123", + Error: false, + }, { + Value: "a", + Error: true, + }, + { + Value: "1", + Error: true, + }, + { + Value: "1-", + Error: true, + }, + { + Value: "a-", + Error: true, + }, + { + Value: "a1-", + Error: true, + }, + { + Value: "1a--1-1-a-", + Error: true, + }, + { + Value: "aa-", + Error: true, + }, + { + Value: "a1-", + Error: true, + }, + { + Value: "1a--a1-", + Error: true, + }, + { + Value: "aa-", + Error: true, + }, + { + Value: "-", + Error: true, + }, + { + Value: "-1", + Error: true, + }, + { + Value: "-a", + Error: true, + }, + { + Value: "AA", + Error: true, + }, + { + Value: "AA-1", + Error: true, + }, + { + Value: "AA-a", + Error: true, + }, + { + Value: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde1234", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Value) + + _, err := IotCentralAppName(v.Value, "unit test") + if err != nil && !v.Error { + t.Fatalf("Expected pass but got an error: %s", err) + } + } +} + +func TestIotCentralAppSubdomain(t *testing.T) { + testData := []struct { + Value string + Error bool + }{ + { + Value: "a1", + Error: false, + }, + { + Value: "11", + Error: false, + }, + { + Value: "1a", + Error: false, + }, + { + Value: "aa", + Error: false, + }, + { + Value: "1-1", + Error: false, + }, + { + Value: "a-a", + Error: false, + }, + { + Value: "a1-1", + Error: false, + }, + { + Value: "a1-a", + Error: false, + }, + { + Value: "1a-1", + Error: false, + }, + { + Value: "1a-a", + Error: false, + }, + { + Value: "a1-11", + Error: false, + }, + { + Value: "aa-11", + Error: false, + }, + { + Value: "11-1a", + Error: false, + }, + { + Value: "11-a1", + Error: false, + }, + { + Value: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde", + Error: false, + }, + { + Value: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde123", + Error: false, + }, + { + Value: "a", + Error: true, + }, + { + Value: "1", + Error: true, + }, + { + Value: "1-", + Error: true, + }, + { + Value: "a-", + Error: true, + }, + { + Value: "a1-", + Error: true, + }, + { + Value: "1a-", + Error: true, + }, + { + Value: "aa-", + Error: true, + }, + { + Value: "-", + Error: true, + }, + { + Value: "-1", + Error: true, + }, + { + Value: "-a", + Error: true, + }, + { + Value: "AA", + Error: true, + }, + { + Value: "AA-1", + Error: true, + }, + { + Value: "AA-a", + Error: true, + }, + { + Value: "A1-", + Error: true, + }, + { + Value: "AA-A", + Error: true, + }, + { + Value: "AA-aA", + Error: true, + }, + { + Value: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde1234", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Value) + + _, err := IotCentralAppSubdomain(v.Value, "unit test") + if err != nil && !v.Error { + t.Fatalf("Expected pass but got an error: %s", err) + } + } +} + +func TestIotCentralAppDisplayName(t *testing.T) { + testData := []struct { + Value string + Error bool + }{ + { + Value: "a", + Error: false, + }, + { + Value: "A", + Error: false, + }, + { + Value: "1", + Error: false, + }, + { + Value: "1-", + Error: false, + }, + { + Value: "a-", + Error: false, + }, + { + Value: "A-", + Error: false, + }, + { + Value: "a1-", + Error: false, + }, + { + Value: "1a-", + Error: false, + }, + { + Value: "aA-", + Error: false, + }, + { + Value: "Aa-", + Error: false, + }, + { + Value: "-", + Error: false, + }, + { + Value: "-1", + Error: false, + }, + { + Value: "_-a", + Error: false, + }, + { + Value: "#$%$#!", + Error: false, + }, + { + Value: "AA", + Error: false, + }, + { + Value: "AA-1", + Error: false, + }, + { + Value: "AA-a", + Error: false, + }, + { + Value: "A1-", + Error: false, + }, + { + Value: "AA-A", + Error: false, + }, + { + Value: "AA-aA", + Error: false, + }, + { + Value: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde1234", + Error: false, + }, + + { + Value: "", + Error: true, + }, + { + Value: "adcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdssdavcadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdsadcdssdavcc", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Value) + + _, err := IotCentralAppDisplayName(v.Value, "unit test") + if err != nil && !v.Error { + t.Fatalf("Expected pass but got an error: %s", err) + } + } +} + +func TestIotCentralAppTemplateName(t *testing.T) { + testData := []struct { + Value string + Error bool + }{ + { + Value: "a", + Error: false, + }, + { + Value: "A", + Error: false, + }, + { + Value: "1", + Error: false, + }, + { + Value: "1-", + Error: false, + }, + { + Value: "a-", + Error: false, + }, + { + Value: "A-", + Error: false, + }, + { + Value: "-", + Error: false, + }, + { + Value: "-1", + Error: false, + }, + { + Value: "_-a", + Error: false, + }, + { + Value: "#$%$#!", + Error: false, + }, + { + Value: "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde", + Error: false, + }, + { + Value: "", + Error: true, + }, + { + Value: "abcdeabcdeabcdeabcde@$#%abcdeabcdeadeabcdeabcdeabcdeabcde-1a", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Value) + + _, err := IotCentralAppTemplateName(v.Value, "unit test") + if err != nil && !v.Error { + t.Fatalf("Expected pass but got an error: %s", err) + } + } +} diff --git a/azurerm/internal/services/iothub/registration.go b/azurerm/internal/services/iothub/registration.go index 5bdcfdd493122..b01c1d4d7a93b 100644 --- a/azurerm/internal/services/iothub/registration.go +++ b/azurerm/internal/services/iothub/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "IoT Hub" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "IoT Hub", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ @@ -23,8 +30,6 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_iot_dps": resourceArmIotDPS(), - "azurerm_iot_dps_certificate": resourceArmIotDPSCertificate(), "azurerm_iothub_dps": resourceArmIotHubDPS(), "azurerm_iothub_dps_certificate": resourceArmIotHubDPSCertificate(), "azurerm_iothub_dps_shared_access_policy": resourceArmIotHubDPSSharedAccessPolicy(), diff --git a/azurerm/internal/services/iothub/resource_arm_iot_dps.go b/azurerm/internal/services/iothub/resource_arm_iot_dps.go deleted file mode 100644 index 31818c1d88e82..0000000000000 --- a/azurerm/internal/services/iothub/resource_arm_iot_dps.go +++ /dev/null @@ -1,381 +0,0 @@ -package iothub - -import ( - "context" - "fmt" - "log" - "regexp" - "strconv" - "time" - - "github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2018-12-01-preview/devices" - "github.com/Azure/azure-sdk-for-go/services/provisioningservices/mgmt/2018-01-22/iothub" - "github.com/hashicorp/go-azure-helpers/response" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmIotDPS() *schema.Resource { - return &schema.Resource{ - Create: resourceArmIotDPSCreateUpdate, - Read: resourceArmIotDPSRead, - Update: resourceArmIotDPSCreateUpdate, - Delete: resourceArmIotDPSDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - DeprecationMessage: `The 'azurerm_iot_dps' resource is deprecated in favour of the renamed version 'azurerm_iothub_dps'. - -Information on migrating to the renamed resource can be found here: https://terraform.io/docs/providers/azurerm/guides/migrating-between-renamed-resources.html - -As such the existing 'azurerm_iot_dps' resource is deprecated and will be removed in the next major version of the AzureRM Provider (2.0). -`, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.IoTHubName, - }, - - "resource_group_name": azure.SchemaResourceGroupName(), // azure.SchemaResourceGroupNameDiffSuppress(), - - "location": azure.SchemaLocation(), - - "sku": { - Type: schema.TypeList, - MaxItems: 1, - Required: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(devices.B1), - string(devices.B2), - string(devices.B3), - string(devices.F1), - string(devices.S1), - string(devices.S2), - string(devices.S3), - }, true), - }, - - "tier": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Deprecated: "This property is no longer required and will be removed in version 2.0 of the provider", - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(devices.Basic), - string(devices.Free), - string(devices.Standard), - }, true), - }, - - "capacity": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntAtLeast(1), - }, - }, - }, - }, - - "linked_hub": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "connection_string": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringIsNotEmpty, - ForceNew: true, - // Azure returns the key as ****. We'll suppress that here. - DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { - secretKeyRegex := regexp.MustCompile("(SharedAccessKey)=[^;]+") - maskedNew := secretKeyRegex.ReplaceAllString(new, "$1=****") - return (new == d.Get(k).(string)) && (maskedNew == old) - }, - Sensitive: true, - }, - "location": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringIsNotEmpty, - StateFunc: azure.NormalizeLocation, - ForceNew: true, - }, - "apply_allocation_policy": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - "allocation_weight": { - Type: schema.TypeInt, - Optional: true, - Default: 0, - ValidateFunc: validation.IntBetween(0, 1000), - }, - "hostname": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - - "tags": tags.Schema(), - }, - } -} - -func resourceArmIotDPSCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).IoTHub.DPSResourceClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, name, resourceGroup) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing IoT Device Provisioning Service %q (Resource Group %q): %+v", name, resourceGroup, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_iot_dps", *existing.ID) - } - } - - iotdps := iothub.ProvisioningServiceDescription{ - Location: utils.String(d.Get("location").(string)), - Name: utils.String(name), - Sku: expandIoTDPSSku(d), - Properties: &iothub.IotDpsPropertiesDescription{ - IotHubs: expandIoTDPSIoTHubs(d.Get("linked_hub").([]interface{})), - }, - Tags: tags.Expand(d.Get("tags").(map[string]interface{})), - } - - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, iotdps) - if err != nil { - return fmt.Errorf("Error creating/updating IoT Device Provisioning Service %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for the completion of the creating/updating of IoT Device Provisioning Service %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - resp, err := client.Get(ctx, name, resourceGroup) - if err != nil { - return fmt.Errorf("Error retrieving IoT Device Provisioning Service %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if resp.ID == nil { - return fmt.Errorf("Cannot read IoT Device Provisioning Service %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - d.SetId(*resp.ID) - - return resourceArmIotDPSRead(d, meta) -} - -func resourceArmIotDPSRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).IoTHub.DPSResourceClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - name := id.Path["provisioningServices"] - - resp, err := client.Get(ctx, name, resourceGroup) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil - } - - return fmt.Errorf("Error retrieving IoT Device Provisioning Service %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - sku := flattenIoTDPSSku(resp.Sku) - if err := d.Set("sku", sku); err != nil { - return fmt.Errorf("Error setting `sku`: %+v", err) - } - - if props := resp.Properties; props != nil { - if err := d.Set("linked_hub", flattenIoTDPSLinkedHub(props.IotHubs)); err != nil { - return fmt.Errorf("Error setting `linked_hub`: %+v", err) - } - } - - return tags.FlattenAndSet(d, resp.Tags) -} - -func resourceArmIotDPSDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).IoTHub.DPSResourceClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - name := id.Path["provisioningServices"] - - future, err := client.Delete(ctx, name, resourceGroup) - if err != nil { - if !response.WasNotFound(future.Response()) { - return fmt.Errorf("Error deleting IoT Device Provisioning Service %q (Resource Group %q): %+v", name, resourceGroup, err) - } - } - - return waitForIotDPSToBeDeleted(ctx, client, resourceGroup, name, d) -} - -func waitForIotDPSToBeDeleted(ctx context.Context, client *iothub.IotDpsResourceClient, resourceGroup, name string, d *schema.ResourceData) error { - // we can't use the Waiter here since the API returns a 404 once it's deleted which is considered a polling status code.. - log.Printf("[DEBUG] Waiting for IoT Device Provisioning Service %q (Resource Group %q) to be deleted", name, resourceGroup) - stateConf := &resource.StateChangeConf{ - Pending: []string{"200"}, - Target: []string{"404"}, - Refresh: iotdpsStateStatusCodeRefreshFunc(ctx, client, resourceGroup, name), - Timeout: d.Timeout(schema.TimeoutDelete), - } - - if _, err := stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for IoT Device Provisioning Service %q (Resource Group %q) to be deleted: %+v", name, resourceGroup, err) - } - - return nil -} - -func iotdpsStateStatusCodeRefreshFunc(ctx context.Context, client *iothub.IotDpsResourceClient, resourceGroup, name string) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - res, err := client.Get(ctx, name, resourceGroup) - - log.Printf("Retrieving IoT Device Provisioning Service %q (Resource Group %q) returned Status %d", resourceGroup, name, res.StatusCode) - - if err != nil { - if utils.ResponseWasNotFound(res.Response) { - return res, strconv.Itoa(res.StatusCode), nil - } - return nil, "", fmt.Errorf("Error polling for the status of the IoT Device Provisioning Service %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - return res, strconv.Itoa(res.StatusCode), nil - } -} - -func expandIoTDPSSku(d *schema.ResourceData) *iothub.IotDpsSkuInfo { - skuList := d.Get("sku").([]interface{}) - skuMap := skuList[0].(map[string]interface{}) - capacity := int64(skuMap["capacity"].(int)) - - name := skuMap["name"].(string) - tier := skuMap["tier"].(string) - - return &iothub.IotDpsSkuInfo{ - Name: iothub.IotDpsSku(name), - Tier: utils.String(tier), - Capacity: utils.Int64(capacity), - } -} - -func expandIoTDPSIoTHubs(input []interface{}) *[]iothub.DefinitionDescription { - linkedHubs := make([]iothub.DefinitionDescription, 0) - - for _, attr := range input { - linkedHubConfig := attr.(map[string]interface{}) - linkedHub := iothub.DefinitionDescription{ - ConnectionString: utils.String(linkedHubConfig["connection_string"].(string)), - AllocationWeight: utils.Int32(int32(linkedHubConfig["allocation_weight"].(int))), - ApplyAllocationPolicy: utils.Bool(linkedHubConfig["apply_allocation_policy"].(bool)), - Location: utils.String(linkedHubConfig["location"].(string)), - } - - linkedHubs = append(linkedHubs, linkedHub) - } - - return &linkedHubs -} - -func flattenIoTDPSSku(input *iothub.IotDpsSkuInfo) []interface{} { - output := make(map[string]interface{}) - - output["name"] = string(input.Name) - output["tier"] = input.Tier - if capacity := input.Capacity; capacity != nil { - output["capacity"] = int(*capacity) - } - - return []interface{}{output} -} - -func flattenIoTDPSLinkedHub(input *[]iothub.DefinitionDescription) []interface{} { - linkedHubs := make([]interface{}, 0) - if input == nil { - return linkedHubs - } - - for _, attr := range *input { - linkedHub := make(map[string]interface{}) - - if attr.Name != nil { - linkedHub["hostname"] = *attr.Name - } - if attr.ApplyAllocationPolicy != nil { - linkedHub["apply_allocation_policy"] = *attr.ApplyAllocationPolicy - } - if attr.AllocationWeight != nil { - linkedHub["allocation_weight"] = *attr.AllocationWeight - } - if attr.ConnectionString != nil { - linkedHub["connection_string"] = *attr.ConnectionString - } - if attr.Location != nil { - linkedHub["location"] = *attr.Location - } - - linkedHubs = append(linkedHubs, linkedHub) - } - - return linkedHubs -} diff --git a/azurerm/internal/services/iothub/resource_arm_iot_dps_certificate.go b/azurerm/internal/services/iothub/resource_arm_iot_dps_certificate.go deleted file mode 100644 index 694cbf1a8fe15..0000000000000 --- a/azurerm/internal/services/iothub/resource_arm_iot_dps_certificate.go +++ /dev/null @@ -1,174 +0,0 @@ -package iothub - -import ( - "fmt" - "time" - - "github.com/Azure/azure-sdk-for-go/services/provisioningservices/mgmt/2018-01-22/iothub" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmIotDPSCertificate() *schema.Resource { - return &schema.Resource{ - Create: resourceArmIotDPSCertificateCreateUpdate, - Read: resourceArmIotDPSCertificateRead, - Update: resourceArmIotDPSCertificateCreateUpdate, - Delete: resourceArmIotDPSCertificateDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - DeprecationMessage: `The 'azurerm_iot_dps_certificate' resource is deprecated in favour of the renamed version 'azurerm_iothub_dps_certificate'. - -Information on migrating to the renamed resource can be found here: https://terraform.io/docs/providers/azurerm/guides/migrating-between-renamed-resources.html - -As such the existing 'azurerm_iot_dps_certificate' resource is deprecated and will be removed in the next major version of the AzureRM Provider (2.0). -`, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.IoTHubName, - }, - - "resource_group_name": azure.SchemaResourceGroupName(), - - "iot_dps_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.IoTHubName, - }, - - "certificate_content": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringIsNotEmpty, - Sensitive: true, - }, - }, - } -} - -func resourceArmIotDPSCertificateCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).IoTHub.DPSCertificateClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - iotDPSName := d.Get("iot_dps_name").(string) - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, name, resourceGroup, iotDPSName, "") - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing IoT Device Provisioning Service Certificate %q (Device Provisioning Service %q / Resource Group %q): %+v", name, iotDPSName, resourceGroup, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_iot_dps_certificate", *existing.ID) - } - } - - certificate := iothub.CertificateBodyDescription{ - Certificate: utils.String(d.Get("certificate_content").(string)), - } - - if _, err := client.CreateOrUpdate(ctx, resourceGroup, iotDPSName, name, certificate, ""); err != nil { - return fmt.Errorf("Error creating/updating IoT Device Provisioning Service Certificate %q (Device Provisioning Service %q / Resource Group %q): %+v", name, iotDPSName, resourceGroup, err) - } - - resp, err := client.Get(ctx, name, resourceGroup, iotDPSName, "") - if err != nil { - return fmt.Errorf("Error retrieving IoT Device Provisioning Service Certificate %q (Device Provisioning Service %q / Resource Group %q): %+v", name, iotDPSName, resourceGroup, err) - } - - if resp.ID == nil { - return fmt.Errorf("Cannot read IoT Device Provisioning Service Certificate %q (Device Provisioning Service %q / Resource Group %q): %+v", name, iotDPSName, resourceGroup, err) - } - - d.SetId(*resp.ID) - - return resourceArmIotDPSCertificateRead(d, meta) -} - -func resourceArmIotDPSCertificateRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).IoTHub.DPSCertificateClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - iotDPSName := id.Path["provisioningServices"] - name := id.Path["certificates"] - - resp, err := client.Get(ctx, name, resourceGroup, iotDPSName, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil - } - return fmt.Errorf("Error retrieving IoT Device Provisioning Service Certificate %q (Device Provisioning Service %q / Resource Group %q): %+v", name, iotDPSName, resourceGroup, err) - } - - d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("iot_dps_name", iotDPSName) - // We are unable to set `certificate_content` since it is not returned from the API - - return nil -} - -func resourceArmIotDPSCertificateDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).IoTHub.DPSCertificateClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - iotDPSName := id.Path["provisioningServices"] - name := id.Path["certificates"] - - resp, err := client.Get(ctx, name, resourceGroup, iotDPSName, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return nil - } - return fmt.Errorf("Error retrieving IoT Device Provisioning Service Certificate %q (Device Provisioning Service %q / Resource Group %q): %+v", name, iotDPSName, resourceGroup, err) - } - - if resp.Etag == nil { - return fmt.Errorf("Error deleting IoT Device Provisioning Service Certificate %q (Device Provisioning Service %q / Resource Group %q) because Etag is nil", name, iotDPSName, resourceGroup) - } - - // TODO address this delete call if https://github.com/Azure/azure-rest-api-specs/pull/6311 get's merged - if _, err := client.Delete(ctx, resourceGroup, *resp.Etag, iotDPSName, name, "", nil, nil, iothub.ServerAuthentication, nil, nil, nil, ""); err != nil { - return fmt.Errorf("Error deleting IoT Device Provisioning Service Certificate %q (Device Provisioning Service %q / Resource Group %q): %+v", name, iotDPSName, resourceGroup, err) - } - return nil -} diff --git a/azurerm/internal/services/iothub/resource_arm_iothub.go b/azurerm/internal/services/iothub/resource_arm_iothub.go index 82501ef838a71..f0587350b78b6 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub.go @@ -26,6 +26,8 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) +// TODO: outside of this pr make this private + var IothubResourceName = "azurerm_iothub" func suppressIfTypeIsNot(t string) schema.SchemaDiffSuppressFunc { @@ -94,20 +96,7 @@ func resourceArmIotHub() *schema.Resource { string(devices.S1), string(devices.S2), string(devices.S3), - }, true), // todo 2.0 make this case sensitive (all constants?) - }, - - "tier": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Deprecated: "This property is no longer required and will be removed in version 2.0 of the provider", - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(devices.Basic), - string(devices.Free), - string(devices.Standard), - }, true), + }, false), }, "capacity": { @@ -880,7 +869,6 @@ func flattenIoTHubSku(input *devices.IotHubSkuInfo) []interface{} { output := make(map[string]interface{}) output["name"] = string(input.Name) - output["tier"] = string(input.Tier) if capacity := input.Capacity; capacity != nil { output["capacity"] = int(*capacity) } diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_consumer_group.go b/azurerm/internal/services/iothub/resource_arm_iothub_consumer_group.go index 709c914bd1050..4c99cecd2ca17 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_consumer_group.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_consumer_group.go @@ -69,7 +69,7 @@ func resourceArmIotHubConsumerGroupCreate(d *schema.ResourceData, meta interface resourceGroup := d.Get("resource_group_name").(string) if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, name) + existing, err := client.GetEventHubConsumerGroup(ctx, resourceGroup, iotHubName, endpointName, name) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { return fmt.Errorf("Error checking for presence of existing Consumer Group %q (Endpoint %q / IoTHub %q / Resource Group %q): %s", name, endpointName, iotHubName, resourceGroup, err) diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_dps.go b/azurerm/internal/services/iothub/resource_arm_iothub_dps.go index 6313b3283c119..b475b62120a71 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_dps.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_dps.go @@ -73,19 +73,7 @@ func resourceArmIotHubDPS() *schema.Resource { string(devices.S1), string(devices.S2), string(devices.S3), - }, true), // todo 2.0 make this case sensitive - }, - - "tier": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Deprecated: "This property is no longer required and will be removed in version 2.0 of the provider", - ValidateFunc: validation.StringInSlice([]string{ - string(devices.Basic), - string(devices.Free), - string(devices.Standard), - }, true), + }, false), }, "capacity": { @@ -354,7 +342,6 @@ func flattenIoTHubDPSSku(input *iothub.IotDpsSkuInfo) []interface{} { output := make(map[string]interface{}) output["name"] = string(input.Name) - output["tier"] = input.Tier if capacity := input.Capacity; capacity != nil { output["capacity"] = int(*capacity) } diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_fallback_route.go b/azurerm/internal/services/iothub/resource_arm_iothub_fallback_route.go index 29d6958880488..d40021cdece11 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_fallback_route.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_fallback_route.go @@ -7,10 +7,8 @@ import ( "github.com/Azure/azure-sdk-for-go/services/preview/iothub/mgmt/2018-12-01-preview/devices" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -90,17 +88,15 @@ func resourceArmIotHubFallbackRouteCreateUpdate(d *schema.ResourceData, meta int return fmt.Errorf("Error loading IotHub %q (Resource Group %q): %+v", iothubName, resourceGroup, err) } + // NOTE: this resource intentionally doesn't support Requires Import + // since a fallback route is created by default + routing := iothub.Properties.Routing if routing == nil { routing = &devices.RoutingProperties{} } - resourceId := fmt.Sprintf("%s/FallbackRoute/defined", *iothub.ID) - if d.IsNewResource() && routing.FallbackRoute != nil && features.ShouldResourcesBeImported() { - return tf.ImportAsExistsError("azurerm_iothub_fallback_route", resourceId) - } - routing.FallbackRoute = &devices.FallbackRouteProperties{ Source: utils.String(string(devices.RoutingSourceDeviceMessages)), Condition: utils.String(d.Get("condition").(string)), @@ -117,6 +113,7 @@ func resourceArmIotHubFallbackRouteCreateUpdate(d *schema.ResourceData, meta int return fmt.Errorf("Error waiting for the completion of the creating/updating of IotHub %q (Resource Group %q): %+v", iothubName, resourceGroup, err) } + resourceId := fmt.Sprintf("%s/FallbackRoute/defined", *iothub.ID) d.SetId(resourceId) return resourceArmIotHubFallbackRouteRead(d, meta) diff --git a/azurerm/internal/services/iothub/tests/data_source_iothub_dps_shared_access_policy_test.go b/azurerm/internal/services/iothub/tests/data_source_iothub_dps_shared_access_policy_test.go index 5cf2c07d3013b..4951963405556 100644 --- a/azurerm/internal/services/iothub/tests/data_source_iothub_dps_shared_access_policy_test.go +++ b/azurerm/internal/services/iothub/tests/data_source_iothub_dps_shared_access_policy_test.go @@ -32,30 +32,37 @@ func TestAccDataSourceAzureRMIotHubDpsSharedAccessPolicy_basic(t *testing.T) { func testAccDataSourceAzureRMIotHubDpsSharedAccessPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" } + resource "azurerm_iothub_dps" "test" { name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" capacity = "1" } } + resource "azurerm_iothub_dps_shared_access_policy" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_dps_name = "${azurerm_iothub_dps.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_dps_name = azurerm_iothub_dps.test.name name = "acctest" service_config = true } + data "azurerm_iothub_dps_shared_access_policy" "test" { - name = "${azurerm_iothub_dps_shared_access_policy.test.name}" - iothub_dps_name = "${azurerm_iothub_dps.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_iothub_dps_shared_access_policy.test.name + iothub_dps_name = azurerm_iothub_dps.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/iothub/tests/data_source_iothub_dps_test.go b/azurerm/internal/services/iothub/tests/data_source_iothub_dps_test.go index 686b5ffc8f5a4..995e9896b82f2 100644 --- a/azurerm/internal/services/iothub/tests/data_source_iothub_dps_test.go +++ b/azurerm/internal/services/iothub/tests/data_source_iothub_dps_test.go @@ -36,8 +36,8 @@ func testAccDataSourceAzureRMIotHubDPS_basic(data acceptance.TestData) string { %s data "azurerm_iothub_dps" "test" { - name = "${azurerm_iothub_dps.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_iothub_dps.test.name + resource_group_name = azurerm_resource_group.test.name } `, template) } diff --git a/azurerm/internal/services/iothub/tests/data_source_iothub_shared_access_policy_test.go b/azurerm/internal/services/iothub/tests/data_source_iothub_shared_access_policy_test.go index 2f208139505c9..25fed4bb454da 100644 --- a/azurerm/internal/services/iothub/tests/data_source_iothub_shared_access_policy_test.go +++ b/azurerm/internal/services/iothub/tests/data_source_iothub_shared_access_policy_test.go @@ -36,9 +36,9 @@ func testAccDataSourceAzureRMIotHubSharedAccessPolicy_basic(data acceptance.Test %s data "azurerm_iothub_shared_access_policy" "test" { - name = "${azurerm_iothub_shared_access_policy.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + name = azurerm_iothub_shared_access_policy.test.name + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name } `, template) } diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iot_dps_certificate_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iot_dps_certificate_test.go deleted file mode 100644 index 03bf322e7f417..0000000000000 --- a/azurerm/internal/services/iothub/tests/resource_arm_iot_dps_certificate_test.go +++ /dev/null @@ -1,216 +0,0 @@ -package tests - -import ( - "fmt" - "net/http" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" -) - -func TestAccAzureRMIotDPSCertificate_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iot_dps_certificate", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotDPSCertificateDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotDPSCertificate_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSCertificateExists(data.ResourceName), - ), - }, - data.ImportStep("certificate_content"), - }, - }) -} - -func TestAccAzureRMIotDPSCertificate_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - - data := acceptance.BuildTestData(t, "azurerm_iot_dps_certificate", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotDPSCertificateDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotDPSCertificate_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSCertificateExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMIotDPSCertificate_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_iotdps"), - }, - }, - }) -} - -func TestAccAzureRMIotDPSCertificate_update(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iot_dps_certificate", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotDPSCertificateDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotDPSCertificate_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSCertificateExists(data.ResourceName), - ), - }, - data.ImportStep("certificate_content"), - { - Config: testAccAzureRMIotDPSCertificate_update(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSCertificateExists(data.ResourceName), - ), - }, - data.ImportStep("certificate_content"), - }, - }) -} - -func testCheckAzureRMIotDPSCertificateDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).IoTHub.DPSCertificateClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_iot_dps_certificate" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - iotDPSName := rs.Primary.Attributes["iot_dps_name"] - - resp, err := client.Get(ctx, name, resourceGroup, iotDPSName, "") - - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("IoT Device Provisioning Service Certificate %s still exists in (device provisioning service %s / resource group %s)", name, iotDPSName, resourceGroup) - } - } - return nil -} - -func testCheckAzureRMIotDPSCertificateExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).IoTHub.DPSCertificateClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - name := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - iotDPSName := rs.Primary.Attributes["iot_dps_name"] - - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for IoT Device Provisioning Service Certificate: %s", name) - } - - resp, err := client.Get(ctx, name, resourceGroup, iotDPSName, "") - if err != nil { - if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: IoT Device Provisioning Service Certificate %q (Device Provisioning Service %q / Resource Group %q) does not exist", name, iotDPSName, resourceGroup) - } - - return fmt.Errorf("Bad: Get on iothubDPSCertificateClient: %+v", err) - } - - return nil - } -} - -func testAccAzureRMIotDPSCertificate_basic(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_iot_dps" "test" { - name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - - sku { - name = "S1" - capacity = "1" - } -} - -resource "azurerm_iot_dps_certificate" "test" { - name = "acctestIoTDPSCertificate-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - iot_dps_name = "${azurerm_iot_dps.test.name}" - - certificate_content = "${filebase64("testdata/batch_certificate.cer")}" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMIotDPSCertificate_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMIotDPS_basic(data) - return fmt.Sprintf(` -%s - -resource "azurerm_iot_dps_certificate" "test" { - name = "${azurerm_iot_dps_certificate.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - iot_dps_name = "${azurerm_iot_dps.test.name}" - - certificate_content = "${filebase64("testdata/batch_certificate.cer")}" -} -`, template) -} - -func testAccAzureRMIotDPSCertificate_update(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_iot_dps" "test" { - name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - - sku { - name = "S1" - capacity = "1" - } - - tags = { - purpose = "testing" - } -} - -resource "azurerm_iot_dps_certificate" "test" { - name = "acctestIoTDPSCertificate-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - iot_dps_name = "${azurerm_iot_dps.test.name}" - - certificate_content = "${filebase64("testdata/application_gateway_test.cer")}" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iot_dps_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iot_dps_test.go deleted file mode 100644 index 8283155704e49..0000000000000 --- a/azurerm/internal/services/iothub/tests/resource_arm_iot_dps_test.go +++ /dev/null @@ -1,284 +0,0 @@ -package tests - -import ( - "fmt" - "net/http" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" -) - -func TestAccAzureRMIotDPS_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iot_dps", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotDPSDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotDPS_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMIotDPS_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - - data := acceptance.BuildTestData(t, "azurerm_iot_dps", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotDPSDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotDPS_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMIotDPS_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_iotdps"), - }, - }, - }) -} - -func TestAccAzureRMIotDPS_update(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iot_dps", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotDPSDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotDPS_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSExists(data.ResourceName), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMIotDPS_update(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMIotDPS_linkedHubs(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_iot_dps", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotDPSDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotDPS_linkedHubs(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSExists(data.ResourceName), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMIotDPS_linkedHubsUpdated(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func testCheckAzureRMIotDPSDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).IoTHub.DPSResourceClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_iotdps" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := client.Get(ctx, resourceGroup, name) - - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("IoT Device Provisioning Service %s still exists in resource group %s", name, resourceGroup) - } - } - return nil -} - -func testCheckAzureRMIotDPSExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - client := acceptance.AzureProvider.Meta().(*clients.Client).IoTHub.DPSResourceClient - - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - iotdpsName := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for IoT Device Provisioning Service: %s", iotdpsName) - } - - resp, err := client.Get(ctx, iotdpsName, resourceGroup) - if err != nil { - if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: IoT Device Provisioning Service %q (Resource Group %q) does not exist", iotdpsName, resourceGroup) - } - - return fmt.Errorf("Bad: Get on iothubDPSResourceClient: %+v", err) - } - - return nil - } -} - -func testAccAzureRMIotDPS_basic(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_iot_dps" "test" { - name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - - sku { - name = "S1" - capacity = "1" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMIotDPS_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMIotDPS_basic(data) - return fmt.Sprintf(` -%s - -resource "azurerm_iot_dps" "import" { - name = "${azurerm_iot_dps.test.name}" - resource_group_name = "${azurerm_iot_dps.test.resource_group_name}" - location = "${azurerm_iot_dps.test.location}" - - sku { - name = "S1" - capacity = "1" - } -} -`, template) -} - -func testAccAzureRMIotDPS_update(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_iot_dps" "test" { - name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - - sku { - name = "S1" - capacity = "1" - } - - tags = { - purpose = "testing" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMIotDPS_linkedHubs(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_iot_dps" "test" { - name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - - sku { - name = "S1" - capacity = "1" - } - - linked_hub { - connection_string = "HostName=test.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=booo" - location = "${azurerm_resource_group.test.location}" - allocation_weight = 15 - apply_allocation_policy = true - } - - linked_hub { - connection_string = "HostName=test2.azure-devices.net;SharedAccessKeyName=iothubowner2;SharedAccessKey=key2" - location = "${azurerm_resource_group.test.location}" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMIotDPS_linkedHubsUpdated(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_iot_dps" "test" { - name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - - sku { - name = "S1" - capacity = "1" - } - - linked_hub { - connection_string = "HostName=test.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=booo" - location = "${azurerm_resource_group.test.location}" - allocation_weight = 150 - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_consumer_group_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_consumer_group_test.go index ac1bbf31e1b94..84dc99dcdb54c 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_consumer_group_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_consumer_group_test.go @@ -136,6 +136,10 @@ func testCheckAzureRMIotHubConsumerGroupExists(resourceName string) resource.Tes func testAccAzureRMIotHubConsumerGroup_basic(data acceptance.TestData, eventName string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -143,12 +147,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub" "test" { name = "acctestIoTHub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "B1" - tier = "Basic" capacity = "1" } @@ -159,9 +162,9 @@ resource "azurerm_iothub" "test" { resource "azurerm_iothub_consumer_group" "test" { name = "test" - iothub_name = "${azurerm_iothub.test.name}" + iothub_name = azurerm_iothub.test.name eventhub_endpoint_name = "%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, eventName) } @@ -172,10 +175,10 @@ func testAccAzureRMIotHubConsumerGroup_requiresImport(data acceptance.TestData, %s resource "azurerm_iothub_consumer_group" "import" { - name = "${azurerm_iothub_consumer_group.test.name}" - iothub_name = "${azurerm_iothub_consumer_group.test.iothub_name}" - eventhub_endpoint_name = "${azurerm_iothub_consumer_group.test.eventhub_endpoint_name}" - resource_group_name = "${azurerm_iothub_consumer_group.test.resource_group_name}" + name = azurerm_iothub_consumer_group.test.name + iothub_name = azurerm_iothub_consumer_group.test.iothub_name + eventhub_endpoint_name = azurerm_iothub_consumer_group.test.eventhub_endpoint_name + resource_group_name = azurerm_iothub_consumer_group.test.resource_group_name } `, template) } diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_certificate_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_certificate_test.go index e0d00abc3b9ca..a6add1065b437 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_certificate_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_certificate_test.go @@ -52,7 +52,7 @@ func TestAccAzureRMIotHubDPSCertificate_requiresImport(t *testing.T) { }, { Config: testAccAzureRMIotHubDPSCertificate_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_iothubdps"), + ExpectError: acceptance.RequiresImportError("azurerm_iothub_dps_certificate"), }, }, }) @@ -142,6 +142,10 @@ func testCheckAzureRMIotHubDPSCertificateExists(resourceName string) resource.Te func testAccAzureRMIotHubDPSCertificate_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -149,8 +153,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub_dps" "test" { name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -160,31 +164,35 @@ resource "azurerm_iothub_dps" "test" { resource "azurerm_iothub_dps_certificate" "test" { name = "acctestIoTDPSCertificate-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - iot_dps_name = "${azurerm_iothub_dps.test.name}" + resource_group_name = azurerm_resource_group.test.name + iot_dps_name = azurerm_iothub_dps.test.name - certificate_content = "${filebase64("testdata/batch_certificate.cer")}" + certificate_content = filebase64("testdata/batch_certificate.cer") } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testAccAzureRMIotHubDPSCertificate_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMIotHubDPS_basic(data) + template := testAccAzureRMIotHubDPSCertificate_basic(data) return fmt.Sprintf(` %s -resource "azurerm_iothub_dps_certificate" "test" { - name = "${azurerm_iothub_dps_certificate.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - iot_dps_name = "${azurerm_iothub_dps.test.name}" +resource "azurerm_iothub_dps_certificate" "import" { + name = azurerm_iothub_dps_certificate.test.name + resource_group_name = azurerm_resource_group.test.name + iot_dps_name = azurerm_iothub_dps.test.name - certificate_content = "${filebase64("testdata/batch_certificate.cer")}" + certificate_content = filebase64("testdata/batch_certificate.cer") } `, template) } func testAccAzureRMIotHubDPSCertificate_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -192,8 +200,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub_dps" "test" { name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -207,10 +215,10 @@ resource "azurerm_iothub_dps" "test" { resource "azurerm_iothub_dps_certificate" "test" { name = "acctestIoTDPSCertificate-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - iot_dps_name = "${azurerm_iothub_dps.test.name}" + resource_group_name = azurerm_resource_group.test.name + iot_dps_name = azurerm_iothub_dps.test.name - certificate_content = "${filebase64("testdata/application_gateway_test.cer")}" + certificate_content = filebase64("testdata/application_gateway_test.cer") } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_shared_access_policy_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_shared_access_policy_test.go index 6cb1cbf874502..da169bc8f863b 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_shared_access_policy_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_shared_access_policy_test.go @@ -91,23 +91,29 @@ func TestAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentWriteWithoutOthers(t *t func testAccAzureRMIotHubDpsSharedAccessPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" } + resource "azurerm_iothub_dps" "test" { name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" capacity = "1" } } + resource "azurerm_iothub_dps_shared_access_policy" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_dps_name = "${azurerm_iothub_dps.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_dps_name = azurerm_iothub_dps.test.name name = "acctest" service_config = true } @@ -116,23 +122,29 @@ resource "azurerm_iothub_dps_shared_access_policy" "test" { func testAccAzureRMIotHubDpsSharedAccessPolicy_writeWithoutRead(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" } + resource "azurerm_iothub_dps" "test" { name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" capacity = "1" } } + resource "azurerm_iothub_dps_shared_access_policy" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_dps_name = "${azurerm_iothub_dps.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_dps_name = azurerm_iothub_dps.test.name name = "acctest" registration_write = true } @@ -141,23 +153,29 @@ resource "azurerm_iothub_dps_shared_access_policy" "test" { func testAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentReadWithoutRegistration(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" } + resource "azurerm_iothub_dps" "test" { name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" capacity = "1" } } + resource "azurerm_iothub_dps_shared_access_policy" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_dps_name = "${azurerm_iothub_dps.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_dps_name = azurerm_iothub_dps.test.name name = "acctest" enrollment_read = true } @@ -166,23 +184,29 @@ resource "azurerm_iothub_dps_shared_access_policy" "test" { func testAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentWriteWithoutOthers(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" } + resource "azurerm_iothub_dps" "test" { name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" capacity = "1" } } + resource "azurerm_iothub_dps_shared_access_policy" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_dps_name = "${azurerm_iothub_dps.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_dps_name = azurerm_iothub_dps.test.name name = "acctest" enrollment_write = true } @@ -240,7 +264,7 @@ func testCheckAzureRMIotHubDpsSharedAccessPolicyDestroy(s *terraform.State) erro for _, sharedAccessPolicy := range *resp.Properties.AuthorizationPolicies { if *sharedAccessPolicy.KeyName == keyName { - return fmt.Errorf("Bad: Shared Access Policy %s still exists on IoTHb DPS %s", keyName, iothubDpsName) + return fmt.Errorf("Bad: Shared Access Policy %s still exists on IoTHub DPS %s", keyName, iothubDpsName) } } } diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_test.go index 2219458d2d30e..4a62908950b62 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_test.go @@ -46,7 +46,7 @@ func TestAccAzureRMIotHubDPS_requiresImport(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotDPSDestroy, + CheckDestroy: testCheckAzureRMIotHubDPSDestroy, Steps: []resource.TestStep{ { Config: testAccAzureRMIotHubDPS_basic(data), @@ -56,7 +56,7 @@ func TestAccAzureRMIotHubDPS_requiresImport(t *testing.T) { }, { Config: testAccAzureRMIotHubDPS_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_iothubdps"), + ExpectError: acceptance.RequiresImportError("azurerm_iothub_dps"), }, }, }) @@ -68,7 +68,7 @@ func TestAccAzureRMIotHubDPS_update(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotDPSDestroy, + CheckDestroy: testCheckAzureRMIotHubDPSDestroy, Steps: []resource.TestStep{ { Config: testAccAzureRMIotHubDPS_basic(data), @@ -119,7 +119,7 @@ func testCheckAzureRMIotHubDPSDestroy(s *terraform.State) error { ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_iothubdps" { + if rs.Type != "azurerm_iothub_dps" { continue } @@ -169,6 +169,10 @@ func testCheckAzureRMIotHubDPSExists(resourceName string) resource.TestCheckFunc func testAccAzureRMIotHubDPS_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -176,8 +180,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub_dps" "test" { name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -193,9 +197,9 @@ func testAccAzureRMIotHubDPS_requiresImport(data acceptance.TestData) string { %s resource "azurerm_iothub_dps" "import" { - name = "${azurerm_iothub_dps.test.name}" - resource_group_name = "${azurerm_iothub_dps.test.resource_group_name}" - location = "${azurerm_iothub_dps.test.location}" + name = azurerm_iothub_dps.test.name + resource_group_name = azurerm_iothub_dps.test.resource_group_name + location = azurerm_iothub_dps.test.location sku { name = "S1" @@ -207,6 +211,10 @@ resource "azurerm_iothub_dps" "import" { func testAccAzureRMIotHubDPS_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -214,8 +222,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub_dps" "test" { name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -231,6 +239,10 @@ resource "azurerm_iothub_dps" "test" { func testAccAzureRMIotHubDPS_linkedHubs(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -238,8 +250,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub_dps" "test" { name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -248,14 +260,14 @@ resource "azurerm_iothub_dps" "test" { linked_hub { connection_string = "HostName=test.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=booo" - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location allocation_weight = 15 apply_allocation_policy = true } linked_hub { connection_string = "HostName=test2.azure-devices.net;SharedAccessKeyName=iothubowner2;SharedAccessKey=key2" - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -263,6 +275,10 @@ resource "azurerm_iothub_dps" "test" { func testAccAzureRMIotHubDPS_linkedHubsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -270,8 +286,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub_dps" "test" { name = "acctestIoTDPS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -280,7 +296,7 @@ resource "azurerm_iothub_dps" "test" { linked_hub { connection_string = "HostName=test.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=booo" - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location allocation_weight = 150 } } diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_eventhub_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_eventhub_test.go index 5292024f84136..ada67f96d0254 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_eventhub_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_eventhub_test.go @@ -61,6 +61,10 @@ func TestAccAzureRMIotHubEndpointEventHub_requiresImport(t *testing.T) { func testAccAzureRMIotHubEndpointEventHub_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" location = "%[2]s" @@ -68,24 +72,24 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Basic" } resource "azurerm_eventhub" "test" { name = "acctesteventhub-%[1]d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name partition_count = 2 message_retention = 1 } resource "azurerm_eventhub_authorization_rule" "test" { 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}" + 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 @@ -94,12 +98,11 @@ resource "azurerm_eventhub_authorization_rule" "test" { resource "azurerm_iothub" "test" { name = "acctestIoTHub-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "B1" - tier = "Basic" capacity = "1" } @@ -109,11 +112,11 @@ resource "azurerm_iothub" "test" { } resource "azurerm_iothub_endpoint_eventhub" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" - connection_string = "${azurerm_eventhub_authorization_rule.test.primary_connection_string}" + connection_string = azurerm_eventhub_authorization_rule.test.primary_connection_string } `, data.RandomInteger, data.Locations.Primary) } @@ -124,11 +127,11 @@ func testAccAzureRMIotHubEndpointEventHub_requiresImport(data acceptance.TestDat %s resource "azurerm_iothub_endpoint_eventhub" "import" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" - connection_string = "${azurerm_eventhub_authorization_rule.test.primary_connection_string}" + connection_string = azurerm_eventhub_authorization_rule.test.primary_connection_string } `, template) } diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_queue_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_queue_test.go index fb9f0c74f1ea9..78f20c34128ab 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_queue_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_queue_test.go @@ -61,32 +61,35 @@ func TestAccAzureRMIotHubEndpointServiceBusQueue_requiresImport(t *testing.T) { func testAccAzureRMIotHubEndpointServiceBusQueue_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" location = "%[2]s" } - resource "azurerm_servicebus_namespace" "test" { name = "acctest-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_servicebus_queue" "test" { name = "acctest-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - namespace_name = "${azurerm_servicebus_namespace.test.name}" + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_servicebus_namespace.test.name enable_partitioning = true } resource "azurerm_servicebus_queue_authorization_rule" "test" { name = "acctest-%[1]d" - namespace_name = "${azurerm_servicebus_namespace.test.name}" - queue_name = "${azurerm_servicebus_queue.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_servicebus_namespace.test.name + queue_name = azurerm_servicebus_queue.test.name + resource_group_name = azurerm_resource_group.test.name listen = false send = true @@ -95,12 +98,11 @@ resource "azurerm_servicebus_queue_authorization_rule" "test" { resource "azurerm_iothub" "test" { name = "acctestIoTHub-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "B1" - tier = "Basic" capacity = "1" } @@ -110,11 +112,11 @@ resource "azurerm_iothub" "test" { } resource "azurerm_iothub_endpoint_servicebus_queue" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" - connection_string = "${azurerm_servicebus_queue_authorization_rule.test.primary_connection_string}" + connection_string = azurerm_servicebus_queue_authorization_rule.test.primary_connection_string } `, data.RandomInteger, data.Locations.Primary) } @@ -125,11 +127,11 @@ func testAccAzureRMIotHubEndpointServiceBusQueue_requiresImport(data acceptance. %s resource "azurerm_iothub_endpoint_servicebus_queue" "import" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" - connection_string = "${azurerm_servicebus_queue_authorization_rule.test.primary_connection_string}" + connection_string = azurerm_servicebus_queue_authorization_rule.test.primary_connection_string } `, template) } diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_topic_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_topic_test.go index fa96e4dc1638f..8fd85bf2d0dc7 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_topic_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_topic_test.go @@ -62,6 +62,10 @@ func TestAccAzureRMIotHubEndpointServiceBusTopic_requiresImport(t *testing.T) { func testAccAzureRMIotHubEndpointServiceBusTopic_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" location = "%[2]s" @@ -69,22 +73,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_servicebus_namespace" "test" { name = "acctest-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" } resource "azurerm_servicebus_topic" "test" { name = "acctestservicebustopic-%[1]d" - namespace_name = "${azurerm_servicebus_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_servicebus_namespace.test.name + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_servicebus_topic_authorization_rule" "test" { name = "acctest-%[1]d" - namespace_name = "${azurerm_servicebus_namespace.test.name}" - topic_name = "${azurerm_servicebus_topic.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_servicebus_namespace.test.name + topic_name = azurerm_servicebus_topic.test.name + resource_group_name = azurerm_resource_group.test.name listen = false send = true @@ -93,12 +97,11 @@ resource "azurerm_servicebus_topic_authorization_rule" "test" { resource "azurerm_iothub" "test" { name = "acctestIoTHub-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "B1" - tier = "Basic" capacity = "1" } @@ -108,11 +111,11 @@ resource "azurerm_iothub" "test" { } resource "azurerm_iothub_endpoint_servicebus_topic" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" - connection_string = "${azurerm_servicebus_topic_authorization_rule.test.primary_connection_string}" + connection_string = azurerm_servicebus_topic_authorization_rule.test.primary_connection_string } `, data.RandomInteger, data.Locations.Primary) } @@ -123,11 +126,11 @@ func testAccAzureRMIotHubEndpointServiceBusTopic_requiresImport(data acceptance. %s resource "azurerm_iothub_endpoint_servicebus_topic" "import" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" - connection_string = "${azurerm_servicebus_topic_authorization_rule.test.primary_connection_string}" + connection_string = azurerm_servicebus_topic_authorization_rule.test.primary_connection_string } `, template) } diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_storage_container_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_storage_container_test.go index 90120fa25e590..e6c1d0d468b82 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_storage_container_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_storage_container_test.go @@ -65,6 +65,10 @@ func TestAccAzureRMIotHubEndpointStorageContainer_requiresImport(t *testing.T) { func testAccAzureRMIotHubEndpointStorageContainer_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" location = "%[2]s" @@ -72,27 +76,25 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acc%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "acctestcont" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } resource "azurerm_iothub" "test" { name = "acctestIoTHub-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "B1" - tier = "Basic" capacity = "1" } @@ -102,12 +104,12 @@ resource "azurerm_iothub" "test" { } resource "azurerm_iothub_endpoint_storage_container" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" container_name = "acctestcont" - connection_string = "${azurerm_storage_account.test.primary_blob_connection_string}" + connection_string = azurerm_storage_account.test.primary_blob_connection_string file_name_format = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}" batch_frequency_in_seconds = 60 @@ -123,12 +125,12 @@ func testAccAzureRMIotHubEndpointStorageContainer_requiresImport(data acceptance %s resource "azurerm_iothub_endpoint_storage_container" "import" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" container_name = "acctestcont" - connection_string = "${azurerm_storage_account.test.primary_blob_connection_string}" + connection_string = azurerm_storage_account.test.primary_blob_connection_string file_name_format = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}" batch_frequency_in_seconds = 60 diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_fallback_route_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_fallback_route_test.go index 1e82148defed5..09fd167e5bc84 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_fallback_route_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_fallback_route_test.go @@ -9,10 +9,12 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) +// NOTE: this resource intentionally doesn't support Requires Import +// since a fallback route is created by default + func TestAccAzureRMIotHubFallbackRoute_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_iothub_fallback_route", "test") @@ -32,33 +34,6 @@ func TestAccAzureRMIotHubFallbackRoute_basic(t *testing.T) { }) } -func TestAccAzureRMIotHubFallbackRoute_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - - data := acceptance.BuildTestData(t, "azurerm_iothub_fallback_route", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIotHubDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIotHubFallbackRoute_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubFallbackRouteExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMIotHubFallbackRoute_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_iothub_fallback_route"), - }, - }, - }) -} - func TestAccAzureRMIotHubFallbackRoute_update(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_iothub_fallback_route", "test") @@ -148,25 +123,12 @@ func testCheckAzureRMIotHubFallbackRouteExists(resourceName string) resource.Tes } } -func testAccAzureRMIotHubFallbackRoute_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMIotHub_basic(data) +func testAccAzureRMIotHubFallbackRoute_basic(data acceptance.TestData) string { return fmt.Sprintf(` -%s - -resource "azurerm_iothub_fallback_route" "import" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" - - source = "DeviceMessages" - condition = "true" - endpoint_names = ["${azurerm_iothub_endpoint_storage_container.test.name}"] - enabled = true -} -`, template) +provider "azurerm" { + features {} } -func testAccAzureRMIotHubFallbackRoute_basic(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" location = "%[2]s" @@ -174,23 +136,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "test-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } resource "azurerm_iothub" "test" { name = "acctestIoTHub-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -203,24 +164,24 @@ resource "azurerm_iothub" "test" { } resource "azurerm_iothub_endpoint_storage_container" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" - connection_string = "${azurerm_storage_account.test.primary_blob_connection_string}" + connection_string = azurerm_storage_account.test.primary_blob_connection_string batch_frequency_in_seconds = 60 max_chunk_size_in_bytes = 10485760 - container_name = "${azurerm_storage_container.test.name}" + container_name = azurerm_storage_container.test.name encoding = "Avro" file_name_format = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}" } resource "azurerm_iothub_fallback_route" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name condition = "true" - endpoint_names = ["${azurerm_iothub_endpoint_storage_container.test.name}"] + endpoint_names = [azurerm_iothub_endpoint_storage_container.test.name] enabled = true } `, data.RandomInteger, data.Locations.Primary, data.RandomString) @@ -228,6 +189,10 @@ resource "azurerm_iothub_fallback_route" "test" { func testAccAzureRMIotHubFallbackRoute_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" location = "%[2]s" @@ -235,23 +200,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "test-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } resource "azurerm_iothub" "test" { name = "acctestIoTHub-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -264,24 +228,24 @@ resource "azurerm_iothub" "test" { } resource "azurerm_iothub_endpoint_storage_container" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" - connection_string = "${azurerm_storage_account.test.primary_blob_connection_string}" + connection_string = azurerm_storage_account.test.primary_blob_connection_string batch_frequency_in_seconds = 60 max_chunk_size_in_bytes = 10485760 - container_name = "${azurerm_storage_container.test.name}" + container_name = azurerm_storage_container.test.name encoding = "Avro" file_name_format = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}" } resource "azurerm_iothub_fallback_route" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name condition = "true" - endpoint_names = ["${azurerm_iothub_endpoint_storage_container.test.name}"] + endpoint_names = [azurerm_iothub_endpoint_storage_container.test.name] enabled = false } `, data.RandomInteger, data.Locations.Primary, data.RandomString) diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_route_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_route_test.go index eb1a49a39b94f..350cd7cd07630 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_route_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_route_test.go @@ -176,13 +176,13 @@ func testAccAzureRMIotHubRoute_requiresImport(data acceptance.TestData) string { %s resource "azurerm_iothub_route" "import" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" source = "DeviceMessages" condition = "true" - endpoint_names = ["${azurerm_iothub_endpoint_storage_container.test.name}"] + endpoint_names = [azurerm_iothub_endpoint_storage_container.test.name] enabled = true } `, template) @@ -190,6 +190,10 @@ resource "azurerm_iothub_route" "import" { func testAccAzureRMIotHubRoute_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" location = "%[2]s" @@ -197,23 +201,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "test%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } resource "azurerm_iothub" "test" { name = "acctestIoTHub%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -226,34 +229,37 @@ resource "azurerm_iothub" "test" { } resource "azurerm_iothub_endpoint_storage_container" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" - connection_string = "${azurerm_storage_account.test.primary_blob_connection_string}" + connection_string = azurerm_storage_account.test.primary_blob_connection_string batch_frequency_in_seconds = 60 max_chunk_size_in_bytes = 10485760 - container_name = "${azurerm_storage_container.test.name}" + container_name = azurerm_storage_container.test.name encoding = "Avro" file_name_format = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}" } resource "azurerm_iothub_route" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" source = "DeviceMessages" condition = "true" - endpoint_names = ["${azurerm_iothub_endpoint_storage_container.test.name}"] + endpoint_names = [azurerm_iothub_endpoint_storage_container.test.name] enabled = true } - `, data.RandomInteger, data.Locations.Primary, data.RandomString) } func testAccAzureRMIotHubRoute_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" location = "%[2]s" @@ -261,23 +267,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "test%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } resource "azurerm_iothub" "test" { name = "acctestIoTHub%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -290,28 +295,27 @@ resource "azurerm_iothub" "test" { } resource "azurerm_iothub_endpoint_storage_container" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" - connection_string = "${azurerm_storage_account.test.primary_blob_connection_string}" + connection_string = azurerm_storage_account.test.primary_blob_connection_string batch_frequency_in_seconds = 60 max_chunk_size_in_bytes = 10485760 - container_name = "${azurerm_storage_container.test.name}" + container_name = azurerm_storage_container.test.name encoding = "Avro" file_name_format = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}" } resource "azurerm_iothub_route" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" source = "DeviceLifecycleEvents" condition = "true" - endpoint_names = ["${azurerm_iothub_endpoint_storage_container.test.name}"] + endpoint_names = [azurerm_iothub_endpoint_storage_container.test.name] enabled = false } - `, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_shared_access_policy_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_shared_access_policy_test.go index e25dff79f6aa9..157be0e94acf2 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_shared_access_policy_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_shared_access_policy_test.go @@ -84,6 +84,10 @@ func TestAccAzureRMIotHubSharedAccessPolicy_requiresImport(t *testing.T) { func testAccAzureRMIotHubSharedAccessPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -91,12 +95,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub" "test" { name = "acctestIoTHub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "B1" - tier = "Basic" capacity = "1" } @@ -106,8 +109,8 @@ resource "azurerm_iothub" "test" { } resource "azurerm_iothub_shared_access_policy" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" registry_read = true @@ -122,8 +125,8 @@ func testAccAzureRMIotHubSharedAccessPolicy_requiresImport(data acceptance.TestD %s resource "azurerm_iothub_shared_access_policy" "import" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" registry_read = true @@ -134,6 +137,10 @@ resource "azurerm_iothub_shared_access_policy" "import" { func testAccAzureRMIotHubSharedAccessPolicy_writeWithoutRead(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -141,12 +148,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub" "test" { name = "acctestIoTHub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "B1" - tier = "Basic" capacity = "1" } @@ -156,8 +162,8 @@ resource "azurerm_iothub" "test" { } resource "azurerm_iothub_shared_access_policy" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - iothub_name = "${azurerm_iothub.test.name}" + resource_group_name = azurerm_resource_group.test.name + iothub_name = azurerm_iothub.test.name name = "acctest" registry_write = true diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_test.go index e1fae76b447ea..654ebc8c769e9 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_test.go @@ -217,6 +217,10 @@ func testCheckAzureRMIotHubExists(resourceName string) resource.TestCheckFunc { func testAccAzureRMIotHub_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -224,8 +228,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub" "test" { name = "acctestIoTHub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "B1" @@ -245,13 +249,12 @@ func testAccAzureRMIotHub_requiresImport(data acceptance.TestData) string { %s resource "azurerm_iothub" "import" { - name = "${azurerm_iothub.test.name}" - resource_group_name = "${azurerm_iothub.test.resource_group_name}" - location = "${azurerm_iothub.test.location}" + name = azurerm_iothub.test.name + resource_group_name = azurerm_iothub.test.resource_group_name + location = azurerm_iothub.test.location sku { name = "B1" - tier = "Basic" capacity = "1" } @@ -264,6 +267,10 @@ resource "azurerm_iothub" "import" { func testAccAzureRMIotHub_standard(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -271,8 +278,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub" "test" { name = "acctestIoTHub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -288,6 +295,10 @@ resource "azurerm_iothub" "test" { func testAccAzureRMIotHub_ipFilterRules(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -295,8 +306,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub" "test" { name = "acctestIoTHub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -318,6 +329,10 @@ resource "azurerm_iothub" "test" { func testAccAzureRMIotHub_customRoutes(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -325,46 +340,45 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "test" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } resource "azurerm_eventhub_namespace" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location name = "acctest-%d" sku = "Basic" } resource "azurerm_eventhub" "test" { name = "acctest" - resource_group_name = "${azurerm_resource_group.test.name}" - namespace_name = "${azurerm_eventhub_namespace.test.name}" + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_eventhub_namespace.test.name partition_count = 2 message_retention = 1 } resource "azurerm_eventhub_authorization_rule" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - eventhub_name = "${azurerm_eventhub.test.name}" + resource_group_name = azurerm_resource_group.test.name + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name name = "acctest" send = true } resource "azurerm_iothub" "test" { name = "acctestIoTHub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -376,18 +390,18 @@ resource "azurerm_iothub" "test" { endpoint { type = "AzureIotHub.StorageContainer" - connection_string = "${azurerm_storage_account.test.primary_blob_connection_string}" + connection_string = azurerm_storage_account.test.primary_blob_connection_string name = "export" batch_frequency_in_seconds = 60 max_chunk_size_in_bytes = 10485760 - container_name = "${azurerm_storage_container.test.name}" + container_name = azurerm_storage_container.test.name encoding = "Avro" file_name_format = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}" } endpoint { type = "AzureIotHub.EventHub" - connection_string = "${azurerm_eventhub_authorization_rule.test.primary_connection_string}" + connection_string = azurerm_eventhub_authorization_rule.test.primary_connection_string name = "export2" } @@ -416,6 +430,10 @@ resource "azurerm_iothub" "test" { func testAccAzureRMIotHub_fallbackRoute(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -423,8 +441,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_iothub" "test" { name = "acctestIoTHub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -446,6 +464,10 @@ resource "azurerm_iothub" "test" { func testAccAzureRMIotHub_fileUpload(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -453,23 +475,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "test" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } resource "azurerm_iothub" "test" { name = "acctestIoTHub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "S1" @@ -477,8 +498,8 @@ resource "azurerm_iothub" "test" { } file_upload { - connection_string = "${azurerm_storage_account.test.primary_blob_connection_string}" - container_name = "${azurerm_storage_container.test.name}" + connection_string = azurerm_storage_account.test.primary_blob_connection_string + container_name = azurerm_storage_container.test.name notifications = true max_delivery_count = 12 sas_ttl = "PT2H" diff --git a/azurerm/internal/services/keyvault/data_source_key_vault.go b/azurerm/internal/services/keyvault/data_source_key_vault.go index 6ff4ad35b13af..86a484a17b715 100644 --- a/azurerm/internal/services/keyvault/data_source_key_vault.go +++ b/azurerm/internal/services/keyvault/data_source_key_vault.go @@ -9,6 +9,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/set" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -26,27 +27,13 @@ func dataSourceArmKeyVault() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: ValidateKeyVaultName, + ValidateFunc: validate.KeyVaultName, }, "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), "location": azure.SchemaLocationForDataSource(), - // Remove in 2.0 - "sku": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - "sku_name": { Type: schema.TypeString, Computed: true, @@ -155,6 +142,16 @@ func dataSourceArmKeyVault() *schema.Resource { }, }, + "purge_protection_enabled": { + Type: schema.TypeBool, + Computed: true, + }, + + "soft_delete_enabled": { + Type: schema.TypeBool, + Computed: true, + }, + "tags": tags.SchemaDataSource(), }, } @@ -189,14 +186,11 @@ func dataSourceArmKeyVaultRead(d *schema.ResourceData, meta interface{}) error { d.Set("enabled_for_deployment", props.EnabledForDeployment) d.Set("enabled_for_disk_encryption", props.EnabledForDiskEncryption) d.Set("enabled_for_template_deployment", props.EnabledForTemplateDeployment) + d.Set("soft_delete_enabled", props.EnableSoftDelete) + d.Set("purge_protection_enabled", props.EnablePurgeProtection) d.Set("vault_uri", props.VaultURI) if sku := props.Sku; sku != nil { - // Remove in 2.0 - if err := d.Set("sku", flattenKeyVaultDataSourceSku(sku)); err != nil { - return fmt.Errorf("Error setting `sku` for KeyVault %q: %+v", *resp.Name, err) - } - if err := d.Set("sku_name", string(sku.Name)); err != nil { return fmt.Errorf("Error setting `sku_name` for KeyVault %q: %+v", *resp.Name, err) } @@ -217,15 +211,6 @@ func dataSourceArmKeyVaultRead(d *schema.ResourceData, meta interface{}) error { return tags.FlattenAndSet(d, resp.Tags) } -// Remove in 2.0 -func flattenKeyVaultDataSourceSku(sku *keyvault.Sku) []interface{} { - result := map[string]interface{}{ - "name": string(sku.Name), - } - - return []interface{}{result} -} - func flattenKeyVaultDataSourceNetworkAcls(input *keyvault.NetworkRuleSet) []interface{} { if input == nil { return []interface{}{} diff --git a/azurerm/internal/services/keyvault/data_source_key_vault_key.go b/azurerm/internal/services/keyvault/data_source_key_vault_key.go index b1d672a650e0c..3b1277b7d91fe 100644 --- a/azurerm/internal/services/keyvault/data_source_key_vault_key.go +++ b/azurerm/internal/services/keyvault/data_source_key_vault_key.go @@ -5,7 +5,6 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" @@ -29,21 +28,9 @@ func dataSourceArmKeyVaultKey() *schema.Resource { }, "key_vault_id": { - Type: schema.TypeString, - Optional: true, //todo required in 2.0 - Computed: true, //todo removed in 2.0 - ValidateFunc: azure.ValidateResourceID, - ConflictsWith: []string{"vault_uri"}, - }, - - // todo remove in 2.0 - "vault_uri": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Deprecated: "This property has been deprecated in favour of the key_vault_id property. This will prevent a class of bugs as described in https://github.com/terraform-providers/terraform-provider-azurerm/issues/2396 and will be removed in version 2.0 of the provider", - ValidateFunc: validation.IsURLWithHTTPS, - ConflictsWith: []string{"key_vault_id"}, + Type: schema.TypeString, + Required: true, + ValidateFunc: azure.ValidateResourceID, }, "key_type": { @@ -90,31 +77,12 @@ func dataSourceArmKeyVaultKeyRead(d *schema.ResourceData, meta interface{}) erro ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - keyVaultBaseUri := d.Get("vault_uri").(string) name := d.Get("name").(string) keyVaultId := d.Get("key_vault_id").(string) - if keyVaultBaseUri == "" { - if keyVaultId == "" { - return fmt.Errorf("one of `key_vault_id` or `vault_uri` must be set") - } - - pKeyVaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) - if err != nil { - return fmt.Errorf("Error looking up Key %q vault url from id %q: %+v", name, keyVaultId, err) - } - - keyVaultBaseUri = pKeyVaultBaseUrl - d.Set("vault_uri", keyVaultBaseUri) - } else { - id, err := azure.GetKeyVaultIDFromBaseUrl(ctx, vaultClient, keyVaultBaseUri) - if err != nil { - return fmt.Errorf("Error retrieving the Resource ID the Key Vault at URL %q: %s", keyVaultBaseUri, err) - } - if id == nil { - return fmt.Errorf("Unable to locate the Resource ID for the Key Vault at URL %q: %s", keyVaultBaseUri, err) - } - d.Set("key_vault_id", id) + keyVaultBaseUri, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + return fmt.Errorf("Error looking up Key %q vault url from id %q: %+v", name, keyVaultId, err) } resp, err := client.GetKey(ctx, keyVaultBaseUri, name, "") @@ -133,6 +101,8 @@ func dataSourceArmKeyVaultKeyRead(d *schema.ResourceData, meta interface{}) erro } d.SetId(id) + d.Set("key_vault_id", keyVaultId) + if key := resp.Key; key != nil { d.Set("key_type", string(key.Kty)) diff --git a/azurerm/internal/services/keyvault/data_source_key_vault_secret.go b/azurerm/internal/services/keyvault/data_source_key_vault_secret.go index 7ce9f365f68c3..0f9c305038337 100644 --- a/azurerm/internal/services/keyvault/data_source_key_vault_secret.go +++ b/azurerm/internal/services/keyvault/data_source_key_vault_secret.go @@ -5,7 +5,6 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" @@ -29,21 +28,9 @@ func dataSourceArmKeyVaultSecret() *schema.Resource { }, "key_vault_id": { - Type: schema.TypeString, - Optional: true, //todo required in 2.0 - Computed: true, //todo removed in 2.0 - ValidateFunc: azure.ValidateResourceID, - ConflictsWith: []string{"vault_uri"}, - }, - - // todo remove in 2.0 - "vault_uri": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Deprecated: "This property has been deprecated in favour of the key_vault_id property. This will prevent a class of bugs as described in https://github.com/terraform-providers/terraform-provider-azurerm/issues/2396 and will be removed in version 2.0 of the provider", - ValidateFunc: validation.IsURLWithHTTPS, - ConflictsWith: []string{"key_vault_id"}, + Type: schema.TypeString, + Required: true, + ValidateFunc: azure.ValidateResourceID, }, "value": { @@ -74,31 +61,11 @@ func dataSourceArmKeyVaultSecretRead(d *schema.ResourceData, meta interface{}) e defer cancel() name := d.Get("name").(string) - keyVaultBaseUri := d.Get("vault_uri").(string) keyVaultId := d.Get("key_vault_id").(string) - if keyVaultBaseUri == "" { - if keyVaultId == "" { - return fmt.Errorf("one of `key_vault_id` or `vault_uri` must be set") - } - - pKeyVaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) - if err != nil { - return fmt.Errorf("Error looking up Secret %q vault url from id %q: %+v", name, keyVaultId, err) - } - - keyVaultBaseUri = pKeyVaultBaseUrl - d.Set("vault_uri", keyVaultBaseUri) - } else { - id, err := azure.GetKeyVaultIDFromBaseUrl(ctx, vaultClient, keyVaultBaseUri) - if err != nil { - return fmt.Errorf("Error retrieving the Resource ID the Key Vault at URL %q: %s", keyVaultBaseUri, err) - } - if id == nil { - return fmt.Errorf("Unable to locate the Resource ID for the Key Vault at URL %q: %s", keyVaultBaseUri, err) - } - - d.Set("key_vault_id", id) + keyVaultBaseUri, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + return fmt.Errorf("Error looking up Secret %q vault url from id %q: %+v", name, keyVaultId, err) } // we always want to get the latest version @@ -119,7 +86,7 @@ func dataSourceArmKeyVaultSecretRead(d *schema.ResourceData, meta interface{}) e d.SetId(*resp.ID) d.Set("name", respID.Name) - d.Set("vault_uri", respID.KeyVaultBaseUrl) + d.Set("key_vault_id", keyVaultId) d.Set("value", resp.Value) d.Set("version", respID.Version) d.Set("content_type", resp.ContentType) diff --git a/azurerm/internal/services/keyvault/parse/key_vault_id.go b/azurerm/internal/services/keyvault/parse/key_vault_id.go new file mode 100644 index 0000000000000..65944f1892411 --- /dev/null +++ b/azurerm/internal/services/keyvault/parse/key_vault_id.go @@ -0,0 +1,31 @@ +package parse + +import ( + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type KeyVaultId struct { + Name string + ResourceGroup string +} + +func KeyVaultID(input string) (*KeyVaultId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + account := KeyVaultId{ + ResourceGroup: id.ResourceGroup, + } + + if account.Name, err = id.PopSegment("vaults"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &account, nil +} diff --git a/azurerm/internal/services/keyvault/parse/key_vault_id_test.go b/azurerm/internal/services/keyvault/parse/key_vault_id_test.go new file mode 100644 index 0000000000000..9c73991d5cf23 --- /dev/null +++ b/azurerm/internal/services/keyvault/parse/key_vault_id_test.go @@ -0,0 +1,73 @@ +package parse + +import ( + "testing" +) + +func TestKeyVaultID(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *KeyVaultId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing Vaults Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.KeyVault/vaults/", + Expected: nil, + }, + { + Name: "Key Vault ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.KeyVault/vaults/vault1", + Expected: &KeyVaultId{ + Name: "vault1", + ResourceGroup: "resGroup1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.KeyVault/Vaults/vault1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := KeyVaultID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/keyvault/registration.go b/azurerm/internal/services/keyvault/registration.go index 95c8c926102c9..d21e83053cac4 100644 --- a/azurerm/internal/services/keyvault/registration.go +++ b/azurerm/internal/services/keyvault/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "KeyVault" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Key Vault", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault.go b/azurerm/internal/services/keyvault/resource_arm_key_vault.go index 62d559c4d2f13..bd91a63452ad9 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault.go @@ -1,12 +1,13 @@ package keyvault import ( + "context" "fmt" "log" "net/http" - "regexp" "time" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2018-02-14/keyvault" @@ -19,7 +20,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/set" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -35,16 +35,16 @@ var keyVaultResourceName = "azurerm_key_vault" func resourceArmKeyVault() *schema.Resource { return &schema.Resource{ - Create: resourceArmKeyVaultCreateUpdate, + Create: resourceArmKeyVaultCreate, Read: resourceArmKeyVaultRead, - Update: resourceArmKeyVaultCreateUpdate, + Update: resourceArmKeyVaultUpdate, Delete: resourceArmKeyVaultDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, - MigrateState: ResourceAzureRMKeyVaultMigrateState, + MigrateState: resourceAzureRMKeyVaultMigrateState, SchemaVersion: 1, Timeouts: &schema.ResourceTimeout{ @@ -59,49 +59,20 @@ func resourceArmKeyVault() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: ValidateKeyVaultName, + ValidateFunc: validate.KeyVaultName, }, "location": azure.SchemaLocation(), "resource_group_name": azure.SchemaResourceGroupName(), - // Remove in 2.0 - "sku": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Deprecated: "This property has been deprecated in favour of the 'sku_name' property and will be removed in version 2.0 of the provider", - ConflictsWith: []string{"sku_name"}, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice([]string{ - string(keyvault.Standard), - string(keyvault.Premium), - }, false), - }, - }, - }, - }, - "sku_name": { Type: schema.TypeString, - Optional: true, - Computed: true, + Required: true, ValidateFunc: validation.StringInSlice([]string{ string(keyvault.Standard), string(keyvault.Premium), - // TODO: revert this in 2.0 - }, true), - }, - - "vault_uri": { - Type: schema.TypeString, - Computed: true, + }, false), }, "tenant_id": { @@ -195,71 +166,90 @@ func resourceArmKeyVault() *schema.Resource { }, }, + "purge_protection_enabled": { + Type: schema.TypeBool, + Optional: true, + }, + + "soft_delete_enabled": { + Type: schema.TypeBool, + Optional: true, + }, + "tags": tags.Schema(), + + // Computed + "vault_uri": { + Type: schema.TypeString, + Computed: true, + }, }, } } -func resourceArmKeyVaultCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceArmKeyVaultCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).KeyVault.VaultsClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - // Remove in 2.0 - var sku keyvault.Sku + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + location := azure.NormalizeLocation(d.Get("location").(string)) - if inputs := d.Get("sku").([]interface{}); len(inputs) != 0 { - input := inputs[0].(map[string]interface{}) - v := input["name"].(string) + // Locking this resource so we don't make modifications to it at the same time if there is a + // key vault access policy trying to update it as well + locks.ByName(name, keyVaultResourceName) + defer locks.UnlockByName(name, keyVaultResourceName) - sku = keyvault.Sku{ - Family: &armKeyVaultSkuFamily, - Name: keyvault.SkuName(v), - } - } else { - // Keep in 2.0 - sku = keyvault.Sku{ - Family: &armKeyVaultSkuFamily, - Name: keyvault.SkuName(d.Get("sku_name").(string)), + // check for the presence of an existing, live one which should be imported into the state + existing, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing Key Vault %q (Resource Group %q): %s", name, resourceGroup, err) } } - if sku.Name == "" { - return fmt.Errorf("either 'sku_name' or 'sku' must be defined in the configuration file") + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_key_vault", *existing.ID) } - log.Printf("[INFO] preparing arguments for Azure ARM KeyVault creation.") - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing Key Vault %q (Resource Group %q): %s", name, resourceGroup, err) - } + // before creating check to see if the key vault exists in the soft delete state + softDeletedKeyVault, err := client.GetDeleted(ctx, name, location) + if err != nil { + if !utils.ResponseWasNotFound(softDeletedKeyVault.Response) { + return fmt.Errorf("Error checking for the presence of an existing Soft-Deleted Key Vault %q (Location %q): %+v", name, location, err) } + } - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_key_vault", *existing.ID) + // if so, does the user want us to recover it? + recoverSoftDeletedKeyVault := false + if !utils.ResponseWasNotFound(softDeletedKeyVault.Response) { + if !meta.(*clients.Client).Features.KeyVault.RecoverSoftDeletedKeyVaults { + // this exists but the users opted out so they must import this it out-of-band + return fmt.Errorf(optedOutOfRecoveringSoftDeletedKeyVaultErrorFmt(name, location)) } + + recoverSoftDeletedKeyVault = true } - location := azure.NormalizeLocation(d.Get("location").(string)) tenantUUID := uuid.FromStringOrNil(d.Get("tenant_id").(string)) enabledForDeployment := d.Get("enabled_for_deployment").(bool) enabledForDiskEncryption := d.Get("enabled_for_disk_encryption").(bool) enabledForTemplateDeployment := d.Get("enabled_for_template_deployment").(bool) t := d.Get("tags").(map[string]interface{}) - networkAclsRaw := d.Get("network_acls").([]interface{}) - networkAcls, subnetIds := expandKeyVaultNetworkAcls(networkAclsRaw) - policies := d.Get("access_policy").([]interface{}) accessPolicies, err := azure.ExpandKeyVaultAccessPolicies(policies) if err != nil { - return fmt.Errorf("Error expanding `access_policy`: %+v", policies) + return fmt.Errorf("Error expanding `access_policy`: %+v", err) + } + + networkAclsRaw := d.Get("network_acls").([]interface{}) + networkAcls, subnetIds := expandKeyVaultNetworkAcls(networkAclsRaw) + + sku := keyvault.Sku{ + Family: &armKeyVaultSkuFamily, + Name: keyvault.SkuName(d.Get("sku_name").(string)), } parameters := keyvault.VaultCreateOrUpdateParameters{ @@ -276,10 +266,17 @@ func resourceArmKeyVaultCreateUpdate(d *schema.ResourceData, meta interface{}) e Tags: tags.Expand(t), } - // Locking this resource so we don't make modifications to it at the same time if there is a - // key vault access policy trying to update it as well - locks.ByName(name, keyVaultResourceName) - defer locks.UnlockByName(name, keyVaultResourceName) + // This settings can only be set if it is true, if set when value is false API returns errors + if softDeleteEnabled := d.Get("soft_delete_enabled").(bool); softDeleteEnabled { + parameters.Properties.EnableSoftDelete = utils.Bool(softDeleteEnabled) + } + if purgeProtectionEnabled := d.Get("purge_protection_enabled").(bool); purgeProtectionEnabled { + parameters.Properties.EnablePurgeProtection = utils.Bool(purgeProtectionEnabled) + } + + if recoverSoftDeletedKeyVault { + parameters.Properties.CreateMode = keyvault.CreateModeRecover + } // also lock on the Virtual Network ID's since modifications in the networking stack are exclusive virtualNetworkNames := make([]string, 0) @@ -290,7 +287,7 @@ func resourceArmKeyVaultCreateUpdate(d *schema.ResourceData, meta interface{}) e } virtualNetworkName := id.Path["virtualNetworks"] - if !network.SliceContainsValue(virtualNetworkNames, virtualNetworkName) { + if !azure.SliceContainsValue(virtualNetworkNames, virtualNetworkName) { virtualNetworkNames = append(virtualNetworkNames, virtualNetworkName) } } @@ -298,8 +295,8 @@ func resourceArmKeyVaultCreateUpdate(d *schema.ResourceData, meta interface{}) e locks.MultipleByName(&virtualNetworkNames, network.VirtualNetworkResourceName) defer locks.UnlockMultipleByName(&virtualNetworkNames, network.VirtualNetworkResourceName) - if _, err = client.CreateOrUpdate(ctx, resourceGroup, name, parameters); err != nil { - return fmt.Errorf("Error updating Key Vault %q (Resource Group %q): %+v", name, resourceGroup, err) + if _, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters); err != nil { + return fmt.Errorf("Error creating Key Vault %q (Resource Group %q): %+v", name, resourceGroup, err) } read, err := client.Get(ctx, resourceGroup, name) @@ -312,23 +309,21 @@ func resourceArmKeyVaultCreateUpdate(d *schema.ResourceData, meta interface{}) e d.SetId(*read.ID) - if d.IsNewResource() { - if props := read.Properties; props != nil { - if vault := props.VaultURI; vault != nil { - log.Printf("[DEBUG] Waiting for Key Vault %q (Resource Group %q) to become available", name, resourceGroup) - stateConf := &resource.StateChangeConf{ - Pending: []string{"pending"}, - Target: []string{"available"}, - Refresh: keyVaultRefreshFunc(*vault), - Delay: 30 * time.Second, - PollInterval: 10 * time.Second, - ContinuousTargetOccurence: 10, - Timeout: d.Timeout(schema.TimeoutCreate), - } + if props := read.Properties; props != nil { + if vault := props.VaultURI; vault != nil { + log.Printf("[DEBUG] Waiting for Key Vault %q (Resource Group %q) to become available", name, resourceGroup) + stateConf := &resource.StateChangeConf{ + Pending: []string{"pending"}, + Target: []string{"available"}, + Refresh: keyVaultRefreshFunc(*vault), + Delay: 30 * time.Second, + PollInterval: 10 * time.Second, + ContinuousTargetOccurence: 10, + Timeout: d.Timeout(schema.TimeoutCreate), + } - if _, err := stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for Key Vault %q (Resource Group %q) to become available: %s", name, resourceGroup, err) - } + if _, err := stateConf.WaitForState(); err != nil { + return fmt.Errorf("Error waiting for Key Vault %q (Resource Group %q) to become available: %s", name, resourceGroup, err) } } } @@ -336,6 +331,179 @@ func resourceArmKeyVaultCreateUpdate(d *schema.ResourceData, meta interface{}) e return resourceArmKeyVaultRead(d, meta) } +func resourceArmKeyVaultUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).KeyVault.VaultsClient + ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["vaults"] + + // Locking this resource so we don't make modifications to it at the same time if there is a + // key vault access policy trying to update it as well + locks.ByName(name, keyVaultResourceName) + defer locks.UnlockByName(name, keyVaultResourceName) + + d.Partial(true) + + // first pull the existing key vault since we need to lock on several bits of it's information + existing, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Error retrieving Key Vault %q (Resource Group %q): %+v", name, resourceGroup, err) + } + if existing.Properties == nil { + return fmt.Errorf("Error retrieving Key Vault %q (Resource Group %q): `properties` was nil", name, resourceGroup) + } + + update := keyvault.VaultPatchParameters{} + + if d.HasChange("access_policy") { + if update.Properties == nil { + update.Properties = &keyvault.VaultPatchProperties{} + } + + policiesRaw := d.Get("access_policy").([]interface{}) + accessPolicies, err := azure.ExpandKeyVaultAccessPolicies(policiesRaw) + if err != nil { + return fmt.Errorf("Error expanding `access_policy`: %+v", err) + } + update.Properties.AccessPolicies = accessPolicies + } + + if d.HasChange("enabled_for_deployment") { + if update.Properties == nil { + update.Properties = &keyvault.VaultPatchProperties{} + } + + update.Properties.EnabledForDeployment = utils.Bool(d.Get("enabled_for_deployment").(bool)) + } + + if d.HasChange("enabled_for_disk_encryption") { + if update.Properties == nil { + update.Properties = &keyvault.VaultPatchProperties{} + } + + update.Properties.EnabledForDiskEncryption = utils.Bool(d.Get("enabled_for_disk_encryption").(bool)) + } + + if d.HasChange("enabled_for_template_deployment") { + if update.Properties == nil { + update.Properties = &keyvault.VaultPatchProperties{} + } + + update.Properties.EnabledForTemplateDeployment = utils.Bool(d.Get("enabled_for_template_deployment").(bool)) + } + + if d.HasChange("network_acls") { + if update.Properties == nil { + update.Properties = &keyvault.VaultPatchProperties{} + } + + networkAclsRaw := d.Get("network_acls").([]interface{}) + networkAcls, subnetIds := expandKeyVaultNetworkAcls(networkAclsRaw) + + // also lock on the Virtual Network ID's since modifications in the networking stack are exclusive + virtualNetworkNames := make([]string, 0) + for _, v := range subnetIds { + id, err2 := azure.ParseAzureResourceID(v) + if err2 != nil { + return err2 + } + + virtualNetworkName := id.Path["virtualNetworks"] + if !azure.SliceContainsValue(virtualNetworkNames, virtualNetworkName) { + virtualNetworkNames = append(virtualNetworkNames, virtualNetworkName) + } + } + + locks.MultipleByName(&virtualNetworkNames, network.VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(&virtualNetworkNames, network.VirtualNetworkResourceName) + + update.Properties.NetworkAcls = networkAcls + } + + if d.HasChange("purge_protection_enabled") { + if update.Properties == nil { + update.Properties = &keyvault.VaultPatchProperties{} + } + + newValue := d.Get("purge_protection_enabled").(bool) + + // existing.Properties guaranteed non-nil above + oldValue := false + if existing.Properties.EnablePurgeProtection != nil { + oldValue = *existing.Properties.EnablePurgeProtection + } + + // whilst this should have got caught in the customizeDiff this won't work if that fields interpolated + // hence the double-checking here + if oldValue && !newValue { + return fmt.Errorf("Error updating Key Vault %q (Resource Group %q): once Purge Protection has been Enabled it's not possible to disable it", name, resourceGroup) + } + + update.Properties.EnablePurgeProtection = utils.Bool(newValue) + } + + if d.HasChange("sku_name") { + if update.Properties == nil { + update.Properties = &keyvault.VaultPatchProperties{} + } + + update.Properties.Sku = &keyvault.Sku{ + Family: &armKeyVaultSkuFamily, + Name: keyvault.SkuName(d.Get("sku_name").(string)), + } + } + + if d.HasChange("soft_delete_enabled") { + if update.Properties == nil { + update.Properties = &keyvault.VaultPatchProperties{} + } + + newValue := d.Get("soft_delete_enabled").(bool) + + // existing.Properties guaranteed non-nil above + oldValue := false + if existing.Properties.EnableSoftDelete != nil { + oldValue = *existing.Properties.EnableSoftDelete + } + + // whilst this should have got caught in the customizeDiff this won't work if that fields interpolated + // hence the double-checking here + if oldValue && !newValue { + return fmt.Errorf("Error updating Key Vault %q (Resource Group %q): once Soft Delete has been Enabled it's not possible to disable it", name, resourceGroup) + } + + update.Properties.EnableSoftDelete = utils.Bool(newValue) + } + + if d.HasChange("tenant_id") { + if update.Properties == nil { + update.Properties = &keyvault.VaultPatchProperties{} + } + + tenantUUID := uuid.FromStringOrNil(d.Get("tenant_id").(string)) + update.Properties.TenantID = &tenantUUID + } + + if d.HasChange("tags") { + t := d.Get("tags").(map[string]interface{}) + update.Tags = tags.Expand(t) + } + + if _, err := client.Update(ctx, resourceGroup, name, update); err != nil { + return fmt.Errorf("Error updating Key Vault %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.Partial(false) + + return resourceArmKeyVaultRead(d, meta) +} + func resourceArmKeyVaultRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).KeyVault.VaultsClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) @@ -369,14 +537,11 @@ func resourceArmKeyVaultRead(d *schema.ResourceData, meta interface{}) error { d.Set("enabled_for_deployment", props.EnabledForDeployment) d.Set("enabled_for_disk_encryption", props.EnabledForDiskEncryption) d.Set("enabled_for_template_deployment", props.EnabledForTemplateDeployment) + d.Set("soft_delete_enabled", props.EnableSoftDelete) + d.Set("purge_protection_enabled", props.EnablePurgeProtection) d.Set("vault_uri", props.VaultURI) if sku := props.Sku; sku != nil { - // Remove in 2.0 - if err := d.Set("sku", flattenKeyVaultSku(sku)); err != nil { - return fmt.Errorf("Error setting 'sku' for KeyVault %q: %+v", *resp.Name, err) - } - if err := d.Set("sku_name", string(sku.Name)); err != nil { return fmt.Errorf("Error setting 'sku_name' for KeyVault %q: %+v", *resp.Name, err) } @@ -406,8 +571,10 @@ func resourceArmKeyVaultDelete(d *schema.ResourceData, meta interface{}) error { if err != nil { return err } + resourceGroup := id.ResourceGroup name := id.Path["vaults"] + location := d.Get("location").(string) locks.ByName(name, keyVaultResourceName) defer locks.UnlockByName(name, keyVaultResourceName) @@ -421,6 +588,20 @@ func resourceArmKeyVaultDelete(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error retrieving Key Vault %q (Resource Group %q): %+v", name, resourceGroup, err) } + if read.Properties == nil { + return fmt.Errorf("Error retrieving Key Vault %q (Resource Group %q): `properties` was nil", name, resourceGroup) + } + + // Check to see if purge protection is enabled or not... + purgeProtectionEnabled := false + if ppe := read.Properties.EnablePurgeProtection; ppe != nil { + purgeProtectionEnabled = *ppe + } + softDeleteEnabled := false + if sde := read.Properties.EnableSoftDelete; sde != nil { + softDeleteEnabled = *sde + } + // ensure we lock on the latest network names, to ensure we handle Azure's networking layer being limited to one change at a time virtualNetworkNames := make([]string, 0) if props := read.Properties; props != nil { @@ -437,7 +618,7 @@ func resourceArmKeyVaultDelete(d *schema.ResourceData, meta interface{}) error { } virtualNetworkName := id.Path["virtualNetworks"] - if !network.SliceContainsValue(virtualNetworkNames, virtualNetworkName) { + if !azure.SliceContainsValue(virtualNetworkNames, virtualNetworkName) { virtualNetworkNames = append(virtualNetworkNames, virtualNetworkName) } } @@ -455,69 +636,39 @@ func resourceArmKeyVaultDelete(d *schema.ResourceData, meta interface{}) error { } } - return nil -} - -// Remove in 2.0 -func flattenKeyVaultSku(sku *keyvault.Sku) []interface{} { - result := map[string]interface{}{ - "name": string(sku.Name), - } - - return []interface{}{result} -} - -func flattenKeyVaultNetworkAcls(input *keyvault.NetworkRuleSet) []interface{} { - if input == nil { - return []interface{}{ - map[string]interface{}{ - "bypass": string(keyvault.AzureServices), - "default_action": string(keyvault.Allow), - "ip_rules": schema.NewSet(schema.HashString, []interface{}{}), - "virtual_network_subnet_ids": schema.NewSet(schema.HashString, []interface{}{}), - }, - } - } - - output := make(map[string]interface{}) - - output["bypass"] = string(input.Bypass) - output["default_action"] = string(input.DefaultAction) - - ipRules := make([]interface{}, 0) - if input.IPRules != nil { - for _, v := range *input.IPRules { - if v.Value == nil { - continue + // Purge the soft deleted key vault permanently if the feature flag is enabled + if meta.(*clients.Client).Features.KeyVault.PurgeSoftDeleteOnDestroy && softDeleteEnabled { + // KeyVaults with Purge Protection Enabled cannot be deleted unless done by Azure + if purgeProtectionEnabled { + deletedInfo, err := getSoftDeletedStateForKeyVault(ctx, client, name, location) + if err != nil { + return fmt.Errorf("Error retrieving the Deletion Details for KeyVault %q: %+v", name, err) } - ipRules = append(ipRules, *v.Value) - } - } - output["ip_rules"] = schema.NewSet(schema.HashString, ipRules) - - virtualNetworkRules := make([]interface{}, 0) - if input.VirtualNetworkRules != nil { - for _, v := range *input.VirtualNetworkRules { - if v.ID == nil { - continue + // in the future it'd be nice to raise a warning, but this is the best we can do for now + if deletedInfo != nil { + log.Printf("[DEBUG] The Key Vault %q has Purge Protection Enabled and was deleted on %q. Azure will purge this on %q", name, deletedInfo.deleteDate, deletedInfo.purgeDate) + } else { + log.Printf("[DEBUG] The Key Vault %q has Purge Protection Enabled and will be purged automatically by Azure", name) } - - virtualNetworkRules = append(virtualNetworkRules, *v.ID) + return nil } - } - output["virtual_network_subnet_ids"] = schema.NewSet(schema.HashString, virtualNetworkRules) - return []interface{}{output} -} + log.Printf("[DEBUG] KeyVault %q marked for purge - executing purge", name) + future, err := client.PurgeDeleted(ctx, name, location) + if err != nil { + return err + } -func ValidateKeyVaultName(v interface{}, k string) (warnings []string, errors []error) { - value := v.(string) - if matched := regexp.MustCompile(`^[a-zA-Z0-9-]{3,24}$`).Match([]byte(value)); !matched { - errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes and must be between 3-24 chars", k)) + log.Printf("[DEBUG] Waiting for purge of KeyVault %q..", name) + err = future.WaitForCompletionRef(ctx, client.Client) + if err != nil { + return fmt.Errorf("Error purging Key Vault %q (Resource Group %q): %+v", name, resourceGroup, err) + } + log.Printf("[DEBUG] Purged KeyVault %q.", name) } - return warnings, errors + return nil } func keyVaultRefreshFunc(vaultUri string) resource.StateRefreshFunc { @@ -583,3 +734,98 @@ func expandKeyVaultNetworkAcls(input []interface{}) (*keyvault.NetworkRuleSet, [ } return &ruleSet, subnetIds } + +func flattenKeyVaultNetworkAcls(input *keyvault.NetworkRuleSet) []interface{} { + if input == nil { + return []interface{}{ + map[string]interface{}{ + "bypass": string(keyvault.AzureServices), + "default_action": string(keyvault.Allow), + "ip_rules": schema.NewSet(schema.HashString, []interface{}{}), + "virtual_network_subnet_ids": schema.NewSet(schema.HashString, []interface{}{}), + }, + } + } + + output := make(map[string]interface{}) + + output["bypass"] = string(input.Bypass) + output["default_action"] = string(input.DefaultAction) + + ipRules := make([]interface{}, 0) + if input.IPRules != nil { + for _, v := range *input.IPRules { + if v.Value == nil { + continue + } + + ipRules = append(ipRules, *v.Value) + } + } + output["ip_rules"] = schema.NewSet(schema.HashString, ipRules) + + virtualNetworkRules := make([]interface{}, 0) + if input.VirtualNetworkRules != nil { + for _, v := range *input.VirtualNetworkRules { + if v.ID == nil { + continue + } + + virtualNetworkRules = append(virtualNetworkRules, *v.ID) + } + } + output["virtual_network_subnet_ids"] = schema.NewSet(schema.HashString, virtualNetworkRules) + + return []interface{}{output} +} + +func optedOutOfRecoveringSoftDeletedKeyVaultErrorFmt(name, location string) string { + return fmt.Sprintf(` +An existing soft-deleted Key Vault exists with the Name %q in the location %q, however +automatically recovering this KeyVault has been disabled via the "features" block. + +Terraform can automatically recover the soft-deleted Key Vault when this behaviour is +enabled within the "features" block (located within the "provider" block) - more +information can be found here: + +https://www.terraform.io/docs/providers/azurerm/index.html#features + +Alternatively you can manually recover this (e.g. using the Azure CLI) and then import +this into Terraform via "terraform import", or pick a different name/location. +`, name, location) +} + +type keyVaultDeletionStatus struct { + deleteDate string + purgeDate string +} + +func getSoftDeletedStateForKeyVault(ctx context.Context, client *keyvault.VaultsClient, name string, location string) (*keyVaultDeletionStatus, error) { + softDel, err := client.GetDeleted(ctx, name, location) + if err != nil { + return nil, err + } + + // we found an existing key vault that is not soft deleted + if softDel.Properties == nil { + return nil, nil + } + + // the logic is this way because the GetDeleted call will return an existing key vault + // that is not soft deleted, but the Deleted Vault properties will be nil + props := *softDel.Properties + + result := keyVaultDeletionStatus{} + if props.DeletionDate != nil { + result.deleteDate = (*props.DeletionDate).Format(time.RFC3339) + } + if props.ScheduledPurgeDate != nil { + result.purgeDate = (*props.ScheduledPurgeDate).Format(time.RFC3339) + } + + if result.deleteDate == "" && result.purgeDate == "" { + return nil, nil + } + + return &result, nil +} diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy.go index e22f0f7ed3579..cda95f3e30c2b 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy.go @@ -3,7 +3,6 @@ package keyvault import ( "fmt" "log" - "regexp" "strings" "time" @@ -39,50 +38,10 @@ func resourceArmKeyVaultAccessPolicy() *schema.Resource { Schema: map[string]*schema.Schema{ "key_vault_id": { - Type: schema.TypeString, - Optional: true, //todo required in 2.0 - Computed: true, //todo removed in 2.0 - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - ConflictsWith: []string{"vault_name"}, - }, - - // todo remove in 2.0 - "vault_name": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - Deprecated: "This property has been deprecated in favour of the key_vault_id property. This will prevent a class of bugs as described in https://github.com/terraform-providers/terraform-provider-azurerm/issues/2396 and will be removed in version 2.0 of the provider", - ValidateFunc: validation.StringIsNotEmpty, - ConflictsWith: []string{"key_vault_id"}, - }, - - // todo remove in 2.0 - "resource_group_name": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - Deprecated: "This property has been deprecated as the resource group is now pulled from the vault ID and will be removed in version 2.0 of the provider", - ValidateFunc: func(v interface{}, k string) (warnings []string, errors []error) { - value := v.(string) - - if len(value) > 80 { - errors = append(errors, fmt.Errorf("%q may not exceed 80 characters in length", k)) - } - - if strings.HasSuffix(value, ".") { - errors = append(errors, fmt.Errorf("%q may not end with a period", k)) - } - - // regex pulled from https://docs.microsoft.com/en-us/rest/api/resources/resourcegroups/createorupdate - if matched := regexp.MustCompile(`^[-\w\._\(\)]+$`).Match([]byte(value)); !matched { - errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters, dash, underscores, parentheses and periods", k)) - } - - return warnings, errors - }, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, }, "tenant_id": { @@ -124,8 +83,6 @@ func resourceArmKeyVaultAccessPolicyCreateOrDelete(d *schema.ResourceData, meta log.Printf("[INFO] Preparing arguments for Key Vault Access Policy: %s.", action) vaultId := d.Get("key_vault_id").(string) - vaultName := d.Get("vault_name").(string) - resourceGroup := d.Get("resource_group_name").(string) tenantIdRaw := d.Get("tenant_id").(string) tenantId, err := uuid.FromString(tenantIdRaw) @@ -136,24 +93,15 @@ func resourceArmKeyVaultAccessPolicyCreateOrDelete(d *schema.ResourceData, meta applicationIdRaw := d.Get("application_id").(string) objectId := d.Get("object_id").(string) - if vaultName == "" { - if vaultId == "" { - return fmt.Errorf("one of `key_vault_id` or `vault_name` must be set") - } - id, err2 := azure.ParseAzureResourceID(vaultId) - if err2 != nil { - return err2 - } - - resourceGroup = id.ResourceGroup + id, err := azure.ParseAzureResourceID(vaultId) + if err != nil { + return err + } - vaultNameTemp, ok := id.Path["vaults"] - if !ok { - return fmt.Errorf("key_value_id does not contain `vaults`: %q", vaultId) - } - vaultName = vaultNameTemp - } else if resourceGroup == "" { - return fmt.Errorf("one of `resource_group_name` must be set when `vault_name` is used") + resourceGroup := id.ResourceGroup + vaultName, ok := id.Path["vaults"] + if !ok { + return fmt.Errorf("key_value_id does not contain `vaults`: %q", vaultId) } keyVault, err := client.Get(ctx, resourceGroup, vaultName) @@ -323,8 +271,6 @@ func resourceArmKeyVaultAccessPolicyRead(d *schema.ResourceData, meta interface{ } d.Set("key_vault_id", resp.ID) - d.Set("vault_name", resp.Name) - d.Set("resource_group_name", resGroup) d.Set("object_id", objectId) if tid := policy.TenantID; tid != nil { diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_certificate.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_certificate.go index 0355f164ba80f..83068b44f346d 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_certificate.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_certificate.go @@ -23,7 +23,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -//todo refactor and find a home for this wayward func +// todo refactor and find a home for this wayward func func resourceArmKeyVaultChildResourceImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { client := meta.(*clients.Client).KeyVault.VaultsClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) @@ -70,23 +70,10 @@ func resourceArmKeyVaultCertificate() *schema.Resource { }, "key_vault_id": { - Type: schema.TypeString, - Optional: true, //todo required in 2.0 - Computed: true, //todo removed in 2.0 - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - ConflictsWith: []string{"vault_uri"}, - }, - - // todo remove in 2.0 - "vault_uri": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - Deprecated: "This property has been deprecated in favour of the key_vault_id property. This will prevent a class of bugs as described in https://github.com/terraform-providers/terraform-provider-azurerm/issues/2396 and will be removed in version 2.0 of the provider", - ValidateFunc: validation.IsURLWithHTTPS, - ConflictsWith: []string{"key_vault_id"}, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, }, "certificate": { @@ -343,7 +330,7 @@ func resourceArmKeyVaultCertificate() *schema.Resource { Computed: true, }, - "tags": tags.Schema(), + "tags": tags.ForceNewSchema(), }, } } @@ -356,25 +343,10 @@ func resourceArmKeyVaultCertificateCreate(d *schema.ResourceData, meta interface name := d.Get("name").(string) keyVaultId := d.Get("key_vault_id").(string) - keyVaultBaseUrl := d.Get("vault_uri").(string) - - if keyVaultBaseUrl == "" { - if keyVaultId == "" { - return fmt.Errorf("one of `key_vault_id` or `vault_uri` must be set") - } - pKeyVaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) - if err != nil { - return fmt.Errorf("Error looking up Certificate %q vault url from id %q: %+v", name, keyVaultId, err) - } - - keyVaultBaseUrl = pKeyVaultBaseUrl - } else { - id, err := azure.GetKeyVaultIDFromBaseUrl(ctx, vaultClient, keyVaultBaseUrl) - if err != nil { - return fmt.Errorf("Error unable to find key vault ID from URL %q for certificate %q: %+v", keyVaultBaseUrl, name, err) - } - d.Set("key_vault_id", id) + keyVaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + return fmt.Errorf("Error looking up Certificate %q vault url from id %q: %+v", name, keyVaultId, err) } if features.ShouldResourcesBeImported() { @@ -497,7 +469,6 @@ func resourceArmKeyVaultCertificateRead(d *schema.ResourceData, meta interface{} } d.Set("name", id.Name) - d.Set("vault_uri", id.KeyVaultBaseUrl) certificatePolicy := flattenKeyVaultCertificatePolicy(cert.Policy) if err := d.Set("certificate_policy", certificatePolicy); err != nil { diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_key.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_key.go index 73dc13da185ef..339960f390a33 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_key.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_key.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" @@ -46,23 +45,10 @@ func resourceArmKeyVaultKey() *schema.Resource { }, "key_vault_id": { - Type: schema.TypeString, - Optional: true, //todo required in 2.0 - Computed: true, //todo removed in 2.0 - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - ConflictsWith: []string{"vault_uri"}, - }, - - // todo remove in 2.0 - "vault_uri": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - Deprecated: "This property has been deprecated in favour of the key_vault_id property. This will prevent a class of bugs as described in https://github.com/terraform-providers/terraform-provider-azurerm/issues/2396 and will be removed in version 2.0 of the provider", - ValidateFunc: validation.IsURLWithHTTPS, - ConflictsWith: []string{"key_vault_id"}, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, }, "key_type": { @@ -126,13 +112,13 @@ func resourceArmKeyVaultKey() *schema.Resource { "not_before_date": { Type: schema.TypeString, Optional: true, - ValidateFunc: validate.RFC3339Time, + ValidateFunc: validation.IsRFC3339Time, }, "expiration_date": { Type: schema.TypeString, Optional: true, - ValidateFunc: validate.RFC3339Time, + ValidateFunc: validation.IsRFC3339Time, }, // Computed @@ -174,26 +160,11 @@ func resourceArmKeyVaultKeyCreate(d *schema.ResourceData, meta interface{}) erro log.Print("[INFO] preparing arguments for AzureRM KeyVault Key creation.") name := d.Get("name").(string) - keyVaultBaseUri := d.Get("vault_uri").(string) keyVaultId := d.Get("key_vault_id").(string) - if keyVaultBaseUri == "" { - if keyVaultId == "" { - return fmt.Errorf("one of `key_vault_id` or `vault_uri` must be set") - } - - pKeyVaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) - if err != nil { - return fmt.Errorf("Error looking up Key %q vault url from id %q: %+v", name, keyVaultId, err) - } - - keyVaultBaseUri = pKeyVaultBaseUrl - } else { - id, err := azure.GetKeyVaultIDFromBaseUrl(ctx, vaultClient, keyVaultBaseUri) - if err != nil { - return fmt.Errorf("Error unable to find key vault ID from URL %q for certificate %q: %+v", keyVaultBaseUri, name, err) - } - d.Set("key_vault_id", id) + keyVaultBaseUri, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + return fmt.Errorf("Error looking up Key %q vault url from id %q: %+v", name, keyVaultId, err) } if features.ShouldResourcesBeImported() { @@ -239,13 +210,13 @@ func resourceArmKeyVaultKeyCreate(d *schema.ResourceData, meta interface{}) erro // https://github.com/Azure/azure-rest-api-specs/issues/1739#issuecomment-332236257 if v, ok := d.GetOk("not_before_date"); ok { - notBeforeDate, _ := time.Parse(time.RFC3339, v.(string)) //validated by schema + notBeforeDate, _ := time.Parse(time.RFC3339, v.(string)) // validated by schema notBeforeUnixTime := date.UnixTime(notBeforeDate) parameters.KeyAttributes.NotBefore = ¬BeforeUnixTime } if v, ok := d.GetOk("expiration_date"); ok { - expirationDate, _ := time.Parse(time.RFC3339, v.(string)) //validated by schema + expirationDate, _ := time.Parse(time.RFC3339, v.(string)) // validated by schema expirationUnixTime := date.UnixTime(expirationDate) parameters.KeyAttributes.Expires = &expirationUnixTime } @@ -306,13 +277,13 @@ func resourceArmKeyVaultKeyUpdate(d *schema.ResourceData, meta interface{}) erro } if v, ok := d.GetOk("not_before_date"); ok { - notBeforeDate, _ := time.Parse(time.RFC3339, v.(string)) //validated by schema + notBeforeDate, _ := time.Parse(time.RFC3339, v.(string)) // validated by schema notBeforeUnixTime := date.UnixTime(notBeforeDate) parameters.KeyAttributes.NotBefore = ¬BeforeUnixTime } if v, ok := d.GetOk("expiration_date"); ok { - expirationDate, _ := time.Parse(time.RFC3339, v.(string)) //validated by schema + expirationDate, _ := time.Parse(time.RFC3339, v.(string)) // validated by schema expirationUnixTime := date.UnixTime(expirationDate) parameters.KeyAttributes.Expires = &expirationUnixTime } @@ -367,7 +338,7 @@ func resourceArmKeyVaultKeyRead(d *schema.ResourceData, meta interface{}) error } d.Set("name", id.Name) - d.Set("vault_uri", id.KeyVaultBaseUrl) + if key := resp.Key; key != nil { d.Set("key_type", string(key.Kty)) diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_migration.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_migration.go index 5e5930a0d2a4c..f3dff4890ebea 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_migration.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_migration.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func ResourceAzureRMKeyVaultMigrateState(v int, is *terraform.InstanceState, _ interface{}) (*terraform.InstanceState, error) { +func resourceAzureRMKeyVaultMigrateState(v int, is *terraform.InstanceState, _ interface{}) (*terraform.InstanceState, error) { switch v { case 0: log.Println("[INFO] Found AzureRM Key Vault State v0; migrating to v1") diff --git a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_migration_test.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_migration_test.go similarity index 98% rename from azurerm/internal/services/keyvault/tests/resource_arm_key_vault_migration_test.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault_migration_test.go index 97a6998d2bf2c..34b92ff2b0b83 100644 --- a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_migration_test.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_migration_test.go @@ -1,14 +1,13 @@ -package tests +package keyvault import ( "reflect" "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault" ) -func TestAzureRMKeyVaultMigrateState(t *testing.T) { +func TestKeyVaultMigrateState(t *testing.T) { cases := map[string]struct { StateVersion int ID string @@ -366,7 +365,7 @@ func TestAzureRMKeyVaultMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.Attributes, } - is, err := keyvault.ResourceAzureRMKeyVaultMigrateState(tc.StateVersion, is, tc.Meta) + is, err := resourceAzureRMKeyVaultMigrateState(tc.StateVersion, is, tc.Meta) if err != nil { t.Fatalf("bad: %q, err: %+v", tn, err) diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_secret.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_secret.go index 1cc2f655ab7e1..76342089bc897 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_secret.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_secret.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" @@ -45,23 +44,10 @@ func resourceArmKeyVaultSecret() *schema.Resource { }, "key_vault_id": { - Type: schema.TypeString, - Optional: true, //todo required in 2.0 - Computed: true, //todo removed in 2.0 - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - ConflictsWith: []string{"vault_uri"}, - }, - - // todo remove in 2.0 - "vault_uri": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Computed: true, - Deprecated: "This property has been deprecated in favour of the key_vault_id property. This will prevent a class of bugs as described in https://github.com/terraform-providers/terraform-provider-azurerm/issues/2396 and will be removed in version 2.0 of the provider", - ValidateFunc: validation.IsURLWithHTTPS, - ConflictsWith: []string{"key_vault_id"}, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, }, "value": { @@ -78,13 +64,13 @@ func resourceArmKeyVaultSecret() *schema.Resource { "not_before_date": { Type: schema.TypeString, Optional: true, - ValidateFunc: validate.RFC3339Time, + ValidateFunc: validation.IsRFC3339Time, }, "expiration_date": { Type: schema.TypeString, Optional: true, - ValidateFunc: validate.RFC3339Time, + ValidateFunc: validation.IsRFC3339Time, }, "version": { @@ -106,26 +92,11 @@ func resourceArmKeyVaultSecretCreate(d *schema.ResourceData, meta interface{}) e log.Print("[INFO] preparing arguments for AzureRM KeyVault Secret creation.") name := d.Get("name").(string) - keyVaultBaseUrl := d.Get("vault_uri").(string) keyVaultId := d.Get("key_vault_id").(string) - if keyVaultBaseUrl == "" { - if keyVaultId == "" { - return fmt.Errorf("one of `key_vault_id` or `vault_uri` must be set") - } - - pKeyVaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) - if err != nil { - return fmt.Errorf("Error looking up Secret %q vault url from id %q: %+v", name, keyVaultId, err) - } - - keyVaultBaseUrl = pKeyVaultBaseUrl - } else { - id, err := azure.GetKeyVaultIDFromBaseUrl(ctx, vaultClient, keyVaultBaseUrl) - if err != nil { - return fmt.Errorf("Error unable to find key vault ID from URL %q for certificate %q: %+v", keyVaultBaseUrl, name, err) - } - d.Set("key_vault_id", id) + keyVaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + return fmt.Errorf("Error looking up Secret %q vault url from id %q: %+v", name, keyVaultId, err) } if features.ShouldResourcesBeImported() { @@ -153,13 +124,13 @@ func resourceArmKeyVaultSecretCreate(d *schema.ResourceData, meta interface{}) e } if v, ok := d.GetOk("not_before_date"); ok { - notBeforeDate, _ := time.Parse(time.RFC3339, v.(string)) //validated by schema + notBeforeDate, _ := time.Parse(time.RFC3339, v.(string)) // validated by schema notBeforeUnixTime := date.UnixTime(notBeforeDate) parameters.SecretAttributes.NotBefore = ¬BeforeUnixTime } if v, ok := d.GetOk("expiration_date"); ok { - expirationDate, _ := time.Parse(time.RFC3339, v.(string)) //validated by schema + expirationDate, _ := time.Parse(time.RFC3339, v.(string)) // validated by schema expirationUnixTime := date.UnixTime(expirationDate) parameters.SecretAttributes.Expires = &expirationUnixTime } @@ -219,13 +190,13 @@ func resourceArmKeyVaultSecretUpdate(d *schema.ResourceData, meta interface{}) e secretAttributes := &keyvault.SecretAttributes{} if v, ok := d.GetOk("not_before_date"); ok { - notBeforeDate, _ := time.Parse(time.RFC3339, v.(string)) //validated by schema + notBeforeDate, _ := time.Parse(time.RFC3339, v.(string)) // validated by schema notBeforeUnixTime := date.UnixTime(notBeforeDate) secretAttributes.NotBefore = ¬BeforeUnixTime } if v, ok := d.GetOk("expiration_date"); ok { - expirationDate, _ := time.Parse(time.RFC3339, v.(string)) //validated by schema + expirationDate, _ := time.Parse(time.RFC3339, v.(string)) // validated by schema expirationUnixTime := date.UnixTime(expirationDate) secretAttributes.Expires = &expirationUnixTime } @@ -319,7 +290,6 @@ func resourceArmKeyVaultSecretRead(d *schema.ResourceData, meta interface{}) err } d.Set("name", respID.Name) - d.Set("vault_uri", respID.KeyVaultBaseUrl) d.Set("value", resp.Value) d.Set("version", respID.Version) d.Set("content_type", resp.ContentType) diff --git a/azurerm/internal/services/keyvault/tests/data_source_key_vault_access_policy_test.go b/azurerm/internal/services/keyvault/tests/data_source_key_vault_access_policy_test.go index 6e55a259b7a6c..3cb57a24ec93d 100644 --- a/azurerm/internal/services/keyvault/tests/data_source_key_vault_access_policy_test.go +++ b/azurerm/internal/services/keyvault/tests/data_source_key_vault_access_policy_test.go @@ -136,6 +136,10 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_keySecretCertificate(t *testin func testAccDataSourceKeyVaultAccessPolicy(name string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_key_vault_access_policy" "test" { name = "%s" } diff --git a/azurerm/internal/services/keyvault/tests/data_source_key_vault_key_test.go b/azurerm/internal/services/keyvault/tests/data_source_key_vault_key_test.go index 0221cc88cac5f..9ed685fdccd1f 100644 --- a/azurerm/internal/services/keyvault/tests/data_source_key_vault_key_test.go +++ b/azurerm/internal/services/keyvault/tests/data_source_key_vault_key_test.go @@ -33,8 +33,8 @@ func testAccDataSourceKeyVaultKey_complete(data acceptance.TestData) string { %s data "azurerm_key_vault_key" "test" { - name = "${azurerm_key_vault_key.test.name}" - key_vault_id = "${azurerm_key_vault.test.id}" + name = azurerm_key_vault_key.test.name + key_vault_id = azurerm_key_vault.test.id } `, t) } diff --git a/azurerm/internal/services/keyvault/tests/data_source_key_vault_secret_test.go b/azurerm/internal/services/keyvault/tests/data_source_key_vault_secret_test.go index 7d0c43e068383..45f3a5c0434b7 100644 --- a/azurerm/internal/services/keyvault/tests/data_source_key_vault_secret_test.go +++ b/azurerm/internal/services/keyvault/tests/data_source_key_vault_secret_test.go @@ -51,8 +51,8 @@ func testAccDataSourceKeyVaultSecret_basic(data acceptance.TestData) string { %s data "azurerm_key_vault_secret" "test" { - name = "${azurerm_key_vault_secret.test.name}" - key_vault_id = "${azurerm_key_vault.test.id}" + name = azurerm_key_vault_secret.test.name + key_vault_id = azurerm_key_vault.test.id } `, r) } @@ -63,8 +63,8 @@ func testAccDataSourceKeyVaultSecret_complete(data acceptance.TestData) string { %s data "azurerm_key_vault_secret" "test" { - name = "${azurerm_key_vault_secret.test.name}" - key_vault_id = "${azurerm_key_vault.test.id}" + name = azurerm_key_vault_secret.test.name + key_vault_id = azurerm_key_vault.test.id } `, r) } diff --git a/azurerm/internal/services/keyvault/tests/data_source_key_vault_test.go b/azurerm/internal/services/keyvault/tests/data_source_key_vault_test.go index 8953c5d82eff8..600e592c86a79 100644 --- a/azurerm/internal/services/keyvault/tests/data_source_key_vault_test.go +++ b/azurerm/internal/services/keyvault/tests/data_source_key_vault_test.go @@ -33,7 +33,7 @@ func TestAccDataSourceAzureRMKeyVault_basic(t *testing.T) { }) } -func TestAccDataSourceAzureRMKeyVault_basicClassic(t *testing.T) { +func TestAccDataSourceAzureRMKeyVault_complete(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_key_vault", "test") resource.ParallelTest(t, resource.TestCase{ @@ -42,23 +42,24 @@ func TestAccDataSourceAzureRMKeyVault_basicClassic(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMKeyVault_basic(data), + Config: testAccDataSourceAzureRMKeyVault_complete(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMKeyVaultExists(data.ResourceName), resource.TestCheckResourceAttrSet(data.ResourceName, "tenant_id"), - resource.TestCheckResourceAttrSet(data.ResourceName, "sku.0.name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "sku_name"), resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.tenant_id"), resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.object_id"), - resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.key_permissions.0", "create"), - resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.secret_permissions.0", "set"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.key_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.secret_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), ), }, }, }) } -func TestAccDataSourceAzureRMKeyVault_complete(t *testing.T) { +func TestAccDataSourceAzureRMKeyVault_networkAcls(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_key_vault", "test") resource.ParallelTest(t, resource.TestCase{ @@ -67,43 +68,39 @@ func TestAccDataSourceAzureRMKeyVault_complete(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMKeyVault_complete(data), + Config: testAccDataSourceAzureRMKeyVault_networkAcls(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMKeyVaultExists(data.ResourceName), resource.TestCheckResourceAttrSet(data.ResourceName, "tenant_id"), - resource.TestCheckResourceAttrSet(data.ResourceName, "sku.0.name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "sku_name"), resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.tenant_id"), resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.object_id"), - resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.key_permissions.0", "get"), - resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.secret_permissions.0", "get"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.key_permissions.0", "create"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.secret_permissions.0", "set"), + resource.TestCheckResourceAttr(data.ResourceName, "network_acls.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "network_acls.0.default_action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, }) } -func TestAccDataSourceAzureRMKeyVault_networkAcls(t *testing.T) { +func TestAccDataSourceAzureRMKeyVault_softDelete(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_key_vault", "test") - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMKeyVault_networkAcls(data), + Config: testAccDataSourceAzureRMKeyVault_enableSoftDelete(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMKeyVaultExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "tenant_id"), - resource.TestCheckResourceAttrSet(data.ResourceName, "sku.0.name"), - resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.tenant_id"), - resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.object_id"), - resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.key_permissions.0", "create"), - resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.secret_permissions.0", "set"), - resource.TestCheckResourceAttr(data.ResourceName, "network_acls.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "network_acls.0.default_action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "false"), + resource.TestCheckResourceAttrSet(data.ResourceName, "sku_name"), resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, @@ -117,8 +114,8 @@ func testAccDataSourceAzureRMKeyVault_basic(data acceptance.TestData) string { %s data "azurerm_key_vault" "test" { - name = "${azurerm_key_vault.test.name}" - resource_group_name = "${azurerm_key_vault.test.resource_group_name}" + name = azurerm_key_vault.test.name + resource_group_name = azurerm_key_vault.test.resource_group_name } `, r) } @@ -129,8 +126,8 @@ func testAccDataSourceAzureRMKeyVault_complete(data acceptance.TestData) string %s data "azurerm_key_vault" "test" { - name = "${azurerm_key_vault.test.name}" - resource_group_name = "${azurerm_key_vault.test.resource_group_name}" + name = azurerm_key_vault.test.name + resource_group_name = azurerm_key_vault.test.resource_group_name } `, r) } @@ -141,8 +138,20 @@ func testAccDataSourceAzureRMKeyVault_networkAcls(data acceptance.TestData) stri %s data "azurerm_key_vault" "test" { - name = "${azurerm_key_vault.test.name}" - resource_group_name = "${azurerm_key_vault.test.resource_group_name}" + name = azurerm_key_vault.test.name + resource_group_name = azurerm_key_vault.test.resource_group_name +} +`, r) +} + +func testAccDataSourceAzureRMKeyVault_enableSoftDelete(data acceptance.TestData) string { + r := testAccAzureRMKeyVault_softDelete(data, true) + return fmt.Sprintf(` +%s + +data "azurerm_key_vault" "test" { + name = azurerm_key_vault.test.name + resource_group_name = azurerm_key_vault.test.resource_group_name } `, r) } diff --git a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_access_policy_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_access_policy_test.go index 41161a553330b..c98e88ea6b535 100644 --- a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_access_policy_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_access_policy_test.go @@ -37,28 +37,6 @@ func TestAccAzureRMKeyVaultAccessPolicy_basic(t *testing.T) { }) } -func TestAccAzureRMKeyVaultAccessPolicy_basicClassic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_key_vault_access_policy", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKeyVaultDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMKeyVaultAccessPolicy_basicClassic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultAccessPolicyExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.0", "get"), - resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.0", "get"), - resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.1", "set"), - ), - }, - data.ImportStep(), - }, - }) -} - func TestAccAzureRMKeyVaultAccessPolicy_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -223,7 +201,7 @@ func testAccAzureRMKeyVaultAccessPolicy_basic(data acceptance.TestData) string { %s resource "azurerm_key_vault_access_policy" "test" { - key_vault_id = "${azurerm_key_vault.test.id}" + key_vault_id = azurerm_key_vault.test.id key_permissions = [ "get", @@ -234,32 +212,8 @@ resource "azurerm_key_vault_access_policy" "test" { "set", ] - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" -} -`, template) -} - -func testAccAzureRMKeyVaultAccessPolicy_basicClassic(data acceptance.TestData) string { - template := testAccAzureRMKeyVaultAccessPolicy_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_key_vault_access_policy" "test" { - vault_name = "${azurerm_key_vault.test.name}" - resource_group_name = "${azurerm_key_vault.test.resource_group_name}" - - key_permissions = [ - "get", - ] - - secret_permissions = [ - "get", - "set", - ] - - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id } `, template) } @@ -270,9 +224,9 @@ func testAccAzureRMKeyVaultAccessPolicy_requiresImport(data acceptance.TestData) %s resource "azurerm_key_vault_access_policy" "import" { - key_vault_id = "${azurerm_key_vault.test.id}" - tenant_id = "${azurerm_key_vault_access_policy.test.tenant_id}" - object_id = "${azurerm_key_vault_access_policy.test.object_id}" + key_vault_id = azurerm_key_vault.test.id + tenant_id = azurerm_key_vault_access_policy.test.tenant_id + object_id = azurerm_key_vault_access_policy.test.object_id key_permissions = [ "get", @@ -292,7 +246,7 @@ func testAccAzureRMKeyVaultAccessPolicy_multiple(data acceptance.TestData) strin %s resource "azurerm_key_vault_access_policy" "test_with_application_id" { - key_vault_id = "${azurerm_key_vault.test.id}" + key_vault_id = azurerm_key_vault.test.id key_permissions = [ "create", @@ -309,13 +263,13 @@ resource "azurerm_key_vault_access_policy" "test_with_application_id" { "delete", ] - application_id = "${data.azurerm_client_config.current.service_principal_application_id}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + application_id = data.azurerm_client_config.current.client_id + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id } resource "azurerm_key_vault_access_policy" "test_no_application_id" { - key_vault_id = "${azurerm_key_vault.test.id}" + key_vault_id = azurerm_key_vault.test.id key_permissions = [ "list", @@ -349,8 +303,8 @@ resource "azurerm_key_vault_access_policy" "test_no_application_id" { "update", ] - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id } `, template) } @@ -361,8 +315,7 @@ func testAccAzureRMKeyVaultAccessPolicy_update(data acceptance.TestData) string %s resource "azurerm_key_vault_access_policy" "test" { - vault_name = "${azurerm_key_vault.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + key_vault_id = azurerm_key_vault.test.id key_permissions = [ "list", @@ -371,15 +324,20 @@ resource "azurerm_key_vault_access_policy" "test" { secret_permissions = [] - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id } `, template) } func testAccAzureRMKeyVaultAccessPolicy_template(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -388,9 +346,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" @@ -403,7 +361,12 @@ resource "azurerm_key_vault" "test" { func testAccAzureRMKeyVaultAccessPolicy_nonExistentVault(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -412,9 +375,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "standard" @@ -427,8 +390,8 @@ resource "azurerm_key_vault_access_policy" "test" { # Must appear to be URL, but not actually exist - appending a string works key_vault_id = "${azurerm_key_vault.test.id}NOPE" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "get", diff --git a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_certificate_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_certificate_test.go index 41d67eb2af812..9fd4acf4be8d6 100644 --- a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_certificate_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_certificate_test.go @@ -35,26 +35,6 @@ func TestAccAzureRMKeyVaultCertificate_basicImportPFX(t *testing.T) { }) } -func TestAccAzureRMKeyVaultCertificate_basicImportPFXClassic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_key_vault_certificate", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKeyVaultCertificateDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMKeyVaultCertificate_basicImportPFXClassic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultCertificateExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "certificate_data"), - ), - }, - data.ImportStep("certificate"), - }, - }) -} - func TestAccAzureRMKeyVaultCertificate_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -233,6 +213,7 @@ func TestAccAzureRMKeyVaultCertificate_emptyExtendedKeyUsage(t *testing.T) { func testCheckAzureRMKeyVaultCertificateDestroy(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.ManagementClient + vaultClient := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext for _, rs := range s.RootModule().Resources { @@ -241,8 +222,12 @@ func testCheckAzureRMKeyVaultCertificateDestroy(s *terraform.State) error { } name := rs.Primary.Attributes["name"] - vaultBaseUrl := rs.Primary.Attributes["vault_uri"] keyVaultId := rs.Primary.Attributes["key_vault_id"] + vaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + // deleted, this is fine. + return nil + } ok, err := azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) if err != nil { @@ -271,6 +256,7 @@ func testCheckAzureRMKeyVaultCertificateDestroy(s *terraform.State) error { func testCheckAzureRMKeyVaultCertificateExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.ManagementClient + vaultClient := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext // Ensure we have enough information in state to look up in API @@ -280,10 +266,13 @@ func testCheckAzureRMKeyVaultCertificateExists(resourceName string) resource.Tes } name := rs.Primary.Attributes["name"] - vaultBaseUrl := rs.Primary.Attributes["vault_uri"] keyVaultId := rs.Primary.Attributes["key_vault_id"] + vaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + return fmt.Errorf("Error looking up Secret %q vault url from id %q: %+v", name, keyVaultId, err) + } - ok, err := azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) + ok, err = azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) if err != nil { return fmt.Errorf("Error checking if key vault %q for Certificate %q in Vault at url %q exists: %v", keyVaultId, name, vaultBaseUrl, err) } @@ -308,6 +297,7 @@ func testCheckAzureRMKeyVaultCertificateExists(resourceName string) resource.Tes func testCheckAzureRMKeyVaultCertificateDisappears(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.ManagementClient + vaultClient := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext // Ensure we have enough information in state to look up in API @@ -316,10 +306,13 @@ func testCheckAzureRMKeyVaultCertificateDisappears(resourceName string) resource return fmt.Errorf("Not found: %s", resourceName) } name := rs.Primary.Attributes["name"] - vaultBaseUrl := rs.Primary.Attributes["vault_uri"] keyVaultId := rs.Primary.Attributes["key_vault_id"] + vaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + return fmt.Errorf("Error looking up Secret %q vault url from id %q: %+v", name, keyVaultId, err) + } - ok, err := azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) + ok, err = azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) if err != nil { return fmt.Errorf("Error checking if key vault %q for Certificate %q in Vault at url %q exists: %v", keyVaultId, name, vaultBaseUrl, err) } @@ -343,74 +336,13 @@ func testCheckAzureRMKeyVaultCertificateDisappears(resourceName string) resource func testAccAzureRMKeyVaultCertificate_basicImportPFX(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_key_vault" "test" { - name = "acctestkeyvault%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - - sku_name = "standard" - - access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" - - certificate_permissions = [ - "delete", - "import", - "get", - ] - - key_permissions = [ - "create", - ] - - secret_permissions = [ - "set", - ] - } +data "azurerm_client_config" "current" { } -resource "azurerm_key_vault_certificate" "test" { - name = "acctestcert%s" - key_vault_id = "${azurerm_key_vault.test.id}" - - certificate { - contents = "${filebase64("testdata/keyvaultcert.pfx")}" - password = "" - } - - certificate_policy { - issuer_parameters { - name = "Self" - } - - key_properties { - exportable = true - key_size = 2048 - key_type = "RSA" - reuse_key = false - } - - secret_properties { - content_type = "application/x-pkcs12" - } - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) -} - -func testAccAzureRMKeyVaultCertificate_basicImportPFXClassic(data acceptance.TestData) string { - return fmt.Sprintf(` -data "azurerm_client_config" "current" {} - resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -418,15 +350,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkeyvault%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "standard" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id certificate_permissions = [ "delete", @@ -441,19 +373,15 @@ resource "azurerm_key_vault" "test" { secret_permissions = [ "set", ] - - storage_permissions = [ - "set", - ] } } resource "azurerm_key_vault_certificate" "test" { - name = "acctestcert%s" - vault_uri = "${azurerm_key_vault.test.vault_uri}" + name = "acctestcert%s" + key_vault_id = azurerm_key_vault.test.id certificate { - contents = "${filebase64("testdata/keyvaultcert.pfx")}" + contents = filebase64("testdata/keyvaultcert.pfx") password = "" } @@ -483,11 +411,11 @@ func testAccAzureRMKeyVaultCertificate_requiresImport(data acceptance.TestData) %s resource "azurerm_key_vault_certificate" "import" { - name = "${azurerm_key_vault_certificate.test.name}" - key_vault_id = "${azurerm_key_vault.test.id}" + name = azurerm_key_vault_certificate.test.name + key_vault_id = azurerm_key_vault.test.id certificate { - contents = "${filebase64("testdata/keyvaultcert.pfx")}" + contents = filebase64("testdata/keyvaultcert.pfx") password = "" } @@ -513,7 +441,12 @@ resource "azurerm_key_vault_certificate" "import" { func testAccAzureRMKeyVaultCertificate_basicGenerate(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -522,15 +455,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkeyvault%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "standard" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id certificate_permissions = [ "create", @@ -555,7 +488,7 @@ resource "azurerm_key_vault" "test" { resource "azurerm_key_vault_certificate" "test" { name = "acctestcert%s" - key_vault_id = "${azurerm_key_vault.test.id}" + key_vault_id = azurerm_key_vault.test.id certificate_policy { issuer_parameters { @@ -603,7 +536,12 @@ resource "azurerm_key_vault_certificate" "test" { func testAccAzureRMKeyVaultCertificate_basicGenerateSans(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -612,15 +550,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkeyvault%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "standard" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id certificate_permissions = [ "create", @@ -645,7 +583,7 @@ resource "azurerm_key_vault" "test" { resource "azurerm_key_vault_certificate" "test" { name = "acctestcert%s" - key_vault_id = "${azurerm_key_vault.test.id}" + key_vault_id = azurerm_key_vault.test.id certificate_policy { issuer_parameters { @@ -700,7 +638,12 @@ resource "azurerm_key_vault_certificate" "test" { func testAccAzureRMKeyVaultCertificate_basicGenerateTags(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -709,15 +652,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkeyvault%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "standard" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id certificate_permissions = [ "create", @@ -738,7 +681,7 @@ resource "azurerm_key_vault" "test" { resource "azurerm_key_vault_certificate" "test" { name = "acctestcert%s" - key_vault_id = "${azurerm_key_vault.test.id}" + key_vault_id = azurerm_key_vault.test.id certificate_policy { issuer_parameters { @@ -790,7 +733,12 @@ resource "azurerm_key_vault_certificate" "test" { func testAccAzureRMKeyVaultCertificate_basicExtendedKeyUsage(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -799,15 +747,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkeyvault%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "standard" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id certificate_permissions = [ "create", @@ -831,8 +779,8 @@ resource "azurerm_key_vault" "test" { } resource "azurerm_key_vault_certificate" "test" { - name = "acctestcert%s" - vault_uri = "${azurerm_key_vault.test.vault_uri}" + name = "acctestcert%s" + key_vault_id = azurerm_key_vault.test.id certificate_policy { issuer_parameters { @@ -886,7 +834,12 @@ resource "azurerm_key_vault_certificate" "test" { func testAccAzureRMKeyVaultCertificate_emptyExtendedKeyUsage(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -895,15 +848,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkeyvault%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "standard" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id certificate_permissions = [ "create", @@ -927,8 +880,8 @@ resource "azurerm_key_vault" "test" { } resource "azurerm_key_vault_certificate" "test" { - name = "acctestcert%s" - vault_uri = "${azurerm_key_vault.test.vault_uri}" + name = "acctestcert%s" + key_vault_id = azurerm_key_vault.test.id certificate_policy { issuer_parameters { diff --git a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_key_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_key_test.go index ec3c7ffc8d9b5..d5630b0a5bfa7 100644 --- a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_key_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_key_test.go @@ -34,25 +34,6 @@ func TestAccAzureRMKeyVaultKey_basicEC(t *testing.T) { }) } -func TestAccAzureRMKeyVaultKey_basicECClassic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_key_vault_key", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKeyVaultKeyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMKeyVaultKey_basicECClassic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultKeyExists(data.ResourceName), - ), - }, - data.ImportStep("key_size"), - }, - }) -} - func TestAccAzureRMKeyVaultKey_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -248,6 +229,7 @@ func TestAccAzureRMKeyVaultKey_disappearsWhenParentKeyVaultDeleted(t *testing.T) func testCheckAzureRMKeyVaultKeyDestroy(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.ManagementClient + vaultClient := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext for _, rs := range s.RootModule().Resources { @@ -256,8 +238,12 @@ func testCheckAzureRMKeyVaultKeyDestroy(s *terraform.State) error { } name := rs.Primary.Attributes["name"] - vaultBaseUrl := rs.Primary.Attributes["vault_uri"] keyVaultId := rs.Primary.Attributes["key_vault_id"] + vaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + // key vault's been deleted + return nil + } ok, err := azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) if err != nil { @@ -286,6 +272,7 @@ func testCheckAzureRMKeyVaultKeyDestroy(s *terraform.State) error { func testCheckAzureRMKeyVaultKeyExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.ManagementClient + vaultClient := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext // Ensure we have enough information in state to look up in API @@ -294,10 +281,13 @@ func testCheckAzureRMKeyVaultKeyExists(resourceName string) resource.TestCheckFu return fmt.Errorf("Not found: %s", resourceName) } name := rs.Primary.Attributes["name"] - vaultBaseUrl := rs.Primary.Attributes["vault_uri"] keyVaultId := rs.Primary.Attributes["key_vault_id"] + vaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + return fmt.Errorf("Error looking up Secret %q vault url from id %q: %+v", name, keyVaultId, err) + } - ok, err := azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) + ok, err = azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) if err != nil { return fmt.Errorf("Error checking if key vault %q for Key %q in Vault at url %q exists: %v", keyVaultId, name, vaultBaseUrl, err) } @@ -322,6 +312,7 @@ func testCheckAzureRMKeyVaultKeyExists(resourceName string) resource.TestCheckFu func testCheckAzureRMKeyVaultKeyDisappears(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.ManagementClient + vaultClient := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext // Ensure we have enough information in state to look up in API @@ -331,10 +322,13 @@ func testCheckAzureRMKeyVaultKeyDisappears(resourceName string) resource.TestChe } name := rs.Primary.Attributes["name"] - vaultBaseUrl := rs.Primary.Attributes["vault_uri"] keyVaultId := rs.Primary.Attributes["key_vault_id"] + vaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + return fmt.Errorf("Error looking up Secret %q vault url from id %q: %+v", name, keyVaultId, err) + } - ok, err := azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) + ok, err = azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) if err != nil { return fmt.Errorf("Error checking if key vault %q for Key %q in Vault at url %q exists: %v", keyVaultId, name, vaultBaseUrl, err) } @@ -358,61 +352,13 @@ func testCheckAzureRMKeyVaultKeyDisappears(resourceName string) resource.TestChe func testAccAzureRMKeyVaultKey_basicEC(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_key_vault" "test" { - name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - - sku_name = "premium" - - access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" - - key_permissions = [ - "create", - "delete", - "get", - ] - - secret_permissions = [ - "get", - "delete", - "set", - ] - } - - tags = { - environment = "Production" - } +data "azurerm_client_config" "current" { } -resource "azurerm_key_vault_key" "test" { - name = "key-%s" - key_vault_id = "${azurerm_key_vault.test.id}" - key_type = "EC" - key_size = 2048 - - key_opts = [ - "sign", - "verify", - ] -} -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) -} - -func testAccAzureRMKeyVaultKey_basicECClassic(data acceptance.TestData) string { - return fmt.Sprintf(` -data "azurerm_client_config" "current" {} - resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -420,15 +366,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", @@ -449,10 +395,10 @@ resource "azurerm_key_vault" "test" { } resource "azurerm_key_vault_key" "test" { - name = "key-%s" - vault_uri = "${azurerm_key_vault.test.vault_uri}" - key_type = "EC" - key_size = 2048 + name = "key-%s" + key_vault_id = azurerm_key_vault.test.id + key_type = "EC" + key_size = 2048 key_opts = [ "sign", @@ -468,8 +414,8 @@ func testAccAzureRMKeyVaultKey_requiresImport(data acceptance.TestData) string { %s resource "azurerm_key_vault_key" "import" { - name = "${azurerm_key_vault_key.test.name}" - key_vault_id = "${azurerm_key_vault.test.id}" + name = azurerm_key_vault_key.test.name + key_vault_id = azurerm_key_vault.test.id key_type = "EC" key_size = 2048 @@ -483,7 +429,12 @@ resource "azurerm_key_vault_key" "import" { func testAccAzureRMKeyVaultKey_basicRSA(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -492,15 +443,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", @@ -523,7 +474,7 @@ resource "azurerm_key_vault" "test" { resource "azurerm_key_vault_key" "test" { name = "key-%s" - key_vault_id = "${azurerm_key_vault.test.id}" + key_vault_id = azurerm_key_vault.test.id key_type = "RSA" key_size = 2048 @@ -541,7 +492,12 @@ resource "azurerm_key_vault_key" "test" { func testAccAzureRMKeyVaultKey_basicRSAHSM(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -550,15 +506,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", @@ -580,7 +536,7 @@ resource "azurerm_key_vault" "test" { resource "azurerm_key_vault_key" "test" { name = "key-%s" - key_vault_id = "${azurerm_key_vault.test.id}" + key_vault_id = azurerm_key_vault.test.id key_type = "RSA-HSM" key_size = 2048 @@ -598,7 +554,12 @@ resource "azurerm_key_vault_key" "test" { func testAccAzureRMKeyVaultKey_complete(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -607,15 +568,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", @@ -637,7 +598,7 @@ resource "azurerm_key_vault" "test" { resource "azurerm_key_vault_key" "test" { name = "key-%s" - key_vault_id = "${azurerm_key_vault.test.id}" + key_vault_id = azurerm_key_vault.test.id key_type = "RSA" key_size = 2048 not_before_date = "2020-01-01T01:02:03Z" @@ -661,7 +622,12 @@ resource "azurerm_key_vault_key" "test" { func testAccAzureRMKeyVaultKey_basicUpdated(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -670,15 +636,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", @@ -700,10 +666,10 @@ resource "azurerm_key_vault" "test" { } resource "azurerm_key_vault_key" "test" { - name = "key-%s" - vault_uri = "${azurerm_key_vault.test.vault_uri}" - key_type = "RSA" - key_size = 2048 + name = "key-%s" + key_vault_id = azurerm_key_vault.test.id + key_type = "RSA" + key_size = 2048 key_opts = [ "encrypt", @@ -718,7 +684,12 @@ resource "azurerm_key_vault_key" "test" { func testAccAzureRMKeyVaultKey_curveEC(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -727,17 +698,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id - sku { - name = "premium" - } + sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", @@ -758,10 +727,10 @@ resource "azurerm_key_vault" "test" { } resource "azurerm_key_vault_key" "test" { - name = "key-%s" - vault_uri = "${azurerm_key_vault.test.vault_uri}" - key_type = "EC" - curve = "P-521" + name = "key-%s" + key_vault_id = azurerm_key_vault.test.id + key_type = "EC" + curve = "P-521" key_opts = [ "sign", @@ -773,7 +742,12 @@ resource "azurerm_key_vault_key" "test" { func testAccAzureRMKeyVaultKey_basicECHSM(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -782,17 +756,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id - sku { - name = "premium" - } + sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", @@ -813,10 +785,10 @@ resource "azurerm_key_vault" "test" { } resource "azurerm_key_vault_key" "test" { - name = "key-%s" - vault_uri = "${azurerm_key_vault.test.vault_uri}" - key_type = "EC-HSM" - curve = "P-521" + name = "key-%s" + key_vault_id = azurerm_key_vault.test.id + key_type = "EC-HSM" + curve = "P-521" key_opts = [ "sign", diff --git a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_secret_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_secret_test.go index 5b2fd6a2d5964..36f0c8b4947aa 100644 --- a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_secret_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_secret_test.go @@ -35,26 +35,6 @@ func TestAccAzureRMKeyVaultSecret_basic(t *testing.T) { }) } -func TestAccAzureRMKeyVaultSecret_basicClassic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_key_vault_secret", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKeyVaultSecretDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMKeyVaultSecret_basicClasic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultSecretExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "value", "rick-and-morty"), - ), - }, - data.ImportStep(), - }, - }) -} - func TestAccAzureRMKeyVaultSecret_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -174,6 +154,7 @@ func TestAccAzureRMKeyVaultSecret_update(t *testing.T) { func testCheckAzureRMKeyVaultSecretDestroy(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.ManagementClient + vaultClient := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext for _, rs := range s.RootModule().Resources { @@ -182,8 +163,12 @@ func testCheckAzureRMKeyVaultSecretDestroy(s *terraform.State) error { } name := rs.Primary.Attributes["name"] - vaultBaseUrl := rs.Primary.Attributes["vault_uri"] keyVaultId := rs.Primary.Attributes["key_vault_id"] + vaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + // key vault's been deleted + return nil + } ok, err := azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) if err != nil { @@ -212,6 +197,7 @@ func testCheckAzureRMKeyVaultSecretDestroy(s *terraform.State) error { func testCheckAzureRMKeyVaultSecretExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.ManagementClient + vaultClient := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext // Ensure we have enough information in state to look up in API @@ -220,10 +206,13 @@ func testCheckAzureRMKeyVaultSecretExists(resourceName string) resource.TestChec return fmt.Errorf("Not found: %s", resourceName) } name := rs.Primary.Attributes["name"] - vaultBaseUrl := rs.Primary.Attributes["vault_uri"] keyVaultId := rs.Primary.Attributes["key_vault_id"] + vaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + return fmt.Errorf("Error looking up Secret %q vault url from id %q: %+v", name, keyVaultId, err) + } - ok, err := azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) + ok, err = azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) if err != nil { return fmt.Errorf("Error checking if key vault %q for Secret %q in Vault at url %q exists: %v", keyVaultId, name, vaultBaseUrl, err) } @@ -248,6 +237,7 @@ func testCheckAzureRMKeyVaultSecretExists(resourceName string) resource.TestChec func testCheckAzureRMKeyVaultSecretDisappears(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.ManagementClient + vaultClient := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext // Ensure we have enough information in state to look up in API @@ -256,10 +246,13 @@ func testCheckAzureRMKeyVaultSecretDisappears(resourceName string) resource.Test return fmt.Errorf("Not found: %s", resourceName) } name := rs.Primary.Attributes["name"] - vaultBaseUrl := rs.Primary.Attributes["vault_uri"] keyVaultId := rs.Primary.Attributes["key_vault_id"] + vaultBaseUrl, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultClient, keyVaultId) + if err != nil { + return fmt.Errorf("Error looking up Secret %q vault url from id %q: %+v", name, keyVaultId, err) + } - ok, err := azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) + ok, err = azure.KeyVaultExists(ctx, acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient, keyVaultId) if err != nil { return fmt.Errorf("Error checking if key vault %q for Secret %q in Vault at url %q exists: %v", keyVaultId, name, vaultBaseUrl, err) } @@ -283,52 +276,12 @@ func testCheckAzureRMKeyVaultSecretDisappears(resourceName string) resource.Test func testAccAzureRMKeyVaultSecret_basic(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_key_vault" "test" { - name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - - sku_name = "premium" - - access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" - - key_permissions = [ - "get", - ] - - secret_permissions = [ - "get", - "delete", - "set", - ] - } - - tags = { - environment = "Production" - } +provider "azurerm" { + features {} } -resource "azurerm_key_vault_secret" "test" { - name = "secret-%s" - value = "rick-and-morty" - key_vault_id = "${azurerm_key_vault.test.id}" +data "azurerm_client_config" "current" { } -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) -} - -func testAccAzureRMKeyVaultSecret_basicClasic(data acceptance.TestData) string { - return fmt.Sprintf(` -data "azurerm_client_config" "current" {} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -337,15 +290,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "get", @@ -364,9 +317,9 @@ resource "azurerm_key_vault" "test" { } resource "azurerm_key_vault_secret" "test" { - name = "secret-%s" - value = "rick-and-morty" - vault_uri = "${azurerm_key_vault.test.vault_uri}" + name = "secret-%s" + value = "rick-and-morty" + key_vault_id = azurerm_key_vault.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } @@ -377,16 +330,21 @@ func testAccAzureRMKeyVaultSecret_requiresImport(data acceptance.TestData) strin %s resource "azurerm_key_vault_secret" "import" { - name = "${azurerm_key_vault_secret.test.name}" - value = "${azurerm_key_vault_secret.test.value}" - key_vault_id = "${azurerm_key_vault_secret.test.key_vault_id}" + name = azurerm_key_vault_secret.test.name + value = azurerm_key_vault_secret.test.value + key_vault_id = azurerm_key_vault_secret.test.key_vault_id } `, template) } func testAccAzureRMKeyVaultSecret_complete(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -395,15 +353,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", @@ -424,7 +382,7 @@ resource "azurerm_key_vault" "test" { resource "azurerm_key_vault_secret" "test" { name = "secret-%s" value = "" - key_vault_id = "${azurerm_key_vault.test.id}" + key_vault_id = azurerm_key_vault.test.id content_type = "application/xml" not_before_date = "2019-01-01T01:02:03Z" expiration_date = "2020-01-01T01:02:03Z" @@ -438,7 +396,12 @@ resource "azurerm_key_vault_secret" "test" { func testAccAzureRMKeyVaultSecret_basicUpdated(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -447,15 +410,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "acctestkv-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.service_principal_object_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id key_permissions = [ "create", @@ -474,9 +437,9 @@ resource "azurerm_key_vault" "test" { } resource "azurerm_key_vault_secret" "test" { - name = "secret-%s" - value = "szechuan" - vault_uri = "${azurerm_key_vault.test.vault_uri}" + name = "secret-%s" + value = "szechuan" + key_vault_id = azurerm_key_vault.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } diff --git a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_test.go index b4d595382d5ba..c201a4a38cc1f 100644 --- a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_test.go @@ -11,67 +11,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAccAzureRMKeyVault_name(t *testing.T) { - cases := []struct { - Input string - ExpectError bool - }{ - { - Input: "", - ExpectError: true, - }, - { - Input: "hi", - ExpectError: true, - }, - { - Input: "hello", - ExpectError: false, - }, - { - Input: "hello-world", - ExpectError: false, - }, - { - Input: "hello-world-21", - ExpectError: false, - }, - { - Input: "hello_world_21", - ExpectError: true, - }, - { - Input: "Hello-World", - ExpectError: false, - }, - { - Input: "20202020", - ExpectError: false, - }, - { - Input: "ABC123!@£", - ExpectError: true, - }, - { - Input: "abcdefghijklmnopqrstuvwxyz", - ExpectError: true, - }, - } - - for _, tc := range cases { - _, errors := keyvault.ValidateKeyVaultName(tc.Input, "") - - hasError := len(errors) > 0 - if tc.ExpectError && !hasError { - t.Fatalf("Expected the Key Vault Name to trigger a validation error for '%s'", tc.Input) - } - } -} - func TestAccAzureRMKeyVault_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") @@ -92,44 +34,6 @@ func TestAccAzureRMKeyVault_basic(t *testing.T) { }) } -// Remove in 2.0 -func TestAccAzureRMKeyVault_basicNotDefined(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKeyVaultDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMKeyVault_basicNotDefined(data), - ExpectError: regexp.MustCompile("either 'sku_name' or 'sku' must be defined in the configuration file"), - }, - }, - }) -} - -// Remove in 2.0 -func TestAccAzureRMKeyVault_basicClassic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKeyVaultDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMKeyVault_basicClassic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "premium"), - ), - }, - data.ImportStep(), - }, - }) -} - func TestAccAzureRMKeyVault_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -331,6 +235,246 @@ func TestAccAzureRMKeyVault_justCert(t *testing.T) { }) } +func TestAccAzureRMKeyVault_softDeleteEnabled(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMKeyVault_softDelete(data, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "false"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMKeyVault_softDeleteViaUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMKeyVault_softDelete(data, false), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "false"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMKeyVault_softDelete(data, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "false"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMKeyVault_softDeleteAttemptToDisable(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMKeyVault_softDelete(data, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "false"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMKeyVault_softDelete(data, false), + ExpectError: regexp.MustCompile("once Soft Delete has been Enabled it's not possible to disable it"), + }, + }, + }) +} + +func TestAccAzureRMKeyVault_softDeleteRecovery(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + // create it regularly + Config: testAccAzureRMKeyVault_softDelete(data, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "false"), + ), + }, + data.ImportStep(), + { + // delete the key vault + Config: testAccAzureRMKeyVault_softDeleteAbsent(data), + }, + { + // attempting to re-create it requires recovery, which is enabled by default + Config: testAccAzureRMKeyVault_softDelete(data, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "false"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMKeyVault_softDeleteRecoveryDisabled(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + // create it regularly + Config: testAccAzureRMKeyVault_softDeleteRecoveryDisabled(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "false"), + ), + }, + data.ImportStep(), + { + // delete the key vault + Config: testAccAzureRMKeyVault_softDeleteAbsent(data), + }, + { + // attempting to re-create it requires recovery, which is enabled by default + Config: testAccAzureRMKeyVault_softDeleteRecoveryDisabled(data), + ExpectError: regexp.MustCompile("An existing soft-deleted Key Vault exists with the Name"), + }, + }, + }) +} + +func TestAccAzureRMKeyVault_purgeProtectionEnabled(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMKeyVault_purgeProtection(data, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "false"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMKeyVault_purgeProtectionAndSoftDeleteEnabled(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMKeyVault_purgeProtectionAndSoftDelete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "true"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMKeyVault_purgeProtectionViaUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMKeyVault_purgeProtection(data, false), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "false"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMKeyVault_purgeProtection(data, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "false"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMKeyVault_purgeProtectionAttemptToDisable(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMKeyVault_purgeProtection(data, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "purge_protection_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_enabled", "false"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMKeyVault_purgeProtection(data, false), + ExpectError: regexp.MustCompile("once Purge Protection has been Enabled it's not possible to disable it"), + }, + }, + }) +} + func testCheckAzureRMKeyVaultDestroy(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).KeyVault.VaultsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -419,71 +563,12 @@ func testCheckAzureRMKeyVaultDisappears(resourceName string) resource.TestCheckF func testAccAzureRMKeyVault_basic(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_key_vault" "test" { - name = "vault%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - - sku_name = "premium" - - access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.client_id}" - - key_permissions = [ - "create", - ] - - secret_permissions = [ - "set", - ] - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMKeyVault_basicNotDefined(data acceptance.TestData) string { - return fmt.Sprintf(` -data "azurerm_client_config" "current" {} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_key_vault" "test" { - name = "vault%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - - access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.client_id}" - - key_permissions = [ - "create", - ] - - secret_permissions = [ - "set", - ] - } +data "azurerm_client_config" "current" { } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMKeyVault_basicClassic(data acceptance.TestData) string { - return fmt.Sprintf(` -data "azurerm_client_config" "current" {} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -492,17 +577,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "vault%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id - sku { - name = "premium" - } + sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.client_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.client_id key_permissions = [ "create", @@ -522,16 +605,16 @@ func testAccAzureRMKeyVault_requiresImport(data acceptance.TestData) string { %s resource "azurerm_key_vault" "import" { - name = "${azurerm_key_vault.test.name}" - location = "${azurerm_key_vault.test.location}" - resource_group_name = "${azurerm_key_vault.test.resource_group_name}" - tenant_id = "${azurerm_key_vault.test.tenant_id}" + name = azurerm_key_vault.test.name + location = azurerm_key_vault.test.location + resource_group_name = azurerm_key_vault.test.resource_group_name + tenant_id = azurerm_key_vault.test.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.client_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.client_id key_permissions = [ "create", @@ -547,7 +630,12 @@ resource "azurerm_key_vault" "import" { func testAccAzureRMKeyVault_networkAclsTemplate(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -557,22 +645,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test_a" { name = "acctestsubneta%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" service_endpoints = ["Microsoft.KeyVault"] } resource "azurerm_subnet" "test_b" { name = "acctestsubnetb%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.4.0/24" service_endpoints = ["Microsoft.KeyVault"] } @@ -586,15 +674,15 @@ func testAccAzureRMKeyVault_networkAcls(data acceptance.TestData) string { resource "azurerm_key_vault" "test" { name = "vault%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.client_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.client_id key_permissions = [ "create", @@ -608,7 +696,7 @@ resource "azurerm_key_vault" "test" { network_acls { default_action = "Deny" bypass = "None" - virtual_network_subnet_ids = ["${azurerm_subnet.test_a.id}", "${azurerm_subnet.test_b.id}"] + virtual_network_subnet_ids = [azurerm_subnet.test_a.id, azurerm_subnet.test_b.id] } } `, template, data.RandomInteger) @@ -621,15 +709,15 @@ func testAccAzureRMKeyVault_networkAclsUpdated(data acceptance.TestData) string resource "azurerm_key_vault" "test" { name = "vault%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.client_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.client_id key_permissions = [ "create", @@ -644,7 +732,7 @@ resource "azurerm_key_vault" "test" { default_action = "Allow" bypass = "AzureServices" ip_rules = ["123.0.0.102/32"] - virtual_network_subnet_ids = ["${azurerm_subnet.test_a.id}"] + virtual_network_subnet_ids = [azurerm_subnet.test_a.id] } } `, template, data.RandomInteger) @@ -657,15 +745,15 @@ func testAccAzureRMKeyVault_networkAclsAllowed(data acceptance.TestData) string resource "azurerm_key_vault" "test" { name = "vault%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.client_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.client_id key_permissions = [ "create", @@ -686,7 +774,12 @@ resource "azurerm_key_vault" "test" { func testAccAzureRMKeyVault_update(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -695,15 +788,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "vault%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.client_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.client_id key_permissions = [ "get", @@ -727,7 +820,12 @@ resource "azurerm_key_vault" "test" { func testAccAzureRMKeyVault_noAccessPolicyBlocks(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -736,13 +834,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "vault%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id - sku { - name = "premium" - } + sku_name = "premium" enabled_for_deployment = true enabled_for_disk_encryption = true @@ -757,7 +853,12 @@ resource "azurerm_key_vault" "test" { func testAccAzureRMKeyVault_accessPolicyExplicitZero(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -766,13 +867,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "vault%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id - sku { - name = "premium" - } + sku_name = "premium" access_policy = [] @@ -789,7 +888,12 @@ resource "azurerm_key_vault" "test" { func testAccAzureRMKeyVault_complete(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -798,16 +902,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "vault%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.client_id}" - application_id = "${data.azurerm_client_config.current.service_principal_application_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.client_id + application_id = data.azurerm_client_config.current.client_id certificate_permissions = [ "get", @@ -831,7 +935,12 @@ resource "azurerm_key_vault" "test" { func testAccAzureRMKeyVault_justCert(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -840,15 +949,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "vault%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" - object_id = "${data.azurerm_client_config.current.client_id}" + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.client_id certificate_permissions = [ "get", @@ -868,7 +977,12 @@ func testAccAzureRMKeyVault_accessPolicyUpperLimit(data acceptance.TestData) str } return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -877,25 +991,28 @@ resource "azurerm_resource_group" "test" { resource "azurerm_key_vault" "test" { name = "vault%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "premium" %s } %s - `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, accessPoliciesConfigs, storageAccountConfigs) } func testAccAzureRMKeyVault_generateStorageAccountConfigs(accountNum int, rs string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_storage_account" "test%d" { name = "testsa%s%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "GRS" @@ -922,7 +1039,7 @@ func testAccAzureRMKeyVault_generateAccessPolicyConfigs(accountNum int) string { return fmt.Sprintf(` access_policy { - tenant_id = "${data.azurerm_client_config.current.tenant_id}" + tenant_id = data.azurerm_client_config.current.tenant_id object_id = "%s" key_permissions = ["get", "create", "delete", "list", "restore", "recover", "unwrapkey", "wrapkey", "purge", "encrypt", "decrypt", "sign", "verify"] @@ -930,3 +1047,125 @@ access_policy { } `, oid) } + +func testAccAzureRMKeyVault_purgeProtection(data acceptance.TestData, enabled bool) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" {} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_key_vault" "test" { + name = "vault%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id + sku_name = "premium" + purge_protection_enabled = %t +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, enabled) +} + +func testAccAzureRMKeyVault_softDelete(data acceptance.TestData, enabled bool) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_key_vault" "test" { + name = "vault%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id + sku_name = "premium" + soft_delete_enabled = %t +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, enabled) +} + +func testAccAzureRMKeyVault_softDeleteAbsent(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features { + key_vault { + recover_soft_deleted_key_vaults = false + } + } +} + +data "azurerm_client_config" "current" { +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} +`, data.RandomInteger, data.Locations.Primary) +} + +func testAccAzureRMKeyVault_softDeleteRecoveryDisabled(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features { + key_vault { + recover_soft_deleted_key_vaults = false + } + } +} + +data "azurerm_client_config" "current" {} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_key_vault" "test" { + name = "vault%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id + sku_name = "premium" + soft_delete_enabled = true +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func testAccAzureRMKeyVault_purgeProtectionAndSoftDelete(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" {} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_key_vault" "test" { + name = "vault%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id + sku_name = "premium" + soft_delete_enabled = true + purge_protection_enabled = true +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} diff --git a/azurerm/internal/services/keyvault/validate/key_vault_id.go b/azurerm/internal/services/keyvault/validate/key_vault_id.go new file mode 100644 index 0000000000000..5b365e71ce475 --- /dev/null +++ b/azurerm/internal/services/keyvault/validate/key_vault_id.go @@ -0,0 +1,22 @@ +package validate + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault/parse" +) + +func KeyVaultID(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) + return + } + + if _, err := parse.KeyVaultID(v); err != nil { + errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err)) + return + } + + return warnings, errors +} diff --git a/azurerm/internal/services/keyvault/validate/name.go b/azurerm/internal/services/keyvault/validate/name.go new file mode 100644 index 0000000000000..764ceba95e23c --- /dev/null +++ b/azurerm/internal/services/keyvault/validate/name.go @@ -0,0 +1,15 @@ +package validate + +import ( + "fmt" + "regexp" +) + +func KeyVaultName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + if matched := regexp.MustCompile(`^[a-zA-Z0-9-]{3,24}$`).Match([]byte(value)); !matched { + errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes and must be between 3-24 chars", k)) + } + + return warnings, errors +} diff --git a/azurerm/internal/services/keyvault/validate/name_test.go b/azurerm/internal/services/keyvault/validate/name_test.go new file mode 100644 index 0000000000000..c574c749f5416 --- /dev/null +++ b/azurerm/internal/services/keyvault/validate/name_test.go @@ -0,0 +1,62 @@ +package validate + +import ( + "testing" +) + +func TestValidateKeyVaultName(t *testing.T) { + cases := []struct { + Input string + ExpectError bool + }{ + { + Input: "", + ExpectError: true, + }, + { + Input: "hi", + ExpectError: true, + }, + { + Input: "hello", + ExpectError: false, + }, + { + Input: "hello-world", + ExpectError: false, + }, + { + Input: "hello-world-21", + ExpectError: false, + }, + { + Input: "hello_world_21", + ExpectError: true, + }, + { + Input: "Hello-World", + ExpectError: false, + }, + { + Input: "20202020", + ExpectError: false, + }, + { + Input: "ABC123!@£", + ExpectError: true, + }, + { + Input: "abcdefghijklmnopqrstuvwxyz", + ExpectError: true, + }, + } + + for _, tc := range cases { + _, errors := KeyVaultName(tc.Input, "") + + hasError := len(errors) > 0 + if tc.ExpectError && !hasError { + t.Fatalf("Expected the Key Vault Name to trigger a validation error for '%s'", tc.Input) + } + } +} diff --git a/azurerm/internal/services/kusto/data_source_kusto_cluster.go b/azurerm/internal/services/kusto/data_source_kusto_cluster.go new file mode 100644 index 0000000000000..1a8d4fd389c48 --- /dev/null +++ b/azurerm/internal/services/kusto/data_source_kusto_cluster.go @@ -0,0 +1,80 @@ +package kusto + +import ( + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceArmKustoCluster() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmKustoClusterRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validateAzureRMKustoClusterName, + }, + + "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + + "location": azure.SchemaLocationForDataSource(), + + "uri": { + Type: schema.TypeString, + Computed: true, + }, + + "data_ingestion_uri": { + Type: schema.TypeString, + Computed: true, + }, + + "tags": tags.SchemaDataSource(), + }, + } +} + +func dataSourceArmKustoClusterRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Kusto.ClustersClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Kusto Cluster %q (Resource Group %q) does not exist", name, resourceGroup) + } + return fmt.Errorf("Error retrieving Kusto Cluster %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.SetId(*resp.ID) + + d.Set("name", name) + d.Set("resource_group_name", resourceGroup) + + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + if clusterProperties := resp.ClusterProperties; clusterProperties != nil { + d.Set("uri", clusterProperties.URI) + d.Set("data_ingestion_uri", clusterProperties.DataIngestionURI) + } + + return tags.FlattenAndSet(d, resp.Tags) +} diff --git a/azurerm/internal/services/kusto/registration.go b/azurerm/internal/services/kusto/registration.go index 7c6688bda6e91..6a0414cffb4ef 100644 --- a/azurerm/internal/services/kusto/registration.go +++ b/azurerm/internal/services/kusto/registration.go @@ -11,9 +11,18 @@ func (r Registration) Name() string { return "Kusto" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Data Explorer", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_kusto_cluster": dataSourceArmKustoCluster(), + } } // SupportedResources returns the supported Resources supported by this Service diff --git a/azurerm/internal/services/kusto/resource_arm_kusto_cluster.go b/azurerm/internal/services/kusto/resource_arm_kusto_cluster.go index 9dd4c0e4589a6..956f7f28bfd2b 100644 --- a/azurerm/internal/services/kusto/resource_arm_kusto_cluster.go +++ b/azurerm/internal/services/kusto/resource_arm_kusto_cluster.go @@ -83,6 +83,16 @@ func resourceArmKustoCluster() *schema.Resource { }, }, + "enable_disk_encryption": { + Type: schema.TypeBool, + Optional: true, + }, + + "enable_streaming_ingest": { + Type: schema.TypeBool, + Optional: true, + }, + "uri": { Type: schema.TypeString, Computed: true, @@ -128,7 +138,10 @@ func resourceArmKustoClusterCreateUpdate(d *schema.ResourceData, meta interface{ return err } - clusterProperties := kusto.ClusterProperties{} + clusterProperties := kusto.ClusterProperties{ + EnableDiskEncryption: utils.Bool(d.Get("enable_disk_encryption").(bool)), + EnableStreamingIngest: utils.Bool(d.Get("enable_streaming_ingest").(bool)), + } t := d.Get("tags").(map[string]interface{}) @@ -198,6 +211,8 @@ func resourceArmKustoClusterRead(d *schema.ResourceData, meta interface{}) error } if clusterProperties := clusterResponse.ClusterProperties; clusterProperties != nil { + d.Set("enable_disk_encryption", clusterProperties.EnableDiskEncryption) + d.Set("enable_streaming_ingest", clusterProperties.EnableStreamingIngest) d.Set("uri", clusterProperties.URI) d.Set("data_ingestion_uri", clusterProperties.DataIngestionURI) } diff --git a/azurerm/internal/services/kusto/tests/data_source_kusto_cluster_test.go b/azurerm/internal/services/kusto/tests/data_source_kusto_cluster_test.go new file mode 100644 index 0000000000000..cfc84acb348de --- /dev/null +++ b/azurerm/internal/services/kusto/tests/data_source_kusto_cluster_test.go @@ -0,0 +1,41 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMKustoCluster_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kusto_cluster", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKustoClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMKustoCluster_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKustoClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "uri"), + resource.TestCheckResourceAttrSet(data.ResourceName, "data_ingestion_uri"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKustoCluster_basic(data acceptance.TestData) string { + template := testAccAzureRMKustoCluster_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_kusto_cluster" "test" { + name = azurerm_kusto_cluster.test.name + resource_group_name = azurerm_resource_group.test.name +} +`, template) +} diff --git a/azurerm/internal/services/kusto/tests/resource_arm_kusto_cluster_test.go b/azurerm/internal/services/kusto/tests/resource_arm_kusto_cluster_test.go index 5e6634c48e0f8..0de371fb47933 100644 --- a/azurerm/internal/services/kusto/tests/resource_arm_kusto_cluster_test.go +++ b/azurerm/internal/services/kusto/tests/resource_arm_kusto_cluster_test.go @@ -30,6 +30,45 @@ func TestAccAzureRMKustoCluster_basic(t *testing.T) { }) } +func TestAccAzureRMKustoCluster_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kusto_cluster", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKustoClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMKustoCluster_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKustoClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_disk_encryption", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_streaming_ingest", "false"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMKustoCluster_update(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKustoClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_disk_encryption", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_streaming_ingest", "true"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMKustoCluster_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKustoClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_disk_encryption", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_streaming_ingest", "false"), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMKustoCluster_withTags(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_kusto_cluster", "test") @@ -89,6 +128,10 @@ func TestAccAzureRMKustoCluster_sku(t *testing.T) { func testAccAzureRMKustoCluster_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -96,8 +139,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_kusto_cluster" "test" { name = "acctestkc%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku { name = "Dev(No SLA)_Standard_D11_v2" @@ -109,6 +152,10 @@ resource "azurerm_kusto_cluster" "test" { func testAccAzureRMKustoCluster_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -116,8 +163,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_kusto_cluster" "test" { name = "acctestkc%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku { name = "Dev(No SLA)_Standard_D11_v2" @@ -133,6 +180,10 @@ resource "azurerm_kusto_cluster" "test" { func testAccAzureRMKustoCluster_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -140,8 +191,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_kusto_cluster" "test" { name = "acctestkc%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku { name = "Dev(No SLA)_Standard_D11_v2" @@ -158,6 +209,10 @@ resource "azurerm_kusto_cluster" "test" { func testAccAzureRMKustoCluster_skuUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -165,8 +220,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_kusto_cluster" "test" { name = "acctestkc%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku { name = "Standard_D11_v2" @@ -176,6 +231,32 @@ resource "azurerm_kusto_cluster" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomString) } +func testAccAzureRMKustoCluster_update(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_kusto_cluster" "test" { + name = "acctestkc%s" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + enable_disk_encryption = true + enable_streaming_ingest = true + + sku { + name = "Dev(No SLA)_Standard_D11_v2" + capacity = 1 + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} + func testCheckAzureRMKustoClusterDestroy(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).Kusto.ClustersClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext diff --git a/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_principal_test.go b/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_principal_test.go index 315c3e02095df..01bf647c1c5e4 100644 --- a/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_principal_test.go +++ b/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_principal_test.go @@ -129,6 +129,10 @@ func testCheckAzureRMKustoDatabasePrincipalExists(resourceName string) resource. func testAccAzureRMKustoDatabasePrincipal_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_client_config" "current" {} diff --git a/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_test.go b/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_test.go index b12eeb4d3568b..99768244227e0 100644 --- a/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_test.go +++ b/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_test.go @@ -84,6 +84,10 @@ func TestAccAzureRMKustoDatabase_hotCachePeriod(t *testing.T) { func testAccAzureRMKustoDatabase_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -111,6 +115,10 @@ resource "azurerm_kusto_database" "test" { func testAccAzureRMKustoDatabase_softDeletePeriod(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -140,6 +148,10 @@ resource "azurerm_kusto_database" "test" { func testAccAzureRMKustoDatabase_softDeletePeriodUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -169,6 +181,10 @@ resource "azurerm_kusto_database" "test" { func testAccAzureRMKustoDatabase_hotCachePeriod(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" @@ -198,6 +214,10 @@ resource "azurerm_kusto_database" "test" { func testAccAzureRMKustoDatabase_hotCachePeriodUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/kusto/tests/resource_arm_kusto_eventhub_data_connection_test.go b/azurerm/internal/services/kusto/tests/resource_arm_kusto_eventhub_data_connection_test.go index f4c0496b65555..bee728cc7eaf9 100644 --- a/azurerm/internal/services/kusto/tests/resource_arm_kusto_eventhub_data_connection_test.go +++ b/azurerm/internal/services/kusto/tests/resource_arm_kusto_eventhub_data_connection_test.go @@ -32,6 +32,10 @@ func TestAccAzureRMKustoEventHubDataConnection_basic(t *testing.T) { func testAccAzureRMKustoEventHubDataConnection_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -39,8 +43,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_kusto_cluster" "test" { name = "acctestkc%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku { name = "Dev(No SLA)_Standard_D11_v2" @@ -50,42 +54,42 @@ resource "azurerm_kusto_cluster" "test" { resource "azurerm_kusto_database" "test" { name = "acctestkd-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - cluster_name = "${azurerm_kusto_cluster.test.name}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + cluster_name = azurerm_kusto_cluster.test.name } resource "azurerm_eventhub_namespace" "test" { name = "acctesteventhubnamespace-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + 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}" + namespace_name = azurerm_eventhub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name partition_count = 1 message_retention = 1 } resource "azurerm_eventhub_consumer_group" "test" { name = "acctesteventhubcg-%d" - namespace_name = "${azurerm_eventhub_namespace.test.name}" - eventhub_name = "${azurerm_eventhub.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + namespace_name = azurerm_eventhub_namespace.test.name + eventhub_name = azurerm_eventhub.test.name + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_kusto_eventhub_data_connection" "test" { name = "acctestkedc-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - cluster_name = "${azurerm_kusto_cluster.test.name}" - database_name = "${azurerm_kusto_database.test.name}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + cluster_name = azurerm_kusto_cluster.test.name + database_name = azurerm_kusto_database.test.name - eventhub_id = "${azurerm_eventhub.test.id}" - consumer_group = "${azurerm_eventhub_consumer_group.test.name}" + eventhub_id = azurerm_eventhub.test.id + consumer_group = azurerm_eventhub_consumer_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/loganalytics/registration.go b/azurerm/internal/services/loganalytics/registration.go index eb5f604af97e4..d8c5f126a26eb 100644 --- a/azurerm/internal/services/loganalytics/registration.go +++ b/azurerm/internal/services/loganalytics/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Log Analytics" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Log Analytics", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go index a97b22fc6eda7..bf56266af5f69 100644 --- a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go @@ -58,32 +58,10 @@ func resourceArmLogAnalyticsLinkedService() *schema.Resource { }, "resource_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - ConflictsWith: []string{"linked_service_properties.0"}, - }, - - "linked_service_properties": { - Type: schema.TypeList, - Optional: true, - Computed: true, - ForceNew: true, - ConflictsWith: []string{"resource_id"}, - MaxItems: 1, - Deprecated: "This property has been deprecated in favour of the 'resource_id' property and will be removed in version 2.0 of the provider", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "resource_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - }, - }, - }, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, }, // Exported properties @@ -122,13 +100,6 @@ func resourceArmLogAnalyticsLinkedServiceCreateUpdate(d *schema.ResourceData, me } resourceId := d.Get("resource_id").(string) - if resourceId == "" { - props := d.Get("linked_service_properties").([]interface{}) - resourceId = expandLogAnalyticsLinkedServiceProperties(props) - if resourceId == "" { - return fmt.Errorf("A `resource_id` must be specified either using the `resource_id` field at the top level or within the `linked_service_properties` block") - } - } t := d.Get("tags").(map[string]interface{}) parameters := operationalinsights.LinkedService{ @@ -187,11 +158,6 @@ func resourceArmLogAnalyticsLinkedServiceRead(d *schema.ResourceData, meta inter d.Set("resource_id", props.ResourceID) } - linkedServiceProperties := flattenLogAnalyticsLinkedServiceProperties(resp.LinkedServiceProperties) - if err := d.Set("linked_service_properties", linkedServiceProperties); err != nil { - return fmt.Errorf("Error setting `linked_service_properties`: %+v", err) - } - return tags.FlattenAndSet(d, resp.Tags) } @@ -220,27 +186,3 @@ func resourceArmLogAnalyticsLinkedServiceDelete(d *schema.ResourceData, meta int return nil } - -func expandLogAnalyticsLinkedServiceProperties(input []interface{}) string { - if len(input) == 0 { - return "" - } - - props := input[0].(map[string]interface{}) - return props["resource_id"].(string) -} - -func flattenLogAnalyticsLinkedServiceProperties(input *operationalinsights.LinkedServiceProperties) []interface{} { - if input == nil { - return []interface{}{} - } - - properties := make(map[string]interface{}) - - // resource id linked service - if resourceID := input.ResourceID; resourceID != nil { - properties["resource_id"] = interface{}(*resourceID) - } - - return []interface{}{properties} -} diff --git a/azurerm/internal/services/loganalytics/tests/data_source_log_analytics_workspace_test.go b/azurerm/internal/services/loganalytics/tests/data_source_log_analytics_workspace_test.go index 56f6b7ce688e8..70db6a07db7b4 100644 --- a/azurerm/internal/services/loganalytics/tests/data_source_log_analytics_workspace_test.go +++ b/azurerm/internal/services/loganalytics/tests/data_source_log_analytics_workspace_test.go @@ -33,8 +33,8 @@ func testAccDataSourceAzureRMLogAnalyticsWorkspace_basicWithDataSource(data acce %s data "azurerm_log_analytics_workspace" "test" { - name = "${azurerm_log_analytics_workspace.test.name}" - resource_group_name = "${azurerm_log_analytics_workspace.test.resource_group_name}" + name = azurerm_log_analytics_workspace.test.name + resource_group_name = azurerm_log_analytics_workspace.test.resource_group_name } `, config) } diff --git a/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_linked_service_test.go b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_linked_service_test.go index d2bf0d4afb052..94f2a45745dc9 100644 --- a/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_linked_service_test.go +++ b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_linked_service_test.go @@ -3,7 +3,6 @@ package tests import ( "fmt" "net/http" - "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -85,43 +84,6 @@ func TestAccAzureRMLogAnalyticsLinkedService_complete(t *testing.T) { }) } -// Deprecated - remove in 2.0 -func TestAccAzureRMLogAnalyticsLinkedService_noResourceID(t *testing.T) { - data := acceptance.BuildTestData(t, "ignored", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogAnalyticsLinkedServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogAnalyticsLinkedService_noResourceID(data), - ExpectError: regexp.MustCompile("A `resource_id` must be specified either using the `resource_id` field at the top level or within the `linked_service_properties` block"), - }, - }, - }) -} - -// Deprecated - remove in 2.0 -func TestAccAzureRMLogAnalyticsLinkedService_linkedServiceProperties(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_log_analytics_linked_service", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogAnalyticsLinkedServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogAnalyticsLinkedService_linkedServiceProperties(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsLinkedServiceExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - func testCheckAzureRMLogAnalyticsLinkedServiceDestroy(s *terraform.State) error { conn := acceptance.AzureProvider.Meta().(*clients.Client).LogAnalytics.LinkedServicesClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -190,9 +152,9 @@ func testAccAzureRMLogAnalyticsLinkedService_basic(data acceptance.TestData) str %s resource "azurerm_log_analytics_linked_service" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - workspace_name = "${azurerm_log_analytics_workspace.test.name}" - resource_id = "${azurerm_automation_account.test.id}" + resource_group_name = azurerm_resource_group.test.name + workspace_name = azurerm_log_analytics_workspace.test.name + resource_id = azurerm_automation_account.test.id } `, template) } @@ -203,9 +165,9 @@ func testAccAzureRMLogAnalyticsLinkedService_requiresImport(data acceptance.Test %s resource "azurerm_log_analytics_linked_service" "import" { - resource_group_name = "${azurerm_log_analytics_linked_service.test.resource_group_name}" - workspace_name = "${azurerm_log_analytics_linked_service.test.workspace_name}" - resource_id = "${azurerm_log_analytics_linked_service.test.resource_id}" + resource_group_name = azurerm_log_analytics_linked_service.test.resource_group_name + workspace_name = azurerm_log_analytics_linked_service.test.workspace_name + resource_id = azurerm_log_analytics_linked_service.test.resource_id } `, template) } @@ -216,43 +178,20 @@ func testAccAzureRMLogAnalyticsLinkedService_complete(data acceptance.TestData) %s resource "azurerm_log_analytics_linked_service" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - workspace_name = "${azurerm_log_analytics_workspace.test.name}" + resource_group_name = azurerm_resource_group.test.name + workspace_name = azurerm_log_analytics_workspace.test.name linked_service_name = "automation" - resource_id = "${azurerm_automation_account.test.id}" -} -`, template) -} - -func testAccAzureRMLogAnalyticsLinkedService_noResourceID(data acceptance.TestData) string { - template := testAccAzureRMLogAnalyticsLinkedService_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_log_analytics_linked_service" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - workspace_name = "${azurerm_log_analytics_workspace.test.name}" + resource_id = azurerm_automation_account.test.id } `, template) } -func testAccAzureRMLogAnalyticsLinkedService_linkedServiceProperties(data acceptance.TestData) string { - template := testAccAzureRMLogAnalyticsLinkedService_template(data) +func testAccAzureRMLogAnalyticsLinkedService_template(data acceptance.TestData) string { return fmt.Sprintf(` -%s - -resource "azurerm_log_analytics_linked_service" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - workspace_name = "${azurerm_log_analytics_workspace.test.name}" - linked_service_properties { - resource_id = "${azurerm_automation_account.test.id}" - } -} -`, template) +provider "azurerm" { + features {} } -func testAccAzureRMLogAnalyticsLinkedService_template(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -260,12 +199,10 @@ resource "azurerm_resource_group" "test" { resource "azurerm_automation_account" "test" { name = "acctestAutomation-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name - sku { - name = "Basic" - } + sku_name = "Basic" tags = { Environment = "Test" @@ -274,8 +211,8 @@ resource "azurerm_automation_account" "test" { resource "azurerm_log_analytics_workspace" "test" { name = "acctestLAW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" retention_in_days = 30 } diff --git a/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_solution_test.go b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_solution_test.go index eeaf07aa6af50..3f97ddb70aabb 100644 --- a/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_solution_test.go +++ b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_solution_test.go @@ -132,6 +132,10 @@ func testCheckAzureRMLogAnalyticsSolutionExists(resourceName string) resource.Te func testAccAzureRMLogAnalyticsSolution_containerMonitoring(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -139,17 +143,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_log_analytics_workspace" "test" { name = "acctestLAW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" } resource "azurerm_log_analytics_solution" "test" { solution_name = "ContainerInsights" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" - workspace_name = "${azurerm_log_analytics_workspace.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + workspace_resource_id = azurerm_log_analytics_workspace.test.id + workspace_name = azurerm_log_analytics_workspace.test.name plan { publisher = "Microsoft" @@ -165,11 +169,11 @@ func testAccAzureRMLogAnalyticsSolution_requiresImport(data acceptance.TestData) %s resource "azurerm_log_analytics_solution" "import" { - solution_name = "${azurerm_log_analytics_solution.test.solution_name}" - location = "${azurerm_log_analytics_solution.test.location}" - resource_group_name = "${azurerm_log_analytics_solution.test.resource_group_name}" - workspace_resource_id = "${azurerm_log_analytics_solution.test.workspace_resource_id}" - workspace_name = "${azurerm_log_analytics_solution.test.workspace_name}" + solution_name = azurerm_log_analytics_solution.test.solution_name + location = azurerm_log_analytics_solution.test.location + resource_group_name = azurerm_log_analytics_solution.test.resource_group_name + workspace_resource_id = azurerm_log_analytics_solution.test.workspace_resource_id + workspace_name = azurerm_log_analytics_solution.test.workspace_name plan { publisher = "Microsoft" @@ -181,6 +185,10 @@ resource "azurerm_log_analytics_solution" "import" { func testAccAzureRMLogAnalyticsSolution_security(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -188,17 +196,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_log_analytics_workspace" "test" { name = "acctestLAW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" } resource "azurerm_log_analytics_solution" "test" { solution_name = "Security" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" - workspace_name = "${azurerm_log_analytics_workspace.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + workspace_resource_id = azurerm_log_analytics_workspace.test.id + workspace_name = azurerm_log_analytics_workspace.test.name plan { publisher = "Microsoft" diff --git a/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_test.go b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_test.go index 1bae804d317a5..28dd8a6080b73 100644 --- a/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_test.go +++ b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_test.go @@ -177,6 +177,10 @@ func testCheckAzureRMLogAnalyticsWorkspaceExists(resourceName string) resource.T } func testAccAzureRMLogAnalyticsWorkspace_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -184,8 +188,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_log_analytics_workspace" "test" { name = "acctestLAW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -197,9 +201,9 @@ func testAccAzureRMLogAnalyticsWorkspace_requiresImport(data acceptance.TestData %s resource "azurerm_log_analytics_workspace" "import" { - name = "${azurerm_log_analytics_workspace.test.name}" - location = "${azurerm_log_analytics_workspace.test.location}" - resource_group_name = "${azurerm_log_analytics_workspace.test.resource_group_name}" + name = azurerm_log_analytics_workspace.test.name + location = azurerm_log_analytics_workspace.test.location + resource_group_name = azurerm_log_analytics_workspace.test.resource_group_name sku = "PerGB2018" } `, template) @@ -207,6 +211,10 @@ resource "azurerm_log_analytics_workspace" "import" { func testAccAzureRMLogAnalyticsWorkspace_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -214,8 +222,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_log_analytics_workspace" "test" { name = "acctestLAW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" retention_in_days = 30 diff --git a/azurerm/internal/services/logic/registration.go b/azurerm/internal/services/logic/registration.go index 87508d474c8a7..7aca0d65af47d 100644 --- a/azurerm/internal/services/logic/registration.go +++ b/azurerm/internal/services/logic/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Logic" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Logic App", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence.go b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence.go index c9ad22c308b34..1982867c7cc56 100644 --- a/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" ) func resourceArmLogicAppTriggerRecurrence() *schema.Resource { @@ -64,7 +63,7 @@ func resourceArmLogicAppTriggerRecurrence() *schema.Resource { "start_time": { Type: schema.TypeString, Optional: true, - ValidateFunc: validate.RFC3339Time, + ValidateFunc: validation.IsRFC3339Time, }, }, } diff --git a/azurerm/internal/services/logic/tests/data_source_logic_app_workflow_test.go b/azurerm/internal/services/logic/tests/data_source_logic_app_workflow_test.go index f8f0393483989..e94336d2d7854 100644 --- a/azurerm/internal/services/logic/tests/data_source_logic_app_workflow_test.go +++ b/azurerm/internal/services/logic/tests/data_source_logic_app_workflow_test.go @@ -55,8 +55,8 @@ func testAccDataSourceAzureRMLogicAppWorkflow_basic(data acceptance.TestData) st %s data "azurerm_logic_app_workflow" "test" { - name = "${azurerm_logic_app_workflow.test.name}" - resource_group_name = "${azurerm_logic_app_workflow.test.resource_group_name}" + name = azurerm_logic_app_workflow.test.name + resource_group_name = azurerm_logic_app_workflow.test.resource_group_name } `, r) } @@ -67,8 +67,8 @@ func testAccDataSourceAzureRMLogicAppWorkflow_tags(data acceptance.TestData) str %s data "azurerm_logic_app_workflow" "test" { - name = "${azurerm_logic_app_workflow.test.name}" - resource_group_name = "${azurerm_logic_app_workflow.test.resource_group_name}" + name = azurerm_logic_app_workflow.test.name + resource_group_name = azurerm_logic_app_workflow.test.resource_group_name } `, r) } diff --git a/azurerm/internal/services/logic/tests/resource_arm_logic_app_action_custom_test.go b/azurerm/internal/services/logic/tests/resource_arm_logic_app_action_custom_test.go index 3cb119ceaaeaf..9e3f8ac7590dc 100644 --- a/azurerm/internal/services/logic/tests/resource_arm_logic_app_action_custom_test.go +++ b/azurerm/internal/services/logic/tests/resource_arm_logic_app_action_custom_test.go @@ -62,7 +62,7 @@ func testAccAzureRMLogicAppActionCustom_basic(data acceptance.TestData) string { resource "azurerm_logic_app_action_custom" "test" { name = "action%d" - logic_app_id = "${azurerm_logic_app_workflow.test.id}" + logic_app_id = azurerm_logic_app_workflow.test.id body = < 10000 { + errors = append(errors, fmt.Errorf("%q must be between 0 and 10000 (inclusive)", k)) + } + + return warnings, errors +} diff --git a/azurerm/internal/services/monitor/data_source_monitor_scheduled_query_rules_alert.go b/azurerm/internal/services/monitor/data_source_monitor_scheduled_query_rules_alert.go new file mode 100644 index 0000000000000..44e6634a01d9d --- /dev/null +++ b/azurerm/internal/services/monitor/data_source_monitor_scheduled_query_rules_alert.go @@ -0,0 +1,218 @@ +package monitor + +import ( + "fmt" + "strconv" + "time" + + "github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2019-06-01/insights" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceArmMonitorScheduledQueryRulesAlert() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmMonitorScheduledQueryRulesAlertRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + + "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + + "location": azure.SchemaLocationForDataSource(), + + "authorized_resource_ids": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "action": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action_group": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "custom_webhook_payload": { + Type: schema.TypeString, + Computed: true, + }, + "email_subject": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "data_source_id": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "enabled": { + Type: schema.TypeBool, + Computed: true, + }, + "frequency": { + Type: schema.TypeInt, + Computed: true, + }, + "query": { + Type: schema.TypeString, + Computed: true, + }, + "query_type": { + Type: schema.TypeString, + Computed: true, + }, + "severity": { + Type: schema.TypeInt, + Computed: true, + }, + "throttling": { + Type: schema.TypeInt, + Computed: true, + }, + "time_window": { + Type: schema.TypeInt, + Computed: true, + }, + "trigger": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "metric_trigger": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "metric_column": { + Type: schema.TypeString, + Computed: true, + }, + "metric_trigger_type": { + Type: schema.TypeString, + Computed: true, + }, + "operator": { + Type: schema.TypeString, + Computed: true, + }, + "threshold": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + "operator": { + Type: schema.TypeString, + Computed: true, + }, + "threshold": { + Type: schema.TypeFloat, + Computed: true, + }, + }, + }, + }, + + "tags": tags.SchemaDataSource(), + }, + } +} + +func dataSourceArmMonitorScheduledQueryRulesAlertRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Monitor.ScheduledQueryRulesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + resourceGroup := d.Get("resource_group_name").(string) + name := d.Get("name").(string) + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("[DEBUG] Scheduled Query Rule %q was not found in Resource Group %q: %+v", name, resourceGroup, err) + } + return fmt.Errorf("Error getting Scheduled Query Rule %q (resource group %q): %+v", name, resourceGroup, err) + } + + d.SetId(*resp.ID) + + d.Set("name", name) + d.Set("resource_group_name", resourceGroup) + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + d.Set("description", resp.Description) + if resp.Enabled == insights.True { + d.Set("enabled", true) + } else { + d.Set("enabled", false) + } + + action, ok := resp.Action.(insights.AlertingAction) + if !ok { + return fmt.Errorf("Wrong action type in Scheduled Query Rule %q (resource group %q): %T", name, resourceGroup, resp.Action) + } + if err = d.Set("action", flattenAzureRmScheduledQueryRulesAlertAction(action.AznsAction)); err != nil { + return fmt.Errorf("Error setting `action`: %+v", err) + } + severity, err := strconv.Atoi(string(action.Severity)) + if err != nil { + return fmt.Errorf("Error converting action.Severity %q in query rule %q to int (resource group %q): %+v", action.Severity, name, resourceGroup, err) + } + d.Set("severity", severity) + d.Set("throttling", action.ThrottlingInMin) + if err = d.Set("trigger", flattenAzureRmScheduledQueryRulesAlertTrigger(action.Trigger)); err != nil { + return fmt.Errorf("Error setting `trigger`: %+v", err) + } + + if schedule := resp.Schedule; schedule != nil { + if schedule.FrequencyInMinutes != nil { + d.Set("frequency", schedule.FrequencyInMinutes) + } + if schedule.TimeWindowInMinutes != nil { + d.Set("time_window", schedule.TimeWindowInMinutes) + } + } + + if source := resp.Source; source != nil { + if source.AuthorizedResources != nil { + d.Set("authorized_resource_ids", utils.FlattenStringSlice(source.AuthorizedResources)) + } + if source.DataSourceID != nil { + d.Set("data_source_id", source.DataSourceID) + } + if source.Query != nil { + d.Set("query", source.Query) + } + d.Set("query_type", string(source.QueryType)) + } + + return tags.FlattenAndSet(d, resp.Tags) +} diff --git a/azurerm/internal/services/monitor/data_source_monitor_scheduled_query_rules_log.go b/azurerm/internal/services/monitor/data_source_monitor_scheduled_query_rules_log.go new file mode 100644 index 0000000000000..3710667bcf8d2 --- /dev/null +++ b/azurerm/internal/services/monitor/data_source_monitor_scheduled_query_rules_log.go @@ -0,0 +1,152 @@ +package monitor + +import ( + "fmt" + "time" + + "github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2019-06-01/insights" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceArmMonitorScheduledQueryRulesLog() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmMonitorScheduledQueryRulesLogRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + }, + + "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + + "location": azure.SchemaLocationForDataSource(), + + "authorized_resource_ids": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "criteria": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dimension": { + Type: schema.TypeSet, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "operator": { + Type: schema.TypeString, + Computed: true, + }, + "values": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + "metric_name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "data_source_id": { + Type: schema.TypeString, + Computed: true, + }, + "description": { + Type: schema.TypeString, + Computed: true, + }, + "enabled": { + Type: schema.TypeBool, + Computed: true, + }, + + "tags": tags.SchemaDataSource(), + }, + } +} + +func dataSourceArmMonitorScheduledQueryRulesLogRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Monitor.ScheduledQueryRulesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + resourceGroup := d.Get("resource_group_name").(string) + name := d.Get("name").(string) + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("[DEBUG] Scheduled Query Rule %q was not found in Resource Group %q: %+v", name, resourceGroup, err) + } + return fmt.Errorf("Error getting Scheduled Query Rule %q (resource group %q): %+v", name, resourceGroup, err) + } + + d.SetId(*resp.ID) + + d.Set("name", name) + d.Set("resource_group_name", resourceGroup) + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + d.Set("description", resp.Description) + if resp.Enabled == insights.True { + d.Set("enabled", true) + } else { + d.Set("enabled", false) + } + + action, ok := resp.Action.(insights.LogToMetricAction) + if !ok { + return fmt.Errorf("Wrong action type in Scheduled Query Rule %q (resource group %q): %T", name, resourceGroup, resp.Action) + } + if err = d.Set("criteria", flattenAzureRmScheduledQueryRulesLogCriteria(action.Criteria)); err != nil { + return fmt.Errorf("Error setting `criteria`: %+v", err) + } + + if schedule := resp.Schedule; schedule != nil { + if schedule.FrequencyInMinutes != nil { + d.Set("frequency", schedule.FrequencyInMinutes) + } + if schedule.TimeWindowInMinutes != nil { + d.Set("time_window", schedule.TimeWindowInMinutes) + } + } + + if source := resp.Source; source != nil { + if source.AuthorizedResources != nil { + d.Set("authorized_resource_ids", utils.FlattenStringSlice(source.AuthorizedResources)) + } + if source.DataSourceID != nil { + d.Set("data_source_id", source.DataSourceID) + } + } + + return tags.FlattenAndSet(d, resp.Tags) +} diff --git a/azurerm/internal/services/monitor/registration.go b/azurerm/internal/services/monitor/registration.go index dfc09bd0b42dd..09676940ddb3d 100644 --- a/azurerm/internal/services/monitor/registration.go +++ b/azurerm/internal/services/monitor/registration.go @@ -11,24 +11,32 @@ func (r Registration) Name() string { return "Monitor" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Monitor", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_monitor_action_group": dataSourceArmMonitorActionGroup(), - "azurerm_monitor_diagnostic_categories": dataSourceArmMonitorDiagnosticCategories(), - "azurerm_monitor_log_profile": dataSourceArmMonitorLogProfile()} + "azurerm_monitor_action_group": dataSourceArmMonitorActionGroup(), + "azurerm_monitor_diagnostic_categories": dataSourceArmMonitorDiagnosticCategories(), + "azurerm_monitor_log_profile": dataSourceArmMonitorLogProfile(), + "azurerm_monitor_scheduled_query_rules_alert": dataSourceArmMonitorScheduledQueryRulesAlert(), + "azurerm_monitor_scheduled_query_rules_log": dataSourceArmMonitorScheduledQueryRulesLog()} } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), - "azurerm_metric_alertrule": resourceArmMetricAlertRule(), - "azurerm_monitor_autoscale_setting": resourceArmMonitorAutoScaleSetting(), - "azurerm_monitor_action_group": resourceArmMonitorActionGroup(), - "azurerm_monitor_activity_log_alert": resourceArmMonitorActivityLogAlert(), - "azurerm_monitor_diagnostic_setting": resourceArmMonitorDiagnosticSetting(), - "azurerm_monitor_log_profile": resourceArmMonitorLogProfile(), - "azurerm_monitor_metric_alert": resourceArmMonitorMetricAlert(), - "azurerm_monitor_metric_alertrule": resourceArmMonitorMetricAlertRule()} + "azurerm_monitor_autoscale_setting": resourceArmMonitorAutoScaleSetting(), + "azurerm_monitor_action_group": resourceArmMonitorActionGroup(), + "azurerm_monitor_activity_log_alert": resourceArmMonitorActivityLogAlert(), + "azurerm_monitor_diagnostic_setting": resourceArmMonitorDiagnosticSetting(), + "azurerm_monitor_log_profile": resourceArmMonitorLogProfile(), + "azurerm_monitor_metric_alert": resourceArmMonitorMetricAlert(), + "azurerm_monitor_scheduled_query_rules_alert": resourceArmMonitorScheduledQueryRulesAlert(), + "azurerm_monitor_scheduled_query_rules_log": resourceArmMonitorScheduledQueryRulesLog()} } diff --git a/azurerm/internal/services/monitor/resource_arm_autoscale_setting.go b/azurerm/internal/services/monitor/resource_arm_autoscale_setting.go deleted file mode 100644 index 636fe22e6522c..0000000000000 --- a/azurerm/internal/services/monitor/resource_arm_autoscale_setting.go +++ /dev/null @@ -1,1087 +0,0 @@ -package monitor - -import ( - "fmt" - "log" - "strconv" - "time" - - "github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2019-06-01/insights" - "github.com/Azure/go-autorest/autorest/date" - "github.com/hashicorp/go-azure-helpers/response" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmAutoScaleSetting() *schema.Resource { - return &schema.Resource{ - DeprecationMessage: `The 'azurerm_autoscale_setting' resource is deprecated in favour of the renamed version 'azurerm_monitor_autoscale_setting'. - -Information on migrating to the renamed resource can be found here: https://terraform.io/docs/providers/azurerm/guides/migrating-between-renamed-resources.html - -As such the existing 'azurerm_autoscale_setting' resource is deprecated and will be removed in the next major version of the AzureRM Provider (2.0). -`, - - Create: resourceArmAutoScaleSettingCreateUpdate, - Read: resourceArmAutoScaleSettingRead, - Update: resourceArmAutoScaleSettingCreateUpdate, - Delete: resourceArmAutoScaleSettingDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - - "resource_group_name": azure.SchemaResourceGroupName(), - - "location": azure.SchemaLocation(), - - "target_resource_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - }, - - "enabled": { - Type: schema.TypeBool, - Optional: true, - Default: true, - }, - - "profile": { - Type: schema.TypeList, - Required: true, - MaxItems: 20, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "capacity": { - Type: schema.TypeList, - Required: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "minimum": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(0, 1000), - }, - "maximum": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(0, 1000), - }, - "default": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(0, 1000), - }, - }, - }, - }, - "rule": { - Type: schema.TypeList, - Optional: true, - MaxItems: 10, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "metric_trigger": { - Type: schema.TypeList, - Required: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "metric_name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "metric_resource_id": { - Type: schema.TypeString, - Required: true, - ValidateFunc: azure.ValidateResourceID, - }, - "time_grain": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validate.ISO8601Duration, - }, - "statistic": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - string(insights.MetricStatisticTypeAverage), - string(insights.MetricStatisticTypeMax), - string(insights.MetricStatisticTypeMin), - string(insights.MetricStatisticTypeSum), - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, - "time_window": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validate.ISO8601Duration, - }, - "time_aggregation": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - string(insights.TimeAggregationTypeAverage), - string(insights.TimeAggregationTypeCount), - string(insights.TimeAggregationTypeMaximum), - string(insights.TimeAggregationTypeMinimum), - string(insights.TimeAggregationTypeTotal), - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, - "operator": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - string(insights.Equals), - string(insights.GreaterThan), - string(insights.GreaterThanOrEqual), - string(insights.LessThan), - string(insights.LessThanOrEqual), - string(insights.NotEquals), - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, - "threshold": { - Type: schema.TypeFloat, - Required: true, - }, - }, - }, - }, - "scale_action": { - Type: schema.TypeList, - Required: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "direction": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - string(insights.ScaleDirectionDecrease), - string(insights.ScaleDirectionIncrease), - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, - "type": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - string(insights.ChangeCount), - string(insights.ExactCount), - string(insights.PercentChangeCount), - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, - "value": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntAtLeast(0), - }, - "cooldown": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validate.ISO8601Duration, - }, - }, - }, - }, - }, - }, - }, - "fixed_date": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "timezone": { - Type: schema.TypeString, - Optional: true, - Default: "UTC", - ValidateFunc: validateAutoScaleSettingsTimeZone(), - }, - "start": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validate.RFC3339Time, - }, - "end": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validate.RFC3339Time, - }, - }, - }, - }, - "recurrence": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "timezone": { - Type: schema.TypeString, - Optional: true, - Default: "UTC", - ValidateFunc: validateAutoScaleSettingsTimeZone(), - }, - "days": { - Type: schema.TypeList, - Required: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.StringInSlice([]string{ - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday", - "Sunday", - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, - }, - "hours": { - Type: schema.TypeList, - Required: true, - MaxItems: 1, - Elem: &schema.Schema{ - Type: schema.TypeInt, - ValidateFunc: validation.IntBetween(0, 23), - }, - }, - "minutes": { - Type: schema.TypeList, - Required: true, - MaxItems: 1, - Elem: &schema.Schema{ - Type: schema.TypeInt, - ValidateFunc: validation.IntBetween(0, 59), - }, - }, - }, - }, - }, - }, - }, - }, - - "notification": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "email": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "send_to_subscription_administrator": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - "send_to_subscription_co_administrator": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - "custom_emails": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - }, - }, - "webhook": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "service_uri": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "properties": { - Type: schema.TypeMap, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - }, - }, - }, - }, - }, - - "tags": tags.Schema(), - }, - } -} - -func resourceArmAutoScaleSettingCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Monitor.AutoscaleSettingsClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing AutoScale Setting %q (Resource Group %q): %s", name, resourceGroup, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_autoscale_setting", *existing.ID) - } - } - - location := azure.NormalizeLocation(d.Get("location").(string)) - enabled := d.Get("enabled").(bool) - targetResourceId := d.Get("target_resource_id").(string) - - notificationsRaw := d.Get("notification").([]interface{}) - notifications := expandAzureRmAutoScaleSettingNotifications(notificationsRaw) - - profilesRaw := d.Get("profile").([]interface{}) - profiles, err := expandAzureRmAutoScaleSettingProfile(profilesRaw) - if err != nil { - return fmt.Errorf("Error expanding `profile`: %+v", err) - } - - t := d.Get("tags").(map[string]interface{}) - expandedTags := tags.Expand(t) - - parameters := insights.AutoscaleSettingResource{ - Location: utils.String(location), - AutoscaleSetting: &insights.AutoscaleSetting{ - Enabled: &enabled, - Profiles: profiles, - Notifications: notifications, - TargetResourceURI: &targetResourceId, - }, - Tags: expandedTags, - } - - if _, err = client.CreateOrUpdate(ctx, resourceGroup, name, parameters); err != nil { - return fmt.Errorf("Error creating AutoScale Setting %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - read, err := client.Get(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("Error retrieving AutoScale Setting %q (Resource Group %q): %+v", name, resourceGroup, err) - } - if read.ID == nil { - return fmt.Errorf("AutoScale Setting %q (Resource Group %q) has no ID", name, resourceGroup) - } - - d.SetId(*read.ID) - - return resourceArmAutoScaleSettingRead(d, meta) -} - -func resourceArmAutoScaleSettingRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Monitor.AutoscaleSettingsClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - name := id.Path["autoscalesettings"] - - resp, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[DEBUG] AutoScale Setting %q (Resource Group %q) was not found - removing from state!", name, resourceGroup) - d.SetId("") - return nil - } - - return fmt.Errorf("Error reading AutoScale Setting %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - d.Set("name", name) - d.Set("resource_group_name", resourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - - d.Set("enabled", resp.Enabled) - d.Set("target_resource_id", resp.TargetResourceURI) - - profile, err := flattenAzureRmAutoScaleSettingProfile(resp.Profiles) - if err != nil { - return fmt.Errorf("Error flattening `profile` of Autoscale Setting %q (Resource Group %q): %+v", name, resourceGroup, err) - } - if err = d.Set("profile", profile); err != nil { - return fmt.Errorf("Error setting `profile` of Autoscale Setting %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - notifications := flattenAzureRmAutoScaleSettingNotification(resp.Notifications) - if err = d.Set("notification", notifications); err != nil { - return fmt.Errorf("Error setting `notification` of Autoscale Setting %q (resource group %q): %+v", name, resourceGroup, err) - } - - // Return a new tag map filtered by the specified tag names. - tagMap := tags.Filter(resp.Tags, "$type") - return tags.FlattenAndSet(d, tagMap) -} - -func resourceArmAutoScaleSettingDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Monitor.AutoscaleSettingsClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - name := id.Path["autoscalesettings"] - - resp, err := client.Delete(ctx, resourceGroup, name) - if err != nil { - if !response.WasNotFound(resp.Response) { - return fmt.Errorf("Error deleting AutoScale Setting %q (Resource Group %q): %+v", name, resourceGroup, err) - } - } - - return nil -} - -func expandAzureRmAutoScaleSettingProfile(input []interface{}) (*[]insights.AutoscaleProfile, error) { - results := make([]insights.AutoscaleProfile, 0) - - for _, v := range input { - raw := v.(map[string]interface{}) - - name := raw["name"].(string) - - // this is Required, so we don't need to check for optionals here - capacitiesRaw := raw["capacity"].([]interface{}) - capacityRaw := capacitiesRaw[0].(map[string]interface{}) - capacity := insights.ScaleCapacity{ - Minimum: utils.String(strconv.Itoa(capacityRaw["minimum"].(int))), - Maximum: utils.String(strconv.Itoa(capacityRaw["maximum"].(int))), - Default: utils.String(strconv.Itoa(capacityRaw["default"].(int))), - } - - recurrencesRaw := raw["recurrence"].([]interface{}) - recurrence := expandAzureRmAutoScaleSettingRecurrence(recurrencesRaw) - - rulesRaw := raw["rule"].([]interface{}) - rules := expandAzureRmAutoScaleSettingRule(rulesRaw) - - fixedDatesRaw := raw["fixed_date"].([]interface{}) - fixedDate, err := expandAzureRmAutoScaleSettingFixedDate(fixedDatesRaw) - if err != nil { - return nil, fmt.Errorf("Error expanding `fixed_date`: %+v", err) - } - - result := insights.AutoscaleProfile{ - Name: utils.String(name), - Capacity: &capacity, - FixedDate: fixedDate, - Recurrence: recurrence, - Rules: rules, - } - results = append(results, result) - } - - return &results, nil -} - -func expandAzureRmAutoScaleSettingRule(input []interface{}) *[]insights.ScaleRule { - rules := make([]insights.ScaleRule, 0) - - for _, v := range input { - ruleRaw := v.(map[string]interface{}) - - triggersRaw := ruleRaw["metric_trigger"].([]interface{}) - triggerRaw := triggersRaw[0].(map[string]interface{}) - metricTrigger := insights.MetricTrigger{ - MetricName: utils.String(triggerRaw["metric_name"].(string)), - MetricResourceURI: utils.String(triggerRaw["metric_resource_id"].(string)), - TimeGrain: utils.String(triggerRaw["time_grain"].(string)), - Statistic: insights.MetricStatisticType(triggerRaw["statistic"].(string)), - TimeWindow: utils.String(triggerRaw["time_window"].(string)), - TimeAggregation: insights.TimeAggregationType(triggerRaw["time_aggregation"].(string)), - Operator: insights.ComparisonOperationType(triggerRaw["operator"].(string)), - Threshold: utils.Float(triggerRaw["threshold"].(float64)), - } - - actionsRaw := ruleRaw["scale_action"].([]interface{}) - actionRaw := actionsRaw[0].(map[string]interface{}) - scaleAction := insights.ScaleAction{ - Direction: insights.ScaleDirection(actionRaw["direction"].(string)), - Type: insights.ScaleType(actionRaw["type"].(string)), - Value: utils.String(strconv.Itoa(actionRaw["value"].(int))), - Cooldown: utils.String(actionRaw["cooldown"].(string)), - } - - rule := insights.ScaleRule{ - MetricTrigger: &metricTrigger, - ScaleAction: &scaleAction, - } - - rules = append(rules, rule) - } - - return &rules -} - -func expandAzureRmAutoScaleSettingFixedDate(input []interface{}) (*insights.TimeWindow, error) { - if len(input) == 0 { - return nil, nil - } - - raw := input[0].(map[string]interface{}) - - startString := raw["start"].(string) - startTime, err := date.ParseTime(time.RFC3339, startString) - if err != nil { - return nil, fmt.Errorf("Failed to parse `start` time %q as an RFC3339 date: %+v", startString, err) - } - endString := raw["end"].(string) - endTime, err := date.ParseTime(time.RFC3339, endString) - if err != nil { - return nil, fmt.Errorf("Failed to parse `end` time %q as an RFC3339 date: %+v", endString, err) - } - - timeZone := raw["timezone"].(string) - timeWindow := insights.TimeWindow{ - TimeZone: utils.String(timeZone), - Start: &date.Time{ - Time: startTime, - }, - End: &date.Time{ - Time: endTime, - }, - } - return &timeWindow, nil -} - -func expandAzureRmAutoScaleSettingRecurrence(input []interface{}) *insights.Recurrence { - if len(input) == 0 { - return nil - } - - recurrenceRaw := input[0].(map[string]interface{}) - - timeZone := recurrenceRaw["timezone"].(string) - days := make([]string, 0) - for _, dayItem := range recurrenceRaw["days"].([]interface{}) { - days = append(days, dayItem.(string)) - } - - hours := make([]int32, 0) - for _, hourItem := range recurrenceRaw["hours"].([]interface{}) { - hours = append(hours, int32(hourItem.(int))) - } - - minutes := make([]int32, 0) - for _, minuteItem := range recurrenceRaw["minutes"].([]interface{}) { - minutes = append(minutes, int32(minuteItem.(int))) - } - - return &insights.Recurrence{ - // API docs say this has to be `Week`. - Frequency: insights.RecurrenceFrequencyWeek, - Schedule: &insights.RecurrentSchedule{ - TimeZone: utils.String(timeZone), - Days: &days, - Hours: &hours, - Minutes: &minutes, - }, - } -} - -func expandAzureRmAutoScaleSettingNotifications(input []interface{}) *[]insights.AutoscaleNotification { - notifications := make([]insights.AutoscaleNotification, 0) - - for _, v := range input { - notificationRaw := v.(map[string]interface{}) - - emailsRaw := notificationRaw["email"].([]interface{}) - emailRaw := emailsRaw[0].(map[string]interface{}) - email := expandAzureRmAutoScaleSettingNotificationEmail(emailRaw) - - configsRaw := notificationRaw["webhook"].([]interface{}) - webhooks := expandAzureRmAutoScaleSettingNotificationWebhook(configsRaw) - - notification := insights.AutoscaleNotification{ - Email: email, - Operation: utils.String("scale"), - Webhooks: webhooks, - } - notifications = append(notifications, notification) - } - - return ¬ifications -} - -func expandAzureRmAutoScaleSettingNotificationEmail(input map[string]interface{}) *insights.EmailNotification { - customEmails := make([]string, 0) - if v, ok := input["custom_emails"]; ok { - for _, item := range v.([]interface{}) { - customEmails = append(customEmails, item.(string)) - } - } - - email := insights.EmailNotification{ - CustomEmails: &customEmails, - SendToSubscriptionAdministrator: utils.Bool(input["send_to_subscription_administrator"].(bool)), - SendToSubscriptionCoAdministrators: utils.Bool(input["send_to_subscription_co_administrator"].(bool)), - } - - return &email -} - -func expandAzureRmAutoScaleSettingNotificationWebhook(input []interface{}) *[]insights.WebhookNotification { - webhooks := make([]insights.WebhookNotification, 0) - - for _, v := range input { - webhookRaw := v.(map[string]interface{}) - - webhook := insights.WebhookNotification{ - ServiceURI: utils.String(webhookRaw["service_uri"].(string)), - } - - if props, ok := webhookRaw["properties"]; ok { - properties := make(map[string]*string) - for key, value := range props.(map[string]interface{}) { - properties[key] = utils.String(value.(string)) - } - - webhook.Properties = properties - } - - webhooks = append(webhooks, webhook) - } - - return &webhooks -} - -func flattenAzureRmAutoScaleSettingProfile(profiles *[]insights.AutoscaleProfile) ([]interface{}, error) { - if profiles == nil { - return []interface{}{}, nil - } - - results := make([]interface{}, 0) - for _, profile := range *profiles { - result := make(map[string]interface{}) - - if name := profile.Name; name != nil { - result["name"] = *name - } - - capacity, err := flattenAzureRmAutoScaleSettingCapacity(profile.Capacity) - if err != nil { - return nil, fmt.Errorf("Error flattening `capacity`: %+v", err) - } - result["capacity"] = capacity - - result["fixed_date"] = flattenAzureRmAutoScaleSettingFixedDate(profile.FixedDate) - result["recurrence"] = flattenAzureRmAutoScaleSettingRecurrence(profile.Recurrence) - - rule, err := flattenAzureRmAutoScaleSettingRules(profile.Rules) - if err != nil { - return nil, fmt.Errorf("Error flattening Rule: %s", err) - } - result["rule"] = rule - - results = append(results, result) - } - return results, nil -} - -func flattenAzureRmAutoScaleSettingCapacity(input *insights.ScaleCapacity) ([]interface{}, error) { - if input == nil { - return []interface{}{}, nil - } - - result := make(map[string]interface{}) - - if minStr := input.Minimum; minStr != nil { - min, err := strconv.Atoi(*minStr) - if err != nil { - return nil, fmt.Errorf("Error converting Minimum Scale Capacity %q to an int: %+v", *minStr, err) - } - result["minimum"] = min - } - - if maxStr := input.Maximum; maxStr != nil { - max, err := strconv.Atoi(*maxStr) - if err != nil { - return nil, fmt.Errorf("Error converting Maximum Scale Capacity %q to an int: %+v", *maxStr, err) - } - result["maximum"] = max - } - - if defaultCapacityStr := input.Default; defaultCapacityStr != nil { - defaultCapacity, err := strconv.Atoi(*defaultCapacityStr) - if err != nil { - return nil, fmt.Errorf("Error converting Default Scale Capacity %q to an int: %+v", *defaultCapacityStr, err) - } - result["default"] = defaultCapacity - } - - return []interface{}{result}, nil -} - -func flattenAzureRmAutoScaleSettingRules(input *[]insights.ScaleRule) ([]interface{}, error) { - if input == nil { - return []interface{}{}, nil - } - - results := make([]interface{}, 0) - for _, rule := range *input { - result := make(map[string]interface{}) - - metricTriggers := make([]interface{}, 0) - if trigger := rule.MetricTrigger; trigger != nil { - output := make(map[string]interface{}) - - output["operator"] = string(trigger.Operator) - output["statistic"] = string(trigger.Statistic) - output["time_aggregation"] = string(trigger.TimeAggregation) - - if trigger.MetricName != nil { - output["metric_name"] = *trigger.MetricName - } - - if trigger.MetricResourceURI != nil { - output["metric_resource_id"] = *trigger.MetricResourceURI - } - - if trigger.TimeGrain != nil { - output["time_grain"] = *trigger.TimeGrain - } - - if trigger.TimeWindow != nil { - output["time_window"] = *trigger.TimeWindow - } - - if trigger.Threshold != nil { - output["threshold"] = *trigger.Threshold - } - - metricTriggers = append(metricTriggers, output) - } - - result["metric_trigger"] = metricTriggers - - scaleActions := make([]interface{}, 0) - if v := rule.ScaleAction; v != nil { - action := make(map[string]interface{}) - - action["direction"] = string(v.Direction) - action["type"] = string(v.Type) - - if v.Cooldown != nil { - action["cooldown"] = *v.Cooldown - } - - if val := v.Value; val != nil && *val != "" { - i, err := strconv.Atoi(*val) - if err != nil { - return nil, fmt.Errorf("`value` %q was not convertable to an int: %s", *val, err) - } - action["value"] = i - } - - scaleActions = append(scaleActions, action) - } - - result["scale_action"] = scaleActions - - results = append(results, result) - } - - return results, nil -} - -func flattenAzureRmAutoScaleSettingFixedDate(input *insights.TimeWindow) []interface{} { - if input == nil { - return []interface{}{} - } - - result := make(map[string]interface{}) - - if timezone := input.TimeZone; timezone != nil { - result["timezone"] = *timezone - } - - if start := input.Start; start != nil { - result["start"] = start.String() - } - - if end := input.End; end != nil { - result["end"] = end.String() - } - - return []interface{}{result} -} - -func flattenAzureRmAutoScaleSettingRecurrence(input *insights.Recurrence) []interface{} { - if input == nil { - return []interface{}{} - } - - result := make(map[string]interface{}) - - if schedule := input.Schedule; schedule != nil { - if timezone := schedule.TimeZone; timezone != nil { - result["timezone"] = *timezone - } - - days := make([]string, 0) - if s := schedule.Days; s != nil { - days = *s - } - result["days"] = days - - hours := make([]int, 0) - if schedule.Hours != nil { - for _, v := range *schedule.Hours { - hours = append(hours, int(v)) - } - } - result["hours"] = hours - - minutes := make([]int, 0) - if schedule.Minutes != nil { - for _, v := range *schedule.Minutes { - minutes = append(minutes, int(v)) - } - } - result["minutes"] = minutes - } - - return []interface{}{result} -} - -func flattenAzureRmAutoScaleSettingNotification(notifications *[]insights.AutoscaleNotification) []interface{} { - results := make([]interface{}, 0) - - if notifications == nil { - return results - } - - for _, notification := range *notifications { - result := make(map[string]interface{}) - - emails := make([]interface{}, 0) - if email := notification.Email; email != nil { - block := make(map[string]interface{}) - - if send := email.SendToSubscriptionAdministrator; send != nil { - block["send_to_subscription_administrator"] = *send - } - - if send := email.SendToSubscriptionCoAdministrators; send != nil { - block["send_to_subscription_co_administrator"] = *send - } - - customEmails := make([]interface{}, 0) - if custom := email.CustomEmails; custom != nil { - for _, v := range *custom { - customEmails = append(customEmails, v) - } - } - block["custom_emails"] = customEmails - - emails = append(emails, block) - } - result["email"] = emails - - webhooks := make([]interface{}, 0) - if hooks := notification.Webhooks; hooks != nil { - for _, v := range *hooks { - hook := make(map[string]interface{}) - - if v.ServiceURI != nil { - hook["service_uri"] = *v.ServiceURI - } - - props := make(map[string]string) - for key, value := range v.Properties { - if value != nil { - props[key] = *value - } - } - hook["properties"] = props - webhooks = append(webhooks, hook) - } - } - - result["webhook"] = webhooks - - results = append(results, result) - } - return results -} - -func validateAutoScaleSettingsTimeZone() schema.SchemaValidateFunc { - // from https://docs.microsoft.com/en-us/rest/api/monitor/autoscalesettings/createorupdate#timewindow - timeZones := []string{ - "Dateline Standard Time", - "UTC-11", - "Hawaiian Standard Time", - "Alaskan Standard Time", - "Pacific Standard Time (Mexico)", - "Pacific Standard Time", - "US Mountain Standard Time", - "Mountain Standard Time (Mexico)", - "Mountain Standard Time", - "Central America Standard Time", - "Central Standard Time", - "Central Standard Time (Mexico)", - "Canada Central Standard Time", - "SA Pacific Standard Time", - "Eastern Standard Time", - "US Eastern Standard Time", - "Venezuela Standard Time", - "Paraguay Standard Time", - "Atlantic Standard Time", - "Central Brazilian Standard Time", - "SA Western Standard Time", - "Pacific SA Standard Time", - "Newfoundland Standard Time", - "E. South America Standard Time", - "Argentina Standard Time", - "SA Eastern Standard Time", - "Greenland Standard Time", - "Montevideo Standard Time", - "Bahia Standard Time", - "UTC-02", - "Mid-Atlantic Standard Time", - "Azores Standard Time", - "Cape Verde Standard Time", - "Morocco Standard Time", - "UTC", - "GMT Standard Time", - "Greenwich Standard Time", - "W. Europe Standard Time", - "Central Europe Standard Time", - "Romance Standard Time", - "Central European Standard Time", - "W. Central Africa Standard Time", - "Namibia Standard Time", - "Jordan Standard Time", - "GTB Standard Time", - "Middle East Standard Time", - "Egypt Standard Time", - "Syria Standard Time", - "E. Europe Standard Time", - "South Africa Standard Time", - "FLE Standard Time", - "Turkey Standard Time", - "Israel Standard Time", - "Kaliningrad Standard Time", - "Libya Standard Time", - "Arabic Standard Time", - "Arab Standard Time", - "Belarus Standard Time", - "Russian Standard Time", - "E. Africa Standard Time", - "Iran Standard Time", - "Arabian Standard Time", - "Azerbaijan Standard Time", - "Russia Time Zone 3", - "Mauritius Standard Time", - "Georgian Standard Time", - "Caucasus Standard Time", - "Afghanistan Standard Time", - "West Asia Standard Time", - "Ekaterinburg Standard Time", - "Pakistan Standard Time", - "India Standard Time", - "Sri Lanka Standard Time", - "Nepal Standard Time", - "Central Asia Standard Time", - "Bangladesh Standard Time", - "N. Central Asia Standard Time", - "Myanmar Standard Time", - "SE Asia Standard Time", - "North Asia Standard Time", - "China Standard Time", - "North Asia East Standard Time", - "Singapore Standard Time", - "W. Australia Standard Time", - "Taipei Standard Time", - "Ulaanbaatar Standard Time", - "Tokyo Standard Time", - "Korea Standard Time", - "Yakutsk Standard Time", - "Cen. Australia Standard Time", - "AUS Central Standard Time", - "E. Australia Standard Time", - "AUS Eastern Standard Time", - "West Pacific Standard Time", - "Tasmania Standard Time", - "Magadan Standard Time", - "Vladivostok Standard Time", - "Russia Time Zone 10", - "Central Pacific Standard Time", - "Russia Time Zone 11", - "New Zealand Standard Time", - "UTC+12", - "Fiji Standard Time", - "Kamchatka Standard Time", - "Tonga Standard Time", - "Samoa Standard Time", - "Line Islands Standard Time", - } - return validation.StringInSlice(timeZones, false) -} diff --git a/azurerm/internal/services/monitor/resource_arm_metric_alertrule.go b/azurerm/internal/services/monitor/resource_arm_metric_alertrule.go deleted file mode 100644 index dba743c5cbdcf..0000000000000 --- a/azurerm/internal/services/monitor/resource_arm_metric_alertrule.go +++ /dev/null @@ -1,476 +0,0 @@ -package monitor - -import ( - "fmt" - "log" - "strings" - "time" - - "github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2019-06-01/insights" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmMetricAlertRule() *schema.Resource { - return &schema.Resource{ - Create: resourceArmMetricAlertRuleCreateUpdate, - Read: resourceArmMetricAlertRuleRead, - Update: resourceArmMetricAlertRuleCreateUpdate, - Delete: resourceArmMetricAlertRuleDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - DeprecationMessage: `The 'azurerm_metric_alertrule' resource is deprecated in favour of the renamed version 'azurerm_monitor_metric_alertrule'. - -Information on migrating to the renamed resource can be found here: https://terraform.io/docs/providers/azurerm/guides/migrating-between-renamed-resources.html - -As such the existing 'azurerm_metric_alertrule' resource is deprecated and will be removed in the next major version of the AzureRM Provider (2.0). -`, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - - "resource_group_name": azure.SchemaResourceGroupName(), - - "location": azure.SchemaLocation(), - - "description": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - - "enabled": { - Type: schema.TypeBool, - Optional: true, - Default: true, - }, - - "resource_id": { - Type: schema.TypeString, - Required: true, - }, - - "metric_name": { - Type: schema.TypeString, - Required: true, - }, - - "operator": { - Type: schema.TypeString, - Required: true, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(insights.ConditionOperatorGreaterThan), - string(insights.ConditionOperatorGreaterThanOrEqual), - string(insights.ConditionOperatorLessThan), - string(insights.ConditionOperatorLessThanOrEqual), - }, true), - }, - - "threshold": { - Type: schema.TypeFloat, - Required: true, - }, - - "period": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validate.ISO8601Duration, - }, - - "aggregation": { - Type: schema.TypeString, - Required: true, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(insights.TimeAggregationOperatorAverage), - string(insights.TimeAggregationOperatorLast), - string(insights.TimeAggregationOperatorMaximum), - string(insights.TimeAggregationOperatorMinimum), - string(insights.TimeAggregationOperatorTotal), - }, true), - }, - - "email_action": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "send_to_service_owners": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - }, - - "custom_emails": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - }, - }, - - "webhook_action": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "service_uri": { - Type: schema.TypeString, - Required: true, - }, - - "properties": { - Type: schema.TypeMap, - Optional: true, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - }, - }, - - "tags": { - Type: schema.TypeMap, - Optional: true, - Computed: true, - ValidateFunc: ValidateMetricAlertRuleTags, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - } -} - -func resourceArmMetricAlertRuleCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Monitor.AlertRulesClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - log.Printf("[INFO] preparing arguments for AzureRM Alert Rule creation.") - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing Alert Rule %q (Resource Group %q): %s", name, resourceGroup, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_metric_alertrule", *existing.ID) - } - } - - location := azure.NormalizeLocation(d.Get("location").(string)) - t := d.Get("tags").(map[string]interface{}) - - alertRule, err := expandAzureRmMetricThresholdAlertRule(d) - if err != nil { - return err - } - - alertRuleResource := insights.AlertRuleResource{ - Name: &name, - Location: &location, - Tags: tags.Expand(t), - AlertRule: alertRule, - } - - if _, err = client.CreateOrUpdate(ctx, resourceGroup, name, alertRuleResource); err != nil { - return err - } - - read, err := client.Get(ctx, resourceGroup, name) - if err != nil { - return err - } - if read.ID == nil { - return fmt.Errorf("Cannot read AzureRM Alert Rule %q (Resource Group %s) ID", name, resourceGroup) - } - - d.SetId(*read.ID) - - return resourceArmMetricAlertRuleRead(d, meta) -} - -func resourceArmMetricAlertRuleRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Monitor.AlertRulesClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - resourceGroup, name, err := resourceGroupAndAlertRuleNameFromId(d.Id()) - if err != nil { - return err - } - - resp, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[DEBUG] Metric Alert Rule %q (resource group %q) was not found - removing from state", name, resourceGroup) - d.SetId("") - return nil - } - - return fmt.Errorf("Error making Read request on AzureRM Metric Alert Rule %q: %+v", name, err) - } - - d.Set("name", name) - d.Set("resource_group_name", resourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - - if alertRule := resp.AlertRule; alertRule != nil { - d.Set("description", alertRule.Description) - d.Set("enabled", alertRule.IsEnabled) - - ruleCondition := alertRule.Condition - - if ruleCondition != nil { - if thresholdRuleCondition, ok := ruleCondition.AsThresholdRuleCondition(); ok && thresholdRuleCondition != nil { - d.Set("operator", string(thresholdRuleCondition.Operator)) - d.Set("threshold", thresholdRuleCondition.Threshold) - d.Set("period", thresholdRuleCondition.WindowSize) - d.Set("aggregation", string(thresholdRuleCondition.TimeAggregation)) - - dataSource := thresholdRuleCondition.DataSource - - if dataSource != nil { - if metricDataSource, ok := dataSource.AsRuleMetricDataSource(); ok && metricDataSource != nil { - d.Set("resource_id", metricDataSource.ResourceURI) - d.Set("metric_name", metricDataSource.MetricName) - } - } - } - } - - email_actions := make([]interface{}, 0) - webhook_actions := make([]interface{}, 0) - - for _, ruleAction := range *alertRule.Actions { - if emailAction, ok := ruleAction.AsRuleEmailAction(); ok && emailAction != nil { - email_action := make(map[string]interface{}, 1) - - if sendToOwners := emailAction.SendToServiceOwners; sendToOwners != nil { - email_action["send_to_service_owners"] = *sendToOwners - } - - custom_emails := make([]string, 0) - if s := emailAction.CustomEmails; s != nil { - custom_emails = *s - } - email_action["custom_emails"] = custom_emails - - email_actions = append(email_actions, email_action) - } else if webhookAction, ok := ruleAction.AsRuleWebhookAction(); ok && webhookAction != nil { - webhook_action := make(map[string]interface{}, 1) - - webhook_action["service_uri"] = *webhookAction.ServiceURI - - properties := make(map[string]string) - for k, v := range webhookAction.Properties { - if k != "$type" { - if v != nil { - properties[k] = *v - } - } - } - webhook_action["properties"] = properties - - webhook_actions = append(webhook_actions, webhook_action) - } - } - - d.Set("email_action", email_actions) - d.Set("webhook_action", webhook_actions) - } - - // Return a new tag map filtered by the specified tag names. - tagMap := tags.Filter(resp.Tags, "$type") - - return tags.FlattenAndSet(d, tagMap) -} - -func resourceArmMetricAlertRuleDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Monitor.AlertRulesClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - resourceGroup, name, err := resourceGroupAndAlertRuleNameFromId(d.Id()) - if err != nil { - return err - } - - resp, err := client.Delete(ctx, resourceGroup, name) - if err != nil { - if utils.ResponseWasNotFound(resp) { - return nil - } - - return fmt.Errorf("Error deleting Metric Alert Rule %q (resource group %q): %+v", name, resourceGroup, err) - } - - return err -} - -func expandAzureRmMetricThresholdAlertRule(d *schema.ResourceData) (*insights.AlertRule, error) { - name := d.Get("name").(string) - - resource := d.Get("resource_id").(string) - metric_name := d.Get("metric_name").(string) - - metricDataSource := insights.RuleMetricDataSource{ - ResourceURI: &resource, - MetricName: &metric_name, - } - - operator := d.Get("operator").(string) - threshold := d.Get("threshold").(float64) - period := d.Get("period").(string) - aggregation := d.Get("aggregation").(string) - - thresholdRuleCondition := insights.ThresholdRuleCondition{ - DataSource: metricDataSource, - Operator: insights.ConditionOperator(operator), - Threshold: &threshold, - TimeAggregation: insights.TimeAggregationOperator(aggregation), - WindowSize: &period, - } - - actions := make([]insights.BasicRuleAction, 0, 2) - - // Email action - - email_actions := d.Get("email_action").([]interface{}) - - if len(email_actions) > 0 { - email_action := email_actions[0].(map[string]interface{}) - emailAction := insights.RuleEmailAction{} - - if v, ok := email_action["custom_emails"]; ok { - custom_emails := v.([]interface{}) - - customEmails := make([]string, 0) - for _, customEmail := range custom_emails { - custom_email := customEmail.(string) - customEmails = append(customEmails, custom_email) - } - - emailAction.CustomEmails = &customEmails - } - - if v, ok := email_action["send_to_service_owners"]; ok { - sendToServiceOwners := v.(bool) - emailAction.SendToServiceOwners = &sendToServiceOwners - } - - actions = append(actions, emailAction) - } - - // Webhook action - - webhook_actions := d.Get("webhook_action").([]interface{}) - - if len(webhook_actions) > 0 { - webhook_action := webhook_actions[0].(map[string]interface{}) - - service_uri := webhook_action["service_uri"].(string) - - webhook_properties := make(map[string]*string) - - if v, ok := webhook_action["properties"]; ok { - properties := v.(map[string]interface{}) - - for property_key, property_value := range properties { - property_string := property_value.(string) - webhook_properties[property_key] = &property_string - } - } - - webhookAction := insights.RuleWebhookAction{ - ServiceURI: &service_uri, - Properties: webhook_properties, - } - - actions = append(actions, webhookAction) - } - - enabled := d.Get("enabled").(bool) - - alertRule := insights.AlertRule{ - Name: &name, - Condition: &thresholdRuleCondition, - Actions: &actions, - IsEnabled: &enabled, - } - - if v, ok := d.GetOk("description"); ok { - description := v.(string) - alertRule.Description = &description - } - - return &alertRule, nil -} - -func ValidateMetricAlertRuleTags(v interface{}, f string) (warnings []string, errors []error) { - // Normal validation required by any AzureRM resource. - warnings, errors = tags.Validate(v, f) - - tagsMap := v.(map[string]interface{}) - - for k := range tagsMap { - if strings.EqualFold(k, "$type") { - errors = append(errors, fmt.Errorf("the %q is not allowed as tag name", k)) - } - } - - return warnings, errors -} - -func resourceGroupAndAlertRuleNameFromId(alertRuleId string) (string, string, error) { - id, err := azure.ParseAzureResourceID(alertRuleId) - if err != nil { - return "", "", err - } - name := id.Path["alertrules"] - resourceGroup := id.ResourceGroup - - return resourceGroup, name, nil -} diff --git a/azurerm/internal/services/monitor/resource_arm_monitor_autoscale_setting.go b/azurerm/internal/services/monitor/resource_arm_monitor_autoscale_setting.go index 202c588e644ac..b667882eb0200 100644 --- a/azurerm/internal/services/monitor/resource_arm_monitor_autoscale_setting.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_autoscale_setting.go @@ -230,12 +230,12 @@ func resourceArmMonitorAutoScaleSetting() *schema.Resource { "start": { Type: schema.TypeString, Required: true, - ValidateFunc: validate.RFC3339Time, + ValidateFunc: validation.IsRFC3339Time, }, "end": { Type: schema.TypeString, Required: true, - ValidateFunc: validate.RFC3339Time, + ValidateFunc: validation.IsRFC3339Time, }, }, }, diff --git a/azurerm/internal/services/monitor/resource_arm_monitor_metric_alert.go b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alert.go index 63983794a554b..8ecd89efb760b 100644 --- a/azurerm/internal/services/monitor/resource_arm_monitor_metric_alert.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alert.go @@ -52,7 +52,7 @@ func resourceArmMonitorMetricAlert() *schema.Resource { // Issue to track: https://github.com/Azure/azure-sdk-for-go/issues/2920 // But to prevent potential state migration in the future, let's stick to use Set now - //lintignore:S018 + // lintignore:S018 "scopes": { Type: schema.TypeSet, Required: true, @@ -166,7 +166,7 @@ func resourceArmMonitorMetricAlert() *schema.Resource { "auto_mitigate": { Type: schema.TypeBool, Optional: true, - Default: false, + Default: true, }, "description": { diff --git a/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule.go b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule.go deleted file mode 100644 index efbaae8559d5d..0000000000000 --- a/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule.go +++ /dev/null @@ -1,462 +0,0 @@ -package monitor - -import ( - "fmt" - "log" - "strings" - "time" - - "github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2019-06-01/insights" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmMonitorMetricAlertRule() *schema.Resource { - return &schema.Resource{ - Create: resourceArmMonitorMetricAlertRuleCreateUpdate, - Read: resourceArmMonitorMetricAlertRuleRead, - Update: resourceArmMonitorMetricAlertRuleCreateUpdate, - Delete: resourceArmMonitorMetricAlertRuleDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - - "resource_group_name": azure.SchemaResourceGroupName(), - - "location": azure.SchemaLocation(), - - "description": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - - "enabled": { - Type: schema.TypeBool, - Optional: true, - Default: true, - }, - - "resource_id": { - Type: schema.TypeString, - Required: true, - }, - - "metric_name": { - Type: schema.TypeString, - Required: true, - }, - - "operator": { - Type: schema.TypeString, - Required: true, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(insights.ConditionOperatorGreaterThan), - string(insights.ConditionOperatorGreaterThanOrEqual), - string(insights.ConditionOperatorLessThan), - string(insights.ConditionOperatorLessThanOrEqual), - }, true), - }, - - "threshold": { - Type: schema.TypeFloat, - Required: true, - }, - - "period": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validate.ISO8601Duration, - }, - - "aggregation": { - Type: schema.TypeString, - Required: true, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(insights.TimeAggregationOperatorAverage), - string(insights.TimeAggregationOperatorLast), - string(insights.TimeAggregationOperatorMaximum), - string(insights.TimeAggregationOperatorMinimum), - string(insights.TimeAggregationOperatorTotal), - }, true), - }, - - "email_action": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "send_to_service_owners": { - Type: schema.TypeBool, - Optional: true, - Computed: true, - }, - - "custom_emails": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - }, - }, - - "webhook_action": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "service_uri": { - Type: schema.TypeString, - Required: true, - }, - - "properties": { - Type: schema.TypeMap, - Optional: true, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - }, - }, - - "tags": { - Type: schema.TypeMap, - Optional: true, - Computed: true, - ValidateFunc: ValidateMetricAlertRuleTags, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - } -} - -func resourceArmMonitorMetricAlertRuleCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Monitor.AlertRulesClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - log.Printf("[INFO] preparing arguments for AzureRM Alert Rule creation.") - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing Alert Rule %q (Resource Group %q): %s", name, resourceGroup, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_monitor_metric_alertrule", *existing.ID) - } - } - - location := azure.NormalizeLocation(d.Get("location").(string)) - t := d.Get("tags").(map[string]interface{}) - - alertRule, err := expandAzureRmMonitorMetricThresholdAlertRule(d) - if err != nil { - return err - } - - alertRuleResource := insights.AlertRuleResource{ - Name: &name, - Location: &location, - Tags: tags.Expand(t), - AlertRule: alertRule, - } - - if _, err = client.CreateOrUpdate(ctx, resourceGroup, name, alertRuleResource); err != nil { - return err - } - - read, err := client.Get(ctx, resourceGroup, name) - if err != nil { - return err - } - if read.ID == nil { - return fmt.Errorf("Cannot read AzureRM Alert Rule %q (Resource Group %s) ID", name, resourceGroup) - } - - d.SetId(*read.ID) - - return resourceArmMonitorMetricAlertRuleRead(d, meta) -} - -func resourceArmMonitorMetricAlertRuleRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Monitor.AlertRulesClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - name := id.Path["alertrules"] - resourceGroup := id.ResourceGroup - - resp, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[DEBUG] Metric Alert Rule %q (resource group %q) was not found - removing from state", name, resourceGroup) - d.SetId("") - return nil - } - - return fmt.Errorf("Error making Read request on AzureRM Metric Alert Rule %q: %+v", name, err) - } - - d.Set("name", name) - d.Set("resource_group_name", resourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - - if alertRule := resp.AlertRule; alertRule != nil { - d.Set("description", alertRule.Description) - d.Set("enabled", alertRule.IsEnabled) - - ruleCondition := alertRule.Condition - - if ruleCondition != nil { - if thresholdRuleCondition, ok := ruleCondition.AsThresholdRuleCondition(); ok && thresholdRuleCondition != nil { - d.Set("operator", string(thresholdRuleCondition.Operator)) - d.Set("threshold", thresholdRuleCondition.Threshold) - d.Set("period", thresholdRuleCondition.WindowSize) - d.Set("aggregation", string(thresholdRuleCondition.TimeAggregation)) - - dataSource := thresholdRuleCondition.DataSource - - if dataSource != nil { - if metricDataSource, ok := dataSource.AsRuleMetricDataSource(); ok && metricDataSource != nil { - d.Set("resource_id", metricDataSource.ResourceURI) - d.Set("metric_name", metricDataSource.MetricName) - } - } - } - } - - email_actions := make([]interface{}, 0) - webhook_actions := make([]interface{}, 0) - - for _, ruleAction := range *alertRule.Actions { - if emailAction, ok := ruleAction.AsRuleEmailAction(); ok && emailAction != nil { - email_action := make(map[string]interface{}, 1) - - if sendToOwners := emailAction.SendToServiceOwners; sendToOwners != nil { - email_action["send_to_service_owners"] = *sendToOwners - } - - custom_emails := make([]string, 0) - if s := emailAction.CustomEmails; s != nil { - custom_emails = *s - } - email_action["custom_emails"] = custom_emails - - email_actions = append(email_actions, email_action) - } else if webhookAction, ok := ruleAction.AsRuleWebhookAction(); ok && webhookAction != nil { - webhook_action := make(map[string]interface{}, 1) - - webhook_action["service_uri"] = *webhookAction.ServiceURI - - properties := make(map[string]string) - for k, v := range webhookAction.Properties { - if k != "$type" { - if v != nil { - properties[k] = *v - } - } - } - webhook_action["properties"] = properties - - webhook_actions = append(webhook_actions, webhook_action) - } - } - - d.Set("email_action", email_actions) - d.Set("webhook_action", webhook_actions) - } - - // Return a new tag map filtered by the specified tag names. - tagMap := tags.Filter(resp.Tags, "$type") - - return tags.FlattenAndSet(d, tagMap) -} - -func resourceArmMonitorMetricAlertRuleDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Monitor.AlertRulesClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - name := id.Path["alertrules"] - resourceGroup := id.ResourceGroup - - resp, err := client.Delete(ctx, resourceGroup, name) - if err != nil { - if utils.ResponseWasNotFound(resp) { - return nil - } - - return fmt.Errorf("Error deleting Metric Alert Rule %q (resource group %q): %+v", name, resourceGroup, err) - } - - return err -} - -func expandAzureRmMonitorMetricThresholdAlertRule(d *schema.ResourceData) (*insights.AlertRule, error) { - name := d.Get("name").(string) - - resource := d.Get("resource_id").(string) - metric_name := d.Get("metric_name").(string) - - metricDataSource := insights.RuleMetricDataSource{ - ResourceURI: &resource, - MetricName: &metric_name, - } - - operator := d.Get("operator").(string) - threshold := d.Get("threshold").(float64) - period := d.Get("period").(string) - aggregation := d.Get("aggregation").(string) - - thresholdRuleCondition := insights.ThresholdRuleCondition{ - DataSource: metricDataSource, - Operator: insights.ConditionOperator(operator), - Threshold: &threshold, - TimeAggregation: insights.TimeAggregationOperator(aggregation), - WindowSize: &period, - } - - actions := make([]insights.BasicRuleAction, 0, 2) - - // Email action - - email_actions := d.Get("email_action").([]interface{}) - - if len(email_actions) > 0 { - email_action := email_actions[0].(map[string]interface{}) - emailAction := insights.RuleEmailAction{} - - if v, ok := email_action["custom_emails"]; ok { - custom_emails := v.([]interface{}) - - customEmails := make([]string, 0) - for _, customEmail := range custom_emails { - custom_email := customEmail.(string) - customEmails = append(customEmails, custom_email) - } - - emailAction.CustomEmails = &customEmails - } - - if v, ok := email_action["send_to_service_owners"]; ok { - sendToServiceOwners := v.(bool) - emailAction.SendToServiceOwners = &sendToServiceOwners - } - - actions = append(actions, emailAction) - } - - // Webhook action - - webhook_actions := d.Get("webhook_action").([]interface{}) - - if len(webhook_actions) > 0 { - webhook_action := webhook_actions[0].(map[string]interface{}) - - service_uri := webhook_action["service_uri"].(string) - - webhook_properties := make(map[string]*string) - - if v, ok := webhook_action["properties"]; ok { - properties := v.(map[string]interface{}) - - for property_key, property_value := range properties { - property_string := property_value.(string) - webhook_properties[property_key] = &property_string - } - } - - webhookAction := insights.RuleWebhookAction{ - ServiceURI: &service_uri, - Properties: webhook_properties, - } - - actions = append(actions, webhookAction) - } - - enabled := d.Get("enabled").(bool) - - alertRule := insights.AlertRule{ - Name: &name, - Condition: &thresholdRuleCondition, - Actions: &actions, - IsEnabled: &enabled, - } - - if v, ok := d.GetOk("description"); ok { - description := v.(string) - alertRule.Description = &description - } - - return &alertRule, nil -} - -func ValidateMonitorMetricAlertRuleTags(v interface{}, f string) (warnings []string, errors []error) { - // Normal validation required by any AzureRM resource. - warnings, errors = tags.Validate(v, f) - - tagsMap := v.(map[string]interface{}) - - for k := range tagsMap { - if strings.EqualFold(k, "$type") { - errors = append(errors, fmt.Errorf("the %q is not allowed as tag name", k)) - } - } - - return warnings, errors -} diff --git a/azurerm/internal/services/monitor/resource_arm_monitor_scheduled_query_rules_alert.go b/azurerm/internal/services/monitor/resource_arm_monitor_scheduled_query_rules_alert.go new file mode 100644 index 0000000000000..e8ad5526e7c49 --- /dev/null +++ b/azurerm/internal/services/monitor/resource_arm_monitor_scheduled_query_rules_alert.go @@ -0,0 +1,484 @@ +package monitor + +import ( + "fmt" + "log" + "strconv" + "strings" + "time" + + "github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2019-06-01/insights" + "github.com/hashicorp/go-azure-helpers/response" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmMonitorScheduledQueryRulesAlert() *schema.Resource { + return &schema.Resource{ + Create: resourceArmMonitorScheduledQueryRulesAlertCreateUpdate, + Read: resourceArmMonitorScheduledQueryRulesAlertRead, + Update: resourceArmMonitorScheduledQueryRulesAlertCreateUpdate, + Delete: resourceArmMonitorScheduledQueryRulesAlertDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringDoesNotContainAny("<>*%&:\\?+/"), + }, + + "resource_group_name": azure.SchemaResourceGroupName(), + + "location": azure.SchemaLocation(), + + "authorized_resource_ids": { + Type: schema.TypeSet, + Optional: true, + MaxItems: 100, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: azure.ValidateResourceID, + }, + }, + "action": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action_group": { + Type: schema.TypeSet, + Required: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: azure.ValidateResourceID, + }, + }, + "custom_webhook_payload": { + Type: schema.TypeString, + Optional: true, + Default: "{}", + ValidateFunc: validation.StringIsJSON, + }, + "email_subject": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + }, + "data_source_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: azure.ValidateResourceID, + }, + "description": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringLenBetween(1, 4096), + }, + "enabled": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "frequency": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(5, 1440), + }, + "query": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "query_type": { + Type: schema.TypeString, + Optional: true, + Default: "ResultCount", + ValidateFunc: validation.StringInSlice([]string{ + "ResultCount", + }, false), + }, + "severity": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(0, 4), + }, + "throttling": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(0, 10000), + }, + "time_window": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(5, 2880), + }, + "trigger": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "metric_trigger": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "metric_column": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "metric_trigger_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "Consecutive", + "Total", + }, false), + }, + "operator": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "GreaterThan", + "LessThan", + "Equal", + }, false), + }, + "threshold": { + Type: schema.TypeFloat, + Required: true, + ValidateFunc: validateMonitorScheduledQueryRulesAlertThreshold, + }, + }, + }, + }, + "operator": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + "GreaterThan", + "LessThan", + "Equal", + }, false), + }, + "threshold": { + Type: schema.TypeFloat, + Required: true, + ValidateFunc: validateMonitorScheduledQueryRulesAlertThreshold, + }, + }, + }, + }, + + "tags": tags.Schema(), + }, + } +} + +func resourceArmMonitorScheduledQueryRulesAlertCreateUpdate(d *schema.ResourceData, meta interface{}) error { + action := expandMonitorScheduledQueryRulesAlertingAction(d) + schedule := expandMonitorScheduledQueryRulesAlertSchedule(d) + client := meta.(*clients.Client).Monitor.ScheduledQueryRulesClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + frequency := d.Get("frequency").(int) + timeWindow := d.Get("time_window").(int) + if timeWindow < frequency { + return fmt.Errorf("Error in parameter values for Scheduled Query Rules %q (Resource Group %q): time_window must be greater than or equal to frequency", name, resourceGroup) + } + + query := d.Get("query").(string) + _, ok := d.GetOk("metric_trigger") + if ok { + if !(strings.Contains(query, "summarize") && + strings.Contains(query, "AggregatedValue") && + strings.Contains(query, "bin")) { + return fmt.Errorf("Error in parameter values for Scheduled Query Rules %q (Resource Group %q): query must contain summarize, AggregatedValue, and bin when metric_trigger is specified", name, resourceGroup) + } + } + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + existing, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing Monitor Scheduled Query Rules %q (Resource Group %q): %s", name, resourceGroup, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_monitor_scheduled_query_rules_alert", *existing.ID) + } + } + + description := d.Get("description").(string) + enabledRaw := d.Get("enabled").(bool) + + enabled := insights.True + if !enabledRaw { + enabled = insights.False + } + + location := azure.NormalizeLocation(d.Get("location")) + + source := expandMonitorScheduledQueryRulesCommonSource(d) + + t := d.Get("tags").(map[string]interface{}) + expandedTags := tags.Expand(t) + + parameters := insights.LogSearchRuleResource{ + Location: utils.String(location), + LogSearchRule: &insights.LogSearchRule{ + Description: utils.String(description), + Enabled: enabled, + Source: source, + Schedule: schedule, + Action: action, + }, + Tags: expandedTags, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters); err != nil { + return fmt.Errorf("Error creating or updating Scheduled Query Rule %q (resource group %q): %+v", name, resourceGroup, err) + } + + read, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return err + } + if read.ID == nil { + return fmt.Errorf("Scheduled query rule %q (resource group %q) ID is empty", name, resourceGroup) + } + d.SetId(*read.ID) + + return resourceArmMonitorScheduledQueryRulesAlertRead(d, meta) +} + +func resourceArmMonitorScheduledQueryRulesAlertRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Monitor.ScheduledQueryRulesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["scheduledqueryrules"] + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[DEBUG] Scheduled Query Rule %q was not found in Resource Group %q", name, resourceGroup) + d.SetId("") + return nil + } + return fmt.Errorf("Error getting Scheduled Query Rule %q (resource group %q): %+v", name, resourceGroup, err) + } + + d.Set("name", name) + d.Set("resource_group_name", resourceGroup) + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + d.Set("description", resp.Description) + if resp.Enabled == insights.True { + d.Set("enabled", true) + } else { + d.Set("enabled", false) + } + + action, ok := resp.Action.(insights.AlertingAction) + if !ok { + return fmt.Errorf("Wrong action type in Scheduled Query Rule %q (resource group %q): %T", name, resourceGroup, resp.Action) + } + if err = d.Set("action", flattenAzureRmScheduledQueryRulesAlertAction(action.AznsAction)); err != nil { + return fmt.Errorf("Error setting `action`: %+v", err) + } + severity, err := strconv.Atoi(string(action.Severity)) + if err != nil { + return fmt.Errorf("Error converting action.Severity %q in query rule %q to int (resource group %q): %+v", action.Severity, name, resourceGroup, err) + } + d.Set("severity", severity) + d.Set("throttling", action.ThrottlingInMin) + if err = d.Set("trigger", flattenAzureRmScheduledQueryRulesAlertTrigger(action.Trigger)); err != nil { + return fmt.Errorf("Error setting `trigger`: %+v", err) + } + + if schedule := resp.Schedule; schedule != nil { + if schedule.FrequencyInMinutes != nil { + d.Set("frequency", schedule.FrequencyInMinutes) + } + if schedule.TimeWindowInMinutes != nil { + d.Set("time_window", schedule.TimeWindowInMinutes) + } + } + + if source := resp.Source; source != nil { + if source.AuthorizedResources != nil { + d.Set("authorized_resource_ids", utils.FlattenStringSlice(source.AuthorizedResources)) + } + if source.DataSourceID != nil { + d.Set("data_source_id", source.DataSourceID) + } + if source.Query != nil { + d.Set("query", source.Query) + } + d.Set("query_type", string(source.QueryType)) + } + + return tags.FlattenAndSet(d, resp.Tags) +} + +func resourceArmMonitorScheduledQueryRulesAlertDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Monitor.ScheduledQueryRulesClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["scheduledqueryrules"] + + if resp, err := client.Delete(ctx, resourceGroup, name); err != nil { + if !response.WasNotFound(resp.Response) { + return fmt.Errorf("Error deleting Scheduled Query Rule %q (resource group %q): %+v", name, resourceGroup, err) + } + } + + return nil +} + +func expandMonitorScheduledQueryRulesAlertingAction(d *schema.ResourceData) *insights.AlertingAction { + alertActionRaw := d.Get("action").([]interface{}) + alertAction := expandMonitorScheduledQueryRulesAlertAction(alertActionRaw) + severityRaw := d.Get("severity").(int) + severity := strconv.Itoa(severityRaw) + throttling := d.Get("throttling").(int) + + triggerRaw := d.Get("trigger").([]interface{}) + trigger := expandMonitorScheduledQueryRulesAlertTrigger(triggerRaw) + + action := insights.AlertingAction{ + AznsAction: alertAction, + Severity: insights.AlertSeverity(severity), + ThrottlingInMin: utils.Int32(int32(throttling)), + Trigger: trigger, + OdataType: insights.OdataTypeMicrosoftWindowsAzureManagementMonitoringAlertsModelsMicrosoftAppInsightsNexusDataContractsResourcesScheduledQueryRulesAlertingAction, + } + + return &action +} + +func expandMonitorScheduledQueryRulesAlertAction(input []interface{}) *insights.AzNsActionGroup { + result := insights.AzNsActionGroup{} + + if len(input) == 0 { + return &result + } + for _, item := range input { + if item == nil { + continue + } + + v, ok := item.(map[string]interface{}) + if !ok { + continue + } + actionGroups := v["action_group"].(*schema.Set).List() + result.ActionGroup = utils.ExpandStringSlice(actionGroups) + result.EmailSubject = utils.String(v["email_subject"].(string)) + result.CustomWebhookPayload = utils.String(v["custom_webhook_payload"].(string)) + } + + return &result +} + +func expandMonitorScheduledQueryRulesAlertMetricTrigger(input []interface{}) *insights.LogMetricTrigger { + if len(input) == 0 { + return nil + } + + result := insights.LogMetricTrigger{} + for _, item := range input { + if item == nil { + continue + } + v, ok := item.(map[string]interface{}) + if !ok { + continue + } + result.ThresholdOperator = insights.ConditionalOperator(v["operator"].(string)) + result.Threshold = utils.Float(v["threshold"].(float64)) + result.MetricTriggerType = insights.MetricTriggerType(v["metric_trigger_type"].(string)) + result.MetricColumn = utils.String(v["metric_column"].(string)) + } + + return &result +} + +func expandMonitorScheduledQueryRulesAlertSchedule(d *schema.ResourceData) *insights.Schedule { + frequency := d.Get("frequency").(int) + timeWindow := d.Get("time_window").(int) + + schedule := insights.Schedule{ + FrequencyInMinutes: utils.Int32(int32(frequency)), + TimeWindowInMinutes: utils.Int32(int32(timeWindow)), + } + + return &schedule +} + +func expandMonitorScheduledQueryRulesAlertTrigger(input []interface{}) *insights.TriggerCondition { + result := insights.TriggerCondition{} + if len(input) == 0 { + return &result + } + + for _, item := range input { + if item == nil { + continue + } + v, ok := item.(map[string]interface{}) + if !ok { + continue + } + metricTriggerRaw := v["metric_trigger"].([]interface{}) + + result.ThresholdOperator = insights.ConditionalOperator(v["operator"].(string)) + result.Threshold = utils.Float(v["threshold"].(float64)) + result.MetricTrigger = expandMonitorScheduledQueryRulesAlertMetricTrigger(metricTriggerRaw) + } + + return &result +} diff --git a/azurerm/internal/services/monitor/resource_arm_monitor_scheduled_query_rules_log.go b/azurerm/internal/services/monitor/resource_arm_monitor_scheduled_query_rules_log.go new file mode 100644 index 0000000000000..4efacb839a5af --- /dev/null +++ b/azurerm/internal/services/monitor/resource_arm_monitor_scheduled_query_rules_log.go @@ -0,0 +1,313 @@ +package monitor + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/preview/monitor/mgmt/2019-06-01/insights" + "github.com/hashicorp/go-azure-helpers/response" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmMonitorScheduledQueryRulesLog() *schema.Resource { + return &schema.Resource{ + Create: resourceArmMonitorScheduledQueryRulesLogCreateUpdate, + Read: resourceArmMonitorScheduledQueryRulesLogRead, + Update: resourceArmMonitorScheduledQueryRulesLogCreateUpdate, + Delete: resourceArmMonitorScheduledQueryRulesLogDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringDoesNotContainAny("<>*%&:\\?+/"), + }, + + "resource_group_name": azure.SchemaResourceGroupName(), + + "location": azure.SchemaLocation(), + + "authorized_resource_ids": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: azure.ValidateResourceID, + }, + }, + + "criteria": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dimension": { + Type: schema.TypeSet, + Required: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "operator": { + Type: schema.TypeString, + Optional: true, + Default: "Include", + ValidateFunc: validation.StringInSlice([]string{ + "Include", + }, false), + }, + "values": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + }, + }, + "metric_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + }, + "data_source_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: azure.ValidateResourceID, + }, + "description": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringLenBetween(1, 4096), + }, + "enabled": { + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + + "tags": tags.Schema(), + }, + } +} + +func resourceArmMonitorScheduledQueryRulesLogCreateUpdate(d *schema.ResourceData, meta interface{}) error { + action := expandMonitorScheduledQueryRulesLogToMetricAction(d) + + client := meta.(*clients.Client).Monitor.ScheduledQueryRulesClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + existing, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing Monitor Scheduled Query Rules %q (Resource Group %q): %s", name, resourceGroup, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_monitor_scheduled_query_rules_alert", *existing.ID) + } + } + + description := d.Get("description").(string) + enabledRaw := d.Get("enabled").(bool) + + enabled := insights.True + if !enabledRaw { + enabled = insights.False + } + + location := azure.NormalizeLocation(d.Get("location")) + + source := expandMonitorScheduledQueryRulesCommonSource(d) + + t := d.Get("tags").(map[string]interface{}) + expandedTags := tags.Expand(t) + + parameters := insights.LogSearchRuleResource{ + Location: utils.String(location), + LogSearchRule: &insights.LogSearchRule{ + Description: utils.String(description), + Enabled: enabled, + Source: source, + Action: action, + }, + Tags: expandedTags, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters); err != nil { + return fmt.Errorf("Error creating or updating Scheduled Query Rule %q (resource group %q): %+v", name, resourceGroup, err) + } + + read, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return err + } + if read.ID == nil { + return fmt.Errorf("Scheduled query rule %q (resource group %q) ID is empty", name, resourceGroup) + } + d.SetId(*read.ID) + + return resourceArmMonitorScheduledQueryRulesLogRead(d, meta) +} + +func resourceArmMonitorScheduledQueryRulesLogRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Monitor.ScheduledQueryRulesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["scheduledqueryrules"] + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[DEBUG] Scheduled Query Rule %q was not found in Resource Group %q", name, resourceGroup) + d.SetId("") + return nil + } + return fmt.Errorf("Error getting Scheduled Query Rule %q (resource group %q): %+v", name, resourceGroup, err) + } + + d.Set("name", name) + d.Set("resource_group_name", resourceGroup) + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + d.Set("description", resp.Description) + if resp.Enabled == insights.True { + d.Set("enabled", true) + } else { + d.Set("enabled", false) + } + + action, ok := resp.Action.(insights.LogToMetricAction) + if !ok { + return fmt.Errorf("Wrong action type in Scheduled Query Rule %q (resource group %q): %T", name, resourceGroup, resp.Action) + } + if err = d.Set("criteria", flattenAzureRmScheduledQueryRulesLogCriteria(action.Criteria)); err != nil { + return fmt.Errorf("Error setting `criteria`: %+v", err) + } + + if source := resp.Source; source != nil { + if source.AuthorizedResources != nil { + d.Set("authorized_resource_ids", utils.FlattenStringSlice(source.AuthorizedResources)) + } + if source.DataSourceID != nil { + d.Set("data_source_id", source.DataSourceID) + } + } + + return tags.FlattenAndSet(d, resp.Tags) +} + +func resourceArmMonitorScheduledQueryRulesLogDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Monitor.ScheduledQueryRulesClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["scheduledqueryrules"] + + if resp, err := client.Delete(ctx, resourceGroup, name); err != nil { + if !response.WasNotFound(resp.Response) { + return fmt.Errorf("Error deleting Scheduled Query Rule %q (resource group %q): %+v", name, resourceGroup, err) + } + } + + return nil +} + +func expandMonitorScheduledQueryRulesLogCriteria(input []interface{}) *[]insights.Criteria { + criteria := make([]insights.Criteria, 0) + if len(input) == 0 { + return &criteria + } + + for _, item := range input { + if item == nil { + continue + } + v, ok := item.(map[string]interface{}) + if !ok { + continue + } + + dimensions := make([]insights.Dimension, 0) + for _, dimension := range v["dimension"].(*schema.Set).List() { + if dimension == nil { + continue + } + dVal, ok := dimension.(map[string]interface{}) + if !ok { + continue + } + dimensions = append(dimensions, insights.Dimension{ + Name: utils.String(dVal["name"].(string)), + Operator: utils.String(dVal["operator"].(string)), + Values: utils.ExpandStringSlice(dVal["values"].([]interface{})), + }) + } + + criteria = append(criteria, insights.Criteria{ + MetricName: utils.String(v["metric_name"].(string)), + Dimensions: &dimensions, + }) + } + return &criteria +} + +func expandMonitorScheduledQueryRulesLogToMetricAction(d *schema.ResourceData) *insights.LogToMetricAction { + criteriaRaw := d.Get("criteria").([]interface{}) + criteria := expandMonitorScheduledQueryRulesLogCriteria(criteriaRaw) + + action := insights.LogToMetricAction{ + Criteria: criteria, + OdataType: insights.OdataTypeMicrosoftWindowsAzureManagementMonitoringAlertsModelsMicrosoftAppInsightsNexusDataContractsResourcesScheduledQueryRulesLogToMetricAction, + } + + return &action +} diff --git a/azurerm/internal/services/monitor/tests/data_source_monitor_action_group_test.go b/azurerm/internal/services/monitor/tests/data_source_monitor_action_group_test.go index 143a0fc6e4081..7226c34f8781e 100644 --- a/azurerm/internal/services/monitor/tests/data_source_monitor_action_group_test.go +++ b/azurerm/internal/services/monitor/tests/data_source_monitor_action_group_test.go @@ -138,6 +138,10 @@ func TestAccDataSourceArmMonitorActionGroup_complete(t *testing.T) { func testAccDataSourceArmMonitorActionGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -145,19 +149,23 @@ resource "azurerm_resource_group" "test" { resource "azurerm_monitor_action_group" "test" { name = "acctestActionGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" } data "azurerm_monitor_action_group" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - name = "${azurerm_monitor_action_group.test.name}" + resource_group_name = azurerm_resource_group.test.name + name = azurerm_monitor_action_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccDataSourceArmMonitorActionGroup_disabledBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -165,20 +173,24 @@ resource "azurerm_resource_group" "test" { resource "azurerm_monitor_action_group" "test" { name = "acctestActionGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" enabled = false } data "azurerm_monitor_action_group" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - name = "${azurerm_monitor_action_group.test.name}" + resource_group_name = azurerm_resource_group.test.name + name = azurerm_monitor_action_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccDataSourceArmMonitorActionGroup_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/monitor/tests/data_source_monitor_diagnostic_categories_test.go b/azurerm/internal/services/monitor/tests/data_source_monitor_diagnostic_categories_test.go index 7c1ed10a5e2ad..8d0245b157cd4 100644 --- a/azurerm/internal/services/monitor/tests/data_source_monitor_diagnostic_categories_test.go +++ b/azurerm/internal/services/monitor/tests/data_source_monitor_diagnostic_categories_test.go @@ -46,6 +46,10 @@ func TestAccDataSourceArmMonitorDiagnosticCategories_storageAccount(t *testing.T func testAccDataSourceArmMonitorDiagnosticCategories_appService(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -53,8 +57,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_app_service_plan" "test" { name = "acctestASP-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku { tier = "Standard" @@ -64,19 +68,23 @@ resource "azurerm_app_service_plan" "test" { resource "azurerm_app_service" "test" { name = "acctestAS-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - app_service_plan_id = "${azurerm_app_service_plan.test.id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + app_service_plan_id = azurerm_app_service_plan.test.id } data "azurerm_monitor_diagnostic_categories" "test" { - resource_id = "${azurerm_app_service.test.id}" + resource_id = azurerm_app_service.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testAccDataSourceArmMonitorDiagnosticCategories_storageAccount(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -84,8 +92,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "GRS" @@ -95,7 +103,7 @@ resource "azurerm_storage_account" "test" { } data "azurerm_monitor_diagnostic_categories" "test" { - resource_id = "${azurerm_storage_account.test.id}" + resource_id = azurerm_storage_account.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/monitor/tests/data_source_monitor_log_profile_test.go b/azurerm/internal/services/monitor/tests/data_source_monitor_log_profile_test.go index 46f4a0f90e6b9..21e915bf607ad 100644 --- a/azurerm/internal/services/monitor/tests/data_source_monitor_log_profile_test.go +++ b/azurerm/internal/services/monitor/tests/data_source_monitor_log_profile_test.go @@ -64,6 +64,10 @@ func testAccDataSourceAzureRMMonitorLogProfile_eventhub(t *testing.T) { func testAccDataSourceAzureRMMonitorLogProfile_storageaccountConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -71,8 +75,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "GRS" } @@ -88,7 +92,7 @@ resource "azurerm_monitor_log_profile" "test" { "%s", ] - storage_account_id = "${azurerm_storage_account.test.id}" + storage_account_id = azurerm_storage_account.test.id retention_policy { enabled = true @@ -97,13 +101,17 @@ resource "azurerm_monitor_log_profile" "test" { } data "azurerm_monitor_log_profile" "test" { - name = "${azurerm_monitor_log_profile.test.name}" + name = azurerm_monitor_log_profile.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.Locations.Primary) } func testAccDataSourceAzureRMMonitorLogProfile_eventhubConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -111,8 +119,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_eventhub_namespace" "test" { name = "acctestehns-%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" capacity = 2 } @@ -138,7 +146,7 @@ resource "azurerm_monitor_log_profile" "test" { } data "azurerm_monitor_log_profile" "test" { - name = "${azurerm_monitor_log_profile.test.name}" + name = azurerm_monitor_log_profile.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/monitor/tests/data_source_monitor_scheduled_query_rules_alert_test.go b/azurerm/internal/services/monitor/tests/data_source_monitor_scheduled_query_rules_alert_test.go new file mode 100644 index 0000000000000..382002fc4d037 --- /dev/null +++ b/azurerm/internal/services/monitor/tests/data_source_monitor_scheduled_query_rules_alert_test.go @@ -0,0 +1,70 @@ +package tests + +import ( + "fmt" + "testing" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMMonitorScheduledQueryRules_AlertingAction(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_monitor_scheduled_query_rules_alert", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMMonitorScheduledQueryRules_AlertingActionConfig(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMMonitorScheduledQueryRules_AlertingActionCrossResource(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_monitor_scheduled_query_rules_alert", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMMonitorScheduledQueryRules_AlertingActionCrossResourceConfig(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMMonitorScheduledQueryRules_AlertingActionConfig(data acceptance.TestData) string { + ts := time.Now().Format(time.RFC3339) + template := testAccAzureRMMonitorScheduledQueryRules_AlertingActionConfigBasic(data, ts) + + return fmt.Sprintf(` +%s + +data "azurerm_monitor_scheduled_query_rules_alert" "test" { + name = basename(azurerm_monitor_scheduled_query_rules_alert.test.id) + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template) +} + +func testAccDataSourceAzureRMMonitorScheduledQueryRules_AlertingActionCrossResourceConfig(data acceptance.TestData) string { + template := testAccAzureRMMonitorScheduledQueryRules_AlertingActionCrossResourceConfig(data) + return fmt.Sprintf(` +%s + +data "azurerm_monitor_scheduled_query_rules_alert" "test" { + name = basename(azurerm_monitor_scheduled_query_rules_alert.test.id) + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template) +} diff --git a/azurerm/internal/services/monitor/tests/data_source_monitor_scheduled_query_rules_log_test.go b/azurerm/internal/services/monitor/tests/data_source_monitor_scheduled_query_rules_log_test.go new file mode 100644 index 0000000000000..6c23137eb96f5 --- /dev/null +++ b/azurerm/internal/services/monitor/tests/data_source_monitor_scheduled_query_rules_log_test.go @@ -0,0 +1,38 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMMonitorScheduledQueryRules_LogToMetricAction(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_monitor_scheduled_query_rules_log", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMMonitorScheduledQueryRules_LogToMetricActionConfig(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMMonitorScheduledQueryRules_LogToMetricActionConfig(data acceptance.TestData) string { + template := testAccAzureRMMonitorScheduledQueryRules_LogToMetricActionConfigBasic(data) + return fmt.Sprintf(` +%s + +data "azurerm_monitor_scheduled_query_rules_log" "test" { + name = basename(azurerm_monitor_scheduled_query_rules_log.test.id) + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template) +} diff --git a/azurerm/internal/services/monitor/tests/resource_arm_autoscale_setting_test.go b/azurerm/internal/services/monitor/tests/resource_arm_autoscale_setting_test.go deleted file mode 100644 index ce680d4a64a48..0000000000000 --- a/azurerm/internal/services/monitor/tests/resource_arm_autoscale_setting_test.go +++ /dev/null @@ -1,918 +0,0 @@ -package tests - -import ( - "fmt" - "net/http" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" -) - -func TestAccAzureRMAutoScaleSetting_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutoScaleSetting_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.name", "metricRules"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.rule.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "0"), - resource.TestCheckNoResourceAttr(data.ResourceName, "tags.$type"), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMAutoScaleSetting_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - - data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutoScaleSetting_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMAutoScaleSetting_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_autoscale_setting"), - }, - }, - }) -} - -func TestAccAzureRMAutoScaleSetting_multipleProfiles(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutoScaleSetting_multipleProfiles(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.name", "primary"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.1.name", "secondary"), - ), - }, - }, - }) -} - -func TestAccAzureRMAutoScaleSetting_update(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutoScaleSetting_capacity(data, 1, 3, 2), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.minimum", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.maximum", "3"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.default", "2"), - ), - }, - { - Config: testAccAzureRMAutoScaleSetting_capacity(data, 0, 400, 0), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.minimum", "0"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.maximum", "400"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.default", "0"), - ), - }, - { - Config: testAccAzureRMAutoScaleSetting_capacity(data, 2, 45, 3), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.minimum", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.maximum", "45"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.default", "3"), - ), - }, - }, - }) -} - -func TestAccAzureRMAutoScaleSetting_multipleRules(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutoScaleSetting_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.name", "metricRules"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.rule.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.rule.0.scale_action.0.direction", "Increase"), - resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "0"), - ), - }, - { - Config: testAccAzureRMAutoScaleSetting_multipleRules(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.name", "metricRules"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.rule.#", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.rule.0.scale_action.0.direction", "Increase"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.rule.1.scale_action.0.direction", "Decrease"), - resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "0"), - ), - }, - }, - }) -} - -func TestAccAzureRMAutoScaleSetting_customEmails(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutoScaleSetting_email(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.0.custom_emails.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.0.custom_emails.0", fmt.Sprintf("acctest1-%d@example.com", data.RandomInteger)), - ), - }, - { - Config: testAccAzureRMAutoScaleSetting_emailUpdated(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.0.custom_emails.#", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.0.custom_emails.0", fmt.Sprintf("acctest1-%d@example.com", data.RandomInteger)), - resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.0.custom_emails.1", fmt.Sprintf("acctest2-%d@example.com", data.RandomInteger)), - ), - }, - }, - }) -} - -func TestAccAzureRMAutoScaleSetting_recurrence(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutoScaleSetting_recurrence(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.name", "recurrence"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "1"), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMAutoScaleSetting_recurrenceUpdate(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutoScaleSetting_recurrence(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.#", "3"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.0", "Monday"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.1", "Wednesday"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.2", "Friday"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.hours.0", "18"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.minutes.0", "0"), - ), - }, - { - Config: testAccAzureRMAutoScaleSetting_recurrenceUpdated(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.#", "3"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.0", "Monday"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.1", "Tuesday"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.2", "Wednesday"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.hours.0", "20"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.minutes.0", "15"), - ), - }, - }, - }) -} - -func TestAccAzureRMAutoScaleSetting_fixedDate(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMAutoScaleSetting_fixedDate(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.name", "fixedDate"), - resource.TestCheckResourceAttr(data.ResourceName, "profile.0.fixed_date.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "0"), - ), - }, - data.ImportStep(), - }, - }) -} - -func testCheckAzureRMAutoScaleSettingExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := acceptance.AzureProvider.Meta().(*clients.Client).Monitor.AutoscaleSettingsClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - autoscaleSettingName := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for AutoScale Setting: %s", autoscaleSettingName) - } - - resp, err := conn.Get(ctx, resourceGroup, autoscaleSettingName) - if err != nil { - return fmt.Errorf("Bad: Get on AutoScale Setting: %+v", err) - } - - if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: AutoScale Setting %q (Resource Group: %q) does not exist", autoscaleSettingName, resourceGroup) - } - - return nil - } -} - -func testCheckAzureRMAutoScaleSettingDestroy(s *terraform.State) error { - conn := acceptance.AzureProvider.Meta().(*clients.Client).Monitor.AutoscaleSettingsClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_autoscale_setting" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := conn.Get(ctx, resourceGroup, name) - - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("AutoScale Setting still exists:\n%#v", resp) - } - } - - return nil -} - -func testAccAzureRMAutoScaleSetting_basic(data acceptance.TestData) string { - template := testAccAzureRMAutoScaleSetting_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_autoscale_setting" "test" { - name = "acctestautoscale-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - - profile { - name = "metricRules" - - capacity { - default = 1 - minimum = 1 - maximum = 30 - } - - rule { - metric_trigger { - metric_name = "Percentage CPU" - metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - time_grain = "PT1M" - statistic = "Average" - time_window = "PT5M" - time_aggregation = "Average" - operator = "GreaterThan" - threshold = 75 - } - - scale_action { - direction = "Increase" - type = "ChangeCount" - value = 1 - cooldown = "PT1M" - } - } - } -} -`, template, data.RandomInteger) -} - -func testAccAzureRMAutoScaleSetting_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMAutoScaleSetting_basic(data) - return fmt.Sprintf(` -%s - -resource "azurerm_autoscale_setting" "import" { - name = "${azurerm_autoscale_setting.test.name}" - resource_group_name = "${azurerm_autoscale_setting.test.resource_group_name}" - location = "${azurerm_autoscale_setting.test.location}" - target_resource_id = "${azurerm_autoscale_setting.test.target_resource_id}" - - profile { - name = "metricRules" - - capacity { - default = 1 - minimum = 1 - maximum = 30 - } - - rule { - metric_trigger { - metric_name = "Percentage CPU" - metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - time_grain = "PT1M" - statistic = "Average" - time_window = "PT5M" - time_aggregation = "Average" - operator = "GreaterThan" - threshold = 75 - } - - scale_action { - direction = "Increase" - type = "ChangeCount" - value = 1 - cooldown = "PT1M" - } - } - } -} -`, template) -} - -func testAccAzureRMAutoScaleSetting_multipleProfiles(data acceptance.TestData) string { - template := testAccAzureRMAutoScaleSetting_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_autoscale_setting" "test" { - name = "acctestautoscale-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - - profile { - name = "primary" - - capacity { - default = 1 - minimum = 1 - maximum = 30 - } - - rule { - metric_trigger { - metric_name = "Percentage CPU" - metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - time_grain = "PT1M" - statistic = "Average" - time_window = "PT5M" - time_aggregation = "Average" - operator = "GreaterThan" - threshold = 75 - } - - scale_action { - direction = "Increase" - type = "ChangeCount" - value = 1 - cooldown = "PT1M" - } - } - - rule { - metric_trigger { - metric_name = "Percentage CPU" - metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - time_grain = "PT1M" - statistic = "Average" - time_window = "PT5M" - time_aggregation = "Average" - operator = "GreaterThan" - threshold = 75 - } - - scale_action { - direction = "Decrease" - type = "ChangeCount" - value = 1 - cooldown = "PT1M" - } - } - } - - profile { - name = "secondary" - - capacity { - default = 1 - minimum = 1 - maximum = 30 - } - - recurrence { - timezone = "Pacific Standard Time" - - days = [ - "Monday", - "Wednesday", - "Friday", - ] - - hours = [18] - minutes = [0] - } - } -} -`, template, data.RandomInteger) -} - -func testAccAzureRMAutoScaleSetting_multipleRules(data acceptance.TestData) string { - template := testAccAzureRMAutoScaleSetting_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_autoscale_setting" "test" { - name = "acctestautoscale-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - enabled = true - - profile { - name = "metricRules" - - capacity { - default = 1 - minimum = 1 - maximum = 30 - } - - rule { - metric_trigger { - metric_name = "Percentage CPU" - metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - time_grain = "PT1M" - statistic = "Average" - time_window = "PT5M" - time_aggregation = "Average" - operator = "GreaterThan" - threshold = 75 - } - - scale_action { - direction = "Increase" - type = "ChangeCount" - value = 1 - cooldown = "PT1M" - } - } - - rule { - metric_trigger { - metric_name = "Percentage CPU" - metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - time_grain = "PT1M" - statistic = "Average" - time_window = "PT5M" - time_aggregation = "Average" - operator = "LessThan" - threshold = 25 - } - - scale_action { - direction = "Decrease" - type = "ChangeCount" - value = 1 - cooldown = "PT1M" - } - } - } -} -`, template, data.RandomInteger) -} - -func testAccAzureRMAutoScaleSetting_capacity(data acceptance.TestData, min int, max int, defaultVal int) string { - template := testAccAzureRMAutoScaleSetting_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_autoscale_setting" "test" { - name = "acctestautoscale-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - enabled = false - - profile { - name = "metricRules" - - capacity { - default = %d - minimum = %d - maximum = %d - } - - rule { - metric_trigger { - metric_name = "Percentage CPU" - metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - time_grain = "PT1M" - statistic = "Average" - time_window = "PT5M" - time_aggregation = "Average" - operator = "GreaterThan" - threshold = 75 - } - - scale_action { - direction = "Increase" - type = "ChangeCount" - value = 1 - cooldown = "PT1M" - } - } - } -} -`, template, data.RandomInteger, defaultVal, min, max) -} - -func testAccAzureRMAutoScaleSetting_email(data acceptance.TestData) string { - template := testAccAzureRMAutoScaleSetting_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_autoscale_setting" "test" { - name = "acctestautoscale-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - - profile { - name = "metricRules" - - capacity { - default = 1 - minimum = 1 - maximum = 30 - } - - rule { - metric_trigger { - metric_name = "Percentage CPU" - metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - time_grain = "PT1M" - statistic = "Average" - time_window = "PT5M" - time_aggregation = "Average" - operator = "GreaterThan" - threshold = 75 - } - - scale_action { - direction = "Increase" - type = "ChangeCount" - value = 1 - cooldown = "PT1M" - } - } - } - - notification { - email { - send_to_subscription_administrator = false - send_to_subscription_co_administrator = false - custom_emails = ["acctest1-%d@example.com"] - } - } -} -`, template, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMAutoScaleSetting_emailUpdated(data acceptance.TestData) string { - template := testAccAzureRMAutoScaleSetting_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_autoscale_setting" "test" { - name = "acctestautoscale-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - - profile { - name = "metricRules" - - capacity { - default = 1 - minimum = 1 - maximum = 30 - } - - rule { - metric_trigger { - metric_name = "Percentage CPU" - metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - time_grain = "PT1M" - statistic = "Average" - time_window = "PT5M" - time_aggregation = "Average" - operator = "GreaterThan" - threshold = 75 - } - - scale_action { - direction = "Increase" - type = "ChangeCount" - value = 1 - cooldown = "PT1M" - } - } - } - - notification { - email { - send_to_subscription_administrator = false - send_to_subscription_co_administrator = false - custom_emails = ["acctest1-%d@example.com", "acctest2-%d@example.com"] - } - } -} -`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMAutoScaleSetting_recurrence(data acceptance.TestData) string { - template := testAccAzureRMAutoScaleSetting_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_autoscale_setting" "test" { - name = "acctestautoscale-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - - profile { - name = "recurrence" - - capacity { - default = 1 - minimum = 1 - maximum = 30 - } - - recurrence { - timezone = "Pacific Standard Time" - - days = [ - "Monday", - "Wednesday", - "Friday", - ] - - hours = [18] - minutes = [0] - } - } - - notification { - email { - send_to_subscription_administrator = false - send_to_subscription_co_administrator = false - } - } -} -`, template, data.RandomInteger) -} - -func testAccAzureRMAutoScaleSetting_recurrenceUpdated(data acceptance.TestData) string { - template := testAccAzureRMAutoScaleSetting_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_autoscale_setting" "test" { - name = "acctestautoscale-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - - profile { - name = "recurrence" - - capacity { - default = 1 - minimum = 1 - maximum = 30 - } - - recurrence { - timezone = "Pacific Standard Time" - - days = [ - "Monday", - "Tuesday", - "Wednesday", - ] - - hours = [20] - minutes = [15] - } - } - - notification { - email { - send_to_subscription_administrator = false - send_to_subscription_co_administrator = false - } - } -} -`, template, data.RandomInteger) -} - -func testAccAzureRMAutoScaleSetting_fixedDate(data acceptance.TestData) string { - template := testAccAzureRMAutoScaleSetting_template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_autoscale_setting" "test" { - name = "acctestautoscale-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}" - - profile { - name = "fixedDate" - - capacity { - default = 1 - minimum = 1 - maximum = 30 - } - - fixed_date { - timezone = "Pacific Standard Time" - start = "2020-06-18T00:00:00Z" - end = "2020-06-18T23:59:59Z" - } - } -} -`, template, data.RandomInteger) -} - -func testAccAzureRMAutoScaleSetting_template(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "internal" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} - -resource "azurerm_virtual_machine_scale_set" "test" { - name = "acctvmss-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - upgrade_policy_mode = "Automatic" - single_placement_group = "false" - - sku { - name = "Standard_DS1_v2" - tier = "Standard" - capacity = 30 - } - - os_profile { - computer_name_prefix = "testvm-%d" - admin_username = "myadmin" - admin_password = "Passwword1234" - } - - network_profile { - name = "TestNetworkProfile-%d" - primary = true - - ip_configuration { - name = "TestIPConfiguration" - subnet_id = "${azurerm_subnet.test.id}" - primary = true - } - } - - storage_profile_os_disk { - name = "" - caching = "ReadWrite" - create_option = "FromImage" - managed_disk_type = "StandardSSD_LRS" - } - - storage_profile_image_reference { - publisher = "Canonical" - offer = "UbuntuServer" - sku = "16.04-LTS" - version = "latest" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} diff --git a/azurerm/internal/services/monitor/tests/resource_arm_metric_alertrule_test.go b/azurerm/internal/services/monitor/tests/resource_arm_metric_alertrule_test.go deleted file mode 100644 index 9fad64b86ac56..0000000000000 --- a/azurerm/internal/services/monitor/tests/resource_arm_metric_alertrule_test.go +++ /dev/null @@ -1,483 +0,0 @@ -package tests - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/monitor" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func TestValidateMetricAlertRuleTags(t *testing.T) { - cases := []struct { - Name string - Value map[string]interface{} - ErrCount int - }{ - { - Name: "Single Valid", - Value: map[string]interface{}{ - "hello": "world", - }, - ErrCount: 0, - }, - { - Name: "Single Invalid", - Value: map[string]interface{}{ - "$Type": "hello/world", - }, - ErrCount: 1, - }, - { - Name: "Single Invalid lowercase", - Value: map[string]interface{}{ - "$type": "hello/world", - }, - ErrCount: 1, - }, - { - Name: "Multiple Valid", - Value: map[string]interface{}{ - "hello": "world", - "foo": "bar", - }, - ErrCount: 0, - }, - { - Name: "Multiple Invalid", - Value: map[string]interface{}{ - "hello": "world", - "$type": "Microsoft.Foo/Bar", - }, - ErrCount: 1, - }, - } - - for _, tc := range cases { - _, errors := monitor.ValidateMetricAlertRuleTags(tc.Value, "azurerm_metric_alert_rule") - - if len(errors) != tc.ErrCount { - t.Fatalf("Expected %q to return %d errors but returned %d", tc.Name, tc.ErrCount, len(errors)) - } - } -} - -func TestAccAzureRMMetricAlertRule_virtualMachineCpu(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_metric_alertrule", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMMetricAlertRuleDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMMetricAlertRule_virtualMachineCpu(data, true), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMetricAlertRuleExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), - resource.TestCheckNoResourceAttr(data.ResourceName, "tags.$type"), - ), - }, - { - Config: testAccAzureRMMetricAlertRule_virtualMachineCpu(data, false), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMetricAlertRuleExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), - resource.TestCheckNoResourceAttr(data.ResourceName, "tags.$type"), - ), - }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMetricAlertRuleExists(data.ResourceName), - resource.TestCheckNoResourceAttr(data.ResourceName, "tags.$type"), - ), - }, - }, - }) -} - -func TestAccAzureRMMetricAlertRule_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - - data := acceptance.BuildTestData(t, "azurerm_metric_alertrule", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMMetricAlertRuleDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMMetricAlertRule_virtualMachineCpu(data, true), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMetricAlertRuleExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMMetricAlertRule_requiresImport(data, true), - ExpectError: acceptance.RequiresImportError("azurerm_metric_alertrule"), - }, - }, - }) -} - -func TestAccAzureRMMetricAlertRule_sqlDatabaseStorage(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_metric_alertrule", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMMetricAlertRuleDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMMetricAlertRule_sqlDatabaseStorage(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMetricAlertRuleExists(data.ResourceName), - resource.TestCheckNoResourceAttr(data.ResourceName, "tags.$type"), - ), - }, - }, - }) -} - -func testCheckAzureRMMetricAlertRuleExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Monitor.AlertRulesClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // Ensure we have enough information in state to look up in API - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - name := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for Alert Rule: %s", name) - } - - resp, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Alert Rule %q (resource group: %q) does not exist", name, resourceGroup) - } - - return fmt.Errorf("Bad: Get on monitorAlertRulesClient: %+v", err) - } - - return nil - } -} - -func testCheckAzureRMMetricAlertRuleDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Monitor.AlertRulesClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_metric_alertrule" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := client.Get(ctx, resourceGroup, name) - - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return nil - } - - return err - } - - return fmt.Errorf("Alert Rule still exists:\n%#v", resp) - } - - return nil -} - -func testAccAzureRMMetricAlertRule_virtualMachineCpu(data acceptance.TestData, enabled bool) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} - -resource "azurerm_network_interface" "test" { - name = "acctni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - } -} - -resource "azurerm_virtual_machine" "test" { - name = "acctvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_D1_v2" - - storage_image_reference { - publisher = "Canonical" - offer = "UbuntuServer" - sku = "16.04-LTS" - version = "latest" - } - - storage_os_disk { - name = "osd-%d" - caching = "ReadWrite" - create_option = "FromImage" - disk_size_gb = "50" - managed_disk_type = "Standard_LRS" - } - - os_profile { - computer_name = "hn%d" - admin_username = "testadmin" - admin_password = "Password1234!" - } - - os_profile_linux_config { - disable_password_authentication = false - } - - tags = { - environment = "Production" - cost-center = "Ops" - } -} - -resource "azurerm_metric_alertrule" "test" { - name = "${azurerm_virtual_machine.test.name}-cpu" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - - description = "An alert rule to watch the metric Percentage CPU" - - enabled = %t - - resource_id = "${azurerm_virtual_machine.test.id}" - metric_name = "Percentage CPU" - operator = "GreaterThan" - threshold = 75 - aggregation = "Average" - period = "PT5M" - - email_action { - send_to_service_owners = false - - custom_emails = [ - "support@azure.microsoft.com", - ] - } - - webhook_action { - service_uri = "https://requestb.in/18jamc41" - - properties = { - severity = "incredible" - acceptance_test = "true" - } - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, enabled) -} - -func testAccAzureRMMetricAlertRule_requiresImport(data acceptance.TestData, enabled bool) string { - template := testAccAzureRMMetricAlertRule_virtualMachineCpu(data, enabled) - return fmt.Sprintf(` -%s - -resource "azurerm_metric_alertrule" "import" { - name = "${azurerm_metric_alertrule.test.name}" - resource_group_name = "${azurerm_metric_alertrule.test.resource_group_name}" - location = "${azurerm_metric_alertrule.test.location}" - description = "${azurerm_metric_alertrule.test.description}" - enabled = "${azurerm_metric_alertrule.test.enabled}" - - resource_id = "${azurerm_virtual_machine.test.id}" - metric_name = "Percentage CPU" - operator = "GreaterThan" - threshold = 75 - aggregation = "Average" - period = "PT5M" - - email_action { - send_to_service_owners = false - - custom_emails = [ - "support@azure.microsoft.com", - ] - } - - webhook_action { - service_uri = "https://requestb.in/18jamc41" - - properties = { - severity = "incredible" - acceptance_test = "true" - } - } -} -`, template) -} - -func testAccAzureRMMetricAlertRule_sqlDatabaseStorage(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%[1]d" - location = "%[2]s" -} - - -resource "azurerm_sql_server" "test" { - name = "acctestsqlserver%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - version = "12.0" - administrator_login = "mradministrator" - administrator_login_password = "thisIsDog11" -} - -resource "azurerm_sql_database" "test" { - name = "acctestdb%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_sql_server.test.name}" - location = "${azurerm_resource_group.test.location}" - edition = "Standard" - collation = "SQL_Latin1_General_CP1_CI_AS" - max_size_bytes = "1073741824" - requested_service_objective_name = "S0" -} - -resource "azurerm_virtual_network" "test" { - name = "acctvn-%[1]d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "acctsub-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} - -resource "azurerm_network_interface" "test" { - name = "acctni-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - } -} - -resource "azurerm_virtual_machine" "test" { - name = "acctvm-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.test.id}"] - vm_size = "Standard_D1_v2" - - storage_image_reference { - publisher = "Canonical" - offer = "UbuntuServer" - sku = "16.04-LTS" - version = "latest" - } - - storage_os_disk { - name = "osd-%[1]d" - caching = "ReadWrite" - create_option = "FromImage" - disk_size_gb = "50" - managed_disk_type = "Standard_LRS" - } - - os_profile { - computer_name = "hn%[1]d" - admin_username = "testadmin" - admin_password = "Password1234!" - } - - os_profile_linux_config { - disable_password_authentication = false - } - - tags = { - environment = "Production" - cost-center = "Ops" - } -} - -resource "azurerm_metric_alertrule" "test" { - name = "${azurerm_sql_database.test.name}-storage" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - - description = "An alert rule to watch the metric Storage" - - enabled = true - - resource_id = "${azurerm_sql_database.test.id}" - metric_name = "storage" - operator = "GreaterThan" - threshold = 1073741824 - aggregation = "Maximum" - period = "PT10M" - - email_action { - send_to_service_owners = false - - custom_emails = [ - "support@azure.microsoft.com", - ] - } - - webhook_action { - service_uri = "https://requestb.in/18jamc41" - - properties = { - severity = "incredible" - acceptance_test = "true" - } - } -} -`, data.RandomInteger, data.Locations.Primary) -} diff --git a/azurerm/internal/services/monitor/tests/resource_arm_monitor_action_group_test.go b/azurerm/internal/services/monitor/tests/resource_arm_monitor_action_group_test.go index a8a0c2fe5e23d..3662ab54a4204 100644 --- a/azurerm/internal/services/monitor/tests/resource_arm_monitor_action_group_test.go +++ b/azurerm/internal/services/monitor/tests/resource_arm_monitor_action_group_test.go @@ -420,6 +420,10 @@ func TestAccAzureRMMonitorActionGroup_multipleReceiversUpdate(t *testing.T) { func testAccAzureRMMonitorActionGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -427,7 +431,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_monitor_action_group" "test" { name = "acctestActionGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -439,15 +443,19 @@ func testAccAzureRMMonitorActionGroup_requiresImport(data acceptance.TestData) s %s resource "azurerm_monitor_action_group" "import" { - name = "${azurerm_monitor_action_group.test.name}" - resource_group_name = "${azurerm_monitor_action_group.test.resource_group_name}" - short_name = "${azurerm_monitor_action_group.test.short_name}" + name = azurerm_monitor_action_group.test.name + resource_group_name = azurerm_monitor_action_group.test.resource_group_name + short_name = azurerm_monitor_action_group.test.short_name } `, template) } func testAccAzureRMMonitorActionGroup_emailReceiver(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -455,7 +463,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_monitor_action_group" "test" { name = "acctestActionGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" email_receiver { @@ -469,6 +477,10 @@ resource "azurerm_monitor_action_group" "test" { func testAccAzureRMMonitorActionGroup_itsmReceiver(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -476,7 +488,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_monitor_action_group" "test" { name = "acctestActionGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" itsm_receiver { @@ -492,6 +504,10 @@ resource "azurerm_monitor_action_group" "test" { func testAccAzureRMMonitorActionGroup_azureAppPushReceiver(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -499,7 +515,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_monitor_action_group" "test" { name = "acctestActionGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" azure_app_push_receiver { @@ -512,6 +528,10 @@ resource "azurerm_monitor_action_group" "test" { func testAccAzureRMMonitorActionGroup_smsReceiver(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -519,7 +539,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_monitor_action_group" "test" { name = "acctestActionGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" sms_receiver { @@ -533,6 +553,10 @@ resource "azurerm_monitor_action_group" "test" { func testAccAzureRMMonitorActionGroup_webhookReceiver(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -540,7 +564,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_monitor_action_group" "test" { name = "acctestActionGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" webhook_receiver { @@ -554,6 +578,10 @@ resource "azurerm_monitor_action_group" "test" { func testAccAzureRMMonitorActionGroup_automationRunbookReceiver(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -604,6 +632,10 @@ resource "azurerm_automation_runbook" "test" { func testAccAzureRMMonitorActionGroup_voiceReceiver(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -611,7 +643,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_monitor_action_group" "test" { name = "acctestActionGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" voice_receiver { @@ -625,6 +657,10 @@ resource "azurerm_monitor_action_group" "test" { func testAccAzureRMMonitorActionGroup_logicAppReceiver(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -632,12 +668,12 @@ resource "azurerm_resource_group" "test" { resource "azurerm_monitor_action_group" "test" { name = "acctestActionGroup-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" logic_app_receiver { name = "logicappaction" - resource_id = "${azurerm_logic_app_workflow.test.id}" + resource_id = azurerm_logic_app_workflow.test.id callback_url = "http://test-host:100/workflows/fb9c8d79b15f41ce9b12861862f43546/versions/08587100027316071865/triggers/manualTrigger/paths/invoke?api-version=2015-08-01-preview&sp=%%2Fversions%%2F08587100027316071865%%2Ftriggers%%2FmanualTrigger%%2Frun&sv=1.0&sig=IxEQ_ygZf6WNEQCbjV0Vs6p6Y4DyNEJVAa86U5B4xhk" use_common_alert_schema = true } @@ -645,13 +681,13 @@ resource "azurerm_monitor_action_group" "test" { resource "azurerm_logic_app_workflow" "test" { name = "acctestLA-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_logic_app_trigger_http_request" "test" { name = "some-http-trigger" - logic_app_id = "${azurerm_logic_app_workflow.test.id}" + logic_app_id = azurerm_logic_app_workflow.test.id schema = < ago(1h) + | where ObjectName == 'Processor' and CounterName == '%%%% Processor Time' + | summarize cpu=avg(CounterValue) by bin(TimeGenerated, 1m) + | extend ts=tostring(TimeGenerated); let b=requests + | where resultCode == '200' and timestamp > ago(1h) + | summarize reqs=count() by bin(timestamp, 1m) + | extend ts = tostring(timestamp); a + | join b on $left.ts == $right.ts + | where cpu > 50 and reqs > 5 +QUERY + , azurerm_log_analytics_workspace.test.id) + + frequency = 60 + time_window = 60 + + severity = 3 + action { + action_group = ["${azurerm_monitor_action_group.test.id}"] + email_subject = "Custom alert email subject" + } + + trigger { + operator = "GreaterThan" + threshold = 5000 + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +} + +func testCheckAzureRMMonitorScheduledQueryRules_AlertDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Monitor.ScheduledQueryRulesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_monitor_scheduled_query_rules_alert" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.Get(ctx, resourceGroup, name) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Scheduled Query Rule still exists:\n%#v", resp) + } + } + + return nil +} + +func testCheckAzureRMMonitorScheduledQueryRules_AlertExists(resourceName 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[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for Scheduled Query Rule Instance: %s", name) + } + + client := acceptance.AzureProvider.Meta().(*clients.Client).Monitor.ScheduledQueryRulesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Bad: Get on monitorScheduledQueryRulesClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Scheduled Query Rule Instance %q (resource group: %q) does not exist", name, resourceGroup) + } + + return nil + } +} diff --git a/azurerm/internal/services/monitor/tests/resource_arm_monitor_scheduled_query_rules_log_test.go b/azurerm/internal/services/monitor/tests/resource_arm_monitor_scheduled_query_rules_log_test.go new file mode 100644 index 0000000000000..c62f37193cd3b --- /dev/null +++ b/azurerm/internal/services/monitor/tests/resource_arm_monitor_scheduled_query_rules_log_test.go @@ -0,0 +1,263 @@ +package tests + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" +) + +func TestAccAzureRMMonitorScheduledQueryRules_LogToMetricActionBasic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_monitor_scheduled_query_rules_log", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMMonitorScheduledQueryRules_LogDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMMonitorScheduledQueryRules_LogToMetricActionConfigBasic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMMonitorScheduledQueryRules_LogExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMMonitorScheduledQueryRules_LogToMetricActionUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_monitor_scheduled_query_rules_log", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMMonitorScheduledQueryRules_LogDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMMonitorScheduledQueryRules_LogToMetricActionConfigBasic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMMonitorScheduledQueryRules_LogExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMMonitorScheduledQueryRules_LogToMetricActionConfigUpdate(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMMonitorScheduledQueryRules_LogExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMMonitorScheduledQueryRules_LogToMetricActionComplete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_monitor_scheduled_query_rules_log", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMMonitorScheduledQueryRules_LogDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMMonitorScheduledQueryRules_LogToMetricActionConfigComplete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMMonitorScheduledQueryRules_LogExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func testAccAzureRMMonitorScheduledQueryRules_LogToMetricActionConfigBasic(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-monitor-%d" + location = "%s" +} + +resource "azurerm_log_analytics_workspace" "test" { + name = "acctestWorkspace-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "PerGB2018" + retention_in_days = 30 +} + +resource "azurerm_monitor_scheduled_query_rules_log" "test" { + name = "acctestsqr-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + + data_source_id = "${azurerm_log_analytics_workspace.test.id}" + + criteria { + metric_name = "Average_%% Idle Time" + dimension { + name = "InstanceName" + operator = "Include" + values = ["1"] + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMMonitorScheduledQueryRules_LogToMetricActionConfigUpdate(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-monitor-%d" + location = "%s" +} + +resource "azurerm_log_analytics_workspace" "test" { + name = "acctestWorkspace-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "PerGB2018" + retention_in_days = 30 +} + +resource "azurerm_monitor_scheduled_query_rules_log" "test" { + name = "acctestsqr-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + description = "test log to metric action" + enabled = true + + data_source_id = "${azurerm_log_analytics_workspace.test.id}" + + criteria { + metric_name = "Average_%% Idle Time" + dimension { + name = "InstanceName" + operator = "Include" + values = ["2"] + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMMonitorScheduledQueryRules_LogToMetricActionConfigComplete(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-monitor-%d" + location = "%s" +} + +resource "azurerm_log_analytics_workspace" "test" { + name = "acctestWorkspace-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "PerGB2018" + retention_in_days = 30 +} + +resource "azurerm_monitor_action_group" "test" { + name = "acctestActionGroup-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + short_name = "acctestag" +} + +resource "azurerm_monitor_scheduled_query_rules_log" "test" { + name = "acctestsqr-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + description = "test log to metric action" + enabled = true + + data_source_id = "${azurerm_log_analytics_workspace.test.id}" + + criteria { + metric_name = "Average_%% Idle Time" + dimension { + name = "Computer" + operator = "Include" + values = ["*"] + } + } +} + +resource "azurerm_monitor_metric_alert" "test" { + name = "acctestmal-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + scopes = ["${azurerm_log_analytics_workspace.test.id}"] + description = "Action will be triggered when Average %% Idle Time is less than 10." + + criteria { + metric_namespace = "Microsoft.OperationalInsights/workspaces" + metric_name = "${azurerm_monitor_scheduled_query_rules_log.test.criteria[0].metric_name}" + aggregation = "Average" + operator = "LessThan" + threshold = 10 + } + + action { + action_group_id = "${azurerm_monitor_action_group.test.id}" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +} + +func testCheckAzureRMMonitorScheduledQueryRules_LogDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Monitor.ScheduledQueryRulesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_monitor_scheduled_query_rules_log" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.Get(ctx, resourceGroup, name) + + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Scheduled Query Rule still exists:\n%#v", resp) + } + } + + return nil +} + +func testCheckAzureRMMonitorScheduledQueryRules_LogExists(resourceName 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[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for Scheduled Query Rule Instance: %s", name) + } + + client := acceptance.AzureProvider.Meta().(*clients.Client).Monitor.ScheduledQueryRulesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Bad: Get on monitorScheduledQueryRulesClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Scheduled Query Rule Instance %q (resource group: %q) does not exist", name, resourceGroup) + } + + return nil + } +} diff --git a/azurerm/internal/services/msi/registration.go b/azurerm/internal/services/msi/registration.go index 1e4a3df1a3d07..bdcb5403a12ea 100644 --- a/azurerm/internal/services/msi/registration.go +++ b/azurerm/internal/services/msi/registration.go @@ -13,6 +13,13 @@ func (r Registration) Name() string { return "Managed Service Identities" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Authorization", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/msi/tests/data_source_user_assigned_identity_test.go b/azurerm/internal/services/msi/tests/data_source_user_assigned_identity_test.go index 0b0afe6602579..57735a1f7948e 100644 --- a/azurerm/internal/services/msi/tests/data_source_user_assigned_identity_test.go +++ b/azurerm/internal/services/msi/tests/data_source_user_assigned_identity_test.go @@ -62,6 +62,10 @@ func testEqualResourceAttr(dataSourceName string, resourceName string, attrName func testAccDataSourceAzureRMUserAssignedIdentity_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctest%d-rg" location = "%s" @@ -69,8 +73,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_user_assigned_identity" "test" { name = "acctest%s-uai" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location tags = { "foo" = "bar" @@ -78,8 +82,8 @@ resource "azurerm_user_assigned_identity" "test" { } data "azurerm_user_assigned_identity" "test" { - name = "${azurerm_user_assigned_identity.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_user_assigned_identity.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/msi/tests/resource_arm_user_assigned_identity_test.go b/azurerm/internal/services/msi/tests/resource_arm_user_assigned_identity_test.go index 4984f059b41f1..2effea3183df6 100644 --- a/azurerm/internal/services/msi/tests/resource_arm_user_assigned_identity_test.go +++ b/azurerm/internal/services/msi/tests/resource_arm_user_assigned_identity_test.go @@ -123,6 +123,10 @@ func testCheckAzureRMUserAssignedIdentityDestroy(s *terraform.State) error { func testAccAzureRMUserAssignedIdentity_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -130,8 +134,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_user_assigned_identity" "test" { name = "acctest%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location } `, data.RandomInteger, data.Locations.Primary, data.RandomString) } @@ -141,9 +145,9 @@ func testAccAzureRMUserAssignedIdentity_requiresImport(data acceptance.TestData) %s resource "azurerm_user_assigned_identity" "import" { - name = "${azurerm_user_assigned_identity.test.name}" - resource_group_name = "${azurerm_user_assigned_identity.test.resource_group_name}" - location = "${azurerm_user_assigned_identity.test.location}" + name = azurerm_user_assigned_identity.test.name + resource_group_name = azurerm_user_assigned_identity.test.resource_group_name + location = azurerm_user_assigned_identity.test.location } `, testAccAzureRMUserAssignedIdentity_basic(data)) } diff --git a/azurerm/internal/services/mssql/registration.go b/azurerm/internal/services/mssql/registration.go index 3cb495dca4c41..d2f13db37bc5d 100644 --- a/azurerm/internal/services/mssql/registration.go +++ b/azurerm/internal/services/mssql/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Microsoft SQL Server / SQL Azure" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Database", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/mssql/resource_arm_mssql_elasticpool.go b/azurerm/internal/services/mssql/resource_arm_mssql_elasticpool.go index 23c8b521d3d32..ab4603acac80c 100644 --- a/azurerm/internal/services/mssql/resource_arm_mssql_elasticpool.go +++ b/azurerm/internal/services/mssql/resource_arm_mssql_elasticpool.go @@ -129,45 +129,6 @@ func resourceArmMsSqlElasticPool() *schema.Resource { }, }, - "elastic_pool_properties": { - Type: schema.TypeList, - Computed: true, - Deprecated: "These properties herein have been moved to the top level or removed", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "state": { - Type: schema.TypeString, - Computed: true, - Deprecated: "This property has been removed", - }, - - "creation_date": { - Type: schema.TypeString, - Computed: true, - Deprecated: "This property has been removed", - }, - - "max_size_bytes": { - Type: schema.TypeInt, - Computed: true, - Deprecated: "This property has been moved to the top level", - }, - - "zone_redundant": { - Type: schema.TypeBool, - Computed: true, - Deprecated: "This property has been moved to the top level", - }, - - "license_type": { - Type: schema.TypeString, - Computed: true, - Deprecated: "This property has been removed", - }, - }, - }, - }, - "max_size_bytes": { Type: schema.TypeInt, Optional: true, @@ -320,11 +281,6 @@ func resourceArmMsSqlElasticPoolRead(d *schema.ResourceData, meta interface{}) e } d.Set("zone_redundant", properties.ZoneRedundant) - // todo remove in 2.0 - if err := d.Set("elastic_pool_properties", flattenAzureRmMsSqlElasticPoolProperties(resp.ElasticPoolProperties)); err != nil { - return fmt.Errorf("Error setting `elastic_pool_properties`: %+v", err) - } - if err := d.Set("per_database_settings", flattenAzureRmMsSqlElasticPoolPerDatabaseSettings(properties.PerDatabaseSettings)); err != nil { return fmt.Errorf("Error setting `per_database_settings`: %+v", err) } @@ -412,23 +368,6 @@ func flattenAzureRmMsSqlElasticPoolSku(input *sql.Sku) []interface{} { return []interface{}{values} } -func flattenAzureRmMsSqlElasticPoolProperties(resp *sql.ElasticPoolProperties) []interface{} { - elasticPoolProperty := map[string]interface{}{} - elasticPoolProperty["state"] = string(resp.State) - - if date := resp.CreationDate; date != nil { - elasticPoolProperty["creation_date"] = date.String() - } - - if zoneRedundant := resp.ZoneRedundant; zoneRedundant != nil { - elasticPoolProperty["zone_redundant"] = *zoneRedundant - } - - elasticPoolProperty["license_type"] = string(resp.LicenseType) - - return []interface{}{elasticPoolProperty} -} - func flattenAzureRmMsSqlElasticPoolPerDatabaseSettings(resp *sql.ElasticPoolPerDatabaseSettings) []interface{} { perDatabaseSettings := map[string]interface{}{} diff --git a/azurerm/internal/services/mssql/tests/data_source_mssql_elasticpool_test.go b/azurerm/internal/services/mssql/tests/data_source_mssql_elasticpool_test.go index 41d2e55a26fed..15eafc48f7217 100644 --- a/azurerm/internal/services/mssql/tests/data_source_mssql_elasticpool_test.go +++ b/azurerm/internal/services/mssql/tests/data_source_mssql_elasticpool_test.go @@ -37,6 +37,10 @@ func TestAccDataSourceAzureRMMsSqlElasticPool_basic(t *testing.T) { func testAccDataSourceAzureRMMsSqlElasticPool_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%s" @@ -44,8 +48,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_sql_server" "test" { name = "acctest%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location version = "12.0" administrator_login = "4dm1n157r470r" administrator_login_password = "4-v3ry-53cr37-p455w0rd" @@ -53,9 +57,9 @@ resource "azurerm_sql_server" "test" { resource "azurerm_mssql_elasticpool" "test" { name = "acctest-pool-dtu-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - server_name = "${azurerm_sql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + server_name = azurerm_sql_server.test.name max_size_gb = 50 zone_redundant = false @@ -73,9 +77,9 @@ resource "azurerm_mssql_elasticpool" "test" { } data "azurerm_mssql_elasticpool" "test" { - name = "${azurerm_mssql_elasticpool.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_sql_server.test.name}" + name = azurerm_mssql_elasticpool.test.name + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_sql_server.test.name } `, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/mssql/tests/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go b/azurerm/internal/services/mssql/tests/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go index 077a98f65ebb4..6222d86de1a28 100644 --- a/azurerm/internal/services/mssql/tests/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go +++ b/azurerm/internal/services/mssql/tests/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go @@ -222,6 +222,10 @@ resource "azurerm_mssql_database_vulnerability_assessment_rule_baseline" "test" func testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_database(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-mssql-%d" location = "%s" diff --git a/azurerm/internal/services/mssql/tests/resource_arm_mssql_elasticpool_test.go b/azurerm/internal/services/mssql/tests/resource_arm_mssql_elasticpool_test.go index 5c4555b8bfba2..d968a6c29281e 100644 --- a/azurerm/internal/services/mssql/tests/resource_arm_mssql_elasticpool_test.go +++ b/azurerm/internal/services/mssql/tests/resource_arm_mssql_elasticpool_test.go @@ -329,18 +329,27 @@ func testAccAzureRMMsSqlElasticPool_basic_DTU(data acceptance.TestData) string { } func testAccAzureRMMsSqlElasticPool_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMMsSqlElasticPool_DTU_Template(data, "BasicPool", "Basic", 50, 5242880000, 0, 5, false) + template := testAccAzureRMMsSqlElasticPool_DTU_Template(data, "BasicPool", "Basic", 50, 4.8828125, 0, 5, false) return fmt.Sprintf(` %s resource "azurerm_mssql_elasticpool" "import" { - name = "${azurerm_mssql_elasticpool.test.name}" - resource_group_name = "${azurerm_mssql_elasticpool.test.resource_group_name}" - location = "${azurerm_mssql_elasticpool.test.location}" - server_name = "${azurerm_mssql_elasticpool.test.server_name}" - max_size_bytes = "${azurerm_mssql_elasticpool.test.max_size_bytes}" - sku = "${azurerm_mssql_elasticpool.test.sku}" - per_database_settings = "${azurerm_mssql_elasticpool.test.per_database_settings}" + name = azurerm_mssql_elasticpool.test.name + resource_group_name = azurerm_mssql_elasticpool.test.resource_group_name + location = azurerm_mssql_elasticpool.test.location + server_name = azurerm_mssql_elasticpool.test.server_name + max_size_gb = 4.8828125 + + sku { + name = "BasicPool" + tier = "Basic" + capacity = 50 + } + + per_database_settings { + min_capacity = 0 + max_capacity = 5 + } } `, template) } @@ -371,6 +380,10 @@ func testAccAzureRMMsSqlElasticPool_resize_vCore(data acceptance.TestData) strin func testAccAzureRMMsSqlElasticPool_vCore_Template(data acceptance.TestData, skuName string, skuTier string, skuCapacity int, skuFamily string, databaseSettingsMin float64, databaseSettingsMax float64) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%s" @@ -378,8 +391,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_sql_server" "test" { name = "acctest%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location version = "12.0" administrator_login = "4dm1n157r470r" administrator_login_password = "4-v3ry-53cr37-p455w0rd" @@ -387,9 +400,9 @@ resource "azurerm_sql_server" "test" { resource "azurerm_mssql_elasticpool" "test" { name = "acctest-pool-vcore-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - server_name = "${azurerm_sql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + server_name = azurerm_sql_server.test.name max_size_gb = 5 sku { @@ -409,6 +422,10 @@ resource "azurerm_mssql_elasticpool" "test" { func testAccAzureRMMsSqlElasticPool_vCore_MaxSizeBytes_Template(data acceptance.TestData, skuName string, skuTier string, skuCapacity int, skuFamily string, databaseSettingsMin float64, databaseSettingsMax float64) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%s" @@ -416,8 +433,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_sql_server" "test" { name = "acctest%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location version = "12.0" administrator_login = "4dm1n157r470r" administrator_login_password = "4-v3ry-53cr37-p455w0rd" @@ -425,9 +442,9 @@ resource "azurerm_sql_server" "test" { resource "azurerm_mssql_elasticpool" "test" { name = "acctest-pool-vcore-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - server_name = "${azurerm_sql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + server_name = azurerm_sql_server.test.name max_size_bytes = 214748364800 sku { @@ -447,6 +464,10 @@ resource "azurerm_mssql_elasticpool" "test" { func testAccAzureRMMsSqlElasticPool_DTU_Template(data acceptance.TestData, skuName string, skuTier string, skuCapacity int, maxSizeGB float64, databaseSettingsMin int, databaseSettingsMax int, zoneRedundant bool) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" location = "%s" @@ -454,8 +475,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_sql_server" "test" { name = "acctest%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location version = "12.0" administrator_login = "4dm1n157r470r" administrator_login_password = "4-v3ry-53cr37-p455w0rd" @@ -463,9 +484,9 @@ resource "azurerm_sql_server" "test" { resource "azurerm_mssql_elasticpool" "test" { name = "acctest-pool-dtu-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - server_name = "${azurerm_sql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + server_name = azurerm_sql_server.test.name max_size_gb = %.7[6]f zone_redundant = %[9]t diff --git a/azurerm/internal/services/mssql/tests/resource_arm_mssql_server_security_alert_policy_test.go b/azurerm/internal/services/mssql/tests/resource_arm_mssql_server_security_alert_policy_test.go index e0c09ac069178..53a8304b71448 100644 --- a/azurerm/internal/services/mssql/tests/resource_arm_mssql_server_security_alert_policy_test.go +++ b/azurerm/internal/services/mssql/tests/resource_arm_mssql_server_security_alert_policy_test.go @@ -163,6 +163,10 @@ resource "azurerm_mssql_server_security_alert_policy" "test" { func testAccAzureRMMssqlServerSecurityAlertPolicy_server(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-mssql-%d" location = "%s" @@ -170,8 +174,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_sql_server" "test" { name = "acctestsqlserver%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location version = "12.0" administrator_login = "mradministrator" administrator_login_password = "thisIsDog11" @@ -179,7 +183,7 @@ resource "azurerm_sql_server" "test" { resource "azurerm_storage_account" "test" { name = "accsa%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name location = "%s" account_tier = "Standard" account_replication_type = "GRS" diff --git a/azurerm/internal/services/mssql/tests/resource_arm_mssql_server_vulnerability_assessment_test.go b/azurerm/internal/services/mssql/tests/resource_arm_mssql_server_vulnerability_assessment_test.go index af965843ca749..61c0f702403d9 100644 --- a/azurerm/internal/services/mssql/tests/resource_arm_mssql_server_vulnerability_assessment_test.go +++ b/azurerm/internal/services/mssql/tests/resource_arm_mssql_server_vulnerability_assessment_test.go @@ -162,6 +162,10 @@ resource "azurerm_mssql_server_vulnerability_assessment" "test" { func testAccAzureRMMssqlServerVulnerabilityAssessment_server(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-mssql-%d" location = "%s" diff --git a/azurerm/internal/services/mysql/registration.go b/azurerm/internal/services/mysql/registration.go index 5e145d34c4d72..cf8e58ead01b0 100644 --- a/azurerm/internal/services/mysql/registration.go +++ b/azurerm/internal/services/mysql/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "MySQL" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Database", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{} diff --git a/azurerm/internal/services/mysql/resource_arm_mysql_configuration.go b/azurerm/internal/services/mysql/resource_arm_mysql_configuration.go index 7b0744e7d22de..ea1cd6e80ad2c 100644 --- a/azurerm/internal/services/mysql/resource_arm_mysql_configuration.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_configuration.go @@ -73,6 +73,9 @@ func resourceArmMySQLConfigurationCreate(d *schema.ResourceData, meta interface{ }, } + // NOTE: this resource intentionally doesn't support Requires Import + // since a fallback route is created by default + future, err := client.CreateOrUpdate(ctx, resourceGroup, serverName, name, properties) if err != nil { return fmt.Errorf("Error issuing create/update request for MySQL Configuration %s (resource group %s, server name %s): %v", name, resourceGroup, serverName, err) diff --git a/azurerm/internal/services/mysql/resource_arm_mysql_server.go b/azurerm/internal/services/mysql/resource_arm_mysql_server.go index 1772bd255339e..7dd5ba650553e 100644 --- a/azurerm/internal/services/mysql/resource_arm_mysql_server.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_server.go @@ -51,10 +51,8 @@ func resourceArmMySqlServer() *schema.Resource { "resource_group_name": azure.SchemaResourceGroupName(), "sku_name": { - Type: schema.TypeString, - Optional: true, // required in 2.0 - Computed: true, // remove in 2.0 - ConflictsWith: []string{"sku"}, + Type: schema.TypeString, + Required: true, ValidateFunc: validation.StringInSlice([]string{ "B_Gen4_1", "B_Gen4_2", @@ -79,82 +77,6 @@ func resourceArmMySqlServer() *schema.Resource { }, false), }, - // remove in 2.0 - "sku": { - Type: schema.TypeList, - Optional: true, - Computed: true, - ConflictsWith: []string{"sku_name"}, - Deprecated: "This property has been deprecated in favour of the 'sku_name' property and will be removed in version 2.0 of the provider", - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - "B_Gen4_1", - "B_Gen4_2", - "B_Gen5_1", - "B_Gen5_2", - "GP_Gen4_2", - "GP_Gen4_4", - "GP_Gen4_8", - "GP_Gen4_16", - "GP_Gen4_32", - "GP_Gen5_2", - "GP_Gen5_4", - "GP_Gen5_8", - "GP_Gen5_16", - "GP_Gen5_32", - "GP_Gen5_64", - "MO_Gen5_2", - "MO_Gen5_4", - "MO_Gen5_8", - "MO_Gen5_16", - "MO_Gen5_32", - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, - - "capacity": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntInSlice([]int{ - 1, - 2, - 4, - 8, - 16, - 32, - 64, - }), - }, - - "tier": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - string(mysql.Basic), - string(mysql.GeneralPurpose), - string(mysql.MemoryOptimized), - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, - - "family": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - "Gen4", - "Gen5", - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, - }, - }, - }, - "administrator_login": { Type: schema.TypeString, Required: true, @@ -239,10 +161,10 @@ func resourceArmMySqlServer() *schema.Resource { }, CustomizeDiff: func(diff *schema.ResourceDiff, v interface{}) error { - tier, _ := diff.GetOk("sku.0.tier") + tier, _ := diff.GetOk("sku_name") storageMB, _ := diff.GetOk("storage_profile.0.storage_mb") - if strings.ToLower(tier.(string)) == "basic" && storageMB.(int) > 1048576 { + if strings.HasPrefix(tier.(string), "B_") && storageMB.(int) > 1048576 { return fmt.Errorf("basic pricing tier only supports upto 1,048,576 MB (1TB) of storage") } @@ -275,17 +197,9 @@ func resourceArmMySqlServerCreate(d *schema.ResourceData, meta interface{}) erro } } - var sku *mysql.Sku - if b, ok := d.GetOk("sku_name"); ok { - var err error - sku, err = expandServerSkuName(b.(string)) - if err != nil { - return fmt.Errorf("error expanding sku_name for MySQL Server %q (Resource Group %q): %v", name, resourceGroup, err) - } - } else if _, ok := d.GetOk("sku"); ok { - sku = expandMySQLServerSku(d) - } else { - return fmt.Errorf("One of `sku` or `sku_name` must be set for MySQL Server %q (Resource Group %q)", name, resourceGroup) + sku, err := expandServerSkuName(d.Get("sku_name").(string)) + if err != nil { + return fmt.Errorf("error expanding sku_name for MySQL Server %q (Resource Group %q): %v", name, resourceGroup, err) } properties := mysql.ServerForCreate{ @@ -335,17 +249,9 @@ func resourceArmMySqlServerUpdate(d *schema.ResourceData, meta interface{}) erro name := d.Get("name").(string) resourceGroup := d.Get("resource_group_name").(string) - var sku *mysql.Sku - if b, ok := d.GetOk("sku_name"); ok { - var err error - sku, err = expandServerSkuName(b.(string)) - if err != nil { - return fmt.Errorf("error expanding sku_name for MySQL Server %q (Resource Group %q): %v", name, resourceGroup, err) - } - } else if _, ok := d.GetOk("sku"); ok { - sku = expandMySQLServerSku(d) - } else { - return fmt.Errorf("One of `sku` or `sku_name` must be set for MySQL Server %q (Resource Group %q)", name, resourceGroup) + sku, err := expandServerSkuName(d.Get("sku_name").(string)) + if err != nil { + return fmt.Errorf("error expanding sku_name for MySQL Server %q (Resource Group %q): %v", name, resourceGroup, err) } properties := mysql.ServerUpdateParameters{ @@ -419,10 +325,6 @@ func resourceArmMySqlServerRead(d *schema.ResourceData, meta interface{}) error d.Set("version", string(resp.Version)) d.Set("ssl_enforcement", string(resp.SslEnforcement)) - if err := d.Set("sku", flattenMySQLServerSku(resp.Sku)); err != nil { - return fmt.Errorf("Error setting `sku`: %+v", err) - } - if err := d.Set("storage_profile", flattenMySQLStorageProfile(resp.StorageProfile)); err != nil { return fmt.Errorf("Error setting `storage_profile`: %+v", err) } @@ -488,23 +390,6 @@ func expandServerSkuName(skuName string) (*mysql.Sku, error) { }, nil } -func expandMySQLServerSku(d *schema.ResourceData) *mysql.Sku { - skus := d.Get("sku").([]interface{}) - sku := skus[0].(map[string]interface{}) - - name := sku["name"].(string) - capacity := sku["capacity"].(int) - tier := sku["tier"].(string) - family := sku["family"].(string) - - return &mysql.Sku{ - Name: utils.String(name), - Tier: mysql.SkuTier(tier), - Capacity: utils.Int32(int32(capacity)), - Family: utils.String(family), - } -} - func expandMySQLStorageProfile(d *schema.ResourceData) *mysql.StorageProfile { storageprofiles := d.Get("storage_profile").([]interface{}) storageprofile := storageprofiles[0].(map[string]interface{}) @@ -522,26 +407,6 @@ func expandMySQLStorageProfile(d *schema.ResourceData) *mysql.StorageProfile { } } -func flattenMySQLServerSku(resp *mysql.Sku) []interface{} { - values := map[string]interface{}{} - - if name := resp.Name; name != nil { - values["name"] = *name - } - - if capacity := resp.Capacity; capacity != nil { - values["capacity"] = *capacity - } - - values["tier"] = string(resp.Tier) - - if family := resp.Family; family != nil { - values["family"] = *family - } - - return []interface{}{values} -} - func flattenMySQLStorageProfile(resp *mysql.StorageProfile) []interface{} { values := map[string]interface{}{} diff --git a/azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule.go b/azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule.go index 303935da3ec19..21a520afca60e 100644 --- a/azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule.go @@ -97,7 +97,7 @@ func resourceArmMySqlVirtualNetworkRuleCreateUpdate(d *schema.ResourceData, meta return fmt.Errorf("Error creating MySQL Virtual Network Rule %q (MySQL Server: %q, Resource Group: %q): %+v", name, serverName, resourceGroup, err) } - //Wait for the provisioning state to become ready + // Wait for the provisioning state to become ready log.Printf("[DEBUG] Waiting for MySQL Virtual Network Rule %q (MySQL Server: %q, Resource Group: %q) to become ready", name, serverName, resourceGroup) stateConf := &resource.StateChangeConf{ Pending: []string{"Initializing", "InProgress", "Unknown", "ResponseNotFound"}, @@ -212,7 +212,7 @@ func mySQLVirtualNetworkStateStatusCodeRefreshFunc(ctx context.Context, client * return resp, string(props.State), nil } - //Valid response was returned but VirtualNetworkRuleProperties was nil. Basically the rule exists, but with no properties for some reason. Assume Unknown instead of returning error. + // Valid response was returned but VirtualNetworkRuleProperties was nil. Basically the rule exists, but with no properties for some reason. Assume Unknown instead of returning error. log.Printf("[DEBUG] Retrieving MySQL Virtual Network Rule %q (MySQL Server: %q, Resource Group: %q) returned empty VirtualNetworkRuleProperties", resourceGroup, serverName, name) return resp, "Unknown", nil } diff --git a/azurerm/internal/services/mysql/tests/resource_arm_mysql_configuration_test.go b/azurerm/internal/services/mysql/tests/resource_arm_mysql_configuration_test.go index 6b68a341db646..0855ebfb58f3b 100644 --- a/azurerm/internal/services/mysql/tests/resource_arm_mysql_configuration_test.go +++ b/azurerm/internal/services/mysql/tests/resource_arm_mysql_configuration_test.go @@ -205,6 +205,10 @@ resource "azurerm_mysql_configuration" "test" { func testAccAzureRMMySQLConfiguration_empty(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -212,8 +216,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" diff --git a/azurerm/internal/services/mysql/tests/resource_arm_mysql_database_test.go b/azurerm/internal/services/mysql/tests/resource_arm_mysql_database_test.go index b4d5f340de505..f22f24f03cb4b 100644 --- a/azurerm/internal/services/mysql/tests/resource_arm_mysql_database_test.go +++ b/azurerm/internal/services/mysql/tests/resource_arm_mysql_database_test.go @@ -156,6 +156,10 @@ func testCheckAzureRMMySQLDatabaseDestroy(s *terraform.State) error { func testAccAzureRMMySQLDatabase_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -163,8 +167,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_mysql_server" "test" { name = "acctestpsqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -182,8 +186,8 @@ resource "azurerm_mysql_server" "test" { resource "azurerm_mysql_database" "test" { name = "acctestdb_%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_mysql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_mysql_server.test.name charset = "utf8" collation = "utf8_unicode_ci" } @@ -195,17 +199,21 @@ func testAccAzureRMMySQLDatabase_requiresImport(data acceptance.TestData) string %s resource "azurerm_mysql_database" "import" { - name = "${azurerm_mysql_database.test.name}" - resource_group_name = "${azurerm_mysql_database.test.resource_group_name}" - server_name = "${azurerm_mysql_database.test.server_name}" - charset = "${azurerm_mysql_database.test.charset}" - collation = "${azurerm_mysql_database.test.collation}" + name = azurerm_mysql_database.test.name + resource_group_name = azurerm_mysql_database.test.resource_group_name + server_name = azurerm_mysql_database.test.server_name + charset = azurerm_mysql_database.test.charset + collation = azurerm_mysql_database.test.collation } `, testAccAzureRMMySQLDatabase_basic(data)) } func testAccAzureRMMySQLDatabase_charsetUppercase(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -213,8 +221,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_mysql_server" "test" { name = "acctestpsqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -232,8 +240,8 @@ resource "azurerm_mysql_server" "test" { resource "azurerm_mysql_database" "test" { name = "acctestdb_%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_mysql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_mysql_server.test.name charset = "UTF8" collation = "utf8_unicode_ci" } @@ -242,6 +250,10 @@ resource "azurerm_mysql_database" "test" { func testAccAzureRMMySQLDatabase_charsetMixedcase(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -249,8 +261,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_mysql_server" "test" { name = "acctestpsqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -268,8 +280,8 @@ resource "azurerm_mysql_server" "test" { resource "azurerm_mysql_database" "test" { name = "acctestdb_%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_mysql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_mysql_server.test.name charset = "Utf8" collation = "utf8_unicode_ci" } diff --git a/azurerm/internal/services/mysql/tests/resource_arm_mysql_firewall_rule_test.go b/azurerm/internal/services/mysql/tests/resource_arm_mysql_firewall_rule_test.go index 9a4d515168ce8..1e419570634c8 100644 --- a/azurerm/internal/services/mysql/tests/resource_arm_mysql_firewall_rule_test.go +++ b/azurerm/internal/services/mysql/tests/resource_arm_mysql_firewall_rule_test.go @@ -117,6 +117,10 @@ func testCheckAzureRMMySQLFirewallRuleDestroy(s *terraform.State) error { func testAccAzureRMMySQLFirewallRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -124,8 +128,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -143,8 +147,8 @@ resource "azurerm_mysql_server" "test" { resource "azurerm_mysql_firewall_rule" "test" { name = "acctestfwrule-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_mysql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_mysql_server.test.name start_ip_address = "0.0.0.0" end_ip_address = "255.255.255.255" } @@ -156,11 +160,11 @@ func testAccAzureRMMySQLFirewallRule_requiresImport(data acceptance.TestData) st %s resource "azurerm_mysql_firewall_rule" "import" { - name = "${azurerm_mysql_firewall_rule.test.name}" - resource_group_name = "${azurerm_mysql_firewall_rule.test.resource_group_name}" - server_name = "${azurerm_mysql_firewall_rule.test.server_name}" - start_ip_address = "${azurerm_mysql_firewall_rule.test.start_ip_address}" - end_ip_address = "${azurerm_mysql_firewall_rule.test.end_ip_address}" + name = azurerm_mysql_firewall_rule.test.name + resource_group_name = azurerm_mysql_firewall_rule.test.resource_group_name + server_name = azurerm_mysql_firewall_rule.test.server_name + start_ip_address = azurerm_mysql_firewall_rule.test.start_ip_address + end_ip_address = azurerm_mysql_firewall_rule.test.end_ip_address } `, testAccAzureRMMySQLFirewallRule_basic(data)) } diff --git a/azurerm/internal/services/mysql/tests/resource_arm_mysql_server_test.go b/azurerm/internal/services/mysql/tests/resource_arm_mysql_server_test.go index b97425bd6887c..d2f84e500487f 100644 --- a/azurerm/internal/services/mysql/tests/resource_arm_mysql_server_test.go +++ b/azurerm/internal/services/mysql/tests/resource_arm_mysql_server_test.go @@ -31,25 +31,6 @@ func TestAccAzureRMMySQLServer_basicFiveSix(t *testing.T) { }) } -func TestAccAzureRMMySQLServer_basicFiveSixOldSku(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_mysql_server", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMMySQLServerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMMySQLServer_basicFiveSixOldSku(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(data.ResourceName), - ), - }, - data.ImportStep("administrator_login_password"), // not returned as sensitive - }, - }) -} - func TestAccAzureRMMySQLServer_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -120,25 +101,6 @@ func TestAccAzureRMMySQLServer_basicEightZero(t *testing.T) { }) } -func TestAccAzureRMMySqlServer_generalPurpose(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_mysql_server", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMMySQLServerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMMySQLServer_generalPurpose(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(data.ResourceName), - ), - }, - data.ImportStep("administrator_login_password"), // not returned as sensitive - }, - }) -} - func TestAccAzureRMMySqlServer_memoryOptimized(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_mysql_server", "test") @@ -169,7 +131,7 @@ func TestAccAzureRMMySQLServer_basicFiveSevenUpdated(t *testing.T) { Config: testAccAzureRMMySQLServer_basicFiveSeven(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMMySQLServerExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "GP_Gen5_2"), resource.TestCheckResourceAttr(data.ResourceName, "version", "5.7"), resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "51200"), resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), @@ -179,7 +141,7 @@ func TestAccAzureRMMySQLServer_basicFiveSevenUpdated(t *testing.T) { Config: testAccAzureRMMySQLServer_basicFiveSevenUpdated(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMMySQLServerExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_4"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "GP_Gen5_4"), resource.TestCheckResourceAttr(data.ResourceName, "version", "5.7"), resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "640000"), resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), @@ -199,25 +161,19 @@ func TestAccAzureRMMySQLServer_updateSKU(t *testing.T) { CheckDestroy: testCheckAzureRMMySQLServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySQLServer_generalPurpose(data), + Config: testAccAzureRMMySQLServer_basicEightZero(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMMySQLServerExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_32"), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "32"), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "GeneralPurpose"), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "Gen5"), - resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "640000"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "GP_Gen5_2"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "51200"), resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, { - Config: testAccAzureRMMySQLServer_memoryOptimized(data), + Config: testAccAzureRMMySQLServer_basicFiveSevenUpdated(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMMySQLServerExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "MO_Gen5_16"), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "16"), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "MemoryOptimized"), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "GP_Gen5_4"), resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "4194304"), resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), @@ -311,6 +267,10 @@ func testCheckAzureRMMySQLServerDestroy(s *terraform.State) error { func testAccAzureRMMySQLServer_basicFiveSix(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -318,8 +278,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -337,41 +297,12 @@ resource "azurerm_mysql_server" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMySQLServer_basicFiveSixOldSku(data acceptance.TestData) string { +func testAccAzureRMMySQLServer_basicFiveSeven(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_mysql_server" "test" { - name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "GP_Gen5_2" - capacity = 2 - tier = "GeneralPurpose" - family = "Gen5" - } - - storage_profile { - storage_mb = 51200 - backup_retention_days = 7 - geo_redundant_backup = "Disabled" - } - - administrator_login = "acctestun" - administrator_login_password = "H@Sh1CoR3!" - version = "5.6" - ssl_enforcement = "Enabled" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMMySQLServer_basicFiveSeven(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -379,8 +310,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -400,6 +331,10 @@ resource "azurerm_mysql_server" "test" { func testAccAzureRMMySQLServer_basicEightZero(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -407,8 +342,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -431,9 +366,9 @@ func testAccAzureRMMySQLServer_requiresImport(data acceptance.TestData) string { %s resource "azurerm_mysql_server" "import" { - name = "${azurerm_mysql_server.test.name}" - location = "${azurerm_mysql_server.test.location}" - resource_group_name = "${azurerm_mysql_server.test.resource_group_name}" + name = azurerm_mysql_server.test.name + location = azurerm_mysql_server.test.location + resource_group_name = azurerm_mysql_server.test.resource_group_name sku_name = "GP_Gen5_2" @@ -453,34 +388,10 @@ resource "azurerm_mysql_server" "import" { func testAccAzureRMMySQLServer_basicFiveSevenUpdated(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_mysql_server" "test" { - name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku_name = "GP_Gen5_4" - - storage_profile { - storage_mb = 640000 - backup_retention_days = 7 - geo_redundant_backup = "Disabled" - } - - administrator_login = "acctestun" - administrator_login_password = "H@Sh1CoR3!" - version = "5.7" - ssl_enforcement = "Enabled" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +provider "azurerm" { + features {} } -func testAccAzureRMMySQLServer_generalPurpose(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -488,15 +399,10 @@ resource "azurerm_resource_group" "test" { resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "GP_Gen5_32" - capacity = 32 - tier = "GeneralPurpose" - family = "Gen5" - } + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + sku_name = "GP_Gen5_4" storage_profile { storage_mb = 640000 @@ -512,36 +418,12 @@ resource "azurerm_mysql_server" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMySQLServer_memoryOptimized(data acceptance.TestData) string { +func testAccAzureRMMySQLServer_memoryOptimizedGeoRedundant(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_mysql_server" "test" { - name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku_name = "MO_Gen5_16" - - storage_profile { - storage_mb = 4194304 - backup_retention_days = 7 - geo_redundant_backup = "Disabled" - } - - administrator_login = "acctestun" - administrator_login_password = "H@Sh1CoR3!" - version = "5.7" - ssl_enforcement = "Enabled" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMMySQLServer_memoryOptimizedGeoRedundant(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -549,8 +431,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "MO_Gen5_16" @@ -570,6 +452,10 @@ resource "azurerm_mysql_server" "test" { func testAccAzureRMMySQLServer_autogrow(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -577,8 +463,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" diff --git a/azurerm/internal/services/mysql/tests/resource_arm_mysql_virtual_network_rule_test.go b/azurerm/internal/services/mysql/tests/resource_arm_mysql_virtual_network_rule_test.go index 0fbbc56d31d08..20c05f9e578c3 100644 --- a/azurerm/internal/services/mysql/tests/resource_arm_mysql_virtual_network_rule_test.go +++ b/azurerm/internal/services/mysql/tests/resource_arm_mysql_virtual_network_rule_test.go @@ -82,8 +82,8 @@ func TestAccAzureRMMySqlVirtualNetworkRule_switchSubnets(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_mysql_virtual_network_rule", "test") // Create regex strings that will ensure that one subnet name exists, but not the other - preConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet1%d)$|(subnet[^2]%d)$", data.RandomInteger, data.RandomInteger)) //subnet 1 but not 2 - postConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet2%d)$|(subnet[^1]%d)$", data.RandomInteger, data.RandomInteger)) //subnet 2 but not 1 + preConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet1%d)$|(subnet[^2]%d)$", data.RandomInteger, data.RandomInteger)) // subnet 1 but not 2 + postConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet2%d)$|(subnet[^1]%d)$", data.RandomInteger, data.RandomInteger)) // subnet 2 but not 1 resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -223,8 +223,8 @@ func testCheckAzureRMMySqlVirtualNetworkRuleDisappears(resourceName string) reso future, err := client.Delete(ctx, resourceGroup, serverName, ruleName) if err != nil { - //If the error is that the resource we want to delete does not exist in the first - //place (404), then just return with no error. + // If the error is that the resource we want to delete does not exist in the first + // place (404), then just return with no error. if response.WasNotFound(future.Response()) { return nil } @@ -233,7 +233,7 @@ func testCheckAzureRMMySqlVirtualNetworkRuleDisappears(resourceName string) reso } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - //Same deal as before. Just in case. + // Same deal as before. Just in case. if response.WasNotFound(future.Response()) { return nil } @@ -247,6 +247,10 @@ func testCheckAzureRMMySqlVirtualNetworkRuleDisappears(resourceName string) reso func testAccAzureRMMySqlVirtualNetworkRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -255,22 +259,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvnet%d" address_space = ["10.7.29.0/29"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.7.29.0/29" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name administrator_login = "acctestun" administrator_login_password = "H@Sh1CoR3!" version = "5.6" @@ -287,15 +291,19 @@ resource "azurerm_mysql_server" "test" { resource "azurerm_mysql_virtual_network_rule" "test" { name = "acctestmysqlvnetrule%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_mysql_server.test.name}" - subnet_id = "${azurerm_subnet.test.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_mysql_server.test.name + subnet_id = azurerm_subnet.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMMySqlVirtualNetworkRule_badsubnet(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -304,22 +312,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvnet%d" address_space = ["10.7.29.0/29"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.7.29.0/29" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name administrator_login = "acctestun" administrator_login_password = "H@Sh1CoR3!" version = "5.6" @@ -336,9 +344,9 @@ resource "azurerm_mysql_server" "test" { resource "azurerm_mysql_virtual_network_rule" "test" { name = "acctestmysqlvnetrule%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_mysql_server.test.name}" - subnet_id = "${azurerm_subnet.test.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_mysql_server.test.name + subnet_id = azurerm_subnet.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } @@ -348,16 +356,20 @@ func testAccAzureRMMySqlVirtualNetworkRule_requiresImport(data acceptance.TestDa %s resource "azurerm_mysql_virtual_network_rule" "import" { - name = "${azurerm_mysql_virtual_network_rule.test.name}" - resource_group_name = "${azurerm_mysql_virtual_network_rule.test.resource_group_name}" - server_name = "${azurerm_mysql_virtual_network_rule.test.server_name}" - subnet_id = "${azurerm_mysql_virtual_network_rule.test.subnet_id}" + name = azurerm_mysql_virtual_network_rule.test.name + resource_group_name = azurerm_mysql_virtual_network_rule.test.resource_group_name + server_name = azurerm_mysql_virtual_network_rule.test.server_name + subnet_id = azurerm_mysql_virtual_network_rule.test.subnet_id } `, testAccAzureRMMySqlVirtualNetworkRule_basic(data)) } func testAccAzureRMMySqlVirtualNetworkRule_subnetSwitchPre(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -366,30 +378,30 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvnet%d" address_space = ["10.7.29.0/24"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test1" { name = "subnet1%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.7.29.0/25" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_subnet" "test2" { name = "subnet2%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.7.29.128/25" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name administrator_login = "acctestun" administrator_login_password = "H@Sh1CoR3!" version = "5.6" @@ -406,15 +418,19 @@ resource "azurerm_mysql_server" "test" { resource "azurerm_mysql_virtual_network_rule" "test" { name = "acctestmysqlvnetrule%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_mysql_server.test.name}" - subnet_id = "${azurerm_subnet.test1.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_mysql_server.test.name + subnet_id = azurerm_subnet.test1.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMMySqlVirtualNetworkRule_subnetSwitchPost(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -423,30 +439,30 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvnet%d" address_space = ["10.7.29.0/24"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test1" { name = "subnet1%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.7.29.0/25" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_subnet" "test2" { name = "subnet2%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.7.29.128/25" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name administrator_login = "acctestun" administrator_login_password = "H@Sh1CoR3!" version = "5.6" @@ -463,15 +479,19 @@ resource "azurerm_mysql_server" "test" { resource "azurerm_mysql_virtual_network_rule" "test" { name = "acctestmysqlvnetrule%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_mysql_server.test.name}" - subnet_id = "${azurerm_subnet.test2.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_mysql_server.test.name + subnet_id = azurerm_subnet.test2.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMMySqlVirtualNetworkRule_multipleSubnets(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -480,45 +500,45 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "vnet1" { name = "acctestvnet1%d" address_space = ["10.7.29.0/24"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_virtual_network" "vnet2" { name = "acctestvnet2%d" address_space = ["10.1.29.0/29"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "vnet1_subnet1" { name = "acctestsubnet1%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.vnet1.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.vnet1.name address_prefix = "10.7.29.0/29" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_subnet" "vnet1_subnet2" { name = "acctestsubnet2%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.vnet1.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.vnet1.name address_prefix = "10.7.29.128/29" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_subnet" "vnet2_subnet1" { name = "acctestsubnet3%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.vnet2.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.vnet2.name address_prefix = "10.1.29.0/29" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_mysql_server" "test" { name = "acctestmysqlsvr-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name administrator_login = "acctestun" administrator_login_password = "H@Sh1CoR3!" version = "5.6" @@ -535,23 +555,23 @@ resource "azurerm_mysql_server" "test" { resource "azurerm_mysql_virtual_network_rule" "rule1" { name = "acctestmysqlvnetrule1%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_mysql_server.test.name}" - subnet_id = "${azurerm_subnet.vnet1_subnet1.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_mysql_server.test.name + subnet_id = azurerm_subnet.vnet1_subnet1.id } resource "azurerm_mysql_virtual_network_rule" "rule2" { name = "acctestmysqlvnetrule2%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_mysql_server.test.name}" - subnet_id = "${azurerm_subnet.vnet1_subnet2.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_mysql_server.test.name + subnet_id = azurerm_subnet.vnet1_subnet2.id } resource "azurerm_mysql_virtual_network_rule" "rule3" { name = "acctestmysqlvnetrule3%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_mysql_server.test.name}" - subnet_id = "${azurerm_subnet.vnet2_subnet1.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_mysql_server.test.name + subnet_id = azurerm_subnet.vnet2_subnet1.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/netapp/client/client.go b/azurerm/internal/services/netapp/client/client.go index cc0127c118bb2..fdffa5a2214d4 100644 --- a/azurerm/internal/services/netapp/client/client.go +++ b/azurerm/internal/services/netapp/client/client.go @@ -1,7 +1,7 @@ package client import ( - "github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp" + "github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common" ) diff --git a/azurerm/internal/services/netapp/data_source_netapp_volume.go b/azurerm/internal/services/netapp/data_source_netapp_volume.go index 5a55474e19bf0..3cb9929de84cd 100644 --- a/azurerm/internal/services/netapp/data_source_netapp_volume.go +++ b/azurerm/internal/services/netapp/data_source_netapp_volume.go @@ -61,6 +61,12 @@ func dataSourceArmNetAppVolume() *schema.Resource { Type: schema.TypeInt, Computed: true, }, + + "protocols": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, }, } } @@ -101,6 +107,12 @@ func dataSourceArmNetAppVolumeRead(d *schema.ResourceData, meta interface{}) err d.Set("service_level", props.ServiceLevel) d.Set("subnet_id", props.SubnetID) + protocolTypes := make([]string, 0) + if prtclTypes := props.ProtocolTypes; prtclTypes != nil { + protocolTypes = append(protocolTypes, *prtclTypes...) + } + d.Set("protocols", protocolTypes) + if props.UsageThreshold != nil { d.Set("storage_quota_in_gb", *props.UsageThreshold/1073741824) } diff --git a/azurerm/internal/services/netapp/parse/netapp_account.go b/azurerm/internal/services/netapp/parse/netapp_account.go new file mode 100644 index 0000000000000..96b2f1e902170 --- /dev/null +++ b/azurerm/internal/services/netapp/parse/netapp_account.go @@ -0,0 +1,33 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type NetAppAccountId struct { + ResourceGroup string + Name string +} + +func NetAppAccountID(input string) (*NetAppAccountId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse NetApp Account ID %q: %+v", input, err) + } + + service := NetAppAccountId{ + ResourceGroup: id.ResourceGroup, + } + + if service.Name, err = id.PopSegment("netAppAccounts"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &service, nil +} diff --git a/azurerm/internal/services/netapp/parse/netapp_account_test.go b/azurerm/internal/services/netapp/parse/netapp_account_test.go new file mode 100644 index 0000000000000..11195171297d3 --- /dev/null +++ b/azurerm/internal/services/netapp/parse/netapp_account_test.go @@ -0,0 +1,73 @@ +package parse + +import ( + "testing" +) + +func TestNetAppAccountId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *NetAppAccountId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing NetApp Account Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/", + Expected: nil, + }, + { + Name: "NetApp Account ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1", + Expected: &NetAppAccountId{ + Name: "account1", + ResourceGroup: "resGroup1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/NETAPPACCOUNTS/account1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := NetAppAccountID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/netapp/parse/netapp_pool.go b/azurerm/internal/services/netapp/parse/netapp_pool.go new file mode 100644 index 0000000000000..23c2fcff7ad07 --- /dev/null +++ b/azurerm/internal/services/netapp/parse/netapp_pool.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type NetAppPoolId struct { + ResourceGroup string + AccountName string + Name string +} + +func NetAppPoolID(input string) (*NetAppPoolId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse NetApp Pool ID %q: %+v", input, err) + } + + service := NetAppPoolId{ + ResourceGroup: id.ResourceGroup, + } + + if service.AccountName, err = id.PopSegment("netAppAccounts"); err != nil { + return nil, err + } + + if service.Name, err = id.PopSegment("capacityPools"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &service, nil +} diff --git a/azurerm/internal/services/netapp/parse/netapp_pool_test.go b/azurerm/internal/services/netapp/parse/netapp_pool_test.go new file mode 100644 index 0000000000000..8e4b0131ed923 --- /dev/null +++ b/azurerm/internal/services/netapp/parse/netapp_pool_test.go @@ -0,0 +1,88 @@ +package parse + +import ( + "testing" +) + +func TestNetAppPoolId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *NetAppPoolId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing NetApp Account Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/", + Expected: nil, + }, + { + Name: "NetApp Account ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1", + Expected: nil, + }, + { + Name: "Missing NetApp Pool Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/", + Expected: nil, + }, + { + Name: "NetApp Pool ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1", + Expected: &NetAppPoolId{ + Name: "pool1", + AccountName: "account1", + ResourceGroup: "resGroup1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/CAPACITYPOOLS/pool1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := NetAppPoolID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + + if actual.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for Account Name", v.Expected.AccountName, actual.AccountName) + } + + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/netapp/parse/netapp_snapshot.go b/azurerm/internal/services/netapp/parse/netapp_snapshot.go new file mode 100644 index 0000000000000..5e0b78a4aaad0 --- /dev/null +++ b/azurerm/internal/services/netapp/parse/netapp_snapshot.go @@ -0,0 +1,48 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type NetAppSnapshotId struct { + ResourceGroup string + AccountName string + PoolName string + VolumeName string + Name string +} + +func NetAppSnapshotID(input string) (*NetAppSnapshotId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse NetApp Snapshot ID %q: %+v", input, err) + } + + service := NetAppSnapshotId{ + ResourceGroup: id.ResourceGroup, + } + + if service.AccountName, err = id.PopSegment("netAppAccounts"); err != nil { + return nil, err + } + + if service.PoolName, err = id.PopSegment("capacityPools"); err != nil { + return nil, err + } + + if service.VolumeName, err = id.PopSegment("volumes"); err != nil { + return nil, err + } + + if service.Name, err = id.PopSegment("snapshots"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &service, nil +} diff --git a/azurerm/internal/services/netapp/parse/netapp_snapshot_test.go b/azurerm/internal/services/netapp/parse/netapp_snapshot_test.go new file mode 100644 index 0000000000000..c0e061a78e8b3 --- /dev/null +++ b/azurerm/internal/services/netapp/parse/netapp_snapshot_test.go @@ -0,0 +1,118 @@ +package parse + +import ( + "testing" +) + +func TestNetAppSnapshotId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *NetAppSnapshotId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing NetApp Account Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/", + Expected: nil, + }, + { + Name: "NetApp Account ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1", + Expected: nil, + }, + { + Name: "Missing NetApp Pool Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/", + Expected: nil, + }, + { + Name: "NetApp Pool ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1", + Expected: nil, + }, + { + Name: "Missing NetApp Volume Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1/volumes/", + Expected: nil, + }, + { + Name: "NetApp Volume ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1/volumes/volume1", + Expected: nil, + }, + { + Name: "Missing NetApp Snapshot Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1/volumes/volume1/snapshots/", + Expected: nil, + }, + { + Name: "NetApp Snapshot ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1/volumes/volume1/snapshots/snapshot1", + Expected: &NetAppSnapshotId{ + Name: "snapshot1", + VolumeName: "volume1", + PoolName: "pool1", + AccountName: "account1", + ResourceGroup: "resGroup1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1/volumes/volume1/SNAPSHOTS/snapshot1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := NetAppSnapshotID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + + if actual.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for Account Name", v.Expected.AccountName, actual.AccountName) + } + + if actual.PoolName != v.Expected.PoolName { + t.Fatalf("Expected %q but got %q for Pool Name", v.Expected.PoolName, actual.PoolName) + } + + if actual.VolumeName != v.Expected.VolumeName { + t.Fatalf("Expected %q but got %q for Volume Name", v.Expected.VolumeName, actual.VolumeName) + } + + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/netapp/parse/netapp_volume.go b/azurerm/internal/services/netapp/parse/netapp_volume.go new file mode 100644 index 0000000000000..cd2d55cf06ae6 --- /dev/null +++ b/azurerm/internal/services/netapp/parse/netapp_volume.go @@ -0,0 +1,43 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type NetAppVolumeId struct { + ResourceGroup string + AccountName string + PoolName string + Name string +} + +func NetAppVolumeID(input string) (*NetAppVolumeId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse NetApp Volume ID %q: %+v", input, err) + } + + service := NetAppVolumeId{ + ResourceGroup: id.ResourceGroup, + } + + if service.AccountName, err = id.PopSegment("netAppAccounts"); err != nil { + return nil, err + } + + if service.PoolName, err = id.PopSegment("capacityPools"); err != nil { + return nil, err + } + + if service.Name, err = id.PopSegment("volumes"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &service, nil +} diff --git a/azurerm/internal/services/netapp/parse/netapp_volume_test.go b/azurerm/internal/services/netapp/parse/netapp_volume_test.go new file mode 100644 index 0000000000000..c893056cb9f9c --- /dev/null +++ b/azurerm/internal/services/netapp/parse/netapp_volume_test.go @@ -0,0 +1,103 @@ +package parse + +import ( + "testing" +) + +func TestNetAppVolumeId(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *NetAppVolumeId + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Expected: nil, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Expected: nil, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Expected: nil, + }, + { + Name: "Missing NetApp Account Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/", + Expected: nil, + }, + { + Name: "NetApp Account ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1", + Expected: nil, + }, + { + Name: "Missing NetApp Pool Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/", + Expected: nil, + }, + { + Name: "NetApp Pool ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1", + Expected: nil, + }, + { + Name: "Missing NetApp Volume Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1/volumes/", + Expected: nil, + }, + { + Name: "NetApp Volume ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1/volumes/volume1", + Expected: &NetAppVolumeId{ + Name: "volume1", + PoolName: "pool1", + AccountName: "account1", + ResourceGroup: "resGroup1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1/VOLUMES/volume1", + Expected: nil, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := NetAppVolumeID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + + if actual.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for Account Name", v.Expected.AccountName, actual.AccountName) + } + + if actual.PoolName != v.Expected.PoolName { + t.Fatalf("Expected %q but got %q for Pool Name", v.Expected.PoolName, actual.PoolName) + } + + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/netapp/registration.go b/azurerm/internal/services/netapp/registration.go index c1bb265794bbf..981ce6c849126 100644 --- a/azurerm/internal/services/netapp/registration.go +++ b/azurerm/internal/services/netapp/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "NetApp" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "NetApp", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/netapp/resource_arm_netapp_account.go b/azurerm/internal/services/netapp/resource_arm_netapp_account.go index 4b606ed848ce1..47953e039d282 100644 --- a/azurerm/internal/services/netapp/resource_arm_netapp_account.go +++ b/azurerm/internal/services/netapp/resource_arm_netapp_account.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp" + "github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp" "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" @@ -16,6 +16,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -27,16 +30,16 @@ func resourceArmNetAppAccount() *schema.Resource { Update: resourceArmNetAppAccountCreateUpdate, Delete: resourceArmNetAppAccountDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), Read: schema.DefaultTimeout(5 * time.Minute), Update: schema.DefaultTimeout(30 * time.Minute), Delete: schema.DefaultTimeout(30 * time.Minute), }, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.NetAppAccountID(id) + return err + }), Schema: map[string]*schema.Schema{ "name": { @@ -68,7 +71,7 @@ func resourceArmNetAppAccount() *schema.Resource { Type: schema.TypeString, Required: true, ValidateFunc: validation.StringMatch( - regexp.MustCompile(`^[(\da-zA-Z)\.]{1,255}$`), + regexp.MustCompile(`^[(\da-zA-Z-)\.]{1,255}$`), `The domain name must end with a letter or number before dot and start with a letter or number after dot and can not be longer than 255 characters in length.`, ), }, @@ -99,7 +102,7 @@ func resourceArmNetAppAccount() *schema.Resource { }, }, - // Handles tags being interface{} until https://github.com/Azure/azure-rest-api-specs/issues/7447 is fixed + "tags": tags.Schema(), }, } } @@ -132,6 +135,7 @@ func resourceArmNetAppAccountCreateUpdate(d *schema.ResourceData, meta interface AccountProperties: &netapp.AccountProperties{ ActiveDirectories: expandArmNetAppActiveDirectories(activeDirectories), }, + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } future, err := client.CreateOrUpdate(ctx, accountParameters, resourceGroup, name) @@ -159,30 +163,28 @@ func resourceArmNetAppAccountRead(d *schema.ResourceData, meta interface{}) erro ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.NetAppAccountID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - name := id.Path["netAppAccounts"] - resp, err := client.Get(ctx, resourceGroup, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { log.Printf("[INFO] NetApp Accounts %q does not exist - removing from state", d.Id()) d.SetId("") return nil } - return fmt.Errorf("Error reading NetApp Accounts %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error reading NetApp Accounts %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) + d.Set("resource_group_name", id.ResourceGroup) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } - return nil + return tags.FlattenAndSet(d, resp.Tags) } func resourceArmNetAppAccountDelete(d *schema.ResourceData, meta interface{}) error { @@ -190,21 +192,19 @@ func resourceArmNetAppAccountDelete(d *schema.ResourceData, meta interface{}) er ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.NetAppAccountID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - name := id.Path["netAppAccounts"] - future, err := client.Delete(ctx, resourceGroup, name) + future, err := client.Delete(ctx, id.ResourceGroup, id.Name) if err != nil { - return fmt.Errorf("Error deleting NetApp Account %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error deleting NetApp Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { if !response.WasNotFound(future.Response()) { - return fmt.Errorf("Error waiting for deleting NetApp Account %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error waiting for deleting NetApp Account %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/netapp/resource_arm_netapp_pool.go b/azurerm/internal/services/netapp/resource_arm_netapp_pool.go index 9c898e8f78d1a..1c1f62d64d965 100644 --- a/azurerm/internal/services/netapp/resource_arm_netapp_pool.go +++ b/azurerm/internal/services/netapp/resource_arm_netapp_pool.go @@ -7,7 +7,7 @@ import ( "strconv" "time" - "github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp" + "github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" @@ -15,6 +15,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -26,16 +29,16 @@ func resourceArmNetAppPool() *schema.Resource { Update: resourceArmNetAppPoolCreateUpdate, Delete: resourceArmNetAppPoolDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), Read: schema.DefaultTimeout(5 * time.Minute), Update: schema.DefaultTimeout(30 * time.Minute), Delete: schema.DefaultTimeout(30 * time.Minute), }, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.NetAppPoolID(id) + return err + }), Schema: map[string]*schema.Schema{ "name": { @@ -71,6 +74,8 @@ func resourceArmNetAppPool() *schema.Resource { Required: true, ValidateFunc: validation.IntBetween(4, 500), }, + + "tags": tags.Schema(), }, } } @@ -108,6 +113,7 @@ func resourceArmNetAppPoolCreateUpdate(d *schema.ResourceData, meta interface{}) ServiceLevel: netapp.ServiceLevel(serviceLevel), Size: utils.Int64(sizeInBytes), }, + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } future, err := client.CreateOrUpdate(ctx, capacityPoolParameters, resourceGroup, accountName, name) @@ -135,27 +141,24 @@ func resourceArmNetAppPoolRead(d *schema.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.NetAppPoolID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - accountName := id.Path["netAppAccounts"] - name := id.Path["capacityPools"] - resp, err := client.Get(ctx, resourceGroup, accountName, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { log.Printf("[INFO] NetApp Pools %q does not exist - removing from state", d.Id()) d.SetId("") return nil } - return fmt.Errorf("Error reading NetApp Pools %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error reading NetApp Pools %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } - d.Set("name", name) - d.Set("resource_group_name", resourceGroup) - d.Set("account_name", accountName) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("account_name", id.AccountName) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } @@ -171,7 +174,7 @@ func resourceArmNetAppPoolRead(d *schema.ResourceData, meta interface{}) error { d.Set("size_in_tb", int(sizeInTB)) } - return nil + return tags.FlattenAndSet(d, resp.Tags) } func resourceArmNetAppPoolDelete(d *schema.ResourceData, meta interface{}) error { @@ -179,29 +182,26 @@ func resourceArmNetAppPoolDelete(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.NetAppPoolID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - accountName := id.Path["netAppAccounts"] - name := id.Path["capacityPools"] - _, err = client.Delete(ctx, resourceGroup, accountName, name) + _, err = client.Delete(ctx, id.ResourceGroup, id.AccountName, id.Name) if err != nil { - return fmt.Errorf("Error deleting NetApp Pool %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error deleting NetApp Pool %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } - log.Printf("[DEBUG] Waiting for NetApp Pool %q (Resource Group %q) to be deleted", name, resourceGroup) + log.Printf("[DEBUG] Waiting for NetApp Pool %q (Resource Group %q) to be deleted", id.Name, id.ResourceGroup) stateConf := &resource.StateChangeConf{ Pending: []string{"200", "202"}, Target: []string{"404"}, - Refresh: netappPoolDeleteStateRefreshFunc(ctx, client, resourceGroup, accountName, name), + Refresh: netappPoolDeleteStateRefreshFunc(ctx, client, id.ResourceGroup, id.AccountName, id.Name), Timeout: d.Timeout(schema.TimeoutDelete), } if _, err := stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for NetApp Pool %q (Resource Group %q) to be deleted: %+v", name, resourceGroup, err) + return fmt.Errorf("Error waiting for NetApp Pool %q (Resource Group %q) to be deleted: %+v", id.Name, id.ResourceGroup, err) } return nil diff --git a/azurerm/internal/services/netapp/resource_arm_netapp_snapshot.go b/azurerm/internal/services/netapp/resource_arm_netapp_snapshot.go index a8599b9e1e9a9..28f1740c58eef 100644 --- a/azurerm/internal/services/netapp/resource_arm_netapp_snapshot.go +++ b/azurerm/internal/services/netapp/resource_arm_netapp_snapshot.go @@ -5,13 +5,16 @@ import ( "log" "time" - "github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp" + "github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp" "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -20,19 +23,19 @@ func resourceArmNetAppSnapshot() *schema.Resource { return &schema.Resource{ Create: resourceArmNetAppSnapshotCreate, Read: resourceArmNetAppSnapshotRead, - Update: nil, + Update: resourceArmNetAppSnapshotUpdate, Delete: resourceArmNetAppSnapshotDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), Read: schema.DefaultTimeout(5 * time.Minute), Update: schema.DefaultTimeout(30 * time.Minute), Delete: schema.DefaultTimeout(30 * time.Minute), }, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.NetAppSnapshotID(id) + return err + }), Schema: map[string]*schema.Schema{ "name": { @@ -66,6 +69,8 @@ func resourceArmNetAppSnapshot() *schema.Resource { ForceNew: true, ValidateFunc: ValidateNetAppVolumeName, }, + + "tags": tags.Schema(), }, } } @@ -97,6 +102,7 @@ func resourceArmNetAppSnapshotCreate(d *schema.ResourceData, meta interface{}) e parameters := netapp.Snapshot{ Location: utils.String(location), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } future, err := client.Create(ctx, parameters, resourceGroup, accountName, poolName, volumeName, name) @@ -124,36 +130,60 @@ func resourceArmNetAppSnapshotRead(d *schema.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.NetAppSnapshotID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - accountName := id.Path["netAppAccounts"] - poolName := id.Path["capacityPools"] - volumeName := id.Path["volumes"] - name := id.Path["snapshots"] - resp, err := client.Get(ctx, resourceGroup, accountName, poolName, volumeName, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.PoolName, id.VolumeName, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { log.Printf("[INFO] NetApp Snapshots %q does not exist - removing from state", d.Id()) d.SetId("") return nil } - return fmt.Errorf("Error reading NetApp Snapshots %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error reading NetApp Snapshots %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } - d.Set("name", name) - d.Set("resource_group_name", resourceGroup) - d.Set("account_name", accountName) - d.Set("pool_name", poolName) - d.Set("volume_name", volumeName) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("account_name", id.AccountName) + d.Set("pool_name", id.PoolName) + d.Set("volume_name", id.VolumeName) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } - return nil + return tags.FlattenAndSet(d, resp.Tags) +} + +func resourceArmNetAppSnapshotUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).NetApp.SnapshotClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.NetAppSnapshotID(d.Id()) + if err != nil { + return err + } + + parameters := netapp.SnapshotPatch{ + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), + } + + if _, err = client.Update(ctx, parameters, id.ResourceGroup, id.AccountName, id.PoolName, id.VolumeName, id.Name); err != nil { + return fmt.Errorf("Error updating NetApp Snapshot %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + } + + resp, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.PoolName, id.VolumeName, id.Name) + if err != nil { + return fmt.Errorf("Error retrieving NetApp Snapshot %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + } + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("Cannot read NetApp Snapshot %q (Resource Group %q) ID", id.Name, id.ResourceGroup) + } + + return resourceArmNetAppSnapshotRead(d, meta) } func resourceArmNetAppSnapshotDelete(d *schema.ResourceData, meta interface{}) error { @@ -161,27 +191,22 @@ func resourceArmNetAppSnapshotDelete(d *schema.ResourceData, meta interface{}) e ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.NetAppSnapshotID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - accountName := id.Path["netAppAccounts"] - poolName := id.Path["capacityPools"] - volumeName := id.Path["volumes"] - name := id.Path["snapshots"] - future, err := client.Delete(ctx, resourceGroup, accountName, poolName, volumeName, name) + future, err := client.Delete(ctx, id.ResourceGroup, id.AccountName, id.PoolName, id.VolumeName, id.Name) if err != nil { if response.WasNotFound(future.Response()) { return nil } - return fmt.Errorf("Error deleting NetApp Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error deleting NetApp Snapshot %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { if !response.WasNotFound(future.Response()) { - return fmt.Errorf("Error waiting for deleting NetApp Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error waiting for deleting NetApp Snapshot %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/netapp/resource_arm_netapp_volume.go b/azurerm/internal/services/netapp/resource_arm_netapp_volume.go index e795aadd9b646..8fa6a6fabc6b6 100644 --- a/azurerm/internal/services/netapp/resource_arm_netapp_volume.go +++ b/azurerm/internal/services/netapp/resource_arm_netapp_volume.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp" + "github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-10-01/netapp" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" @@ -17,6 +17,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp/parse" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -28,16 +31,16 @@ func resourceArmNetAppVolume() *schema.Resource { Update: resourceArmNetAppVolumeCreateUpdate, Delete: resourceArmNetAppVolumeDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), Read: schema.DefaultTimeout(5 * time.Minute), Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(60 * time.Minute), }, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { + _, err := parse.NetAppVolumeID(id) + return err + }), Schema: map[string]*schema.Schema{ "name": { @@ -75,6 +78,7 @@ func resourceArmNetAppVolume() *schema.Resource { "service_level": { Type: schema.TypeString, Required: true, + ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ string(netapp.Premium), string(netapp.Standard), @@ -89,6 +93,20 @@ func resourceArmNetAppVolume() *schema.Resource { ValidateFunc: azure.ValidateResourceID, }, + "protocols": { + Type: schema.TypeSet, + ForceNew: true, + Optional: true, + Computed: true, + MaxItems: 2, + Elem: &schema.Schema{Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{ + "NFSv3", + "NFSv4.1", + "CIFS", + }, false)}, + }, + "storage_quota_in_gb": { Type: schema.TypeInt, Required: true, @@ -96,7 +114,7 @@ func resourceArmNetAppVolume() *schema.Resource { }, "export_policy_rule": { - Type: schema.TypeSet, + Type: schema.TypeList, Optional: true, MaxItems: 5, Elem: &schema.Resource{ @@ -106,6 +124,7 @@ func resourceArmNetAppVolume() *schema.Resource { Required: true, ValidateFunc: validation.IntBetween(1, 5), }, + "allowed_clients": { Type: schema.TypeSet, Required: true, @@ -114,22 +133,47 @@ func resourceArmNetAppVolume() *schema.Resource { ValidateFunc: validate.CIDR, }, }, + + "protocols_enabled": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + MinItems: 1, + Elem: &schema.Schema{Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{ + "NFSv3", + "NFSv4.1", + "CIFS", + }, false)}, + }, + "cifs_enabled": { - Type: schema.TypeBool, - Required: true, + Type: schema.TypeBool, + Optional: true, + Computed: true, + Deprecated: "Deprecated in favor of `protocols_enabled`", }, + "nfsv3_enabled": { - Type: schema.TypeBool, - Required: true, + Type: schema.TypeBool, + Optional: true, + Computed: true, + Deprecated: "Deprecated in favor of `protocols_enabled`", }, + "nfsv4_enabled": { - Type: schema.TypeBool, - Required: true, + Type: schema.TypeBool, + Optional: true, + Computed: true, + Deprecated: "Deprecated in favor of `protocols_enabled`", }, + "unix_read_only": { Type: schema.TypeBool, Optional: true, }, + "unix_read_write": { Type: schema.TypeBool, Optional: true, @@ -137,6 +181,8 @@ func resourceArmNetAppVolume() *schema.Resource { }, }, }, + + "tags": tags.Schema(), }, } } @@ -167,8 +213,13 @@ func resourceArmNetAppVolumeCreateUpdate(d *schema.ResourceData, meta interface{ volumePath := d.Get("volume_path").(string) serviceLevel := d.Get("service_level").(string) subnetId := d.Get("subnet_id").(string) + protocols := d.Get("protocols").(*schema.Set).List() + if len(protocols) == 0 { + protocols = append(protocols, "NFSv3") + } + storageQuotaInGB := int64(d.Get("storage_quota_in_gb").(int) * 1073741824) - exportPolicyRule := d.Get("export_policy_rule").(*schema.Set).List() + exportPolicyRule := d.Get("export_policy_rule").([]interface{}) parameters := netapp.Volume{ Location: utils.String(location), @@ -176,9 +227,11 @@ func resourceArmNetAppVolumeCreateUpdate(d *schema.ResourceData, meta interface{ CreationToken: utils.String(volumePath), ServiceLevel: netapp.ServiceLevel(serviceLevel), SubnetID: utils.String(subnetId), + ProtocolTypes: utils.ExpandStringSlice(protocols), UsageThreshold: utils.Int64(storageQuotaInGB), ExportPolicy: expandArmNetAppVolumeExportPolicyRule(exportPolicyRule), }, + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } future, err := client.CreateOrUpdate(ctx, parameters, resourceGroup, accountName, poolName, name) @@ -206,29 +259,25 @@ func resourceArmNetAppVolumeRead(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.NetAppVolumeID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - accountName := id.Path["netAppAccounts"] - poolName := id.Path["capacityPools"] - name := id.Path["volumes"] - resp, err := client.Get(ctx, resourceGroup, accountName, poolName, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.PoolName, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { log.Printf("[INFO] NetApp Volumes %q does not exist - removing from state", d.Id()) d.SetId("") return nil } - return fmt.Errorf("Error reading NetApp Volumes %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error reading NetApp Volumes %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } - d.Set("name", name) - d.Set("resource_group_name", resourceGroup) - d.Set("account_name", accountName) - d.Set("pool_name", poolName) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("account_name", id.AccountName) + d.Set("pool_name", id.PoolName) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } @@ -236,7 +285,7 @@ func resourceArmNetAppVolumeRead(d *schema.ResourceData, meta interface{}) error d.Set("volume_path", props.CreationToken) d.Set("service_level", props.ServiceLevel) d.Set("subnet_id", props.SubnetID) - + d.Set("protocols", props.ProtocolTypes) if props.UsageThreshold != nil { d.Set("storage_quota_in_gb", *props.UsageThreshold/1073741824) } @@ -245,7 +294,7 @@ func resourceArmNetAppVolumeRead(d *schema.ResourceData, meta interface{}) error } } - return nil + return tags.FlattenAndSet(d, resp.Tags) } func resourceArmNetAppVolumeDelete(d *schema.ResourceData, meta interface{}) error { @@ -253,17 +302,13 @@ func resourceArmNetAppVolumeDelete(d *schema.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.NetAppVolumeID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - accountName := id.Path["netAppAccounts"] - poolName := id.Path["capacityPools"] - name := id.Path["volumes"] - if _, err = client.Delete(ctx, resourceGroup, accountName, poolName, name); err != nil { - return fmt.Errorf("Error deleting NetApp Volume %q (Resource Group %q): %+v", name, resourceGroup, err) + if _, err = client.Delete(ctx, id.ResourceGroup, id.AccountName, id.PoolName, id.Name); err != nil { + return fmt.Errorf("Error deleting NetApp Volume %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } // The resource NetApp Volume depends on the resource NetApp Pool. @@ -271,16 +316,16 @@ func resourceArmNetAppVolumeDelete(d *schema.ResourceData, meta interface{}) err // Then it tries to immediately delete NetApp Pool but it still throws error `Can not delete resource before nested resources are deleted.` // In this case we're going to try triggering the Deletion again, in-case it didn't work prior to this attempt. // For more details, see related Bug: https://github.com/Azure/azure-sdk-for-go/issues/6485 - log.Printf("[DEBUG] Waiting for NetApp Volume Provisioning Service %q (Resource Group %q) to be deleted", name, resourceGroup) + log.Printf("[DEBUG] Waiting for NetApp Volume Provisioning Service %q (Resource Group %q) to be deleted", id.Name, id.ResourceGroup) stateConf := &resource.StateChangeConf{ Pending: []string{"200", "202"}, Target: []string{"404"}, - Refresh: netappVolumeDeleteStateRefreshFunc(ctx, client, resourceGroup, accountName, poolName, name), + Refresh: netappVolumeDeleteStateRefreshFunc(ctx, client, id.ResourceGroup, id.AccountName, id.PoolName, id.Name), Timeout: d.Timeout(schema.TimeoutDelete), } if _, err := stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for NetApp Volume Provisioning Service %q (Resource Group %q) to be deleted: %+v", name, resourceGroup, err) + return fmt.Errorf("Error waiting for NetApp Volume Provisioning Service %q (Resource Group %q) to be deleted: %+v", id.Name, id.ResourceGroup, err) } return nil @@ -310,9 +355,34 @@ func expandArmNetAppVolumeExportPolicyRule(input []interface{}) *netapp.VolumePr v := item.(map[string]interface{}) ruleIndex := int32(v["rule_index"].(int)) allowedClients := strings.Join(*utils.ExpandStringSlice(v["allowed_clients"].(*schema.Set).List()), ",") - cifsEnabled := v["cifs_enabled"].(bool) - nfsv3Enabled := v["nfsv3_enabled"].(bool) - nfsv4Enabled := v["nfsv4_enabled"].(bool) + + cifsEnabled := false + nfsv3Enabled := false + nfsv41Enabled := false + + if vpe := v["protocols_enabled"]; vpe != nil { + protocolsEnabled := vpe.([]interface{}) + if len(protocolsEnabled) != 0 { + for _, protocol := range protocolsEnabled { + if protocol != nil { + switch strings.ToLower(protocol.(string)) { + case "cifs": + cifsEnabled = true + case "nfsv3": + nfsv3Enabled = true + case "nfsv4.1": + nfsv41Enabled = true + } + } + } + } else { + // TODO: Remove in next major version + cifsEnabled = v["cifs_enabled"].(bool) + nfsv3Enabled = v["nfsv3_enabled"].(bool) + nfsv41Enabled = v["nfsv4_enabled"].(bool) + } + } + unixReadOnly := v["unix_read_only"].(bool) unixReadWrite := v["unix_read_write"].(bool) @@ -320,7 +390,7 @@ func expandArmNetAppVolumeExportPolicyRule(input []interface{}) *netapp.VolumePr AllowedClients: utils.String(allowedClients), Cifs: utils.Bool(cifsEnabled), Nfsv3: utils.Bool(nfsv3Enabled), - Nfsv4: utils.Bool(nfsv4Enabled), + Nfsv41: utils.Bool(nfsv41Enabled), RuleIndex: utils.Int32(ruleIndex), UnixReadOnly: utils.Bool(unixReadOnly), UnixReadWrite: utils.Bool(unixReadWrite), @@ -350,17 +420,29 @@ func flattenArmNetAppVolumeExportPolicyRule(input *netapp.VolumePropertiesExport if v := item.AllowedClients; v != nil { allowedClients = strings.Split(*v, ",") } + // TODO: Start - Remove in next major version cifsEnabled := false + nfsv3Enabled := false + nfsv4Enabled := false + // End - Remove in next major version + protocolsEnabled := []string{} if v := item.Cifs; v != nil { - cifsEnabled = *v + if *v { + protocolsEnabled = append(protocolsEnabled, "CIFS") + } + cifsEnabled = *v // TODO: Remove in next major version } - nfsv3Enabled := false if v := item.Nfsv3; v != nil { - nfsv3Enabled = *v + if *v { + protocolsEnabled = append(protocolsEnabled, "NFSv3") + } + nfsv3Enabled = *v // TODO: Remove in next major version } - nfsv4Enabled := false - if v := item.Nfsv4; v != nil { - nfsv4Enabled = *v + if v := item.Nfsv41; v != nil { + if *v { + protocolsEnabled = append(protocolsEnabled, "NFSv4.1") + } + nfsv4Enabled = *v // TODO: Remove in next major version } unixReadOnly := false if v := item.UnixReadOnly; v != nil { @@ -372,13 +454,15 @@ func flattenArmNetAppVolumeExportPolicyRule(input *netapp.VolumePropertiesExport } results = append(results, map[string]interface{}{ - "rule_index": ruleIndex, - "allowed_clients": utils.FlattenStringSlice(&allowedClients), - "cifs_enabled": cifsEnabled, - "nfsv3_enabled": nfsv3Enabled, - "nfsv4_enabled": nfsv4Enabled, - "unix_read_only": unixReadOnly, - "unix_read_write": unixReadWrite, + "rule_index": ruleIndex, + "allowed_clients": utils.FlattenStringSlice(&allowedClients), + "unix_read_only": unixReadOnly, + "unix_read_write": unixReadWrite, + "protocols_enabled": utils.FlattenStringSlice(&protocolsEnabled), + // TODO: Remove in next major version + "cifs_enabled": cifsEnabled, + "nfsv3_enabled": nfsv3Enabled, + "nfsv4_enabled": nfsv4Enabled, }) } diff --git a/azurerm/internal/services/netapp/tests/data_source_netapp_account_test.go b/azurerm/internal/services/netapp/tests/data_source_netapp_account_test.go index e0267b233cda3..ff9ebdd91a9d9 100644 --- a/azurerm/internal/services/netapp/tests/data_source_netapp_account_test.go +++ b/azurerm/internal/services/netapp/tests/data_source_netapp_account_test.go @@ -32,8 +32,8 @@ func testAccDataSourceNetAppAccount_basicConfig(data acceptance.TestData) string %s data "azurerm_netapp_account" "test" { - resource_group_name = "${azurerm_netapp_account.test.resource_group_name}" - name = "${azurerm_netapp_account.test.name}" + resource_group_name = azurerm_netapp_account.test.resource_group_name + name = azurerm_netapp_account.test.name } `, config) } diff --git a/azurerm/internal/services/netapp/tests/data_source_netapp_pool_test.go b/azurerm/internal/services/netapp/tests/data_source_netapp_pool_test.go index 074ff09041f43..09794a84d812a 100644 --- a/azurerm/internal/services/netapp/tests/data_source_netapp_pool_test.go +++ b/azurerm/internal/services/netapp/tests/data_source_netapp_pool_test.go @@ -35,9 +35,9 @@ func testAccDataSourceNetAppPool_basic(data acceptance.TestData) string { %s data "azurerm_netapp_pool" "test" { - resource_group_name = "${azurerm_netapp_pool.test.resource_group_name}" - account_name = "${azurerm_netapp_pool.test.account_name}" - name = "${azurerm_netapp_pool.test.name}" + resource_group_name = azurerm_netapp_pool.test.resource_group_name + account_name = azurerm_netapp_pool.test.account_name + name = azurerm_netapp_pool.test.name } `, config) } diff --git a/azurerm/internal/services/netapp/tests/data_source_netapp_snapshot_test.go b/azurerm/internal/services/netapp/tests/data_source_netapp_snapshot_test.go index 272ff9cd055ff..f5ea73ff628b6 100644 --- a/azurerm/internal/services/netapp/tests/data_source_netapp_snapshot_test.go +++ b/azurerm/internal/services/netapp/tests/data_source_netapp_snapshot_test.go @@ -31,11 +31,11 @@ func testAccDataSourceNetAppSnapshot_basic(data acceptance.TestData) string { %s data "azurerm_netapp_snapshot" "test" { - resource_group_name = "${azurerm_netapp_snapshot.test.resource_group_name}" - account_name = "${azurerm_netapp_snapshot.test.account_name}" - pool_name = "${azurerm_netapp_snapshot.test.pool_name}" - volume_name = "${azurerm_netapp_snapshot.test.volume_name}" - name = "${azurerm_netapp_snapshot.test.name}" + resource_group_name = azurerm_netapp_snapshot.test.resource_group_name + account_name = azurerm_netapp_snapshot.test.account_name + pool_name = azurerm_netapp_snapshot.test.pool_name + volume_name = azurerm_netapp_snapshot.test.volume_name + name = azurerm_netapp_snapshot.test.name } `, config) } diff --git a/azurerm/internal/services/netapp/tests/data_source_netapp_volume_test.go b/azurerm/internal/services/netapp/tests/data_source_netapp_volume_test.go index 2b8d6e59f58e5..3429d7fe785eb 100644 --- a/azurerm/internal/services/netapp/tests/data_source_netapp_volume_test.go +++ b/azurerm/internal/services/netapp/tests/data_source_netapp_volume_test.go @@ -22,6 +22,7 @@ func TestAccDataSourceAzureRMNetAppVolume_basic(t *testing.T) { resource.TestCheckResourceAttrSet(data.ResourceName, "service_level"), resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), resource.TestCheckResourceAttrSet(data.ResourceName, "storage_quota_in_gb"), + resource.TestCheckResourceAttrSet(data.ResourceName, "protocols.0"), ), }, }, @@ -34,10 +35,10 @@ func testAccDataSourceNetAppVolume_basic(data acceptance.TestData) string { %s data "azurerm_netapp_volume" "test" { - resource_group_name = "${azurerm_netapp_volume.test.resource_group_name}" - account_name = "${azurerm_netapp_volume.test.account_name}" - pool_name = "${azurerm_netapp_volume.test.pool_name}" - name = "${azurerm_netapp_volume.test.name}" + resource_group_name = azurerm_netapp_volume.test.resource_group_name + account_name = azurerm_netapp_volume.test.account_name + pool_name = azurerm_netapp_volume.test.pool_name + name = azurerm_netapp_volume.test.name } `, config) } diff --git a/azurerm/internal/services/netapp/tests/resource_arm_netapp_account_test.go b/azurerm/internal/services/netapp/tests/resource_arm_netapp_account_test.go index 5498991b7dd6d..4707d89700281 100644 --- a/azurerm/internal/services/netapp/tests/resource_arm_netapp_account_test.go +++ b/azurerm/internal/services/netapp/tests/resource_arm_netapp_account_test.go @@ -98,6 +98,8 @@ func testAccAzureRMNetAppAccount_complete(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetAppAccountExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "active_directory.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.FoO", "BaR"), ), }, data.ImportStep("active_directory"), @@ -118,6 +120,7 @@ func testAccAzureRMNetAppAccount_update(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetAppAccountExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "active_directory.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, { @@ -125,6 +128,8 @@ func testAccAzureRMNetAppAccount_update(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetAppAccountExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "active_directory.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.FoO", "BaR"), ), }, data.ImportStep("active_directory"), @@ -182,6 +187,10 @@ func testCheckAzureRMNetAppAccountDestroy(s *terraform.State) error { func testAccAzureRMNetAppAccount_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-netapp-%d" location = "%s" @@ -189,8 +198,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_netapp_account" "test" { name = "acctest-NetAppAccount-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -199,15 +208,19 @@ func testAccAzureRMNetAppAccount_requiresImportConfig(data acceptance.TestData) return fmt.Sprintf(` %s resource "azurerm_netapp_account" "import" { - name = "${azurerm_netapp_account.test.name}" - location = "${azurerm_netapp_account.test.location}" - resource_group_name = "${azurerm_netapp_account.test.resource_group_name}" + name = azurerm_netapp_account.test.name + location = azurerm_netapp_account.test.location + resource_group_name = azurerm_netapp_account.test.resource_group_name } `, testAccAzureRMNetAppAccount_basicConfig(data)) } func testAccAzureRMNetAppAccount_completeConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-netapp-%d" location = "%s" @@ -215,8 +228,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_netapp_account" "test" { name = "acctest-NetAppAccount-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name active_directory { username = "aduser" @@ -226,6 +239,10 @@ resource "azurerm_netapp_account" "test" { domain = "westcentralus.com" organizational_unit = "OU=FirstLevel" } + + tags = { + "FoO" = "BaR" + } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/netapp/tests/resource_arm_netapp_pool_test.go b/azurerm/internal/services/netapp/tests/resource_arm_netapp_pool_test.go index 0fc0e185bcd3f..ee8497556d50c 100644 --- a/azurerm/internal/services/netapp/tests/resource_arm_netapp_pool_test.go +++ b/azurerm/internal/services/netapp/tests/resource_arm_netapp_pool_test.go @@ -72,6 +72,8 @@ func TestAccAzureRMNetAppPool_complete(t *testing.T) { testCheckAzureRMNetAppPoolExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Standard"), resource.TestCheckResourceAttr(data.ResourceName, "size_in_tb", "15"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.FoO", "BaR"), ), }, data.ImportStep(), @@ -91,8 +93,9 @@ func TestAccAzureRMNetAppPool_update(t *testing.T) { Config: testAccAzureRMNetAppPool_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetAppPoolExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Premium"), + resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Standard"), resource.TestCheckResourceAttr(data.ResourceName, "size_in_tb", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, data.ImportStep(), @@ -102,6 +105,8 @@ func TestAccAzureRMNetAppPool_update(t *testing.T) { testCheckAzureRMNetAppPoolExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Standard"), resource.TestCheckResourceAttr(data.ResourceName, "size_in_tb", "15"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.FoO", "BaR"), ), }, data.ImportStep(), @@ -161,6 +166,10 @@ func testCheckAzureRMNetAppPoolDestroy(s *terraform.State) error { func testAccAzureRMNetAppPool_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-netapp-%d" location = "%s" @@ -168,16 +177,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_netapp_account" "test" { name = "acctest-NetAppAccount-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_netapp_pool" "test" { name = "acctest-NetAppPool-%d" - account_name = "${azurerm_netapp_account.test.name}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - service_level = "Premium" + account_name = azurerm_netapp_account.test.name + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + service_level = "Standard" size_in_tb = 4 } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) @@ -187,15 +196,22 @@ func testAccAzureRMNetAppPool_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s resource "azurerm_netapp_pool" "import" { - name = "${azurerm_netapp_pool.test.name}" - location = "${azurerm_netapp_pool.test.location}" - resource_group_name = "${azurerm_netapp_pool.test.resource_group_name}" + name = azurerm_netapp_pool.test.name + location = azurerm_netapp_pool.test.location + resource_group_name = azurerm_netapp_pool.test.resource_group_name + account_name = azurerm_netapp_pool.test.account_name + service_level = azurerm_netapp_pool.test.service_level + size_in_tb = azurerm_netapp_pool.test.size_in_tb } `, testAccAzureRMNetAppPool_basic(data)) } func testAccAzureRMNetAppPool_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-netapp-%d" location = "%s" @@ -203,17 +219,21 @@ resource "azurerm_resource_group" "test" { resource "azurerm_netapp_account" "test" { name = "acctest-NetAppAccount-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_netapp_pool" "test" { name = "acctest-NetAppPool-%d" - account_name = "${azurerm_netapp_account.test.name}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + account_name = azurerm_netapp_account.test.name + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name service_level = "Standard" size_in_tb = 15 + + tags = { + "FoO" = "BaR" + } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/netapp/tests/resource_arm_netapp_snapshot_test.go b/azurerm/internal/services/netapp/tests/resource_arm_netapp_snapshot_test.go index e472f7dd38cf7..50e1fc277d3f2 100644 --- a/azurerm/internal/services/netapp/tests/resource_arm_netapp_snapshot_test.go +++ b/azurerm/internal/services/netapp/tests/resource_arm_netapp_snapshot_test.go @@ -70,6 +70,8 @@ func TestAccAzureRMNetAppSnapshot_complete(t *testing.T) { Config: testAccAzureRMNetAppSnapshot_complete(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetAppSnapshotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.FoO", "BaR"), ), }, data.ImportStep(), @@ -92,6 +94,18 @@ func TestAccAzureRMNetAppSnapshot_update(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetAppSnapshotExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "volume_name", oldVolumeName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.FoO", "BaR"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetAppSnapshot_updateTags(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetAppSnapshotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "volume_name", oldVolumeName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.FoO", "BaZ"), ), }, data.ImportStep(), @@ -100,6 +114,7 @@ func TestAccAzureRMNetAppSnapshot_update(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetAppSnapshotExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "volume_name", newVolumeName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, data.ImportStep(), @@ -168,11 +183,11 @@ func testAccAzureRMNetAppSnapshot_basic(data acceptance.TestData) string { resource "azurerm_netapp_snapshot" "test" { name = "acctest-NetAppSnapshot-%d" - account_name = "${azurerm_netapp_account.test.name}" - pool_name = "${azurerm_netapp_pool.test.name}" - volume_name = "${azurerm_netapp_volume.test.name}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + account_name = azurerm_netapp_account.test.name + pool_name = azurerm_netapp_pool.test.name + volume_name = azurerm_netapp_volume.test.name + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, template, data.RandomInteger) } @@ -182,9 +197,12 @@ func testAccAzureRMNetAppSnapshot_requiresImport(data acceptance.TestData) strin %s resource "azurerm_netapp_snapshot" "import" { - name = "${azurerm_netapp_snapshot.test.name}" - location = "${azurerm_netapp_snapshot.test.location}" - resource_group_name = "${azurerm_netapp_snapshot.test.resource_group_name}" + name = azurerm_netapp_snapshot.test.name + location = azurerm_netapp_snapshot.test.location + resource_group_name = azurerm_netapp_snapshot.test.resource_group_name + account_name = azurerm_netapp_snapshot.test.account_name + pool_name = azurerm_netapp_snapshot.test.pool_name + volume_name = azurerm_netapp_snapshot.test.volume_name } `, testAccAzureRMNetAppSnapshot_basic(data)) } @@ -196,11 +214,35 @@ func testAccAzureRMNetAppSnapshot_complete(data acceptance.TestData) string { resource "azurerm_netapp_snapshot" "test" { name = "acctest-NetAppSnapshot-%d" - account_name = "${azurerm_netapp_account.test.name}" - pool_name = "${azurerm_netapp_pool.test.name}" - volume_name = "${azurerm_netapp_volume.test.name}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + account_name = azurerm_netapp_account.test.name + pool_name = azurerm_netapp_pool.test.name + volume_name = azurerm_netapp_volume.test.name + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + tags = { + "FoO" = "BaR" + } +} +`, template, data.RandomInteger) +} + +func testAccAzureRMNetAppSnapshot_updateTags(data acceptance.TestData) string { + template := testAccAzureRMNetAppSnapshot_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_netapp_snapshot" "test" { + name = "acctest-NetAppSnapshot-%d" + account_name = azurerm_netapp_account.test.name + pool_name = azurerm_netapp_pool.test.name + volume_name = azurerm_netapp_volume.test.name + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + tags = { + "FoO" = "BaZ" + } } `, template, data.RandomInteger) } @@ -212,18 +254,20 @@ func testAccAzureRMNetAppSnapshot_update(data acceptance.TestData) string { resource "azurerm_virtual_network" "update" { name = "acctest-updated-VirtualNetwork-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "update" { name = "acctest-updated-Subnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.update.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.update.name address_prefix = "10.0.2.0/24" + delegation { name = "netapp" + service_delegation { name = "Microsoft.Netapp/volumes" actions = ["Microsoft.Network/networkinterfaces/*", "Microsoft.Network/virtualNetworks/subnets/join/action"] @@ -233,29 +277,33 @@ resource "azurerm_subnet" "update" { resource "azurerm_netapp_volume" "update" { name = "acctest-updated-NetAppVolume-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - account_name = "${azurerm_netapp_account.test.name}" - pool_name = "${azurerm_netapp_pool.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + account_name = azurerm_netapp_account.test.name + pool_name = azurerm_netapp_pool.test.name volume_path = "my-updated-unique-file-path-%d" service_level = "Premium" - subnet_id = "${azurerm_subnet.update.id}" + subnet_id = azurerm_subnet.update.id storage_quota_in_gb = 100 } resource "azurerm_netapp_snapshot" "test" { name = "acctest-NetAppSnapshot-%d" - account_name = "${azurerm_netapp_account.test.name}" - pool_name = "${azurerm_netapp_pool.test.name}" - volume_name = "${azurerm_netapp_volume.update.name}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + account_name = azurerm_netapp_account.test.name + pool_name = azurerm_netapp_pool.test.name + volume_name = azurerm_netapp_volume.update.name + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMNetAppSnapshot_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-netapp-%d" location = "%s" @@ -263,15 +311,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctest-VirtualNetwork-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "acctest-Subnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" delegation { @@ -286,28 +334,28 @@ resource "azurerm_subnet" "test" { resource "azurerm_netapp_account" "test" { name = "acctest-NetAppAccount-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_netapp_pool" "test" { name = "acctest-NetAppPool-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - account_name = "${azurerm_netapp_account.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + account_name = azurerm_netapp_account.test.name service_level = "Premium" size_in_tb = 4 } resource "azurerm_netapp_volume" "test" { name = "acctest-NetAppVolume-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - account_name = "${azurerm_netapp_account.test.name}" - pool_name = "${azurerm_netapp_pool.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + account_name = azurerm_netapp_account.test.name + pool_name = azurerm_netapp_pool.test.name volume_path = "my-unique-file-path-%d" service_level = "Premium" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id storage_quota_in_gb = 100 } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) diff --git a/azurerm/internal/services/netapp/tests/resource_arm_netapp_volume_test.go b/azurerm/internal/services/netapp/tests/resource_arm_netapp_volume_test.go index 7f1030885d34a..c6543d8bd69a0 100644 --- a/azurerm/internal/services/netapp/tests/resource_arm_netapp_volume_test.go +++ b/azurerm/internal/services/netapp/tests/resource_arm_netapp_volume_test.go @@ -25,6 +25,27 @@ func TestAccAzureRMNetAppVolume_basic(t *testing.T) { Config: testAccAzureRMNetAppVolume_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetAppVolumeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "protocols.2676449260", "NFSv3"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMNetAppVolume_nfsv41(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_netapp_volume", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMNetAppVolumeDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetAppVolume_nfsv41(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetAppVolumeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "protocols.3098200649", "NFSv4.1"), ), }, data.ImportStep(), @@ -71,9 +92,11 @@ func TestAccAzureRMNetAppVolume_complete(t *testing.T) { Config: testAccAzureRMNetAppVolume_complete(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetAppVolumeExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Premium"), + resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Standard"), resource.TestCheckResourceAttr(data.ResourceName, "storage_quota_in_gb", "101"), - resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.FoO", "BaR"), ), }, data.ImportStep(), @@ -95,6 +118,7 @@ func TestAccAzureRMNetAppVolume_update(t *testing.T) { testCheckAzureRMNetAppVolumeExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "storage_quota_in_gb", "100"), resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, data.ImportStep(), @@ -103,7 +127,9 @@ func TestAccAzureRMNetAppVolume_update(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetAppVolumeExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "storage_quota_in_gb", "101"), - resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.FoO", "BaR"), ), }, data.ImportStep(), @@ -113,6 +139,7 @@ func TestAccAzureRMNetAppVolume_update(t *testing.T) { testCheckAzureRMNetAppVolumeExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "storage_quota_in_gb", "100"), resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, data.ImportStep(), @@ -170,7 +197,7 @@ func TestAccAzureRMNetAppVolume_updateExportPolicyRule(t *testing.T) { Config: testAccAzureRMNetAppVolume_complete(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetAppVolumeExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "3"), ), }, data.ImportStep(), @@ -243,6 +270,25 @@ func testAccAzureRMNetAppVolume_basic(data acceptance.TestData) string { return fmt.Sprintf(` %s +resource "azurerm_netapp_volume" "test" { + name = "acctest-NetAppVolume-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + account_name = azurerm_netapp_account.test.name + pool_name = azurerm_netapp_pool.test.name + volume_path = "my-unique-file-path-%d" + service_level = "Standard" + subnet_id = azurerm_subnet.test.id + storage_quota_in_gb = 100 +} +`, template, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMNetAppVolume_nfsv41(data acceptance.TestData) string { + template := testAccAzureRMNetAppVolume_template(data) + return fmt.Sprintf(` +%s + resource "azurerm_netapp_volume" "test" { name = "acctest-NetAppVolume-%d" location = "${azurerm_resource_group.test.location}" @@ -250,9 +296,18 @@ resource "azurerm_netapp_volume" "test" { account_name = "${azurerm_netapp_account.test.name}" pool_name = "${azurerm_netapp_pool.test.name}" volume_path = "my-unique-file-path-%d" - service_level = "Premium" + service_level = "Standard" subnet_id = "${azurerm_subnet.test.id}" + protocols = ["NFSv4.1"] storage_quota_in_gb = 100 + + export_policy_rule { + rule_index = 1 + allowed_clients = ["1.2.3.0/24"] + protocols_enabled = ["NFSv4.1"] + unix_read_only = false + unix_read_write = true + } } `, template, data.RandomInteger, data.RandomInteger) } @@ -262,9 +317,15 @@ func testAccAzureRMNetAppVolume_requiresImport(data acceptance.TestData) string %s resource "azurerm_netapp_volume" "import" { - name = "${azurerm_netapp_volume.test.name}" - location = "${azurerm_netapp_volume.test.location}" - resource_group_name = "${azurerm_netapp_volume.test.resource_group_name}" + name = azurerm_netapp_volume.test.name + location = azurerm_netapp_volume.test.location + resource_group_name = azurerm_netapp_volume.test.resource_group_name + account_name = azurerm_netapp_volume.test.account_name + pool_name = azurerm_netapp_volume.test.pool_name + volume_path = azurerm_netapp_volume.test.volume_path + service_level = azurerm_netapp_volume.test.service_level + subnet_id = azurerm_netapp_volume.test.subnet_id + storage_quota_in_gb = azurerm_netapp_volume.test.storage_quota_in_gb } `, testAccAzureRMNetAppVolume_basic(data)) } @@ -276,34 +337,45 @@ func testAccAzureRMNetAppVolume_complete(data acceptance.TestData) string { resource "azurerm_netapp_volume" "test" { name = "acctest-NetAppVolume-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - account_name = "${azurerm_netapp_account.test.name}" - pool_name = "${azurerm_netapp_pool.test.name}" - service_level = "Premium" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + account_name = azurerm_netapp_account.test.name + pool_name = azurerm_netapp_pool.test.name + service_level = "Standard" volume_path = "my-unique-file-path-%d" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id + protocols = ["NFSv3"] storage_quota_in_gb = 101 export_policy_rule { - rule_index = 1 - allowed_clients = ["1.2.3.0/24"] - cifs_enabled = false - nfsv3_enabled = true - nfsv4_enabled = false - unix_read_only = false - unix_read_write = true + rule_index = 1 + allowed_clients = ["1.2.3.0/24"] + protocols_enabled = ["NFSv3"] + unix_read_only = false + unix_read_write = true } export_policy_rule { - rule_index = 2 - allowed_clients = ["1.2.5.0"] + rule_index = 2 + allowed_clients = ["1.2.5.0"] + protocols_enabled = ["NFSv3"] + unix_read_only = true + unix_read_write = false + } + + export_policy_rule { + rule_index = 3 + allowed_clients = ["1.2.6.0/24"] cifs_enabled = false nfsv3_enabled = true nfsv4_enabled = false unix_read_only = true unix_read_write = false } + + tags = { + "FoO" = "BaR" + } } `, template, data.RandomInteger, data.RandomInteger) } @@ -315,15 +387,15 @@ func testAccAzureRMNetAppVolume_updateSubnet(data acceptance.TestData) string { resource "azurerm_virtual_network" "updated" { name = "acctest-updated-VirtualNetwork-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.1.0.0/16"] } resource "azurerm_subnet" "updated" { name = "acctest-updated-Subnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.updated.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.updated.name address_prefix = "10.1.3.0/24" delegation { @@ -338,13 +410,14 @@ resource "azurerm_subnet" "updated" { resource "azurerm_netapp_volume" "test" { name = "acctest-updated-NetAppVolume-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - account_name = "${azurerm_netapp_account.test.name}" - pool_name = "${azurerm_netapp_pool.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + account_name = azurerm_netapp_account.test.name + pool_name = azurerm_netapp_pool.test.name volume_path = "my-updated-unique-file-path-%d" - service_level = "Premium" - subnet_id = "${azurerm_subnet.updated.id}" + service_level = "Standard" + subnet_id = azurerm_subnet.updated.id + protocols = ["NFSv3"] storage_quota_in_gb = 100 } `, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -357,23 +430,26 @@ func testAccAzureRMNetAppVolume_updateExportPolicyRule(data acceptance.TestData) resource "azurerm_netapp_volume" "test" { name = "acctest-NetAppVolume-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - account_name = "${azurerm_netapp_account.test.name}" - pool_name = "${azurerm_netapp_pool.test.name}" - service_level = "Premium" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + account_name = azurerm_netapp_account.test.name + pool_name = azurerm_netapp_pool.test.name + service_level = "Standard" volume_path = "my-unique-file-path-%d" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id + protocols = ["NFSv3"] storage_quota_in_gb = 101 export_policy_rule { - rule_index = 1 - allowed_clients = ["1.2.4.0/24", "1.3.4.0"] - cifs_enabled = false - nfsv3_enabled = true - nfsv4_enabled = false - unix_read_only = false - unix_read_write = true + rule_index = 1 + allowed_clients = ["1.2.4.0/24", "1.3.4.0"] + protocols_enabled = ["NFSv3"] + unix_read_only = false + unix_read_write = true + } + + tags = { + "FoO" = "BaR" } } `, template, data.RandomInteger, data.RandomInteger) @@ -381,6 +457,10 @@ resource "azurerm_netapp_volume" "test" { func testAccAzureRMNetAppVolume_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-netapp-%d" location = "%s" @@ -388,15 +468,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctest-VirtualNetwork-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "acctest-Subnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" delegation { @@ -411,16 +491,16 @@ resource "azurerm_subnet" "test" { resource "azurerm_netapp_account" "test" { name = "acctest-NetAppAccount-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_netapp_pool" "test" { name = "acctest-NetAppPool-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - account_name = "${azurerm_netapp_account.test.name}" - service_level = "Premium" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + account_name = azurerm_netapp_account.test.name + service_level = "Standard" size_in_tb = 4 } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) diff --git a/azurerm/internal/services/network/client/client.go b/azurerm/internal/services/network/client/client.go index 2788d928b6a77..9794b251ef663 100644 --- a/azurerm/internal/services/network/client/client.go +++ b/azurerm/internal/services/network/client/client.go @@ -14,6 +14,7 @@ type Client struct { DDOSProtectionPlansClient *network.DdosProtectionPlansClient ExpressRouteAuthsClient *network.ExpressRouteCircuitAuthorizationsClient ExpressRouteCircuitsClient *network.ExpressRouteCircuitsClient + ExpressRouteGatewaysClient *network.ExpressRouteGatewaysClient ExpressRoutePeeringsClient *network.ExpressRouteCircuitPeeringsClient InterfacesClient *network.InterfacesClient LoadBalancersClient *network.LoadBalancersClient @@ -68,6 +69,9 @@ func NewClient(o *common.ClientOptions) *Client { ExpressRouteCircuitsClient := network.NewExpressRouteCircuitsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&ExpressRouteCircuitsClient.Client, o.ResourceManagerAuthorizer) + ExpressRouteGatewaysClient := network.NewExpressRouteGatewaysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&ExpressRouteGatewaysClient.Client, o.ResourceManagerAuthorizer) + ExpressRoutePeeringsClient := network.NewExpressRouteCircuitPeeringsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&ExpressRoutePeeringsClient.Client, o.ResourceManagerAuthorizer) @@ -158,6 +162,7 @@ func NewClient(o *common.ClientOptions) *Client { DDOSProtectionPlansClient: &DDOSProtectionPlansClient, ExpressRouteAuthsClient: &ExpressRouteAuthsClient, ExpressRouteCircuitsClient: &ExpressRouteCircuitsClient, + ExpressRouteGatewaysClient: &ExpressRouteGatewaysClient, ExpressRoutePeeringsClient: &ExpressRoutePeeringsClient, InterfacesClient: &InterfacesClient, LoadBalancersClient: &LoadBalancersClient, diff --git a/azurerm/internal/services/network/data_source_network_interface.go b/azurerm/internal/services/network/data_source_network_interface.go index 7e934893da4ea..e1a0ea6df3469 100644 --- a/azurerm/internal/services/network/data_source_network_interface.go +++ b/azurerm/internal/services/network/data_source_network_interface.go @@ -73,7 +73,6 @@ func dataSourceArmNetworkInterface() *schema.Resource { Computed: true, }, - //TODO: should this be renamed to private_ip_address_allocation_method or private_ip_allocation_method ? "private_ip_address_allocation": { Type: schema.TypeString, Computed: true, @@ -139,20 +138,6 @@ func dataSourceArmNetworkInterface() *schema.Resource { Set: schema.HashString, }, - "internal_fqdn": { - Type: schema.TypeString, - Deprecated: "This field has been removed by Azure", - Computed: true, - }, - - /** - * As of 2018-01-06: AN (aka. SR-IOV) on Azure is GA on Windows and Linux. - * - * Refer to: https://azure.microsoft.com/en-us/blog/maximize-your-vm-s-performance-with-accelerated-networking-now-generally-available-for-both-windows-and-linux/ - * - * Refer to: https://docs.microsoft.com/en-us/azure/virtual-network/create-vm-accelerated-networking-cli - * For details, VM configuration and caveats. - */ "enable_accelerated_networking": { Type: schema.TypeBool, Computed: true, @@ -241,7 +226,6 @@ func dataSourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) dnsServers = *s } - d.Set("internal_fqdn", dnsSettings.InternalFqdn) d.Set("internal_dns_name_label", dnsSettings.InternalDNSNameLabel) } diff --git a/azurerm/internal/services/network/data_source_private_link_endpoint_connection.go b/azurerm/internal/services/network/data_source_private_link_endpoint_connection.go deleted file mode 100644 index 505d1943146b7..0000000000000 --- a/azurerm/internal/services/network/data_source_private_link_endpoint_connection.go +++ /dev/null @@ -1,167 +0,0 @@ -package network - -import ( - "fmt" - "time" - - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func dataSourceArmPrivateLinkEndpointConnection() *schema.Resource { - return &schema.Resource{ - DeprecationMessage: `The 'azurerm_private_link_endpoint_connection' resource is being deprecated in favour of the renamed version 'azurerm_private_endpoint_connection'. - -Information on migrating to the renamed resource can be found here: https://terraform.io/docs/providers/azurerm/guides/migrating-between-renamed-resources.html - -As such the existing 'azurerm_private_link_endpoint_connection' resource is deprecated and will be removed in the next major version of the AzureRM Provider (2.0). -`, - - Read: dataSourceArmPrivateLinkEndpointConnectionRead, - Timeouts: &schema.ResourceTimeout{ - Read: schema.DefaultTimeout(5 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ValidateFunc: ValidatePrivateLinkName, - }, - - "location": azure.SchemaLocationForDataSource(), - - "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), - - "private_service_connection": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Computed: true, - }, - "request_response": { - Type: schema.TypeString, - Computed: true, - }, - "status": { - Type: schema.TypeString, - Computed: true, - }, - "private_ip_address": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - }, - } -} - -func dataSourceArmPrivateLinkEndpointConnectionRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.PrivateEndpointClient - nicsClient := meta.(*clients.Client).Network.InterfacesClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - - resp, err := client.Get(ctx, resourceGroup, name, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil - } - return fmt.Errorf("Error reading Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) - } - if resp.ID == nil || *resp.ID == "" { - return fmt.Errorf("API returns a nil/empty id on Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - d.SetId(*resp.ID) - d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - - if props := resp.PrivateEndpointProperties; props != nil { - privateIpAddress := "" - - if nics := props.NetworkInterfaces; nics != nil && len(*nics) > 0 { - nic := (*nics)[0] - if nic.ID != nil && *nic.ID != "" { - privateIpAddress = getPrivateIpAddress(ctx, nicsClient, *nic.ID) - } - } - - if err := d.Set("private_service_connection", dataSourceFlattenArmPrivateLinkEndpointServiceConnection(props.PrivateLinkServiceConnections, props.ManualPrivateLinkServiceConnections, privateIpAddress)); err != nil { - return fmt.Errorf("Error setting `private_service_connection`: %+v", err) - } - } - - return nil -} - -func dataSourceFlattenArmPrivateLinkEndpointServiceConnection(serviceConnections *[]network.PrivateLinkServiceConnection, manualServiceConnections *[]network.PrivateLinkServiceConnection, privateIpAddress string) []interface{} { - results := make([]interface{}, 0) - if serviceConnections == nil && manualServiceConnections == nil { - return results - } - - if serviceConnections != nil { - for _, item := range *serviceConnections { - result := make(map[string]interface{}) - result["private_ip_address"] = privateIpAddress - - if v := item.Name; v != nil { - result["name"] = *v - } - if props := item.PrivateLinkServiceConnectionProperties; props != nil { - if v := props.PrivateLinkServiceConnectionState; v != nil { - if s := v.Status; s != nil { - result["status"] = *s - } - if d := v.Description; d != nil { - result["request_response"] = *d - } - } - } - - results = append(results, result) - } - } - - if manualServiceConnections != nil { - for _, item := range *manualServiceConnections { - result := make(map[string]interface{}) - result["private_ip_address"] = privateIpAddress - - if v := item.Name; v != nil { - result["name"] = *v - } - if props := item.PrivateLinkServiceConnectionProperties; props != nil { - if v := props.PrivateLinkServiceConnectionState; v != nil { - if s := v.Status; s != nil { - result["status"] = *s - } - if d := v.Description; d != nil { - result["request_response"] = *d - } - } - } - - results = append(results, result) - } - } - - return results -} diff --git a/azurerm/internal/services/network/data_source_private_link_service.go b/azurerm/internal/services/network/data_source_private_link_service.go index 3d35d3ebcab61..cccd3fd6cdf44 100644 --- a/azurerm/internal/services/network/data_source_private_link_service.go +++ b/azurerm/internal/services/network/data_source_private_link_service.go @@ -89,13 +89,6 @@ func dataSourceArmPrivateLinkService() *schema.Resource { Computed: true, }, - "network_interface_ids": { - Type: schema.TypeList, - Computed: true, - Deprecated: "This field has been deprecated and will be removed in version 2.0 of the Azure Provider", - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "tags": tags.SchemaDataSource(), }, } @@ -149,11 +142,6 @@ func dataSourceArmPrivateLinkServiceRead(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error setting `load_balancer_frontend_ip_configuration_ids`: %+v", err) } } - if props.NetworkInterfaces != nil { - if err := d.Set("network_interface_ids", dataSourceFlattenArmPrivateLinkServiceInterface(props.NetworkInterfaces)); err != nil { - return fmt.Errorf("Error setting `network_interface_ids`: %+v", err) - } - } } if resp.ID == nil || *resp.ID == "" { @@ -178,18 +166,3 @@ func dataSourceFlattenArmPrivateLinkServiceFrontendIPConfiguration(input *[]netw return results } - -func dataSourceFlattenArmPrivateLinkServiceInterface(input *[]network.Interface) []string { - results := make([]string, 0) - if input == nil { - return results - } - - for _, item := range *input { - if id := item.ID; id != nil { - results = append(results, *id) - } - } - - return results -} diff --git a/azurerm/internal/services/network/data_source_public_ip.go b/azurerm/internal/services/network/data_source_public_ip.go index 3d241ea1688da..d808124e50716 100644 --- a/azurerm/internal/services/network/data_source_public_ip.go +++ b/azurerm/internal/services/network/data_source_public_ip.go @@ -99,8 +99,8 @@ func dataSourceArmPublicIPRead(d *schema.ResourceData, meta interface{}) error { d.Set("zones", resp.Zones) - //ensure values are at least set to "", d.Set() is a noop on a nil - //there must be a better way... + // ensure values are at least set to "", d.Set() is a noop on a nil + // there must be a better way... d.Set("location", "") d.Set("sku", "") d.Set("fqdn", "") diff --git a/azurerm/internal/services/network/data_source_subnet.go b/azurerm/internal/services/network/data_source_subnet.go index befd916815880..752579d715852 100644 --- a/azurerm/internal/services/network/data_source_subnet.go +++ b/azurerm/internal/services/network/data_source_subnet.go @@ -2,7 +2,6 @@ package network import ( "fmt" - "strings" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -51,13 +50,6 @@ func dataSourceArmSubnet() *schema.Resource { Computed: true, }, - "ip_configurations": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - }, - "service_endpoints": { Type: schema.TypeList, Computed: true, @@ -104,32 +96,23 @@ func dataSourceArmSubnetRead(d *schema.ResourceData, meta interface{}) error { if props := resp.SubnetPropertiesFormat; props != nil { d.Set("address_prefix", props.AddressPrefix) - if pe := props.PrivateEndpointNetworkPolicies; pe != nil { - d.Set("enforce_private_link_endpoint_network_policies", strings.EqualFold("Disabled", *pe)) - } - - if ps := props.PrivateLinkServiceNetworkPolicies; ps != nil { - d.Set("enforce_private_link_service_network_policies", strings.EqualFold("Disabled", *ps)) - } - - if props.NetworkSecurityGroup != nil { - d.Set("network_security_group_id", props.NetworkSecurityGroup.ID) - } else { - d.Set("network_security_group_id", "") - } + d.Set("enforce_private_link_endpoint_network_policies", flattenSubnetPrivateLinkNetworkPolicy(props.PrivateEndpointNetworkPolicies)) + d.Set("enforce_private_link_service_network_policies", flattenSubnetPrivateLinkNetworkPolicy(props.PrivateLinkServiceNetworkPolicies)) - if props.RouteTable != nil { - d.Set("route_table_id", props.RouteTable.ID) - } else { - d.Set("route_table_id", "") + networkSecurityGroupId := "" + if props.NetworkSecurityGroup != nil && props.NetworkSecurityGroup.ID != nil { + networkSecurityGroupId = *props.NetworkSecurityGroup.ID } + d.Set("network_security_group_id", networkSecurityGroupId) - if err := d.Set("ip_configurations", flattenSubnetIPConfigurations(props.IPConfigurations)); err != nil { - return err + routeTableId := "" + if props.RouteTable != nil && props.RouteTable.ID != nil { + routeTableId = *props.RouteTable.ID } + d.Set("route_table_id", routeTableId) if err := d.Set("service_endpoints", flattenSubnetServiceEndpoints(props.ServiceEndpoints)); err != nil { - return err + return fmt.Errorf("Error setting `service_endpoints`: %+v", err) } } diff --git a/azurerm/internal/services/network/data_source_virtual_network.go b/azurerm/internal/services/network/data_source_virtual_network.go index 2890b6e5d6ff3..dca55e7f23f64 100644 --- a/azurerm/internal/services/network/data_source_virtual_network.go +++ b/azurerm/internal/services/network/data_source_virtual_network.go @@ -32,15 +32,6 @@ func dataSourceArmVirtualNetwork() *schema.Resource { "location": azure.SchemaLocationForDataSource(), - "address_spaces": { - Type: schema.TypeList, - Computed: true, - Deprecated: "This resource has been deprecated in favour of `address_space` to be more consistent with the `azurerm_virtual_network` resource", - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "address_space": { Type: schema.TypeList, Computed: true, @@ -104,9 +95,6 @@ func dataSourceArmVnetRead(d *schema.ResourceData, meta interface{}) error { if props := resp.VirtualNetworkPropertiesFormat; props != nil { if as := props.AddressSpace; as != nil { - if err := d.Set("address_spaces", utils.FlattenStringSlice(as.AddressPrefixes)); err != nil { // todo remove in 2.0 - return fmt.Errorf("error setting `address_spaces`: %v", err) - } if err := d.Set("address_space", utils.FlattenStringSlice(as.AddressPrefixes)); err != nil { return fmt.Errorf("error setting `address_space`: %v", err) } diff --git a/azurerm/internal/services/network/network_interface.go b/azurerm/internal/services/network/network_interface.go new file mode 100644 index 0000000000000..798b38580bb45 --- /dev/null +++ b/azurerm/internal/services/network/network_interface.go @@ -0,0 +1,134 @@ +package network + +import ( + "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +type networkInterfaceUpdateInformation struct { + applicationGatewayBackendAddressPoolIDs []string + applicationSecurityGroupIDs []string + loadBalancerBackendAddressPoolIDs []string + loadBalancerInboundNatRuleIDs []string + networkSecurityGroupID string +} + +func parseFieldsFromNetworkInterface(input network.InterfacePropertiesFormat) networkInterfaceUpdateInformation { + networkSecurityGroupId := "" + if input.NetworkSecurityGroup != nil && input.NetworkSecurityGroup.ID != nil { + networkSecurityGroupId = *input.NetworkSecurityGroup.ID + } + + var mapToSlice = func(input map[string]struct{}) []string { + output := make([]string, 0) + + for id := range input { + output = append(output, id) + } + + return output + } + + applicationSecurityGroupIds := make(map[string]struct{}) + applicationGatewayBackendAddressPoolIds := make(map[string]struct{}) + loadBalancerBackendAddressPoolIds := make(map[string]struct{}) + loadBalancerInboundNatRuleIds := make(map[string]struct{}) + + if input.IPConfigurations != nil { + for _, v := range *input.IPConfigurations { + if v.InterfaceIPConfigurationPropertiesFormat == nil { + continue + } + + props := *v.InterfaceIPConfigurationPropertiesFormat + if props.ApplicationSecurityGroups != nil { + for _, asg := range *props.ApplicationSecurityGroups { + if asg.ID != nil { + applicationSecurityGroupIds[*asg.ID] = struct{}{} + } + } + } + + if props.ApplicationGatewayBackendAddressPools != nil { + for _, pool := range *props.ApplicationGatewayBackendAddressPools { + if pool.ID != nil { + applicationGatewayBackendAddressPoolIds[*pool.ID] = struct{}{} + } + } + } + + if props.LoadBalancerBackendAddressPools != nil { + for _, pool := range *props.LoadBalancerBackendAddressPools { + if pool.ID != nil { + loadBalancerBackendAddressPoolIds[*pool.ID] = struct{}{} + } + } + } + + if props.LoadBalancerInboundNatRules != nil { + for _, rule := range *props.LoadBalancerInboundNatRules { + if rule.ID != nil { + loadBalancerInboundNatRuleIds[*rule.ID] = struct{}{} + } + } + } + } + } + + return networkInterfaceUpdateInformation{ + applicationGatewayBackendAddressPoolIDs: mapToSlice(applicationGatewayBackendAddressPoolIds), + applicationSecurityGroupIDs: mapToSlice(applicationSecurityGroupIds), + loadBalancerBackendAddressPoolIDs: mapToSlice(loadBalancerBackendAddressPoolIds), + loadBalancerInboundNatRuleIDs: mapToSlice(loadBalancerInboundNatRuleIds), + networkSecurityGroupID: networkSecurityGroupId, + } +} + +func mapFieldsToNetworkInterface(input *[]network.InterfaceIPConfiguration, info networkInterfaceUpdateInformation) *[]network.InterfaceIPConfiguration { + output := input + + applicationSecurityGroups := make([]network.ApplicationSecurityGroup, 0) + for _, id := range info.applicationSecurityGroupIDs { + applicationSecurityGroups = append(applicationSecurityGroups, network.ApplicationSecurityGroup{ + ID: utils.String(id), + }) + } + + applicationGatewayBackendAddressPools := make([]network.ApplicationGatewayBackendAddressPool, 0) + for _, id := range info.applicationGatewayBackendAddressPoolIDs { + applicationGatewayBackendAddressPools = append(applicationGatewayBackendAddressPools, network.ApplicationGatewayBackendAddressPool{ + ID: utils.String(id), + }) + } + + loadBalancerBackendAddressPools := make([]network.BackendAddressPool, 0) + for _, id := range info.loadBalancerBackendAddressPoolIDs { + loadBalancerBackendAddressPools = append(loadBalancerBackendAddressPools, network.BackendAddressPool{ + ID: utils.String(id), + }) + } + + loadBalancerInboundNatRules := make([]network.InboundNatRule, 0) + for _, id := range info.loadBalancerInboundNatRuleIDs { + loadBalancerInboundNatRules = append(loadBalancerInboundNatRules, network.InboundNatRule{ + ID: utils.String(id), + }) + } + + for _, config := range *output { + if config.InterfaceIPConfigurationPropertiesFormat == nil { + continue + } + + if config.InterfaceIPConfigurationPropertiesFormat.PrivateIPAddressVersion != network.IPv4 { + continue + } + + config.ApplicationSecurityGroups = &applicationSecurityGroups + config.ApplicationGatewayBackendAddressPools = &applicationGatewayBackendAddressPools + config.LoadBalancerBackendAddressPools = &loadBalancerBackendAddressPools + config.LoadBalancerInboundNatRules = &loadBalancerInboundNatRules + } + + return output +} diff --git a/azurerm/internal/services/network/network_interface_application_security_group_association_migration.go b/azurerm/internal/services/network/network_interface_application_security_group_association_migration.go new file mode 100644 index 0000000000000..2899e7d66fc22 --- /dev/null +++ b/azurerm/internal/services/network/network_interface_application_security_group_association_migration.go @@ -0,0 +1,43 @@ +package network + +import ( + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +func resourceNetworkInterfaceApplicationSecurityGroupAssociationUpgradeV0Schema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "network_interface_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, + }, + + "application_security_group_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, + }, + }, + } +} + +func resourceNetworkInterfaceApplicationSecurityGroupAssociationUpgradeV0ToV1(rawState map[string]interface{}, _ interface{}) (map[string]interface{}, error) { + // after shipping support for this Resource Azure's since changed the behaviour to require that all IP Configurations + // are connected to the same Application Security Group + applicationSecurityGroupId := rawState["application_security_group_id"].(string) + networkInterfaceId := rawState["network_interface_id"].(string) + + oldID := rawState["id"].(string) + newID := fmt.Sprintf("%s|%s", networkInterfaceId, applicationSecurityGroupId) + log.Printf("[DEBUG] Updating ID from %q to %q", oldID, newID) + + rawState["id"] = newID + return rawState, nil +} diff --git a/azurerm/internal/services/network/resource_arm_network_interface_application_security_group_association.go b/azurerm/internal/services/network/network_interface_application_security_group_association_resource.go similarity index 61% rename from azurerm/internal/services/network/resource_arm_network_interface_application_security_group_association.go rename to azurerm/internal/services/network/network_interface_application_security_group_association_resource.go index b093079d34328..77104acd8b768 100644 --- a/azurerm/internal/services/network/resource_arm_network_interface_application_security_group_association.go +++ b/azurerm/internal/services/network/network_interface_application_security_group_association_resource.go @@ -6,13 +6,10 @@ import ( "strings" "time" - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -27,6 +24,15 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociation() *schema.Re State: schema.ImportStatePassthrough, }, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: resourceNetworkInterfaceApplicationSecurityGroupAssociationUpgradeV0Schema().CoreConfigSchema().ImpliedType(), + Upgrade: resourceNetworkInterfaceApplicationSecurityGroupAssociationUpgradeV0ToV1, + Version: 0, + }, + }, + Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), Read: schema.DefaultTimeout(5 * time.Minute), @@ -42,13 +48,6 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociation() *schema.Re ValidateFunc: azure.ValidateResourceID, }, - "ip_configuration_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "application_security_group_id": { Type: schema.TypeString, Required: true, @@ -67,7 +66,6 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociationCreate(d *sch log.Printf("[INFO] preparing arguments for Network Interface <-> Application Security Group Association creation.") networkInterfaceId := d.Get("network_interface_id").(string) - ipConfigurationName := d.Get("ip_configuration_name").(string) applicationSecurityGroupId := d.Get("application_security_group_id").(string) id, err := azure.ParseAzureResourceID(networkInterfaceId) @@ -94,49 +92,19 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociationCreate(d *sch if props == nil { return fmt.Errorf("Error: `properties` was nil for Network Interface %q (Resource Group %q)", networkInterfaceName, resourceGroup) } - - ipConfigs := props.IPConfigurations - if ipConfigs == nil { - return fmt.Errorf("Error: `properties.IPConfigurations` was nil for Network Interface %q (Resource Group %q)", networkInterfaceName, resourceGroup) - } - - c := azure.FindNetworkInterfaceIPConfiguration(props.IPConfigurations, ipConfigurationName) - if c == nil { - return fmt.Errorf("Error: IP Configuration %q was not found on Network Interface %q (Resource Group %q)", ipConfigurationName, networkInterfaceName, resourceGroup) - } - - config := *c - p := config.InterfaceIPConfigurationPropertiesFormat - if p == nil { - return fmt.Errorf("Error: `IPConfiguration.properties` was nil for Network Interface %q (Resource Group %q)", networkInterfaceName, resourceGroup) + if props.IPConfigurations == nil { + return fmt.Errorf("Error: `properties.ipConfigurations` was nil for Network Interface %q (Resource Group %q)", networkInterfaceName, resourceGroup) } - applicationSecurityGroups := make([]network.ApplicationSecurityGroup, 0) - - // first double-check it doesn't exist - if p.ApplicationSecurityGroups != nil { - for _, existingGroup := range *p.ApplicationSecurityGroups { - if id := existingGroup.ID; id != nil { - if *id == applicationSecurityGroupId { - if features.ShouldResourcesBeImported() { - return tf.ImportAsExistsError("azurerm_network_interface_application_security_group_association", *id) - } - - continue - } - - applicationSecurityGroups = append(applicationSecurityGroups, existingGroup) - } - } + info := parseFieldsFromNetworkInterface(*props) + resourceId := fmt.Sprintf("%s|%s", networkInterfaceId, applicationSecurityGroupId) + if azure.SliceContainsValue(info.applicationSecurityGroupIDs, applicationSecurityGroupId) { + return tf.ImportAsExistsError("azurerm_network_interface_application_security_group_association", resourceId) } - group := network.ApplicationSecurityGroup{ - ID: utils.String(applicationSecurityGroupId), - } - applicationSecurityGroups = append(applicationSecurityGroups, group) - p.ApplicationSecurityGroups = &applicationSecurityGroups + info.applicationSecurityGroupIDs = append(info.applicationSecurityGroupIDs, applicationSecurityGroupId) - props.IPConfigurations = azure.UpdateNetworkInterfaceIPConfiguration(config, props.IPConfigurations) + read.InterfacePropertiesFormat.IPConfigurations = mapFieldsToNetworkInterface(props.IPConfigurations, info) future, err := client.CreateOrUpdate(ctx, resourceGroup, networkInterfaceName, read) if err != nil { @@ -147,7 +115,6 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociationCreate(d *sch return fmt.Errorf("Error waiting for completion of Application Security Group Association for NIC %q (Resource Group %q): %+v", networkInterfaceName, resourceGroup, err) } - resourceId := fmt.Sprintf("%s/ipConfigurations/%s|%s", networkInterfaceId, ipConfigurationName, applicationSecurityGroupId) d.SetId(resourceId) return resourceArmNetworkInterfaceApplicationSecurityGroupAssociationRead(d, meta) @@ -160,7 +127,7 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociationRead(d *schem splitId := strings.Split(d.Id(), "|") if len(splitId) != 2 { - return fmt.Errorf("Expected ID to be in the format {networkInterfaceId}/ipConfigurations/{ipConfigurationName}|{applicationSecurityGroupId} but got %q", d.Id()) + return fmt.Errorf("Expected ID to be in the format {networkInterfaceId}|{applicationSecurityGroupId} but got %q", d.Id()) } nicID, err := azure.ParseAzureResourceID(splitId[0]) @@ -168,7 +135,6 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociationRead(d *schem return err } - ipConfigurationName := nicID.Path["ipConfigurations"] networkInterfaceName := nicID.Path["networkInterfaces"] resourceGroup := nicID.ResourceGroup applicationSecurityGroupId := splitId[1] @@ -187,43 +153,21 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociationRead(d *schem return fmt.Errorf("Error: `properties` was nil for Network Interface %q (Resource Group %q)", networkInterfaceName, resourceGroup) } - ipConfigs := nicProps.IPConfigurations - if ipConfigs == nil { - return fmt.Errorf("Error: `properties.IPConfigurations` was nil for Network Interface %q (Resource Group %q)", networkInterfaceName, resourceGroup) - } - - c := azure.FindNetworkInterfaceIPConfiguration(nicProps.IPConfigurations, ipConfigurationName) - if c == nil { - log.Printf("IP Configuration %q was not found in Network Interface %q (Resource Group %q) - removing from state!", ipConfigurationName, networkInterfaceName, resourceGroup) - d.SetId("") - return nil - } - config := *c - - found := false - if props := config.InterfaceIPConfigurationPropertiesFormat; props != nil { - if groups := props.ApplicationSecurityGroups; groups != nil { - for _, group := range *groups { - if group.ID == nil { - continue - } - - if *group.ID == applicationSecurityGroupId { - found = true - break - } - } + info := parseFieldsFromNetworkInterface(*nicProps) + exists := false + for _, groupId := range info.applicationSecurityGroupIDs { + if groupId == applicationSecurityGroupId { + exists = true } } - if !found { + if !exists { log.Printf("[DEBUG] Association between Network Interface %q (Resource Group %q) and Application Security Group %q was not found - removing from state!", networkInterfaceName, resourceGroup, applicationSecurityGroupId) d.SetId("") return nil } d.Set("application_security_group_id", applicationSecurityGroupId) - d.Set("ip_configuration_name", ipConfigurationName) d.Set("network_interface_id", read.ID) return nil @@ -236,7 +180,7 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociationDelete(d *sch splitId := strings.Split(d.Id(), "|") if len(splitId) != 2 { - return fmt.Errorf("Expected ID to be in the format {networkInterfaceId}/ipConfigurations/{ipConfigurationName}|{applicationSecurityGroupId} but got %q", d.Id()) + return fmt.Errorf("Expected ID to be in the format {networkInterfaceId}|{applicationSecurityGroupId} but got %q", d.Id()) } nicID, err := azure.ParseAzureResourceID(splitId[0]) @@ -244,7 +188,6 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociationDelete(d *sch return err } - ipConfigurationName := nicID.Path["ipConfigurations"] networkInterfaceName := nicID.Path["networkInterfaces"] resourceGroup := nicID.ResourceGroup applicationSecurityGroupId := splitId[1] @@ -261,41 +204,25 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociationDelete(d *sch return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", networkInterfaceName, resourceGroup, err) } - nicProps := read.InterfacePropertiesFormat - if nicProps == nil { + props := read.InterfacePropertiesFormat + if props == nil { return fmt.Errorf("Error: `properties` was nil for Network Interface %q (Resource Group %q)", networkInterfaceName, resourceGroup) } - ipConfigs := nicProps.IPConfigurations - if ipConfigs == nil { - return fmt.Errorf("Error: `properties.IPConfigurations` was nil for Network Interface %q (Resource Group %q)", networkInterfaceName, resourceGroup) - } - - c := azure.FindNetworkInterfaceIPConfiguration(nicProps.IPConfigurations, ipConfigurationName) - if c == nil { - return fmt.Errorf("Error: IP Configuration %q was not found on Network Interface %q (Resource Group %q)", ipConfigurationName, networkInterfaceName, resourceGroup) - } - config := *c - - props := config.InterfaceIPConfigurationPropertiesFormat - if props == nil { - return fmt.Errorf("Error: Properties for IPConfiguration %q was nil for Network Interface %q (Resource Group %q)", ipConfigurationName, networkInterfaceName, resourceGroup) + if props.IPConfigurations == nil { + return fmt.Errorf("Error: `properties.ipConfigurations` was nil for Network Interface %q (Resource Group %q)", networkInterfaceName, resourceGroup) } - applicationSecurityGroups := make([]network.ApplicationSecurityGroup, 0) - if groups := props.ApplicationSecurityGroups; groups != nil { - for _, pool := range *groups { - if pool.ID == nil { - continue - } + info := parseFieldsFromNetworkInterface(*props) - if *pool.ID != applicationSecurityGroupId { - applicationSecurityGroups = append(applicationSecurityGroups, pool) - } + applicationSecurityGroupIds := make([]string, 0) + for _, v := range info.applicationSecurityGroupIDs { + if v != applicationSecurityGroupId { + applicationSecurityGroupIds = append(applicationSecurityGroupIds, v) } } - props.ApplicationSecurityGroups = &applicationSecurityGroups - nicProps.IPConfigurations = azure.UpdateNetworkInterfaceIPConfiguration(config, nicProps.IPConfigurations) + info.applicationSecurityGroupIDs = applicationSecurityGroupIds + read.InterfacePropertiesFormat.IPConfigurations = mapFieldsToNetworkInterface(props.IPConfigurations, info) future, err := client.CreateOrUpdate(ctx, resourceGroup, networkInterfaceName, read) if err != nil { diff --git a/azurerm/internal/services/network/network_interface_locking.go b/azurerm/internal/services/network/network_interface_locking.go new file mode 100644 index 0000000000000..9e599ce482b8b --- /dev/null +++ b/azurerm/internal/services/network/network_interface_locking.go @@ -0,0 +1,61 @@ +package network + +import ( + "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" +) + +type networkInterfaceIPConfigurationLockingDetails struct { + subnetNamesToLock []string + virtualNetworkNamesToLock []string +} + +func (details networkInterfaceIPConfigurationLockingDetails) lock() { + locks.MultipleByName(&details.subnetNamesToLock, SubnetResourceName) + locks.MultipleByName(&details.virtualNetworkNamesToLock, VirtualNetworkResourceName) +} + +func (details networkInterfaceIPConfigurationLockingDetails) unlock() { + locks.UnlockMultipleByName(&details.subnetNamesToLock, SubnetResourceName) + locks.UnlockMultipleByName(&details.virtualNetworkNamesToLock, VirtualNetworkResourceName) +} + +func determineResourcesToLockFromIPConfiguration(input *[]network.InterfaceIPConfiguration) (*networkInterfaceIPConfigurationLockingDetails, error) { + if input == nil { + return &networkInterfaceIPConfigurationLockingDetails{ + subnetNamesToLock: []string{}, + virtualNetworkNamesToLock: []string{}, + }, nil + } + + subnetNamesToLock := make([]string, 0) + virtualNetworkNamesToLock := make([]string, 0) + + for _, config := range *input { + if config.Subnet == nil || config.Subnet.ID == nil { + continue + } + + id, err := azure.ParseAzureResourceID(*config.Subnet.ID) + if err != nil { + return nil, err + } + + virtualNetworkName := id.Path["virtualNetworks"] + subnetName := id.Path["subnets"] + + if !azure.SliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { + virtualNetworkNamesToLock = append(virtualNetworkNamesToLock, virtualNetworkName) + } + + if !azure.SliceContainsValue(subnetNamesToLock, subnetName) { + subnetNamesToLock = append(subnetNamesToLock, subnetName) + } + } + + return &networkInterfaceIPConfigurationLockingDetails{ + subnetNamesToLock: subnetNamesToLock, + virtualNetworkNamesToLock: virtualNetworkNamesToLock, + }, nil +} diff --git a/azurerm/internal/services/network/network_interface_network_security_group_association_resource.go b/azurerm/internal/services/network/network_interface_network_security_group_association_resource.go new file mode 100644 index 0000000000000..b71f335adb043 --- /dev/null +++ b/azurerm/internal/services/network/network_interface_network_security_group_association_resource.go @@ -0,0 +1,218 @@ +package network + +import ( + "fmt" + "log" + "strings" + "time" + + "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/azuresdkhacks" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmNetworkInterfaceSecurityGroupAssociation() *schema.Resource { + return &schema.Resource{ + Create: resourceArmNetworkInterfaceSecurityGroupAssociationCreate, + Read: resourceArmNetworkInterfaceSecurityGroupAssociationRead, + Delete: resourceArmNetworkInterfaceSecurityGroupAssociationDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "network_interface_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, + }, + + "network_security_group_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, + }, + }, + } +} + +func resourceArmNetworkInterfaceSecurityGroupAssociationCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Network.InterfacesClient + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) + defer cancel() + + log.Printf("[INFO] preparing arguments for Network Interface <-> Network Security Group Association creation.") + + networkInterfaceId := d.Get("network_interface_id").(string) + networkSecurityGroupId := d.Get("network_security_group_id").(string) + + nicId, err := azure.ParseAzureResourceID(networkInterfaceId) + if err != nil { + return err + } + + networkInterfaceName := nicId.Path["networkInterfaces"] + resourceGroup := nicId.ResourceGroup + + locks.ByName(networkInterfaceName, networkInterfaceResourceName) + defer locks.UnlockByName(networkInterfaceName, networkInterfaceResourceName) + + nsgId, err := azure.ParseAzureResourceID(networkSecurityGroupId) + if err != nil { + return err + } + nsgName := nsgId.Path["networkSecurityGroups"] + + locks.ByName(nsgName, networkSecurityGroupResourceName) + defer locks.UnlockByName(nsgName, networkSecurityGroupResourceName) + + read, err := client.Get(ctx, resourceGroup, networkInterfaceName, "") + if err != nil { + if utils.ResponseWasNotFound(read.Response) { + return fmt.Errorf("Network Interface %q (Resource Group %q) was not found!", networkInterfaceName, resourceGroup) + } + + return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", networkInterfaceName, resourceGroup, err) + } + + props := read.InterfacePropertiesFormat + if props == nil { + return fmt.Errorf("Error: `properties` was nil for Network Interface %q (Resource Group %q)", networkInterfaceName, resourceGroup) + } + + // first double-check it doesn't exist + resourceId := fmt.Sprintf("%s|%s", networkInterfaceId, networkSecurityGroupId) + if features.ShouldResourcesBeImported() { + if props.NetworkSecurityGroup != nil { + return tf.ImportAsExistsError("azurerm_network_interface_security_group_association", resourceGroup) + } + } + + props.NetworkSecurityGroup = &network.SecurityGroup{ + ID: utils.String(networkSecurityGroupId), + } + + future, err := client.CreateOrUpdate(ctx, resourceGroup, networkInterfaceName, read) + if err != nil { + return fmt.Errorf("Error updating Security Group Association for Network Interface %q (Resource Group %q): %+v", networkInterfaceName, resourceGroup, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for completion of Security Group Association for NIC %q (Resource Group %q): %+v", networkInterfaceName, resourceGroup, err) + } + + d.SetId(resourceId) + + return resourceArmNetworkInterfaceSecurityGroupAssociationRead(d, meta) +} + +func resourceArmNetworkInterfaceSecurityGroupAssociationRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Network.InterfacesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + splitId := strings.Split(d.Id(), "|") + if len(splitId) != 2 { + return fmt.Errorf("Expected ID to be in the format {networkInterfaceId}|{networkSecurityGroupId} but got %q", d.Id()) + } + + nicID, err := azure.ParseAzureResourceID(splitId[0]) + if err != nil { + return err + } + + name := nicID.Path["networkInterfaces"] + resourceGroup := nicID.ResourceGroup + + read, err := client.Get(ctx, resourceGroup, name, "") + if err != nil { + if utils.ResponseWasNotFound(read.Response) { + return fmt.Errorf("Network Interface %q (Resource Group %q) was not found!", name, resourceGroup) + } + + return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + props := read.InterfacePropertiesFormat + if props == nil { + return fmt.Errorf("Error: `properties` was nil for Network Interface %q (Resource Group %q)", name, resourceGroup) + } + + if props.NetworkSecurityGroup == nil || props.NetworkSecurityGroup.ID == nil { + log.Printf("Network Interface %q (Resource Group %q) doesn't have a Security Group attached - removing from state!", name, resourceGroup) + d.SetId("") + return nil + } + + d.Set("network_interface_id", read.ID) + + // nil-checked above + d.Set("network_security_group_id", props.NetworkSecurityGroup.ID) + + return nil +} + +func resourceArmNetworkInterfaceSecurityGroupAssociationDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Network.InterfacesClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + splitId := strings.Split(d.Id(), "|") + if len(splitId) != 2 { + return fmt.Errorf("Expected ID to be in the format {networkInterfaceId}/{networkSecurityGroup} but got %q", d.Id()) + } + + nicID, err := azure.ParseAzureResourceID(splitId[0]) + if err != nil { + return err + } + + name := nicID.Path["networkInterfaces"] + resourceGroup := nicID.ResourceGroup + + locks.ByName(name, networkInterfaceResourceName) + defer locks.UnlockByName(name, networkInterfaceResourceName) + + read, err := client.Get(ctx, resourceGroup, name, "") + if err != nil { + if utils.ResponseWasNotFound(read.Response) { + return fmt.Errorf("Network Interface %q (Resource Group %q) was not found!", name, resourceGroup) + } + + return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + props := read.InterfacePropertiesFormat + if props == nil { + return fmt.Errorf("Error: `properties` was nil for Network Interface %q (Resource Group %q)", name, resourceGroup) + } + + props.NetworkSecurityGroup = nil + read.InterfacePropertiesFormat = props + + future, err := azuresdkhacks.UpdateNetworkInterfaceAllowingRemovalOfNSG(ctx, client, resourceGroup, name, read) + if err != nil { + return fmt.Errorf("Error updating Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) + } + if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for update of Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + return nil +} diff --git a/azurerm/internal/services/network/parse/subnet.go b/azurerm/internal/services/network/parse/subnet.go new file mode 100644 index 0000000000000..a60ca6a007318 --- /dev/null +++ b/azurerm/internal/services/network/parse/subnet.go @@ -0,0 +1,38 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type SubnetId struct { + ResourceGroup string + VirtualNetworkName string + Name string +} + +func SubnetID(input string) (*SubnetId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse Subnet ID %q: %+v", input, err) + } + + subnet := SubnetId{ + ResourceGroup: id.ResourceGroup, + } + + if subnet.VirtualNetworkName, err = id.PopSegment("virtualNetworks"); err != nil { + return nil, err + } + + if subnet.Name, err = id.PopSegment("subnets"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &subnet, nil +} diff --git a/azurerm/internal/services/network/parse/subnet_test.go b/azurerm/internal/services/network/parse/subnet_test.go new file mode 100644 index 0000000000000..ef696cba59b85 --- /dev/null +++ b/azurerm/internal/services/network/parse/subnet_test.go @@ -0,0 +1,90 @@ +package parse + +import ( + "testing" +) + +func TestSubnetID(t *testing.T) { + testData := []struct { + Name string + Input string + Error bool + Expect *SubnetId + }{ + { + Name: "Empty", + Input: "", + Error: true, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Error: true, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Error: true, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Error: true, + }, + { + Name: "Missing Virtual Networks Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/virtualNetworks/", + Error: true, + }, + { + Name: "Missing Subnets Key", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/virtualNetworks/network1", + Error: true, + }, + { + Name: "Missing Subnets Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/virtualNetworks/network1/subnets/", + Error: true, + }, + { + Name: "Subnet ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/virtualNetworks/network1/subnets/subnet1", + Error: false, + Expect: &SubnetId{ + ResourceGroup: "resGroup1", + VirtualNetworkName: "network1", + Name: "subnet1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/virtualNetworks/network1/Subnets/subnet1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := SubnetID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expect.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name) + } + + if actual.VirtualNetworkName != v.Expect.VirtualNetworkName { + t.Fatalf("Expected %q but got %q for Virtual Network Name", v.Expect.VirtualNetworkName, actual.VirtualNetworkName) + } + + if actual.ResourceGroup != v.Expect.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expect.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/network/parse/virtual_network.go b/azurerm/internal/services/network/parse/virtual_network.go new file mode 100644 index 0000000000000..b789e8aefb40a --- /dev/null +++ b/azurerm/internal/services/network/parse/virtual_network.go @@ -0,0 +1,33 @@ +package parse + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" +) + +type VirtualNetworkId struct { + ResourceGroup string + Name string +} + +func VirtualNetworkID(input string) (*VirtualNetworkId, error) { + id, err := azure.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("[ERROR] Unable to parse Virtual Network ID %q: %+v", input, err) + } + + vnet := VirtualNetworkId{ + ResourceGroup: id.ResourceGroup, + } + + if vnet.Name, err = id.PopSegment("virtualNetworks"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &vnet, nil +} diff --git a/azurerm/internal/services/network/parse/virtual_network_test.go b/azurerm/internal/services/network/parse/virtual_network_test.go new file mode 100644 index 0000000000000..b9eb6b35d3575 --- /dev/null +++ b/azurerm/internal/services/network/parse/virtual_network_test.go @@ -0,0 +1,70 @@ +package parse + +import ( + "testing" +) + +func TestVirtualNetworkID(t *testing.T) { + testData := []struct { + Name string + Input string + Error bool + Expect *VirtualNetworkId + }{ + { + Name: "Empty", + Input: "", + Error: true, + }, + { + Name: "No Resource Groups Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000", + Error: true, + }, + { + Name: "No Resource Groups Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", + Error: true, + }, + { + Name: "Resource Group ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", + Error: true, + }, + { + Name: "Virtual Network ID", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/virtualNetworks/network1", + Error: false, + Expect: &VirtualNetworkId{ + ResourceGroup: "resGroup1", + Name: "network1", + }, + }, + { + Name: "Wrong Casing", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/VirtualNetworks/network1", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := VirtualNetworkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expect.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expect.Name, actual.Name) + } + + if actual.ResourceGroup != v.Expect.ResourceGroup { + t.Fatalf("Expected %q but got %q for Resource Group", v.Expect.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/network/registration.go b/azurerm/internal/services/network/registration.go index fc30e925d99b7..a9fbaafdfc570 100644 --- a/azurerm/internal/services/network/registration.go +++ b/azurerm/internal/services/network/registration.go @@ -11,6 +11,14 @@ func (r Registration) Name() string { return "Network" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Load Balancer", + "Network", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ @@ -24,7 +32,6 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { "azurerm_network_interface": dataSourceArmNetworkInterface(), "azurerm_network_security_group": dataSourceArmNetworkSecurityGroup(), "azurerm_network_watcher": dataSourceArmNetworkWatcher(), - "azurerm_private_link_endpoint_connection": dataSourceArmPrivateLinkEndpointConnection(), "azurerm_private_endpoint_connection": dataSourceArmPrivateEndpointConnection(), "azurerm_private_link_service": dataSourceArmPrivateLinkService(), "azurerm_private_link_service_endpoint_connections": dataSourceArmPrivateLinkServiceEndpointConnections(), @@ -46,11 +53,10 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_application_gateway": resourceArmApplicationGateway(), "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), "azurerm_bastion_host": resourceArmBastionHost(), - "azurerm_connection_monitor": resourceArmConnectionMonitor(), - "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), + "azurerm_express_route_gateway": resourceArmExpressRouteGateway(), "azurerm_firewall_application_rule_collection": resourceArmFirewallApplicationRuleCollection(), "azurerm_firewall_nat_rule_collection": resourceArmFirewallNatRuleCollection(), "azurerm_firewall_network_rule_collection": resourceArmFirewallNetworkRuleCollection(), @@ -71,11 +77,11 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_network_interface_application_security_group_association": resourceArmNetworkInterfaceApplicationSecurityGroupAssociation(), "azurerm_network_interface_backend_address_pool_association": resourceArmNetworkInterfaceBackendAddressPoolAssociation(), "azurerm_network_interface_nat_rule_association": resourceArmNetworkInterfaceNatRuleAssociation(), + "azurerm_network_interface_security_group_association": resourceArmNetworkInterfaceSecurityGroupAssociation(), "azurerm_network_packet_capture": resourceArmNetworkPacketCapture(), "azurerm_network_profile": resourceArmNetworkProfile(), "azurerm_packet_capture": resourceArmPacketCapture(), "azurerm_point_to_site_vpn_gateway": resourceArmPointToSiteVPNGateway(), - "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), "azurerm_private_endpoint": resourceArmPrivateEndpoint(), "azurerm_private_link_service": resourceArmPrivateLinkService(), "azurerm_public_ip": resourceArmPublicIp(), diff --git a/azurerm/internal/services/network/resource_arm_application_gateway.go b/azurerm/internal/services/network/resource_arm_application_gateway.go index 6d113a17c0475..90fa875465e24 100644 --- a/azurerm/internal/services/network/resource_arm_application_gateway.go +++ b/azurerm/internal/services/network/resource_arm_application_gateway.go @@ -3,6 +3,7 @@ package network import ( "fmt" "log" + "strings" "time" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" @@ -113,7 +114,6 @@ func resourceArmApplicationGateway() *schema.Resource { "fqdns": { Type: schema.TypeList, Optional: true, - Computed: true, MinItems: 1, Elem: &schema.Schema{ Type: schema.TypeString, @@ -123,7 +123,6 @@ func resourceArmApplicationGateway() *schema.Resource { "ip_addresses": { Type: schema.TypeList, Optional: true, - Computed: true, MinItems: 1, Elem: &schema.Schema{ Type: schema.TypeString, @@ -131,31 +130,6 @@ func resourceArmApplicationGateway() *schema.Resource { }, }, - // TODO: remove in 2.0 - "fqdn_list": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Deprecated: "`fqdn_list` has been deprecated in favour of the `fqdns` field", - MinItems: 1, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - - // TODO: remove in 2.0 - "ip_address_list": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Deprecated: "`ip_address_list` has been deprecated in favour of the `ip_addresses` field", - MinItems: 1, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validate.IPv4Address, - }, - }, - "id": { Type: schema.TypeString, Computed: true, @@ -687,9 +661,8 @@ func resourceArmApplicationGateway() *schema.Resource { }, "capacity": { - Type: schema.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(1, 32), + Type: schema.TypeInt, + Optional: true, }, }, }, @@ -755,23 +728,6 @@ func resourceArmApplicationGateway() *schema.Resource { }, }, - // TODO: remove in 2.0 - "disabled_ssl_protocols": { - Type: schema.TypeList, - Optional: true, - Computed: true, - Deprecated: "has been replaced by `ssl_policy`.`disabled_protocols`", - Elem: &schema.Schema{ - Type: schema.TypeString, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(network.TLSv10), - string(network.TLSv11), - string(network.TLSv12), - }, true), - }, - }, - "ssl_policy": { Type: schema.TypeList, Optional: true, @@ -781,7 +737,6 @@ func resourceArmApplicationGateway() *schema.Resource { "disabled_protocols": { Type: schema.TypeList, Optional: true, - Computed: true, Elem: &schema.Schema{ Type: schema.TypeString, ValidateFunc: validation.StringInSlice([]string{ @@ -1350,6 +1305,8 @@ func resourceArmApplicationGateway() *schema.Resource { "tags": tags.Schema(), }, + + CustomizeDiff: ApplicationGatewayCustomizeDiff, } } @@ -1573,10 +1530,6 @@ func resourceArmApplicationGatewayRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting `backend_http_settings`: %+v", setErr) } - if setErr := d.Set("disabled_ssl_protocols", flattenApplicationGatewayDisabledSSLProtocols(props.SslPolicy)); setErr != nil { - return fmt.Errorf("Error setting `disabled_ssl_protocols`: %+v", setErr) - } - if setErr := d.Set("ssl_policy", flattenApplicationGatewaySslPolicy(props.SslPolicy)); setErr != nil { return fmt.Errorf("Error setting `ssl_policy`: %+v", setErr) } @@ -1887,21 +1840,6 @@ func expandApplicationGatewayBackendAddressPools(d *schema.ResourceData) *[]netw }) } - if len(backendAddresses) == 0 { - // TODO: remove in 2.0 - for _, ip := range v["ip_address_list"].([]interface{}) { - backendAddresses = append(backendAddresses, network.ApplicationGatewayBackendAddress{ - IPAddress: utils.String(ip.(string)), - }) - } - // TODO: remove in 2.0 - for _, ip := range v["fqdn_list"].([]interface{}) { - backendAddresses = append(backendAddresses, network.ApplicationGatewayBackendAddress{ - Fqdn: utils.String(ip.(string)), - }) - } - } - name := v["name"].(string) output := network.ApplicationGatewayBackendAddressPool{ Name: utils.String(name), @@ -1941,10 +1879,6 @@ func flattenApplicationGatewayBackendAddressPools(input *[]network.ApplicationGa output := map[string]interface{}{ "fqdns": fqdnList, "ip_addresses": ipAddressList, - - // TODO: deprecated - remove in 2.0 - "ip_address_list": ipAddressList, - "fqdn_list": fqdnList, } if config.ID != nil { @@ -2190,25 +2124,11 @@ func expandApplicationGatewaySslPolicy(d *schema.ResourceData) *network.Applicat disabledSSLPolicies := make([]network.ApplicationGatewaySslProtocol, 0) vs := d.Get("ssl_policy").([]interface{}) - vsdsp := d.Get("disabled_ssl_protocols").([]interface{}) - - if len(vsdsp) == 0 && len(vs) == 0 { - policy = network.ApplicationGatewaySslPolicy{ - DisabledSslProtocols: &disabledSSLPolicies, - } - } - - for _, policy := range vsdsp { - disabledSSLPolicies = append(disabledSSLPolicies, network.ApplicationGatewaySslProtocol(policy.(string))) - } if len(vs) > 0 { v := vs[0].(map[string]interface{}) policyType := network.ApplicationGatewaySslPolicyType(v["policy_type"].(string)) - // reset disabledSSLPolicies here to always use the new disabled_protocols block in favor of disabled_ssl_protocols - disabledSSLPolicies = disabledSSLPolicies[:0] - for _, policy := range v["disabled_protocols"].([]interface{}) { disabledSSLPolicies = append(disabledSSLPolicies, network.ApplicationGatewaySslProtocol(policy.(string))) } @@ -2276,19 +2196,6 @@ func flattenApplicationGatewaySslPolicy(input *network.ApplicationGatewaySslPoli return results } -func flattenApplicationGatewayDisabledSSLProtocols(input *network.ApplicationGatewaySslPolicy) []interface{} { - results := make([]interface{}, 0) - if input == nil || input.DisabledSslProtocols == nil { - return results - } - - for _, v := range *input.DisabledSslProtocols { - results = append(results, string(v)) - } - - return results -} - func expandApplicationGatewayHTTPListeners(d *schema.ResourceData, gatewayID string) *[]network.ApplicationGatewayHTTPListener { vs := d.Get("http_listener").([]interface{}) results := make([]network.ApplicationGatewayHTTPListener, 0) @@ -3819,3 +3726,25 @@ func flattenApplicationGatewayCustomErrorConfigurations(input *[]network.Applica return results } + +func ApplicationGatewayCustomizeDiff(d *schema.ResourceDiff, _ interface{}) error { + _, hasAutoscaleConfig := d.GetOk("autoscale_configuration.0") + capacity, hasCapacity := d.GetOk("sku.0.capacity") + tier := d.Get("sku.0.tier").(string) + + if !hasAutoscaleConfig && !hasCapacity { + return fmt.Errorf("The Application Gateway must specify either `capacity` or `autoscale_configuration` for the selected SKU tier %q", tier) + } + + if hasCapacity { + if (strings.EqualFold(tier, string(network.ApplicationGatewayTierStandard)) || strings.EqualFold(tier, string(network.ApplicationGatewayTierWAF))) && (capacity.(int) < 1 || capacity.(int) > 32) { + return fmt.Errorf("The value '%d' exceeds the maximum capacity allowed for a %q V1 SKU, the %q SKU must have a capacity value between 1 and 32", capacity, tier, tier) + } + + if (strings.EqualFold(tier, string(network.ApplicationGatewayTierStandardV2)) || strings.EqualFold(tier, string(network.ApplicationGatewayTierWAFV2))) && (capacity.(int) < 1 || capacity.(int) > 125) { + return fmt.Errorf("The value '%d' exceeds the maximum capacity allowed for a %q V2 SKU, the %q SKU must have a capacity value between 1 and 125", capacity, tier, tier) + } + } + + return nil +} diff --git a/azurerm/internal/services/network/resource_arm_connection_monitor.go b/azurerm/internal/services/network/resource_arm_connection_monitor.go deleted file mode 100644 index e9a794a120270..0000000000000 --- a/azurerm/internal/services/network/resource_arm_connection_monitor.go +++ /dev/null @@ -1,351 +0,0 @@ -package network - -import ( - "fmt" - "time" - - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" - "github.com/hashicorp/go-azure-helpers/response" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmConnectionMonitor() *schema.Resource { - return &schema.Resource{ - Create: resourceArmConnectionMonitorCreateUpdate, - Read: resourceArmConnectionMonitorRead, - Update: resourceArmConnectionMonitorCreateUpdate, - Delete: resourceArmConnectionMonitorDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - DeprecationMessage: `The 'azurerm_connection_monitor' resource is deprecated in favour of the renamed version 'azurerm_network_connection_monitor'. - -Information on migrating to the renamed resource can be found here: https://terraform.io/docs/providers/azurerm/guides/migrating-between-renamed-resources.html - -As such the existing 'azurerm_connection_monitor' resource is deprecated and will be removed in the next major version of the AzureRM Provider (2.0). -`, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - - "resource_group_name": azure.SchemaResourceGroupName(), - - "network_watcher_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - - "location": azure.SchemaLocation(), - - "auto_start": { - Type: schema.TypeBool, - Optional: true, - ForceNew: true, - Default: true, - }, - - "interval_in_seconds": { - Type: schema.TypeInt, - Optional: true, - Default: 60, - ValidateFunc: validation.IntAtLeast(30), - }, - - "source": { - Type: schema.TypeList, - Required: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "virtual_machine_id": { - Type: schema.TypeString, - Required: true, - ValidateFunc: azure.ValidateResourceID, - }, - "port": { - Type: schema.TypeInt, - Optional: true, - Default: 0, - ValidateFunc: validate.PortNumberOrZero, - }, - }, - }, - }, - - "destination": { - Type: schema.TypeList, - Required: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "virtual_machine_id": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: azure.ValidateResourceID, - ConflictsWith: []string{"destination.0.address"}, - }, - "address": { - Type: schema.TypeString, - Optional: true, - ConflictsWith: []string{"destination.0.virtual_machine_id"}, - }, - "port": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validate.PortNumber, - }, - }, - }, - }, - - "tags": tags.Schema(), - }, - } -} - -func resourceArmConnectionMonitorCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.ConnectionMonitorsClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - name := d.Get("name").(string) - watcherName := d.Get("network_watcher_name").(string) - resourceGroup := d.Get("resource_group_name").(string) - location := azure.NormalizeLocation(d.Get("location").(string)) - autoStart := d.Get("auto_start").(bool) - intervalInSeconds := int32(d.Get("interval_in_seconds").(int)) - - source, err := expandArmConnectionMonitorSource(d) - if err != nil { - return err - } - - dest, err := expandArmConnectionMonitorDestination(d) - if err != nil { - return err - } - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, watcherName, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing Connection Monitor %q (Watcher %q / Resource Group %q): %s", name, watcherName, resourceGroup, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_connection_monitor", *existing.ID) - } - } - - t := d.Get("tags").(map[string]interface{}) - - properties := network.ConnectionMonitor{ - Location: utils.String(location), - Tags: tags.Expand(t), - ConnectionMonitorParameters: &network.ConnectionMonitorParameters{ - Source: source, - Destination: dest, - AutoStart: utils.Bool(autoStart), - MonitoringIntervalInSeconds: utils.Int32(intervalInSeconds), - }, - } - - future, err := client.CreateOrUpdate(ctx, resourceGroup, watcherName, name, properties) - if err != nil { - return fmt.Errorf("Error creating Connection Monitor %q (Watcher %q / Resource Group %q): %+v", name, watcherName, resourceGroup, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for completion of Connection Monitor %q (Watcher %q / Resource Group %q): %+v", name, watcherName, resourceGroup, err) - } - - resp, err := client.Get(ctx, resourceGroup, watcherName, name) - if err != nil { - return fmt.Errorf("Error retrieving Connection Monitor %q (Watcher %q / Resource Group %q): %+v", name, watcherName, resourceGroup, err) - } - if resp.ID == nil { - return fmt.Errorf("Cannot read Connection Monitor %q (Watcher %q / Resource Group %q) ID", name, watcherName, resourceGroup) - } - - d.SetId(*resp.ID) - - return resourceArmConnectionMonitorRead(d, meta) -} - -func resourceArmConnectionMonitorRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.ConnectionMonitorsClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - watcherName := id.Path["networkWatchers"] - name := id.Path["connectionMonitors"] - - resp, err := client.Get(ctx, resourceGroup, watcherName, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil - } - return fmt.Errorf("Error reading Connection Monitor %q (Watcher %q / Resource Group %q) %+v", name, watcherName, resourceGroup, err) - } - - d.Set("name", name) - d.Set("network_watcher_name", watcherName) - d.Set("resource_group_name", resourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - - if props := resp.ConnectionMonitorResultProperties; props != nil { - d.Set("auto_start", props.AutoStart) - d.Set("interval_in_seconds", props.MonitoringIntervalInSeconds) - - source := flattenArmConnectionMonitorSource(props.Source) - if err := d.Set("source", source); err != nil { - return fmt.Errorf("Error setting `source`: %+v", err) - } - - dest := flattenArmConnectionMonitorDestination(props.Destination) - if err := d.Set("destination", dest); err != nil { - return fmt.Errorf("Error setting `destination`: %+v", err) - } - } - - return tags.FlattenAndSet(d, resp.Tags) -} - -func resourceArmConnectionMonitorDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.ConnectionMonitorsClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - watcherName := id.Path["networkWatchers"] - name := id.Path["connectionMonitors"] - - future, err := client.Delete(ctx, resourceGroup, watcherName, name) - if err != nil { - if !response.WasNotFound(future.Response()) { - return fmt.Errorf("Error deleting Connection Monitor %q (Watcher %q / Resource Group %q): %+v", name, watcherName, resourceGroup, err) - } - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for the deletion of Connection Monitor %q (Watcher %q / Resource Group %q): %+v", name, watcherName, resourceGroup, err) - } - - return nil -} - -func flattenArmConnectionMonitorSource(input *network.ConnectionMonitorSource) []interface{} { - if input == nil { - return []interface{}{} - } - - output := make(map[string]interface{}) - - if resourceID := input.ResourceID; resourceID != nil { - output["virtual_machine_id"] = *resourceID - } - if port := input.Port; port != nil { - output["port"] = *port - } - - return []interface{}{output} -} - -func expandArmConnectionMonitorSource(d *schema.ResourceData) (*network.ConnectionMonitorSource, error) { - sources := d.Get("source").([]interface{}) - source := sources[0].(map[string]interface{}) - - monitorSource := network.ConnectionMonitorSource{} - if v := source["virtual_machine_id"]; v != "" { - monitorSource.ResourceID = utils.String(v.(string)) - } - if v := source["port"]; v != "" { - monitorSource.Port = utils.Int32(int32(v.(int))) - } - - return &monitorSource, nil -} - -func flattenArmConnectionMonitorDestination(input *network.ConnectionMonitorDestination) []interface{} { - if input == nil { - return []interface{}{} - } - - output := make(map[string]interface{}) - - // When monitoring a VM, the address field will contain the current address - // of the VM. We only want to copy over the address field if the virtual - // machine field is not set to avoid unwanted diffs. - if resourceID := input.ResourceID; resourceID != nil { - output["virtual_machine_id"] = *resourceID - } else if address := input.Address; address != nil { - output["address"] = *address - } - - if port := input.Port; port != nil { - output["port"] = *port - } - - return []interface{}{output} -} - -func expandArmConnectionMonitorDestination(d *schema.ResourceData) (*network.ConnectionMonitorDestination, error) { - dests := d.Get("destination").([]interface{}) - dest := dests[0].(map[string]interface{}) - - monitorDest := network.ConnectionMonitorDestination{} - - if v := dest["virtual_machine_id"]; v != "" { - monitorDest.ResourceID = utils.String(v.(string)) - } - if v := dest["address"]; v != "" { - monitorDest.Address = utils.String(v.(string)) - } - if v := dest["port"]; v != "" { - monitorDest.Port = utils.Int32(int32(v.(int))) - } - - if monitorDest.ResourceID == nil && monitorDest.Address == nil { - return nil, fmt.Errorf("Error: either `destination.virtual_machine_id` or `destination.address` must be specified") - } - - return &monitorDest, nil -} diff --git a/azurerm/internal/services/network/resource_arm_ddos_protection_plan.go b/azurerm/internal/services/network/resource_arm_ddos_protection_plan.go deleted file mode 100644 index 29edffb05e505..0000000000000 --- a/azurerm/internal/services/network/resource_arm_ddos_protection_plan.go +++ /dev/null @@ -1,254 +0,0 @@ -package network - -import ( - "fmt" - "log" - "time" - - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -const azureDDoSProtectionPlanResourceName = "azurerm_ddos_protection_plan" - -func resourceArmDDoSProtectionPlan() *schema.Resource { - return &schema.Resource{ - Create: resourceArmDDoSProtectionPlanCreateUpdate, - Read: resourceArmDDoSProtectionPlanRead, - Update: resourceArmDDoSProtectionPlanCreateUpdate, - Delete: resourceArmDDoSProtectionPlanDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - DeprecationMessage: `The 'azurerm_ddos_protection_plan' resource is deprecated in favour of the renamed version 'azurerm_network_ddos_protection_plan'. - -Information on migrating to the renamed resource can be found here: https://terraform.io/docs/providers/azurerm/guides/migrating-between-renamed-resources.html - -As such the existing 'azurerm_ddos_protection_plan' resource is deprecated and will be removed in the next major version of the AzureRM Provider (2.0). -`, - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - - "location": azure.SchemaLocation(), - - "resource_group_name": azure.SchemaResourceGroupName(), - - "virtual_network_ids": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - - "tags": tags.Schema(), - }, - } -} - -func resourceArmDDoSProtectionPlanCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.DDOSProtectionPlansClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - log.Printf("[INFO] preparing arguments for DDoS protection plan creation") - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing DDoS Protection Plan %q (Resource Group %q): %s", name, resourceGroup, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_ddos_protection_plan", *existing.ID) - } - } - - location := azure.NormalizeLocation(d.Get("location").(string)) - t := d.Get("tags").(map[string]interface{}) - - vnetsToLock, err := extractVnetNames(d) - if err != nil { - return fmt.Errorf("Error extracting names of Virtual Network: %+v", err) - } - - locks.ByName(name, azureDDoSProtectionPlanResourceName) - defer locks.UnlockByName(name, azureDDoSProtectionPlanResourceName) - - locks.MultipleByName(vnetsToLock, VirtualNetworkResourceName) - defer locks.UnlockMultipleByName(vnetsToLock, VirtualNetworkResourceName) - - parameters := network.DdosProtectionPlan{ - Location: &location, - Tags: tags.Expand(t), - } - - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters) - if err != nil { - return fmt.Errorf("Error creating/updating DDoS Protection Plan %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for creation/update of DDoS Protection Plan %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - plan, err := client.Get(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("Error retrieving DDoS Protection Plan %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if plan.ID == nil { - return fmt.Errorf("Cannot read DDoS Protection Plan %q (Resource Group %q) ID", name, resourceGroup) - } - - d.SetId(*plan.ID) - - return resourceArmDDoSProtectionPlanRead(d, meta) -} - -func resourceArmDDoSProtectionPlanRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.DDOSProtectionPlansClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - name := id.Path["ddosProtectionPlans"] - - plan, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if utils.ResponseWasNotFound(plan.Response) { - log.Printf("[DEBUG] DDoS Protection Plan %q was not found in Resource Group %q - removing from state!", name, resourceGroup) - d.SetId("") - return nil - } - - return fmt.Errorf("Error making Read request on DDoS Protection Plan %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - d.Set("name", plan.Name) - d.Set("resource_group_name", resourceGroup) - if location := plan.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - - if props := plan.DdosProtectionPlanPropertiesFormat; props != nil { - vNetIDs := flattenArmVirtualNetworkIDs(props.VirtualNetworks) - if err := d.Set("virtual_network_ids", vNetIDs); err != nil { - return fmt.Errorf("Error setting `virtual_network_ids`: %+v", err) - } - } - - return tags.FlattenAndSet(d, plan.Tags) -} - -func resourceArmDDoSProtectionPlanDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.DDOSProtectionPlansClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - name := id.Path["ddosProtectionPlans"] - - read, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if utils.ResponseWasNotFound(read.Response) { - // deleted outside of TF - log.Printf("[DEBUG] DDoS Protection Plan %q was not found in Resource Group %q - assuming removed!", name, resourceGroup) - return nil - } - - return fmt.Errorf("Error retrieving DDoS Protection Plan %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - vnetsToLock, err := extractVnetNames(d) - if err != nil { - return fmt.Errorf("Error extracting names of Virtual Network: %+v", err) - } - - locks.ByName(name, azureDDoSProtectionPlanResourceName) - defer locks.UnlockByName(name, azureDDoSProtectionPlanResourceName) - - locks.MultipleByName(vnetsToLock, VirtualNetworkResourceName) - defer locks.UnlockMultipleByName(vnetsToLock, VirtualNetworkResourceName) - - future, err := client.Delete(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("Error deleting DDoS Protection Plan %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for the deletion of DDoS Protection Plan %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - return err -} - -func extractVnetNames(d *schema.ResourceData) (*[]string, error) { - vnetIDs := d.Get("virtual_network_ids").([]interface{}) - vnetNames := make([]string, 0) - - for _, vnetID := range vnetIDs { - vnetResourceID, err := azure.ParseAzureResourceID(vnetID.(string)) - if err != nil { - return nil, err - } - - vnetName := vnetResourceID.Path["virtualNetworks"] - - if !SliceContainsValue(vnetNames, vnetName) { - vnetNames = append(vnetNames, vnetName) - } - } - - return &vnetNames, nil -} - -func flattenArmVirtualNetworkIDs(input *[]network.SubResource) []string { - vnetIDs := make([]string, 0) - if input == nil { - return vnetIDs - } - - // if-continue is used to simplify the deeply nested if-else statement. - for _, subRes := range *input { - if subRes.ID != nil { - vnetIDs = append(vnetIDs, *subRes.ID) - } - } - - return vnetIDs -} diff --git a/azurerm/internal/services/network/resource_arm_express_route_gateway.go b/azurerm/internal/services/network/resource_arm_express_route_gateway.go new file mode 100644 index 0000000000000..7414ef94a633e --- /dev/null +++ b/azurerm/internal/services/network/resource_arm_express_route_gateway.go @@ -0,0 +1,202 @@ +package network + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" + "github.com/hashicorp/go-azure-helpers/response" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmExpressRouteGateway() *schema.Resource { + return &schema.Resource{ + Create: resourceArmExpressRouteGatewayCreateUpdate, + Read: resourceArmExpressRouteGatewayRead, + Update: resourceArmExpressRouteGatewayCreateUpdate, + Delete: resourceArmExpressRouteGatewayDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(90 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(90 * time.Minute), + Delete: schema.DefaultTimeout(90 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "location": azure.SchemaLocation(), + + "resource_group_name": azure.SchemaResourceGroupName(), + + "virtual_hub_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azure.ValidateResourceID, + }, + + "scale_units": { + Type: schema.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(1, 10), + }, + + "tags": tags.Schema(), + }, + } +} + +func resourceArmExpressRouteGatewayCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Network.ExpressRouteGatewaysClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + log.Println("[INFO] preparing arguments for ExpressRoute Gateway creation.") + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error checking for present of existing ExpressRoute Gateway %q (Resource Group %q): %+v", name, resourceGroup, err) + } + } + if resp.ID != nil && *resp.ID != "" { + return tf.ImportAsExistsError("azurerm_express_route_gateway", *resp.ID) + } + } + + location := azure.NormalizeLocation(d.Get("location").(string)) + virtualHubId := d.Get("virtual_hub_id").(string) + t := d.Get("tags").(map[string]interface{}) + + minScaleUnits := int32(d.Get("scale_units").(int)) + parameters := network.ExpressRouteGateway{ + Location: utils.String(location), + ExpressRouteGatewayProperties: &network.ExpressRouteGatewayProperties{ + AutoScaleConfiguration: &network.ExpressRouteGatewayPropertiesAutoScaleConfiguration{ + Bounds: &network.ExpressRouteGatewayPropertiesAutoScaleConfigurationBounds{ + Min: &minScaleUnits, + }, + }, + VirtualHub: &network.VirtualHubID{ + ID: &virtualHubId, + }, + }, + Tags: tags.Expand(t), + } + + future, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters) + if err != nil { + return fmt.Errorf("Error creating ExpressRoute Gateway %q (Resource Group %q): %+v", name, resourceGroup, err) + } + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for creation of ExpressRoute Gateway %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Error retrieving ExpressRoute Gateway %q (Resource Group %q): %+v", name, resourceGroup, err) + } + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("Cannot read ExpressRoute Gateway %q (Resource Group %q) ID", name, resourceGroup) + } + d.SetId(*resp.ID) + + return resourceArmExpressRouteGatewayRead(d, meta) +} + +func resourceArmExpressRouteGatewayRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Network.ExpressRouteGatewaysClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["expressRouteGateways"] + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] ExpressRoute Gateway %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading ExpressRoute Gateway %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + if props := resp.ExpressRouteGatewayProperties; props != nil { + virtualHubId := "" + if props.VirtualHub != nil && props.VirtualHub.ID != nil { + virtualHubId = *props.VirtualHub.ID + } + d.Set("virtual_hub_id", virtualHubId) + + scaleUnits := 0 + if props.AutoScaleConfiguration != nil && props.AutoScaleConfiguration.Bounds != nil && props.AutoScaleConfiguration.Bounds.Min != nil { + scaleUnits = int(*props.AutoScaleConfiguration.Bounds.Min) + } + d.Set("scale_units", scaleUnits) + } + + return tags.FlattenAndSet(d, resp.Tags) +} + +func resourceArmExpressRouteGatewayDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Network.ExpressRouteGatewaysClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["expressRouteGateways"] + + future, err := client.Delete(ctx, resourceGroup, name) + if err != nil { + if response.WasNotFound(future.Response()) { + return nil + } + return fmt.Errorf("Error deleting ExpressRoute Gateway %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + if !response.WasNotFound(future.Response()) { + return fmt.Errorf("Error waiting for deleting ExpressRoute Gateway %q (Resource Group %q): %+v", name, resourceGroup, err) + } + } + + return nil +} diff --git a/azurerm/internal/services/network/resource_arm_firewall.go b/azurerm/internal/services/network/resource_arm_firewall.go index 9b4ac25596ad5..2155dbfa09fce 100644 --- a/azurerm/internal/services/network/resource_arm_firewall.go +++ b/azurerm/internal/services/network/resource_arm_firewall.go @@ -32,10 +32,10 @@ func resourceArmFirewall() *schema.Resource { }, Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(40 * time.Minute), + Create: schema.DefaultTimeout(90 * time.Minute), Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(40 * time.Minute), - Delete: schema.DefaultTimeout(40 * time.Minute), + Update: schema.DefaultTimeout(90 * time.Minute), + Delete: schema.DefaultTimeout(90 * time.Minute), }, Schema: map[string]*schema.Schema{ @@ -66,17 +66,9 @@ func resourceArmFirewall() *schema.Resource { ForceNew: true, ValidateFunc: validateAzureFirewallSubnetName, }, - "internal_public_ip_address_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: azure.ValidateResourceID, - Deprecated: "This field has been deprecated in favour of the `public_ip_address_id` property to better match the Azure SDK.", - }, "public_ip_address_id": { Type: schema.TypeString, - Optional: true, - Computed: true, + Required: true, ValidateFunc: azure.ValidateResourceID, }, "private_ip_address": { @@ -267,12 +259,12 @@ func resourceArmFirewallDelete(d *schema.ResourceData, meta interface{}) error { } subnetName := parsedSubnetId.Path["subnets"] - if !SliceContainsValue(subnetNamesToLock, subnetName) { + if !azure.SliceContainsValue(subnetNamesToLock, subnetName) { subnetNamesToLock = append(subnetNamesToLock, subnetName) } virtualNetworkName := parsedSubnetId.Path["virtualNetworks"] - if !SliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { + if !azure.SliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { virtualNetworkNamesToLock = append(virtualNetworkNamesToLock, virtualNetworkName) } } @@ -310,15 +302,7 @@ func expandArmFirewallIPConfigurations(d *schema.ResourceData) (*[]network.Azure data := configRaw.(map[string]interface{}) name := data["name"].(string) subnetId := data["subnet_id"].(string) - - pubID, exist := data["internal_public_ip_address_id"].(string) - if !exist || pubID == "" { - pubID, exist = data["public_ip_address_id"].(string) - } - - if !exist || pubID == "" { - return nil, nil, nil, fmt.Errorf("one of `internal_public_ip_address_id` or `public_ip_address_id` must be set") - } + pubID := data["public_ip_address_id"].(string) ipConfig := network.AzureFirewallIPConfiguration{ Name: utils.String(name), @@ -338,11 +322,11 @@ func expandArmFirewallIPConfigurations(d *schema.ResourceData) (*[]network.Azure subnetName := subnetID.Path["subnets"] virtualNetworkName := subnetID.Path["virtualNetworks"] - if !SliceContainsValue(subnetNamesToLock, subnetName) { + if !azure.SliceContainsValue(subnetNamesToLock, subnetName) { subnetNamesToLock = append(subnetNamesToLock, subnetName) } - if !SliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { + if !azure.SliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { virtualNetworkNamesToLock = append(virtualNetworkNamesToLock, virtualNetworkName) } @@ -384,7 +368,6 @@ func flattenArmFirewallIPConfigurations(input *[]network.AzureFirewallIPConfigur if pip := props.PublicIPAddress; pip != nil { if id := pip.ID; id != nil { - afIPConfig["internal_public_ip_address_id"] = *id afIPConfig["public_ip_address_id"] = *id } } diff --git a/azurerm/internal/services/network/resource_arm_lb_backend_address_pool.go b/azurerm/internal/services/network/resource_arm_lb_backend_address_pool.go index 66294b426b369..5b23a7bfa3f1b 100644 --- a/azurerm/internal/services/network/resource_arm_lb_backend_address_pool.go +++ b/azurerm/internal/services/network/resource_arm_lb_backend_address_pool.go @@ -41,8 +41,6 @@ func resourceArmLoadBalancerBackendAddressPool() *schema.Resource { ValidateFunc: validation.StringIsNotEmpty, }, - "location": azure.SchemaLocationDeprecated(), - "resource_group_name": azure.SchemaResourceGroupName(), "loadbalancer_id": { diff --git a/azurerm/internal/services/network/resource_arm_lb_nat_pool.go b/azurerm/internal/services/network/resource_arm_lb_nat_pool.go index 40120ba98367e..c437eae427588 100644 --- a/azurerm/internal/services/network/resource_arm_lb_nat_pool.go +++ b/azurerm/internal/services/network/resource_arm_lb_nat_pool.go @@ -45,8 +45,6 @@ func resourceArmLoadBalancerNatPool() *schema.Resource { ValidateFunc: validation.StringIsNotEmpty, }, - "location": azure.SchemaLocationDeprecated(), - "resource_group_name": azure.SchemaResourceGroupName(), "loadbalancer_id": { diff --git a/azurerm/internal/services/network/resource_arm_lb_nat_rule.go b/azurerm/internal/services/network/resource_arm_lb_nat_rule.go index e45c680d45132..e62b4278656d5 100644 --- a/azurerm/internal/services/network/resource_arm_lb_nat_rule.go +++ b/azurerm/internal/services/network/resource_arm_lb_nat_rule.go @@ -46,8 +46,6 @@ func resourceArmLoadBalancerNatRule() *schema.Resource { ValidateFunc: validation.StringIsNotEmpty, }, - "location": azure.SchemaLocationDeprecated(), - "resource_group_name": azure.SchemaResourceGroupName(), "loadbalancer_id": { diff --git a/azurerm/internal/services/network/resource_arm_lb_probe.go b/azurerm/internal/services/network/resource_arm_lb_probe.go index 19d6336b3d541..15cc869d7f8e8 100644 --- a/azurerm/internal/services/network/resource_arm_lb_probe.go +++ b/azurerm/internal/services/network/resource_arm_lb_probe.go @@ -44,8 +44,6 @@ func resourceArmLoadBalancerProbe() *schema.Resource { ValidateFunc: validation.StringIsNotEmpty, }, - "location": azure.SchemaLocationDeprecated(), - "resource_group_name": azure.SchemaResourceGroupName(), "loadbalancer_id": { diff --git a/azurerm/internal/services/network/resource_arm_lb_rule.go b/azurerm/internal/services/network/resource_arm_lb_rule.go index a09cdf1dae140..855fb0e77cc0b 100644 --- a/azurerm/internal/services/network/resource_arm_lb_rule.go +++ b/azurerm/internal/services/network/resource_arm_lb_rule.go @@ -46,8 +46,6 @@ func resourceArmLoadBalancerRule() *schema.Resource { ValidateFunc: ValidateArmLoadBalancerRuleName, }, - "location": azure.SchemaLocationDeprecated(), - "resource_group_name": azure.SchemaResourceGroupName(), "loadbalancer_id": { diff --git a/azurerm/internal/services/network/resource_arm_network_ddos_protection_plan.go b/azurerm/internal/services/network/resource_arm_network_ddos_protection_plan.go index f8c8b7131d434..e7664d5b366f3 100644 --- a/azurerm/internal/services/network/resource_arm_network_ddos_protection_plan.go +++ b/azurerm/internal/services/network/resource_arm_network_ddos_protection_plan.go @@ -223,7 +223,7 @@ func expandArmNetworkDDoSProtectionPlanVnetNames(d *schema.ResourceData) (*[]str vnetName := vnetResourceID.Path["virtualNetworks"] - if !SliceContainsValue(vnetNames, vnetName) { + if !azure.SliceContainsValue(vnetNames, vnetName) { vnetNames = append(vnetNames, vnetName) } } @@ -246,3 +246,23 @@ func flattenArmNetworkDDoSProtectionPlanVirtualNetworkIDs(input *[]network.SubRe return vnetIDs } + +func extractVnetNames(d *schema.ResourceData) (*[]string, error) { + vnetIDs := d.Get("virtual_network_ids").([]interface{}) + vnetNames := make([]string, 0) + + for _, vnetID := range vnetIDs { + vnetResourceID, err := azure.ParseAzureResourceID(vnetID.(string)) + if err != nil { + return nil, err + } + + vnetName := vnetResourceID.Path["virtualNetworks"] + + if !azure.SliceContainsValue(vnetNames, vnetName) { + vnetNames = append(vnetNames, vnetName) + } + } + + return &vnetNames, nil +} diff --git a/azurerm/internal/services/network/resource_arm_network_interface.go b/azurerm/internal/services/network/resource_arm_network_interface.go index 67d9a448b7fb1..4b4c388d54994 100644 --- a/azurerm/internal/services/network/resource_arm_network_interface.go +++ b/azurerm/internal/services/network/resource_arm_network_interface.go @@ -3,7 +3,6 @@ package network import ( "fmt" "log" - "strings" "time" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" @@ -12,7 +11,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" @@ -26,9 +24,9 @@ var networkInterfaceResourceName = "azurerm_network_interface" func resourceArmNetworkInterface() *schema.Resource { return &schema.Resource{ - Create: resourceArmNetworkInterfaceCreateUpdate, + Create: resourceArmNetworkInterfaceCreate, Read: resourceArmNetworkInterfaceRead, - Update: resourceArmNetworkInterfaceCreateUpdate, + Update: resourceArmNetworkInterfaceUpdate, Delete: resourceArmNetworkInterfaceDelete, Importer: &schema.ResourceImporter{ @@ -53,26 +51,6 @@ func resourceArmNetworkInterface() *schema.Resource { "resource_group_name": azure.SchemaResourceGroupName(), - "network_security_group_id": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: azure.ValidateResourceIDOrEmpty, - }, - - "mac_address": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validate.MACAddress, - }, - - "virtual_machine_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: azure.ValidateResourceID, - }, - "ip_configuration": { Type: schema.TypeList, Required: true, @@ -107,7 +85,6 @@ func resourceArmNetworkInterface() *schema.Resource { }, false), }, - //TODO: should this be renamed to private_ip_address_allocation_method or private_ip_allocation_method ? "private_ip_address_allocation": { Type: schema.TypeString, Required: true, @@ -125,54 +102,6 @@ func resourceArmNetworkInterface() *schema.Resource { ValidateFunc: azure.ValidateResourceIDOrEmpty, }, - "application_gateway_backend_address_pools_ids": { - Type: schema.TypeSet, - Optional: true, - Computed: true, - Deprecated: "This field has been deprecated in favour of the `azurerm_network_interface_application_gateway_backend_address_pool_association` resource.", - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: azure.ValidateResourceID, - }, - Set: schema.HashString, - }, - - "load_balancer_backend_address_pools_ids": { - Type: schema.TypeSet, - Optional: true, - Computed: true, - Deprecated: "This field has been deprecated in favour of the `azurerm_network_interface_backend_address_pool_association` resource.", - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: azure.ValidateResourceID, - }, - Set: schema.HashString, - }, - - "load_balancer_inbound_nat_rules_ids": { - Type: schema.TypeSet, - Optional: true, - Computed: true, - Deprecated: "This field has been deprecated in favour of the `azurerm_network_interface_nat_rule_association` resource.", - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: azure.ValidateResourceID, - }, - Set: schema.HashString, - }, - - "application_security_group_ids": { - Type: schema.TypeSet, - Optional: true, - Computed: true, - Deprecated: "This field has been deprecated in favour of the `azurerm_network_interface_application_security_group_association` resource.", - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: azure.ValidateResourceID, - }, - Set: schema.HashString, - }, - "primary": { Type: schema.TypeBool, Optional: true, @@ -183,14 +112,25 @@ func resourceArmNetworkInterface() *schema.Resource { }, "dns_servers": { - Type: schema.TypeSet, + Type: schema.TypeList, Optional: true, Computed: true, Elem: &schema.Schema{ Type: schema.TypeString, ValidateFunc: validation.StringIsNotEmpty, }, - Set: schema.HashString, + }, + + "enable_accelerated_networking": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + + "enable_ip_forwarding": { + Type: schema.TypeBool, + Optional: true, + Default: false, }, "internal_dns_name_label": { @@ -200,45 +140,22 @@ func resourceArmNetworkInterface() *schema.Resource { ValidateFunc: validation.StringIsNotEmpty, }, + "tags": tags.Schema(), + + // Computed "applied_dns_servers": { - Type: schema.TypeSet, - Optional: true, + Type: schema.TypeList, Computed: true, Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.StringIsNotEmpty, + Type: schema.TypeString, }, - Set: schema.HashString, - }, - - "internal_fqdn": { - Type: schema.TypeString, - Optional: true, - Computed: true, - Deprecated: "This field has been removed by Azure", }, - /** - * As of 2018-01-06: AN (aka. SR-IOV) on Azure is GA on Windows and Linux. - * - * Refer to: https://azure.microsoft.com/en-us/blog/maximize-your-vm-s-performance-with-accelerated-networking-now-generally-available-for-both-windows-and-linux/ - * - * Refer to: https://docs.microsoft.com/en-us/azure/virtual-network/create-vm-accelerated-networking-cli - * For details, VM configuration and caveats. - */ - "enable_accelerated_networking": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - - "enable_ip_forwarding": { - Type: schema.TypeBool, - Optional: true, - Default: false, + "mac_address": { + Type: schema.TypeString, + Computed: true, }, - // todo consider removing this one day as it is exposed in `private_ip_addresses.0` "private_ip_address": { Type: schema.TypeString, Computed: true, @@ -252,26 +169,27 @@ func resourceArmNetworkInterface() *schema.Resource { }, }, - "tags": tags.Schema(), + "virtual_machine_id": { + Type: schema.TypeString, + Computed: true, + }, }, } } -func resourceArmNetworkInterfaceCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceArmNetworkInterfaceCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.InterfacesClient ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - log.Printf("[INFO] preparing arguments for AzureRM Network Interface creation.") - name := d.Get("name").(string) - resGroup := d.Get("resource_group_name").(string) + resourceGroup := d.Get("resource_group_name").(string) if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, resGroup, name, "") + existing, err := client.Get(ctx, resourceGroup, name, "") if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing Network Interface %q (Resource Group %q): %s", name, resGroup, err) + return fmt.Errorf("Error checking for presence of existing Network Interface %q (Resource Group %q): %s", name, resourceGroup, err) } } @@ -293,90 +211,172 @@ func resourceArmNetworkInterfaceCreateUpdate(d *schema.ResourceData, meta interf locks.ByName(name, networkInterfaceResourceName) defer locks.UnlockByName(name, networkInterfaceResourceName) - if v, ok := d.GetOk("network_security_group_id"); ok { - nsgId := v.(string) - properties.NetworkSecurityGroup = &network.SecurityGroup{ - ID: &nsgId, - } - - parsedNsgID, err := azure.ParseAzureResourceID(nsgId) - if err != nil { - return fmt.Errorf("Error parsing Network Security Group ID %q: %+v", nsgId, err) - } - - networkSecurityGroupName := parsedNsgID.Path["networkSecurityGroups"] - - locks.ByName(networkSecurityGroupName, networkSecurityGroupResourceName) - defer locks.UnlockByName(networkSecurityGroupName, networkSecurityGroupResourceName) - } - dns, hasDns := d.GetOk("dns_servers") nameLabel, hasNameLabel := d.GetOk("internal_dns_name_label") if hasDns || hasNameLabel { - ifaceDnsSettings := network.InterfaceDNSSettings{} + dnsSettings := network.InterfaceDNSSettings{} if hasDns { - var dnsServers []string - dns := dns.(*schema.Set).List() - for _, v := range dns { - str := v.(string) - dnsServers = append(dnsServers, str) - } - ifaceDnsSettings.DNSServers = &dnsServers + dnsRaw := dns.([]interface{}) + dns := expandNetworkInterfaceDnsServers(dnsRaw) + dnsSettings.DNSServers = &dns } if hasNameLabel { - name_label := nameLabel.(string) - ifaceDnsSettings.InternalDNSNameLabel = &name_label + dnsSettings.InternalDNSNameLabel = utils.String(nameLabel.(string)) } - properties.DNSSettings = &ifaceDnsSettings + properties.DNSSettings = &dnsSettings } - ipConfigs, subnetnToLock, vnnToLock, sgErr := expandAzureRmNetworkInterfaceIpConfigurations(d) - if sgErr != nil { - return fmt.Errorf("Error Building list of Network Interface IP Configurations: %+v", sgErr) + ipConfigsRaw := d.Get("ip_configuration").([]interface{}) + ipConfigs, err := expandNetworkInterfaceIPConfigurations(ipConfigsRaw) + if err != nil { + return fmt.Errorf("Error expanding `ip_configuration`: %+v", err) + } + lockingDetails, err := determineResourcesToLockFromIPConfiguration(ipConfigs) + if err != nil { + return fmt.Errorf("Error determining locking details: %+v", err) } - locks.MultipleByName(subnetnToLock, SubnetResourceName) - defer locks.UnlockMultipleByName(subnetnToLock, SubnetResourceName) - - locks.MultipleByName(vnnToLock, VirtualNetworkResourceName) - defer locks.UnlockMultipleByName(vnnToLock, VirtualNetworkResourceName) + lockingDetails.lock() + defer lockingDetails.unlock() - if len(ipConfigs) > 0 { - properties.IPConfigurations = &ipConfigs + if len(*ipConfigs) > 0 { + properties.IPConfigurations = ipConfigs } iface := network.Interface{ - Name: &name, - Location: &location, + Name: utils.String(name), + Location: utils.String(location), InterfacePropertiesFormat: &properties, Tags: tags.Expand(t), } - future, err := client.CreateOrUpdate(ctx, resGroup, name, iface) + future, err := client.CreateOrUpdate(ctx, resourceGroup, name, iface) if err != nil { - return err + return fmt.Errorf("Error creating Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return err + return fmt.Errorf("Error waiting for creation of Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) } - read, err := client.Get(ctx, resGroup, name, "") + read, err := client.Get(ctx, resourceGroup, name, "") if err != nil { - return err + return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) } if read.ID == nil { - return fmt.Errorf("Cannot read NIC %q (resource group %q) ID", name, resGroup) + return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): ID was nil", name, resourceGroup) } - d.SetId(*read.ID) return resourceArmNetworkInterfaceRead(d, meta) } +func resourceArmNetworkInterfaceUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Network.InterfacesClient + ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["networkInterfaces"] + + locks.ByName(name, networkInterfaceResourceName) + defer locks.UnlockByName(name, networkInterfaceResourceName) + + // first get the existing one so that we can pull things as needed + existing, err := client.Get(ctx, resourceGroup, name, "") + if err != nil { + return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if existing.InterfacePropertiesFormat == nil { + return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): `properties` was nil", name, resourceGroup) + } + + // then pull out things we need to lock on + info := parseFieldsFromNetworkInterface(*existing.InterfacePropertiesFormat) + + location := azure.NormalizeLocation(d.Get("location").(string)) + update := network.Interface{ + Name: utils.String(name), + Location: utils.String(location), + InterfacePropertiesFormat: &network.InterfacePropertiesFormat{}, + } + + if d.HasChange("dns_servers") { + if update.InterfacePropertiesFormat.DNSSettings == nil { + update.InterfacePropertiesFormat.DNSSettings = &network.InterfaceDNSSettings{} + } + + dnsServersRaw := d.Get("dns_servers").([]interface{}) + dnsServers := expandNetworkInterfaceDnsServers(dnsServersRaw) + + update.InterfacePropertiesFormat.DNSSettings.DNSServers = &dnsServers + } + + if d.HasChange("enable_accelerated_networking") { + update.InterfacePropertiesFormat.EnableAcceleratedNetworking = utils.Bool(d.Get("enable_accelerated_networking").(bool)) + } + + if d.HasChange("enable_ip_forwarding") { + update.InterfacePropertiesFormat.EnableIPForwarding = utils.Bool(d.Get("enable_ip_forwarding").(bool)) + } + + if d.HasChange("internal_dns_name_label") { + if update.InterfacePropertiesFormat.DNSSettings == nil { + update.InterfacePropertiesFormat.DNSSettings = &network.InterfaceDNSSettings{} + } + + update.InterfacePropertiesFormat.DNSSettings.InternalDNSNameLabel = utils.String(d.Get("internal_dns_name_label").(string)) + } + + if d.HasChange("ip_configuration") { + ipConfigsRaw := d.Get("ip_configuration").([]interface{}) + ipConfigs, err := expandNetworkInterfaceIPConfigurations(ipConfigsRaw) + if err != nil { + return fmt.Errorf("Error expanding `ip_configuration`: %+v", err) + } + lockingDetails, err := determineResourcesToLockFromIPConfiguration(ipConfigs) + if err != nil { + return fmt.Errorf("Error determining locking details: %+v", err) + } + + lockingDetails.lock() + defer lockingDetails.unlock() + + // then map the fields managed in other resources back + ipConfigs = mapFieldsToNetworkInterface(ipConfigs, info) + + update.InterfacePropertiesFormat.IPConfigurations = ipConfigs + } else { + update.InterfacePropertiesFormat.IPConfigurations = existing.InterfacePropertiesFormat.IPConfigurations + } + + if d.HasChange("tags") { + tagsRaw := d.Get("tags").(map[string]interface{}) + update.Tags = tags.Expand(tagsRaw) + } + + // this can be managed in another resource, so just port it over + update.InterfacePropertiesFormat.NetworkSecurityGroup = existing.InterfacePropertiesFormat.NetworkSecurityGroup + + future, err := client.CreateOrUpdate(ctx, resourceGroup, name, update) + if err != nil { + return fmt.Errorf("Error updating Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) + } + if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for update of Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + return nil +} + func resourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.InterfacesClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) @@ -386,80 +386,83 @@ func resourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) e if err != nil { return err } - resGroup := id.ResourceGroup + resourceGroup := id.ResourceGroup name := id.Path["networkInterfaces"] - resp, err := client.Get(ctx, resGroup, name, "") + resp, err := client.Get(ctx, resourceGroup, name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error making Read request on Azure Network Interface %q (Resource Group %q): %+v", name, resGroup, err) + return fmt.Errorf("Error making Read request on Azure Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resGroup) + d.Set("resource_group_name", resourceGroup) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } if props := resp.InterfacePropertiesFormat; props != nil { - d.Set("mac_address", props.MacAddress) - addresses := make([]interface{}, 0) + primaryPrivateIPAddress := "" + privateIPAddresses := make([]interface{}, 0) if configs := props.IPConfigurations; configs != nil { for i, config := range *props.IPConfigurations { if ipProps := config.InterfaceIPConfigurationPropertiesFormat; ipProps != nil { - if v := ipProps.PrivateIPAddress; v != nil { - if i == 0 { - d.Set("private_ip_address", v) - } - addresses = append(addresses, *v) + v := ipProps.PrivateIPAddress + if v == nil { + continue } - } - } - } - if err := d.Set("private_ip_addresses", addresses); err != nil { - return err - } - if props.IPConfigurations != nil { - configs := flattenNetworkInterfaceIPConfigurations(props.IPConfigurations) - if err := d.Set("ip_configuration", configs); err != nil { - return fmt.Errorf("Error setting `ip_configuration`: %+v", err) - } - } + if i == 0 { + primaryPrivateIPAddress = *v + } - if vm := props.VirtualMachine; vm != nil { - d.Set("virtual_machine_id", vm.ID) + privateIPAddresses = append(privateIPAddresses, *v) + } + } } - var appliedDNSServers []string - var dnsServers []string + appliedDNSServers := make([]string, 0) + dnsServers := make([]string, 0) + internalDnsNameLabel := "" if dnsSettings := props.DNSSettings; dnsSettings != nil { - if s := dnsSettings.AppliedDNSServers; s != nil { - appliedDNSServers = *s - } + appliedDNSServers = flattenNetworkInterfaceDnsServers(dnsSettings.AppliedDNSServers) + dnsServers = flattenNetworkInterfaceDnsServers(dnsSettings.DNSServers) - if s := dnsSettings.DNSServers; s != nil { - dnsServers = *s + if dnsSettings.InternalDNSNameLabel != nil { + internalDnsNameLabel = *dnsSettings.InternalDNSNameLabel } + } - d.Set("internal_fqdn", dnsSettings.InternalFqdn) - d.Set("internal_dns_name_label", dnsSettings.InternalDNSNameLabel) + virtualMachineId := "" + if props.VirtualMachine != nil && props.VirtualMachine.ID != nil { + virtualMachineId = *props.VirtualMachine.ID } - d.Set("applied_dns_servers", appliedDNSServers) - d.Set("dns_servers", dnsServers) + if err := d.Set("applied_dns_servers", appliedDNSServers); err != nil { + return fmt.Errorf("Error setting `applied_dns_servers`: %+v", err) + } - if nsg := props.NetworkSecurityGroup; nsg != nil { - d.Set("network_security_group_id", nsg.ID) - } else { - d.Set("network_security_group_id", "") + if err := d.Set("dns_servers", dnsServers); err != nil { + return fmt.Errorf("Error setting `applied_dns_servers`: %+v", err) } d.Set("enable_ip_forwarding", resp.EnableIPForwarding) d.Set("enable_accelerated_networking", resp.EnableAcceleratedNetworking) + d.Set("internal_dns_name_label", internalDnsNameLabel) + d.Set("mac_address", props.MacAddress) + d.Set("private_ip_address", primaryPrivateIPAddress) + d.Set("virtual_machine_id", virtualMachineId) + + if err := d.Set("ip_configuration", flattenNetworkInterfaceIPConfigurations(props.IPConfigurations)); err != nil { + return fmt.Errorf("Error setting `ip_configuration`: %+v", err) + } + + if err := d.Set("private_ip_addresses", privateIPAddresses); err != nil { + return fmt.Errorf("Error setting `private_ip_addresses`: %+v", err) + } } return tags.FlattenAndSet(d, resp.Tags) @@ -474,178 +477,71 @@ func resourceArmNetworkInterfaceDelete(d *schema.ResourceData, meta interface{}) if err != nil { return err } - resGroup := id.ResourceGroup + resourceGroup := id.ResourceGroup name := id.Path["networkInterfaces"] locks.ByName(name, networkInterfaceResourceName) defer locks.UnlockByName(name, networkInterfaceResourceName) - if v, ok := d.GetOk("network_security_group_id"); ok { - networkSecurityGroupId := v.(string) - parsedNsgID, err := azure.ParseAzureResourceID(networkSecurityGroupId) - if err != nil { - return fmt.Errorf("Error parsing Network Security Group ID %q: %+v", networkSecurityGroupId, err) + existing, err := client.Get(ctx, resourceGroup, name, "") + if err != nil { + if utils.ResponseWasNotFound(existing.Response) { + log.Printf("[DEBUG] Network Interface %q was not found in Resource Group %q - removing from state", name, resourceGroup) + d.SetId("") + return nil } - networkSecurityGroupName := parsedNsgID.Path["networkSecurityGroups"] - - locks.ByName(networkSecurityGroupName, networkSecurityGroupResourceName) - defer locks.UnlockByName(networkSecurityGroupName, networkSecurityGroupResourceName) + return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) } - configs := d.Get("ip_configuration").([]interface{}) - subnetNamesToLock := make([]string, 0) - virtualNetworkNamesToLock := make([]string, 0) - - for _, configRaw := range configs { - data := configRaw.(map[string]interface{}) - - subnet_id := data["subnet_id"].(string) - if subnet_id != "" { - subnetId, err2 := azure.ParseAzureResourceID(subnet_id) - if err2 != nil { - return err2 - } - subnetName := subnetId.Path["subnets"] - if !SliceContainsValue(subnetNamesToLock, subnetName) { - subnetNamesToLock = append(subnetNamesToLock, subnetName) - } - - virtualNetworkName := subnetId.Path["virtualNetworks"] - if !SliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { - virtualNetworkNamesToLock = append(virtualNetworkNamesToLock, virtualNetworkName) - } - } + if existing.InterfacePropertiesFormat == nil { + return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): `properties` was nil", name, resourceGroup) } + props := *existing.InterfacePropertiesFormat - locks.MultipleByName(&subnetNamesToLock, SubnetResourceName) - defer locks.UnlockMultipleByName(&subnetNamesToLock, SubnetResourceName) + lockingDetails, err := determineResourcesToLockFromIPConfiguration(props.IPConfigurations) + if err != nil { + return fmt.Errorf("Error determining locking details: %+v", err) + } - locks.MultipleByName(&virtualNetworkNamesToLock, VirtualNetworkResourceName) - defer locks.UnlockMultipleByName(&virtualNetworkNamesToLock, VirtualNetworkResourceName) + lockingDetails.lock() + defer lockingDetails.unlock() - future, err := client.Delete(ctx, resGroup, name) + future, err := client.Delete(ctx, resourceGroup, name) if err != nil { - return fmt.Errorf("Error deleting Network Interface %q (Resource Group %q): %+v", name, resGroup, err) + return fmt.Errorf("Error deleting Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for the deletion of Network Interface %q (Resource Group %q): %+v", name, resGroup, err) + return fmt.Errorf("Error waiting for the deletion of Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) } - return err -} - -func flattenNetworkInterfaceIPConfigurations(ipConfigs *[]network.InterfaceIPConfiguration) []interface{} { - result := make([]interface{}, 0, len(*ipConfigs)) - for _, ipConfig := range *ipConfigs { - niIPConfig := make(map[string]interface{}) - - props := ipConfig.InterfaceIPConfigurationPropertiesFormat - - niIPConfig["name"] = *ipConfig.Name - - if props.Subnet != nil && props.Subnet.ID != nil { - niIPConfig["subnet_id"] = *props.Subnet.ID - } - - niIPConfig["private_ip_address_allocation"] = strings.ToLower(string(props.PrivateIPAllocationMethod)) - - if props.PrivateIPAddress != nil { - niIPConfig["private_ip_address"] = *props.PrivateIPAddress - } - - if props.PrivateIPAddressVersion != "" { - niIPConfig["private_ip_address_version"] = string(props.PrivateIPAddressVersion) - } - - if props.PublicIPAddress != nil { - niIPConfig["public_ip_address_id"] = *props.PublicIPAddress.ID - } - - if props.Primary != nil { - niIPConfig["primary"] = *props.Primary - } - - var poolsAG []interface{} - if props.ApplicationGatewayBackendAddressPools != nil { - for _, pool := range *props.ApplicationGatewayBackendAddressPools { - poolsAG = append(poolsAG, *pool.ID) - } - } - niIPConfig["application_gateway_backend_address_pools_ids"] = schema.NewSet(schema.HashString, poolsAG) - - var pools []interface{} - if props.LoadBalancerBackendAddressPools != nil { - for _, pool := range *props.LoadBalancerBackendAddressPools { - pools = append(pools, *pool.ID) - } - } - niIPConfig["load_balancer_backend_address_pools_ids"] = schema.NewSet(schema.HashString, pools) - - var rules []interface{} - if props.LoadBalancerInboundNatRules != nil { - for _, rule := range *props.LoadBalancerInboundNatRules { - rules = append(rules, *rule.ID) - } - } - niIPConfig["load_balancer_inbound_nat_rules_ids"] = schema.NewSet(schema.HashString, rules) - - securityGroups := make([]interface{}, 0) - if sgs := props.ApplicationSecurityGroups; sgs != nil { - for _, sg := range *sgs { - securityGroups = append(securityGroups, *sg.ID) - } - } - niIPConfig["application_security_group_ids"] = schema.NewSet(schema.HashString, securityGroups) - - result = append(result, niIPConfig) - } - return result + return nil } -func expandAzureRmNetworkInterfaceIpConfigurations(d *schema.ResourceData) ([]network.InterfaceIPConfiguration, *[]string, *[]string, error) { - configs := d.Get("ip_configuration").([]interface{}) - ipConfigs := make([]network.InterfaceIPConfiguration, 0, len(configs)) - subnetNamesToLock := make([]string, 0) - virtualNetworkNamesToLock := make([]string, 0) +func expandNetworkInterfaceIPConfigurations(input []interface{}) (*[]network.InterfaceIPConfiguration, error) { + ipConfigs := make([]network.InterfaceIPConfiguration, 0) - for _, configRaw := range configs { + for _, configRaw := range input { data := configRaw.(map[string]interface{}) - subnet_id := data["subnet_id"].(string) - private_ip_allocation_method := data["private_ip_address_allocation"].(string) - private_ip_address_version := network.IPVersion(data["private_ip_address_version"].(string)) + subnetId := data["subnet_id"].(string) + privateIpAllocationMethod := data["private_ip_address_allocation"].(string) + privateIpAddressVersion := network.IPVersion(data["private_ip_address_version"].(string)) - allocationMethod := network.IPAllocationMethod(private_ip_allocation_method) + allocationMethod := network.IPAllocationMethod(privateIpAllocationMethod) properties := network.InterfaceIPConfigurationPropertiesFormat{ PrivateIPAllocationMethod: allocationMethod, - PrivateIPAddressVersion: private_ip_address_version, + PrivateIPAddressVersion: privateIpAddressVersion, } - if private_ip_address_version == network.IPv4 && subnet_id == "" { - return nil, nil, nil, fmt.Errorf("A Subnet ID must be specified for an IPv4 Network Interface.") + if privateIpAddressVersion == network.IPv4 && subnetId == "" { + return nil, fmt.Errorf("A Subnet ID must be specified for an IPv4 Network Interface.") } - if subnet_id != "" { + if subnetId != "" { properties.Subnet = &network.Subnet{ - ID: &subnet_id, - } - - subnetId, err := azure.ParseAzureResourceID(subnet_id) - if err != nil { - return []network.InterfaceIPConfiguration{}, nil, nil, err - } - - subnetName := subnetId.Path["subnets"] - virtualNetworkName := subnetId.Path["virtualNetworks"] - - if !SliceContainsValue(subnetNamesToLock, subnetName) { - subnetNamesToLock = append(subnetNamesToLock, subnetName) - } - - if !SliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { - virtualNetworkNamesToLock = append(virtualNetworkNamesToLock, virtualNetworkName) + ID: &subnetId, } } @@ -660,77 +556,14 @@ func expandAzureRmNetworkInterfaceIpConfigurations(d *schema.ResourceData) ([]ne } if v, ok := data["primary"]; ok { - b := v.(bool) - properties.Primary = &b - } - - if v, ok := data["application_gateway_backend_address_pools_ids"]; ok { - var ids []network.ApplicationGatewayBackendAddressPool - pools := v.(*schema.Set).List() - for _, p := range pools { - pool_id := p.(string) - id := network.ApplicationGatewayBackendAddressPool{ - ID: &pool_id, - } - - ids = append(ids, id) - } - - properties.ApplicationGatewayBackendAddressPools = &ids - } - - if v, ok := data["load_balancer_backend_address_pools_ids"]; ok { - var ids []network.BackendAddressPool - pools := v.(*schema.Set).List() - for _, p := range pools { - pool_id := p.(string) - id := network.BackendAddressPool{ - ID: &pool_id, - } - - ids = append(ids, id) - } - - properties.LoadBalancerBackendAddressPools = &ids - } - - if v, ok := data["load_balancer_inbound_nat_rules_ids"]; ok { - var natRules []network.InboundNatRule - rules := v.(*schema.Set).List() - for _, r := range rules { - rule_id := r.(string) - rule := network.InboundNatRule{ - ID: &rule_id, - } - - natRules = append(natRules, rule) - } - - properties.LoadBalancerInboundNatRules = &natRules - } - - if v, ok := data["application_security_group_ids"]; ok { - var securityGroups []network.ApplicationSecurityGroup - rules := v.(*schema.Set).List() - for _, r := range rules { - groupId := r.(string) - group := network.ApplicationSecurityGroup{ - ID: &groupId, - } - - securityGroups = append(securityGroups, group) - } - - properties.ApplicationSecurityGroups = &securityGroups + properties.Primary = utils.Bool(v.(bool)) } name := data["name"].(string) - ipConfig := network.InterfaceIPConfiguration{ + ipConfigs = append(ipConfigs, network.InterfaceIPConfiguration{ Name: &name, InterfaceIPConfigurationPropertiesFormat: &properties, - } - - ipConfigs = append(ipConfigs, ipConfig) + }) } // if we've got multiple IP Configurations - one must be designated Primary @@ -744,19 +577,77 @@ func expandAzureRmNetworkInterfaceIpConfigurations(d *schema.ResourceData) ([]ne } if !hasPrimary { - return nil, nil, nil, fmt.Errorf("If multiple `ip_configurations` are specified - one must be designated as `primary`.") + return nil, fmt.Errorf("If multiple `ip_configurations` are specified - one must be designated as `primary`.") } } - return ipConfigs, &subnetNamesToLock, &virtualNetworkNamesToLock, nil + return &ipConfigs, nil } -func SliceContainsValue(input []string, value string) bool { - for _, v := range input { - if v == value { - return true +func flattenNetworkInterfaceIPConfigurations(input *[]network.InterfaceIPConfiguration) []interface{} { + if input == nil { + return []interface{}{} + } + + result := make([]interface{}, 0) + for _, ipConfig := range *input { + props := ipConfig.InterfaceIPConfigurationPropertiesFormat + + name := "" + if ipConfig.Name != nil { + name = *ipConfig.Name + } + + subnetId := "" + if props.Subnet != nil && props.Subnet.ID != nil { + subnetId = *props.Subnet.ID + } + + privateIPAddress := "" + if props.PrivateIPAddress != nil { + privateIPAddress = *props.PrivateIPAddress + } + + privateIPAddressVersion := "" + if props.PrivateIPAddressVersion != "" { + privateIPAddressVersion = string(props.PrivateIPAddressVersion) } + + publicIPAddressId := "" + if props.PublicIPAddress != nil && props.PublicIPAddress.ID != nil { + publicIPAddressId = *props.PublicIPAddress.ID + } + + primary := false + if props.Primary != nil { + primary = *props.Primary + } + + result = append(result, map[string]interface{}{ + "name": name, + "primary": primary, + "private_ip_address": privateIPAddress, + "private_ip_address_allocation": string(props.PrivateIPAllocationMethod), + "private_ip_address_version": privateIPAddressVersion, + "public_ip_address_id": publicIPAddressId, + "subnet_id": subnetId, + }) + } + return result +} + +func expandNetworkInterfaceDnsServers(input []interface{}) []string { + dnsServers := make([]string, 0) + for _, v := range input { + dnsServers = append(dnsServers, v.(string)) + } + return dnsServers +} + +func flattenNetworkInterfaceDnsServers(input *[]string) []string { + if input == nil { + return make([]string, 0) } - return false + return *input } diff --git a/azurerm/internal/services/network/resource_arm_network_profile.go b/azurerm/internal/services/network/resource_arm_network_profile.go index 40c8bd3593e0c..f3338e0dc9721 100644 --- a/azurerm/internal/services/network/resource_arm_network_profile.go +++ b/azurerm/internal/services/network/resource_arm_network_profile.go @@ -315,11 +315,11 @@ func expandNetworkProfileVirtualNetworkSubnetNames(d *schema.ResourceData) (*[]s subnetName := subnetResourceID.Path["subnets"] vnetName := subnetResourceID.Path["virtualNetworks"] - if !SliceContainsValue(subnetNames, subnetName) { + if !azure.SliceContainsValue(subnetNames, subnetName) { subnetNames = append(subnetNames, subnetName) } - if !SliceContainsValue(vnetNames, vnetName) { + if !azure.SliceContainsValue(vnetNames, vnetName) { vnetNames = append(vnetNames, vnetName) } } diff --git a/azurerm/internal/services/network/resource_arm_network_security_rule.go b/azurerm/internal/services/network/resource_arm_network_security_rule.go index 8ca6e1a092ad2..fe76f486facf3 100644 --- a/azurerm/internal/services/network/resource_arm_network_security_rule.go +++ b/azurerm/internal/services/network/resource_arm_network_security_rule.go @@ -123,7 +123,7 @@ func resourceArmNetworkSecurityRule() *schema.Resource { ConflictsWith: []string{"destination_address_prefix"}, }, - //lintignore:S018 + // lintignore:S018 "source_application_security_group_ids": { Type: schema.TypeSet, MaxItems: 1, @@ -132,7 +132,7 @@ func resourceArmNetworkSecurityRule() *schema.Resource { Set: schema.HashString, }, - //lintignore:S018 + // lintignore:S018 "destination_application_security_group_ids": { Type: schema.TypeSet, MaxItems: 1, diff --git a/azurerm/internal/services/network/resource_arm_network_watcher_flow_log.go b/azurerm/internal/services/network/resource_arm_network_watcher_flow_log.go index e98419ee6c4c4..3f089f552b459 100644 --- a/azurerm/internal/services/network/resource_arm_network_watcher_flow_log.go +++ b/azurerm/internal/services/network/resource_arm_network_watcher_flow_log.go @@ -141,6 +141,13 @@ func resourceArmNetworkWatcherFlowLog() *schema.Resource { Required: true, ValidateFunc: azure.ValidateResourceIDOrEmpty, }, + + "interval_in_minutes": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntInSlice([]int{10, 60}), + Default: 60, + }, }, }, }, @@ -386,6 +393,9 @@ func flattenAzureRmNetworkWatcherFlowLogTrafficAnalytics(input *network.TrafficA if cfg.WorkspaceResourceID != nil { result["workspace_resource_id"] = *cfg.WorkspaceResourceID } + if cfg.TrafficAnalyticsInterval != nil { + result["interval_in_minutes"] = int(*cfg.TrafficAnalyticsInterval) + } } return []interface{}{result} @@ -399,13 +409,15 @@ func expandAzureRmNetworkWatcherFlowLogTrafficAnalytics(d *schema.ResourceData) workspaceID := v["workspace_id"].(string) workspaceRegion := v["workspace_region"].(string) workspaceResourceID := v["workspace_resource_id"].(string) + interval := v["interval_in_minutes"].(int) return &network.TrafficAnalyticsProperties{ NetworkWatcherFlowAnalyticsConfiguration: &network.TrafficAnalyticsConfigurationProperties{ - Enabled: utils.Bool(enabled), - WorkspaceID: utils.String(workspaceID), - WorkspaceRegion: utils.String(workspaceRegion), - WorkspaceResourceID: utils.String(workspaceResourceID), + Enabled: utils.Bool(enabled), + WorkspaceID: utils.String(workspaceID), + WorkspaceRegion: utils.String(workspaceRegion), + WorkspaceResourceID: utils.String(workspaceResourceID), + TrafficAnalyticsInterval: utils.Int32(int32(interval)), }, } } diff --git a/azurerm/internal/services/network/resource_arm_private_endpoint.go b/azurerm/internal/services/network/resource_arm_private_endpoint.go index cce2878f8e830..db7d08aae658e 100644 --- a/azurerm/internal/services/network/resource_arm_private_endpoint.go +++ b/azurerm/internal/services/network/resource_arm_private_endpoint.go @@ -90,6 +90,10 @@ func resourceArmPrivateEndpoint() *schema.Resource { Optional: true, ValidateFunc: validation.StringLenBetween(1, 140), }, + "private_ip_address": { + Type: schema.TypeString, + Computed: true, + }, }, }, }, @@ -166,6 +170,7 @@ func resourceArmPrivateEndpointCreateUpdate(d *schema.ResourceData, meta interfa func resourceArmPrivateEndpointRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.PrivateEndpointClient + nicsClient := meta.(*clients.Client).Network.InterfacesClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() @@ -193,7 +198,20 @@ func resourceArmPrivateEndpointRead(d *schema.ResourceData, meta interface{}) er } if props := resp.PrivateEndpointProperties; props != nil { + privateIpAddress := "" + + if nics := props.NetworkInterfaces; nics != nil && len(*nics) > 0 { + nic := (*nics)[0] + if nic.ID != nil && *nic.ID != "" { + privateIpAddress = getPrivateIpAddress(ctx, nicsClient, *nic.ID) + } + } + flattenedConnection := flattenArmPrivateLinkEndpointServiceConnection(props.PrivateLinkServiceConnections, props.ManualPrivateLinkServiceConnections) + for _, item := range flattenedConnection { + v := item.(map[string]interface{}) + v["private_ip_address"] = privateIpAddress + } if err := d.Set("private_service_connection", flattenedConnection); err != nil { return fmt.Errorf("Error setting `private_service_connection`: %+v", err) } diff --git a/azurerm/internal/services/network/resource_arm_private_link_endpoint.go b/azurerm/internal/services/network/resource_arm_private_link_endpoint.go deleted file mode 100644 index b4f420a316494..0000000000000 --- a/azurerm/internal/services/network/resource_arm_private_link_endpoint.go +++ /dev/null @@ -1,242 +0,0 @@ -package network - -import ( - "fmt" - "log" - "time" - - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" - "github.com/hashicorp/go-azure-helpers/response" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmPrivateLinkEndpoint() *schema.Resource { - return &schema.Resource{ - DeprecationMessage: `The 'azurerm_private_link_endpoint' resource is being deprecated in favour of the renamed version 'azurerm_private_endpoint'. - -Information on migrating to the renamed resource can be found here: https://terraform.io/docs/providers/azurerm/guides/migrating-between-renamed-resources.html - -As such the existing 'azurerm_private_link_endpoint' resource is deprecated and will be removed in the next major version of the AzureRM Provider (2.0). -`, - - Create: resourceArmPrivateLinkEndpointCreateUpdate, - Read: resourceArmPrivateLinkEndpointRead, - Update: resourceArmPrivateLinkEndpointCreateUpdate, - Delete: resourceArmPrivateLinkEndpointDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(60 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(60 * time.Minute), - Delete: schema.DefaultTimeout(60 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: ValidatePrivateLinkName, - }, - - "location": azure.SchemaLocation(), - - "resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(), - - "subnet_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - }, - - "private_service_connection": { - Type: schema.TypeList, - Required: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: ValidatePrivateLinkName, - }, - "is_manual_connection": { - Type: schema.TypeBool, - Required: true, - ForceNew: true, - }, - "private_connection_resource_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - }, - "subresource_names": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: ValidatePrivateLinkSubResourceName, - }, - }, - "request_message": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringLenBetween(1, 140), - }, - }, - }, - }, - - // tags has been removed - // API Issue "Unable to remove Tags from Private Link Endpoint": https://github.com/Azure/azure-sdk-for-go/issues/6467 - }, - } -} - -func resourceArmPrivateLinkEndpointCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.PrivateEndpointClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - - if err := ValidatePrivateEndpointSettings(d); err != nil { - return fmt.Errorf("Error validating the configuration for the Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, name, "") - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_private_link_endpoint", *existing.ID) - } - } - - location := azure.NormalizeLocation(d.Get("location").(string)) - privateServiceConnections := d.Get("private_service_connection").([]interface{}) - subnetId := d.Get("subnet_id").(string) - - parameters := network.PrivateEndpoint{ - Location: utils.String(location), - PrivateEndpointProperties: &network.PrivateEndpointProperties{ - PrivateLinkServiceConnections: expandArmPrivateLinkEndpointServiceConnection(privateServiceConnections, false), - ManualPrivateLinkServiceConnections: expandArmPrivateLinkEndpointServiceConnection(privateServiceConnections, true), - Subnet: &network.Subnet{ - ID: utils.String(subnetId), - }, - }, - } - - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, parameters) - if err != nil { - return fmt.Errorf("Error creating Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) - } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for creation of Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - resp, err := client.Get(ctx, resourceGroup, name, "") - if err != nil { - return fmt.Errorf("Error retrieving Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) - } - if resp.ID == nil || *resp.ID == "" { - return fmt.Errorf("API returns a nil/empty id on Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) - } - d.SetId(*resp.ID) - - return resourceArmPrivateLinkEndpointRead(d, meta) -} - -func resourceArmPrivateLinkEndpointRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.PrivateEndpointClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - name := id.Path["privateEndpoints"] - - resp, err := client.Get(ctx, resourceGroup, name, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] Private Link Endpoint %q does not exist - removing from state", d.Id()) - d.SetId("") - return nil - } - return fmt.Errorf("Error reading Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - - if props := resp.PrivateEndpointProperties; props != nil { - flattenedConnection := flattenArmPrivateLinkEndpointServiceConnection(props.PrivateLinkServiceConnections, props.ManualPrivateLinkServiceConnections) - if err := d.Set("private_service_connection", flattenedConnection); err != nil { - return fmt.Errorf("Error setting `private_service_connection`: %+v", err) - } - - subnetId := "" - if subnet := props.Subnet; subnet != nil { - subnetId = *subnet.ID - } - d.Set("subnet_id", subnetId) - } - - // API Issue "Unable to remove Tags from Private Link Endpoint": https://github.com/Azure/azure-sdk-for-go/issues/6467 - return nil -} - -func resourceArmPrivateLinkEndpointDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Network.PrivateEndpointClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resourceGroup := id.ResourceGroup - name := id.Path["privateEndpoints"] - - future, err := client.Delete(ctx, resourceGroup, name) - if err != nil { - if response.WasNotFound(future.Response()) { - return nil - } - return fmt.Errorf("Error deleting Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - if !response.WasNotFound(future.Response()) { - return fmt.Errorf("Error waiting for deletion of Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) - } - } - - return nil -} diff --git a/azurerm/internal/services/network/resource_arm_private_link_service.go b/azurerm/internal/services/network/resource_arm_private_link_service.go index b2e1f8c5a6212..5b686571f5007 100644 --- a/azurerm/internal/services/network/resource_arm_private_link_service.go +++ b/azurerm/internal/services/network/resource_arm_private_link_service.go @@ -56,7 +56,7 @@ func resourceArmPrivateLinkService() *schema.Resource { Optional: true, Elem: &schema.Schema{ Type: schema.TypeString, - ValidateFunc: validate.GUID, + ValidateFunc: validation.IsUUID, }, Set: schema.HashString, }, @@ -71,7 +71,7 @@ func resourceArmPrivateLinkService() *schema.Resource { Optional: true, Elem: &schema.Schema{ Type: schema.TypeString, - ValidateFunc: validate.GUID, + ValidateFunc: validation.IsUUID, }, Set: schema.HashString, }, @@ -136,17 +136,6 @@ func resourceArmPrivateLinkService() *schema.Resource { Computed: true, }, - "network_interface_ids": { - Type: schema.TypeSet, - Computed: true, - Deprecated: "This field is deprecated and be removed in version 2.0 of the Azure Provider", - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: azure.ValidateResourceID, - }, - Set: schema.HashString, - }, - "tags": tags.Schema(), }, @@ -298,11 +287,6 @@ func resourceArmPrivateLinkServiceRead(d *schema.ResourceData, meta interface{}) if err := d.Set("load_balancer_frontend_ip_configuration_ids", flattenArmPrivateLinkServiceFrontendIPConfiguration(props.LoadBalancerFrontendIPConfigurations)); err != nil { return fmt.Errorf("Error setting `load_balancer_frontend_ip_configuration_ids`: %+v", err) } - - // TODO: remove in 2.0 - if err := d.Set("network_interface_ids", flattenArmPrivateLinkServiceInterface(props.NetworkInterfaces)); err != nil { - return fmt.Errorf("Error setting `network_interface_ids`: %+v", err) - } } return tags.FlattenAndSet(d, resp.Tags) @@ -454,21 +438,6 @@ func flattenArmPrivateLinkServiceFrontendIPConfiguration(input *[]network.Fronte return results } -func flattenArmPrivateLinkServiceInterface(input *[]network.Interface) *schema.Set { - results := &schema.Set{F: schema.HashString} - if input == nil { - return results - } - - for _, item := range *input { - if id := item.ID; id != nil { - results.Add(*id) - } - } - - return results -} - func privateLinkServiceWaitForReadyRefreshFunc(ctx context.Context, client *network.PrivateLinkServicesClient, resourceGroupName string, name string) resource.StateRefreshFunc { return func() (interface{}, string, error) { res, err := client.Get(ctx, resourceGroupName, name, "") diff --git a/azurerm/internal/services/network/resource_arm_public_ip.go b/azurerm/internal/services/network/resource_arm_public_ip.go index 0b1c6bfacde37..3812caed14c26 100644 --- a/azurerm/internal/services/network/resource_arm_public_ip.go +++ b/azurerm/internal/services/network/resource_arm_public_ip.go @@ -16,7 +16,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/state" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -62,31 +61,14 @@ func resourceArmPublicIp() *schema.Resource { "resource_group_name": azure.SchemaResourceGroupName(), "allocation_method": { - Type: schema.TypeString, - //Required: true, //revert in 2.0 - Optional: true, - Computed: true, // remove in 2.0 - ConflictsWith: []string{"public_ip_address_allocation"}, + Type: schema.TypeString, + Required: true, ValidateFunc: validation.StringInSlice([]string{ string(network.Static), string(network.Dynamic), }, false), }, - "public_ip_address_allocation": { - Type: schema.TypeString, - Optional: true, - DiffSuppressFunc: suppress.CaseDifference, - StateFunc: state.IgnoreCase, - ConflictsWith: []string{"allocation_method"}, - Computed: true, - Deprecated: "this property has been deprecated in favor of `allocation_method` to better match the api", - ValidateFunc: validation.StringInSlice([]string{ - string(network.Static), - string(network.Dynamic), - }, true), - }, - "ip_version": { Type: schema.TypeString, Optional: true, @@ -168,15 +150,7 @@ func resourceArmPublicIpCreateUpdate(d *schema.ResourceData, meta interface{}) e zones := azure.ExpandZones(d.Get("zones").([]interface{})) idleTimeout := d.Get("idle_timeout_in_minutes").(int) ipVersion := network.IPVersion(d.Get("ip_version").(string)) - - ipAllocationMethod := "" - if v, ok := d.GetOk("allocation_method"); ok { - ipAllocationMethod = v.(string) - } else if v, ok := d.GetOk("public_ip_address_allocation"); ok { - ipAllocationMethod = v.(string) - } else { - return fmt.Errorf("Either `allocation_method` or `public_ip_address_allocation` must be specified.") - } + ipAllocationMethod := d.Get("allocation_method").(string) if strings.EqualFold(string(ipVersion), string(network.IPv6)) { if strings.EqualFold(ipAllocationMethod, "static") { @@ -299,7 +273,6 @@ func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error { } if props := resp.PublicIPAddressPropertiesFormat; props != nil { - d.Set("public_ip_address_allocation", string(props.PublicIPAllocationMethod)) d.Set("allocation_method", string(props.PublicIPAllocationMethod)) d.Set("ip_version", string(props.PublicIPAddressVersion)) diff --git a/azurerm/internal/services/network/resource_arm_public_ip_prefix.go b/azurerm/internal/services/network/resource_arm_public_ip_prefix.go index 4249c2ed00b8d..304f093f68f05 100644 --- a/azurerm/internal/services/network/resource_arm_public_ip_prefix.go +++ b/azurerm/internal/services/network/resource_arm_public_ip_prefix.go @@ -59,7 +59,7 @@ func resourceArmPublicIpPrefix() *schema.Resource { Optional: true, Default: 28, ForceNew: true, - ValidateFunc: validation.IntBetween(24, 31), + ValidateFunc: validation.IntBetween(28, 31), }, "ip_prefix": { diff --git a/azurerm/internal/services/network/resource_arm_subnet.go b/azurerm/internal/services/network/resource_arm_subnet.go index 725b51482d26a..d7d38b7e309b9 100644 --- a/azurerm/internal/services/network/resource_arm_subnet.go +++ b/azurerm/internal/services/network/resource_arm_subnet.go @@ -22,9 +22,9 @@ var SubnetResourceName = "azurerm_subnet" func resourceArmSubnet() *schema.Resource { return &schema.Resource{ - Create: resourceArmSubnetCreateUpdate, + Create: resourceArmSubnetCreate, Read: resourceArmSubnetRead, - Update: resourceArmSubnetCreateUpdate, + Update: resourceArmSubnetUpdate, Delete: resourceArmSubnetDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -57,26 +57,6 @@ func resourceArmSubnet() *schema.Resource { Required: true, }, - "network_security_group_id": { - Type: schema.TypeString, - Optional: true, - Deprecated: "Use the `azurerm_subnet_network_security_group_association` resource instead.", - }, - - "route_table_id": { - Type: schema.TypeString, - Optional: true, - Deprecated: "Use the `azurerm_subnet_route_table_association` resource instead.", - }, - - "ip_configurations": { - Type: schema.TypeSet, - Optional: true, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - }, - "service_endpoints": { Type: schema.TypeList, Optional: true, @@ -119,10 +99,10 @@ func resourceArmSubnet() *schema.Resource { "Microsoft.Web/serverFarms", }, false), }, + "actions": { Type: schema.TypeList, Optional: true, - Computed: true, ConfigMode: schema.SchemaConfigModeAttr, Elem: &schema.Schema{ Type: schema.TypeString, @@ -157,7 +137,8 @@ func resourceArmSubnet() *schema.Resource { } } -func resourceArmSubnetCreateUpdate(d *schema.ResourceData, meta interface{}) error { +// TODO: refactor the create/flatten functions +func resourceArmSubnetCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.SubnetsClient ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -168,7 +149,7 @@ func resourceArmSubnetCreateUpdate(d *schema.ResourceData, meta interface{}) err vnetName := d.Get("virtual_network_name").(string) resGroup := d.Get("resource_group_name").(string) - if features.ShouldResourcesBeImported() && d.IsNewResource() { + if features.ShouldResourcesBeImported() { existing, err := client.Get(ctx, resGroup, vnetName, name, "") if err != nil { if !utils.ResponseWasNotFound(existing.Response) { @@ -186,71 +167,22 @@ func resourceArmSubnetCreateUpdate(d *schema.ResourceData, meta interface{}) err locks.ByName(vnetName, VirtualNetworkResourceName) defer locks.UnlockByName(vnetName, VirtualNetworkResourceName) - properties := network.SubnetPropertiesFormat{ - AddressPrefix: &addressPrefix, - } - - if v, ok := d.GetOk("enforce_private_link_service_network_policies"); ok { - // To enable private endpoints you must disable the network policies for the - // subnet because Network policies like network security groups are not - // supported by private endpoints. - if v.(bool) { - properties.PrivateLinkServiceNetworkPolicies = utils.String("Disabled") - } - } + privateEndpointNetworkPolicies := d.Get("enforce_private_link_endpoint_network_policies").(bool) + privateLinkServiceNetworkPolicies := d.Get("enforce_private_link_service_network_policies").(bool) - if v, ok := d.GetOk("network_security_group_id"); ok { - nsgId := v.(string) - properties.NetworkSecurityGroup = &network.SecurityGroup{ - ID: &nsgId, - } - - parsedNsgId, err := ParseNetworkSecurityGroupID(nsgId) - if err != nil { - return err - } - - locks.ByName(parsedNsgId.Name, networkSecurityGroupResourceName) - defer locks.UnlockByName(parsedNsgId.Name, networkSecurityGroupResourceName) - } else { - properties.NetworkSecurityGroup = nil - } - - if v, ok := d.GetOk("route_table_id"); ok { - rtId := v.(string) - properties.RouteTable = &network.RouteTable{ - ID: &rtId, - } - - parsedRouteTableId, err := ParseRouteTableID(rtId) - if err != nil { - return err - } + serviceEndpointsRaw := d.Get("service_endpoints").([]interface{}) + properties := network.SubnetPropertiesFormat{ + AddressPrefix: &addressPrefix, + ServiceEndpoints: expandSubnetServiceEndpoints(serviceEndpointsRaw), - locks.ByName(parsedRouteTableId.Name, routeTableResourceName) - defer locks.UnlockByName(parsedRouteTableId.Name, routeTableResourceName) - } else { - properties.RouteTable = nil - } - - if v, ok := d.GetOk("enforce_private_link_endpoint_network_policies"); ok { - // This is strange logic, but to get the schema to make sense for the end user - // I exposed it with the same name that the Azure CLI does to be consistent - // between the tool sets, which means true == Disabled. - // - // To enable private endpoints you must disable the network policies for the - // subnet because Network policies like network security groups are not - // supported by private endpoints. - if v.(bool) { - properties.PrivateEndpointNetworkPolicies = utils.String("Disabled") - } + // To enable private endpoints you must disable the network policies for the subnet because + // Network policies like network security groups are not supported by private endpoints. + PrivateEndpointNetworkPolicies: expandSubnetPrivateLinkNetworkPolicy(privateEndpointNetworkPolicies), + PrivateLinkServiceNetworkPolicies: expandSubnetPrivateLinkNetworkPolicy(privateLinkServiceNetworkPolicies), } - serviceEndpoints := expandSubnetServiceEndpoints(d) - properties.ServiceEndpoints = &serviceEndpoints - - delegations := expandSubnetDelegation(d) - properties.Delegations = &delegations + delegationsRaw := d.Get("delegation").([]interface{}) + properties.Delegations = expandSubnetDelegation(delegationsRaw) subnet := network.Subnet{ Name: &name, @@ -279,6 +211,73 @@ func resourceArmSubnetCreateUpdate(d *schema.ResourceData, meta interface{}) err return resourceArmSubnetRead(d, meta) } +func resourceArmSubnetUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Network.SubnetsClient + ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + networkName := id.Path["virtualNetworks"] + name := id.Path["subnets"] + + existing, err := client.Get(ctx, resourceGroup, networkName, name, "") + if err != nil { + return fmt.Errorf("Error retrieving existing Subnet %q (Virtual Network %q / Resource Group %q): %+v", name, networkName, resourceGroup, err) + } + + if existing.SubnetPropertiesFormat == nil { + return fmt.Errorf("Error retrieving existing Subnet %q (Virtual Network %q / Resource Group %q): `properties` was nil", name, networkName, resourceGroup) + } + + // TODO: locking on the NSG/Route Table if applicable + + props := *existing.SubnetPropertiesFormat + + if d.HasChange("address_prefix") { + props.AddressPrefix = utils.String(d.Get("address_prefix").(string)) + } + + if d.HasChange("delegation") { + delegationsRaw := d.Get("delegation").([]interface{}) + props.Delegations = expandSubnetDelegation(delegationsRaw) + } + + if d.HasChange("enforce_private_link_endpoint_network_policies") { + v := d.Get("enforce_private_link_endpoint_network_policies").(bool) + props.PrivateEndpointNetworkPolicies = expandSubnetPrivateLinkNetworkPolicy(v) + } + + if d.HasChange("enforce_private_link_service_network_policies") { + v := d.Get("enforce_private_link_service_network_policies").(bool) + props.PrivateLinkServiceNetworkPolicies = expandSubnetPrivateLinkNetworkPolicy(v) + } + + if d.HasChange("service_endpoints") { + serviceEndpointsRaw := d.Get("service_endpoints").([]interface{}) + props.ServiceEndpoints = expandSubnetServiceEndpoints(serviceEndpointsRaw) + } + + subnet := network.Subnet{ + Name: utils.String(name), + SubnetPropertiesFormat: &props, + } + + future, err := client.CreateOrUpdate(ctx, resourceGroup, networkName, name, subnet) + if err != nil { + return fmt.Errorf("Error updating Subnet %q (Virtual Network %q / Resource Group %q): %+v", name, networkName, resourceGroup, err) + } + + if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for update of Subnet %q (Virtual Network %q / Resource Group %q): %+v", name, networkName, resourceGroup, err) + } + + return resourceArmSubnetRead(d, meta) +} + func resourceArmSubnetRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.SubnetsClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) @@ -288,71 +287,38 @@ func resourceArmSubnetRead(d *schema.ResourceData, meta interface{}) error { if err != nil { return err } - resGroup := id.ResourceGroup - vnetName := id.Path["virtualNetworks"] + resourceGroup := id.ResourceGroup + networkName := id.Path["virtualNetworks"] name := id.Path["subnets"] - resp, err := client.Get(ctx, resGroup, vnetName, name, "") + resp, err := client.Get(ctx, resourceGroup, networkName, name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error making Read request on Azure Subnet %q: %+v", name, err) + return fmt.Errorf("Error retrieving Subnet %q (Virtual Network %q / Resource Group %q): %+v", name, networkName, resourceGroup, err) } d.Set("name", name) - d.Set("resource_group_name", resGroup) - d.Set("virtual_network_name", vnetName) + d.Set("resource_group_name", resourceGroup) + d.Set("virtual_network_name", networkName) if props := resp.SubnetPropertiesFormat; props != nil { d.Set("address_prefix", props.AddressPrefix) - if p := props.PrivateLinkServiceNetworkPolicies; p != nil { - // To enable private endpoints you must disable the network policies for the - // subnet because Network policies like network security groups are not - // supported by private endpoints. - - d.Set("enforce_private_link_service_network_policies", strings.EqualFold("Disabled", *p)) - } - - var securityGroupId *string - if props.NetworkSecurityGroup != nil { - securityGroupId = props.NetworkSecurityGroup.ID - } - d.Set("network_security_group_id", securityGroupId) - - var routeTableId string - if props.RouteTable != nil && props.RouteTable.ID != nil { - routeTableId = *props.RouteTable.ID + delegation := flattenSubnetDelegation(props.Delegations) + if err := d.Set("delegation", delegation); err != nil { + return fmt.Errorf("Error flattening `delegation`: %+v", err) } - d.Set("route_table_id", routeTableId) - ips := flattenSubnetIPConfigurations(props.IPConfigurations) - if err := d.Set("ip_configurations", ips); err != nil { - return err - } + d.Set("enforce_private_link_endpoint_network_policies", flattenSubnetPrivateLinkNetworkPolicy(props.PrivateEndpointNetworkPolicies)) + d.Set("enforce_private_link_service_network_policies", flattenSubnetPrivateLinkNetworkPolicy(props.PrivateLinkServiceNetworkPolicies)) serviceEndpoints := flattenSubnetServiceEndpoints(props.ServiceEndpoints) if err := d.Set("service_endpoints", serviceEndpoints); err != nil { - return err - } - - // This is strange logic, but to get the schema to make sense for the end user - // I exposed it with the same name that the Azure CLI does to be consistent - // between the tool sets, which means true == Disabled. - // - // To enable private endpoints you must disable the network policies for the - // subnet because Network policies like network security groups are not - // supported by private endpoints. - if privateEndpointNetworkPolicies := props.PrivateEndpointNetworkPolicies; privateEndpointNetworkPolicies != nil { - d.Set("enforce_private_link_endpoint_network_policies", *privateEndpointNetworkPolicies == "Disabled") - } - - delegation := flattenSubnetDelegation(props.Delegations) - if err := d.Set("delegation", delegation); err != nil { - return fmt.Errorf("Error flattening `delegation`: %+v", err) + return fmt.Errorf("Error setting `service_endpoints`: %+v", err) } } @@ -368,55 +334,32 @@ func resourceArmSubnetDelete(d *schema.ResourceData, meta interface{}) error { if err != nil { return err } - resGroup := id.ResourceGroup + resourceGroup := id.ResourceGroup name := id.Path["subnets"] - vnetName := id.Path["virtualNetworks"] + networkName := id.Path["virtualNetworks"] - if v, ok := d.GetOk("network_security_group_id"); ok { - networkSecurityGroupId := v.(string) - parsedNetworkSecurityGroupId, err2 := ParseNetworkSecurityGroupID(networkSecurityGroupId) - if err2 != nil { - return err2 - } - - locks.ByName(parsedNetworkSecurityGroupId.Name, networkSecurityGroupResourceName) - defer locks.UnlockByName(parsedNetworkSecurityGroupId.Name, networkSecurityGroupResourceName) - } - - if v, ok := d.GetOk("route_table_id"); ok { - rtId := v.(string) - parsedRouteTableId, err2 := ParseRouteTableID(rtId) - if err2 != nil { - return err2 - } - - locks.ByName(parsedRouteTableId.Name, routeTableResourceName) - defer locks.UnlockByName(parsedRouteTableId.Name, routeTableResourceName) - } - - locks.ByName(vnetName, VirtualNetworkResourceName) - defer locks.UnlockByName(vnetName, VirtualNetworkResourceName) + locks.ByName(networkName, VirtualNetworkResourceName) + defer locks.UnlockByName(networkName, VirtualNetworkResourceName) locks.ByName(name, SubnetResourceName) defer locks.UnlockByName(name, SubnetResourceName) - future, err := client.Delete(ctx, resGroup, vnetName, name) + future, err := client.Delete(ctx, resourceGroup, networkName, name) if err != nil { - return fmt.Errorf("Error deleting Subnet %q (Virtual Network %q / Resource Group %q): %+v", name, vnetName, resGroup, err) + return fmt.Errorf("Error deleting Subnet %q (Virtual Network %q / Resource Group %q): %+v", name, networkName, resourceGroup, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for completion for Subnet %q (Virtual Network %q / Resource Group %q): %+v", name, vnetName, resGroup, err) + return fmt.Errorf("Error waiting for deletion of Subnet %q (Virtual Network %q / Resource Group %q): %+v", name, networkName, resourceGroup, err) } return nil } -func expandSubnetServiceEndpoints(d *schema.ResourceData) []network.ServiceEndpointPropertiesFormat { - serviceEndpoints := d.Get("service_endpoints").([]interface{}) +func expandSubnetServiceEndpoints(input []interface{}) *[]network.ServiceEndpointPropertiesFormat { endpoints := make([]network.ServiceEndpointPropertiesFormat, 0) - for _, svcEndpointRaw := range serviceEndpoints { + for _, svcEndpointRaw := range input { if svc, ok := svcEndpointRaw.(string); ok { endpoint := network.ServiceEndpointPropertiesFormat{ Service: &svc, @@ -425,7 +368,7 @@ func expandSubnetServiceEndpoints(d *schema.ResourceData) []network.ServiceEndpo } } - return endpoints + return &endpoints } func flattenSubnetServiceEndpoints(serviceEndpoints *[]network.ServiceEndpointPropertiesFormat) []string { @@ -444,23 +387,10 @@ func flattenSubnetServiceEndpoints(serviceEndpoints *[]network.ServiceEndpointPr return endpoints } -func flattenSubnetIPConfigurations(ipConfigurations *[]network.IPConfiguration) []string { - ips := make([]string, 0) - - if ipConfigurations != nil { - for _, ip := range *ipConfigurations { - ips = append(ips, *ip.ID) - } - } - - return ips -} - -func expandSubnetDelegation(d *schema.ResourceData) []network.Delegation { - delegations := d.Get("delegation").([]interface{}) +func expandSubnetDelegation(input []interface{}) *[]network.Delegation { retDelegations := make([]network.Delegation, 0) - for _, deleValue := range delegations { + for _, deleValue := range input { deleData := deleValue.(map[string]interface{}) deleName := deleData["name"].(string) srvDelegations := deleData["service_delegation"].([]interface{}) @@ -485,7 +415,7 @@ func expandSubnetDelegation(d *schema.ResourceData) []network.Delegation { retDelegations = append(retDelegations, retDelegation) } - return retDelegations + return &retDelegations } func flattenSubnetDelegation(delegations *[]network.Delegation) []interface{} { @@ -522,3 +452,27 @@ func flattenSubnetDelegation(delegations *[]network.Delegation) []interface{} { return retDeles } + +// TODO: confirm this logic below + +func expandSubnetPrivateLinkNetworkPolicy(enabled bool) *string { + // This is strange logic, but to get the schema to make sense for the end user + // I exposed it with the same name that the Azure CLI does to be consistent + // between the tool sets, which means true == Disabled. + if enabled { + return utils.String("Disabled") + } + + return utils.String("Enabled") +} + +func flattenSubnetPrivateLinkNetworkPolicy(input *string) bool { + // This is strange logic, but to get the schema to make sense for the end user + // I exposed it with the same name that the Azure CLI does to be consistent + // between the tool sets, which means true == Disabled. + if input == nil { + return false + } + + return strings.EqualFold(*input, "Disabled") +} diff --git a/azurerm/internal/services/network/resource_arm_virtual_network.go b/azurerm/internal/services/network/resource_arm_virtual_network.go index 3bc5e00805675..25f761ef7e8b8 100644 --- a/azurerm/internal/services/network/resource_arm_virtual_network.go +++ b/azurerm/internal/services/network/resource_arm_virtual_network.go @@ -178,7 +178,7 @@ func resourceArmVirtualNetworkCreateUpdate(d *schema.ResourceData, meta interfac networkSecurityGroupName := parsedNsgID.Path["networkSecurityGroups"] - if !SliceContainsValue(networkSecurityGroupNames, networkSecurityGroupName) { + if !azure.SliceContainsValue(networkSecurityGroupNames, networkSecurityGroupName) { networkSecurityGroupNames = append(networkSecurityGroupNames, networkSecurityGroupName) } } @@ -297,7 +297,7 @@ func expandVirtualNetworkProperties(ctx context.Context, d *schema.ResourceData, name := subnet["name"].(string) log.Printf("[INFO] setting subnets inside vNet, processing %q", name) - //since subnets can also be created outside of vNet definition (as root objects) + // since subnets can also be created outside of vNet definition (as root objects) // do a GET on subnet properties from the server before setting them resGroup := d.Get("resource_group_name").(string) vnetName := d.Get("name").(string) @@ -310,7 +310,7 @@ func expandVirtualNetworkProperties(ctx context.Context, d *schema.ResourceData, prefix := subnet["address_prefix"].(string) secGroup := subnet["security_group"].(string) - //set the props from config and leave the rest intact + // set the props from config and leave the rest intact subnetObj.Name = &name if subnetObj.SubnetPropertiesFormat == nil { subnetObj.SubnetPropertiesFormat = &network.SubnetPropertiesFormat{} @@ -452,7 +452,7 @@ func getExistingSubnet(ctx context.Context, resGroup string, vnetName string, su if resp.StatusCode == http.StatusNotFound { return &network.Subnet{}, nil } - //raise an error if there was an issue other than 404 in getting subnet properties + // raise an error if there was an issue other than 404 in getting subnet properties return nil, err } @@ -480,7 +480,7 @@ func expandAzureRmVirtualNetworkVirtualNetworkSecurityGroupNames(d *schema.Resou networkSecurityGroupName := parsedNsgID.Path["networkSecurityGroups"] - if !SliceContainsValue(nsgNames, networkSecurityGroupName) { + if !azure.SliceContainsValue(nsgNames, networkSecurityGroupName) { nsgNames = append(nsgNames, networkSecurityGroupName) } } diff --git a/azurerm/internal/services/network/resource_arm_virtual_network_peering.go b/azurerm/internal/services/network/resource_arm_virtual_network_peering.go index 43f796abd0890..d9d9dbc4fa5ea 100644 --- a/azurerm/internal/services/network/resource_arm_virtual_network_peering.go +++ b/azurerm/internal/services/network/resource_arm_virtual_network_peering.go @@ -63,7 +63,7 @@ func resourceArmVirtualNetworkPeering() *schema.Resource { "allow_virtual_network_access": { Type: schema.TypeBool, Optional: true, - Computed: true, + Default: true, }, "allow_forwarded_traffic": { diff --git a/azurerm/internal/services/network/resource_arm_virtual_wan.go b/azurerm/internal/services/network/resource_arm_virtual_wan.go index 0fd574bf28150..d0d49e7c82a06 100644 --- a/azurerm/internal/services/network/resource_arm_virtual_wan.go +++ b/azurerm/internal/services/network/resource_arm_virtual_wan.go @@ -77,14 +77,13 @@ func resourceArmVirtualWan() *schema.Resource { Default: string(network.OfficeTrafficCategoryNone), }, - "tags": tags.Schema(), - - // Remove in 2.0 - "security_provider_name": { - Type: schema.TypeString, - Optional: true, - Deprecated: "This field has been removed by Azure and will be removed in version 2.0 of the Azure Provider", + "type": { + Type: schema.TypeString, + Optional: true, + Default: "Standard", }, + + "tags": tags.Schema(), }, } } @@ -103,6 +102,7 @@ func resourceArmVirtualWanCreateUpdate(d *schema.ResourceData, meta interface{}) allowBranchToBranchTraffic := d.Get("allow_branch_to_branch_traffic").(bool) allowVnetToVnetTraffic := d.Get("allow_vnet_to_vnet_traffic").(bool) office365LocalBreakoutCategory := d.Get("office365_local_breakout_category").(string) + virtualWanType := d.Get("type").(string) t := d.Get("tags").(map[string]interface{}) if features.ShouldResourcesBeImported() && d.IsNewResource() { @@ -126,6 +126,7 @@ func resourceArmVirtualWanCreateUpdate(d *schema.ResourceData, meta interface{}) AllowBranchToBranchTraffic: utils.Bool(allowBranchToBranchTraffic), AllowVnetToVnetTraffic: utils.Bool(allowVnetToVnetTraffic), Office365LocalBreakoutCategory: network.OfficeTrafficCategory(office365LocalBreakoutCategory), + Type: utils.String(virtualWanType), }, } @@ -184,6 +185,7 @@ func resourceArmVirtualWanRead(d *schema.ResourceData, meta interface{}) error { d.Set("allow_branch_to_branch_traffic", props.AllowBranchToBranchTraffic) d.Set("allow_vnet_to_vnet_traffic", props.AllowVnetToVnetTraffic) d.Set("office365_local_breakout_category", props.Office365LocalBreakoutCategory) + d.Set("type", props.Type) } return tags.FlattenAndSet(d, resp.Tags) diff --git a/azurerm/internal/services/network/tests/data_source_application_security_group_test.go b/azurerm/internal/services/network/tests/data_source_application_security_group_test.go index 4ab4b31459be6..462b22f1a7796 100644 --- a/azurerm/internal/services/network/tests/data_source_application_security_group_test.go +++ b/azurerm/internal/services/network/tests/data_source_application_security_group_test.go @@ -49,6 +49,10 @@ func TestAccDataSourceAzureRMApplicationSecurityGroup_complete(t *testing.T) { func testAccDataSourceApplicationSecurityGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -56,19 +60,23 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_security_group" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } data "azurerm_application_security_group" "test" { - name = "${azurerm_application_security_group.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_application_security_group.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccDataSourceApplicationSecurityGroup_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -76,8 +84,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_security_group" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { Hello = "World" @@ -85,8 +93,8 @@ resource "azurerm_application_security_group" "test" { } data "azurerm_application_security_group" "test" { - name = "${azurerm_application_security_group.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_application_security_group.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/data_source_express_route_circuit_test.go b/azurerm/internal/services/network/tests/data_source_express_route_circuit_test.go index e0e824f3caabb..8af2ef47bf3c6 100644 --- a/azurerm/internal/services/network/tests/data_source_express_route_circuit_test.go +++ b/azurerm/internal/services/network/tests/data_source_express_route_circuit_test.go @@ -37,9 +37,9 @@ func testAccDataSourceAzureRMExpressRoute_basic(data acceptance.TestData) string return fmt.Sprintf(` %s -data "azurerm_express_route_circuit" test { - resource_group_name = "${azurerm_resource_group.test.name}" - name = "${azurerm_express_route_circuit.test.name}" +data "azurerm_express_route_circuit" "test" { + resource_group_name = azurerm_resource_group.test.name + name = azurerm_express_route_circuit.test.name } `, config) } diff --git a/azurerm/internal/services/network/tests/data_source_firewall_test.go b/azurerm/internal/services/network/tests/data_source_firewall_test.go index 8b6fa76c17a61..7144d209f6e2b 100644 --- a/azurerm/internal/services/network/tests/data_source_firewall_test.go +++ b/azurerm/internal/services/network/tests/data_source_firewall_test.go @@ -29,6 +29,10 @@ func TestAccDataSourceAzureRMFirewall_basic(t *testing.T) { func testAccDataSourceFirewall_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -37,40 +41,40 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "AzureFirewallSubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_firewall" "test" { name = "acctestfirewall%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "configuration" - subnet_id = "${azurerm_subnet.test.id}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + subnet_id = azurerm_subnet.test.id + public_ip_address_id = azurerm_public_ip.test.id } } data "azurerm_firewall" "test" { - name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/data_source_loadbalancer_backend_address_pool_test.go b/azurerm/internal/services/network/tests/data_source_loadbalancer_backend_address_pool_test.go index e9331c97908f1..8fc7d6de8dfab 100644 --- a/azurerm/internal/services/network/tests/data_source_loadbalancer_backend_address_pool_test.go +++ b/azurerm/internal/services/network/tests/data_source_loadbalancer_backend_address_pool_test.go @@ -34,8 +34,8 @@ func testAccAzureRMDataSourceLoadBalancerBackEndAddressPool_basic(data acceptanc %s data "azurerm_lb_backend_address_pool" "test" { - name = "${azurerm_lb_backend_address_pool.test.name}" - loadbalancer_id = "${azurerm_lb_backend_address_pool.test.loadbalancer_id}" + name = azurerm_lb_backend_address_pool.test.name + loadbalancer_id = azurerm_lb_backend_address_pool.test.loadbalancer_id } `, resource) } diff --git a/azurerm/internal/services/network/tests/data_source_loadbalancer_test.go b/azurerm/internal/services/network/tests/data_source_loadbalancer_test.go index 50b056d5adada..2d9f89ba71c09 100644 --- a/azurerm/internal/services/network/tests/data_source_loadbalancer_test.go +++ b/azurerm/internal/services/network/tests/data_source_loadbalancer_test.go @@ -33,8 +33,8 @@ func testAccAzureRMDataSourceLoadBalancer_basic(data acceptance.TestData) string %s data "azurerm_lb" "test" { - name = "${azurerm_lb.test.name}" - resource_group_name = "${azurerm_lb.test.resource_group_name}" + name = azurerm_lb.test.name + resource_group_name = azurerm_lb.test.resource_group_name } `, resource) } diff --git a/azurerm/internal/services/network/tests/data_source_nat_gateway_test.go b/azurerm/internal/services/network/tests/data_source_nat_gateway_test.go index efc71a2869382..c9607ed50faea 100644 --- a/azurerm/internal/services/network/tests/data_source_nat_gateway_test.go +++ b/azurerm/internal/services/network/tests/data_source_nat_gateway_test.go @@ -51,8 +51,8 @@ func testAccDataSourceNatGateway_basic(data acceptance.TestData) string { %s data "azurerm_nat_gateway" "test" { - resource_group_name = "${azurerm_nat_gateway.test.resource_group_name}" - name = "${azurerm_nat_gateway.test.name}" + resource_group_name = azurerm_nat_gateway.test.resource_group_name + name = azurerm_nat_gateway.test.name } `, config) } @@ -63,8 +63,8 @@ func testAccDataSourceNatGateway_complete(data acceptance.TestData) string { %s data "azurerm_nat_gateway" "test" { - resource_group_name = "${azurerm_nat_gateway.test.resource_group_name}" - name = "${azurerm_nat_gateway.test.name}" + resource_group_name = azurerm_nat_gateway.test.resource_group_name + name = azurerm_nat_gateway.test.name } `, config) } diff --git a/azurerm/internal/services/network/tests/data_source_network_ddos_protection_plan_test.go b/azurerm/internal/services/network/tests/data_source_network_ddos_protection_plan_test.go index e4680a4e97927..cd72c0f71ed91 100644 --- a/azurerm/internal/services/network/tests/data_source_network_ddos_protection_plan_test.go +++ b/azurerm/internal/services/network/tests/data_source_network_ddos_protection_plan_test.go @@ -32,8 +32,8 @@ func testAccAzureRMNetworkDDoSProtectionPlanDataSource_basicConfig(data acceptan %s data "azurerm_network_ddos_protection_plan" "test" { - name = "${azurerm_network_ddos_protection_plan.test.name}" - resource_group_name = "${azurerm_network_ddos_protection_plan.test.resource_group_name}" + name = azurerm_network_ddos_protection_plan.test.name + resource_group_name = azurerm_network_ddos_protection_plan.test.resource_group_name } `, testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(data)) } diff --git a/azurerm/internal/services/network/tests/data_source_network_interface_test.go b/azurerm/internal/services/network/tests/data_source_network_interface_test.go index e4c0bd02235ec..c40a91de9e186 100644 --- a/azurerm/internal/services/network/tests/data_source_network_interface_test.go +++ b/azurerm/internal/services/network/tests/data_source_network_interface_test.go @@ -8,124 +8,34 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) -func TestAccDataSourceArmVirtualNetworkInterface_basic(t *testing.T) { +func TestAccDataSourceArmNetworkInterface_basic(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_network_interface", "test") - name := fmt.Sprintf("acctest-nic-%d", data.RandomInteger) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceArmVirtualNetworkInterface_basic(data), + Config: testAccAzureRMNetworkInterface_static(data), }, { - Config: testAccDataSourceArmVirtualNetworkInterface_withDataSource(data), + Config: testAccDataSourceNetworkInterface_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(data.ResourceName, "name", name), - resource.TestCheckResourceAttrSet(data.ResourceName, "id"), - resource.TestCheckResourceAttr(data.ResourceName, "private_ip_address", "10.0.1.4"), - resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttr(data.ResourceName, "private_ip_address", "10.0.2.15"), ), }, }, }) } -func testAccDataSourceArmVirtualNetworkInterface_basic(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctest-%d-rg" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctest-vn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_network_security_group" "test" { - name = "acctest-nsg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "subnet1" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.1.0/24" -} - -resource "azurerm_network_interface" "test" { - name = "acctest-nic-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_security_group_id = "${azurerm_network_security_group.test.id}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - } - - tags = { - environment = "staging" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testAccDataSourceArmVirtualNetworkInterface_withDataSource(data acceptance.TestData) string { +func testAccDataSourceNetworkInterface_basic(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_static(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctest-%d-rg" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctest-vn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_network_security_group" "test" { - name = "acctest-nsg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "subnet1" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.1.0/24" -} - -resource "azurerm_network_interface" "test" { - name = "acctest-nic-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_security_group_id = "${azurerm_network_security_group.test.id}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - } - - tags = { - environment = "staging" - } -} +%s data "azurerm_network_interface" "test" { - name = "acctest-nic-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_network_interface.test.name + resource_group_name = azurerm_network_interface.test.resource_group_name } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template) } diff --git a/azurerm/internal/services/network/tests/data_source_network_security_group_test.go b/azurerm/internal/services/network/tests/data_source_network_security_group_test.go index 3132a66de2833..f7e0b0996f57a 100644 --- a/azurerm/internal/services/network/tests/data_source_network_security_group_test.go +++ b/azurerm/internal/services/network/tests/data_source_network_security_group_test.go @@ -80,6 +80,10 @@ func TestAccDataSourceAzureRMNetworkSecurityGroup_tags(t *testing.T) { func testAccDataSourceAzureRMNetworkSecurityGroupBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -87,19 +91,23 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_security_group" "test" { name = "acctestnsg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } data "azurerm_network_security_group" "test" { - name = "${azurerm_network_security_group.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_network_security_group.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccDataSourceAzureRMNetworkSecurityGroupWithRules(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -107,8 +115,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_security_group" "test" { name = "acctestnsg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name security_rule { name = "test123" @@ -124,14 +132,18 @@ resource "azurerm_network_security_group" "test" { } data "azurerm_network_security_group" "test" { - name = "${azurerm_network_security_group.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_network_security_group.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccDataSourceAzureRMNetworkSecurityGroupTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -139,8 +151,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_security_group" "test" { name = "acctestnsg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { environment = "staging" @@ -148,8 +160,8 @@ resource "azurerm_network_security_group" "test" { } data "azurerm_network_security_group" "test" { - name = "${azurerm_network_security_group.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_network_security_group.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/data_source_network_watcher_test.go b/azurerm/internal/services/network/tests/data_source_network_watcher_test.go index 5677cb7f271f4..ffb426387eda6 100644 --- a/azurerm/internal/services/network/tests/data_source_network_watcher_test.go +++ b/azurerm/internal/services/network/tests/data_source_network_watcher_test.go @@ -35,6 +35,10 @@ func testAccDataSourceAzureRMNetworkWatcher_basic(t *testing.T) { func testAccDataSourceAzureRMNetworkWatcher_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -42,8 +46,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_watcher" "test" { name = "acctestnw-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { env = "test" @@ -51,8 +55,8 @@ resource "azurerm_network_watcher" "test" { } data "azurerm_network_watcher" "test" { - name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/data_source_private_link_endpoint_connection_test.go b/azurerm/internal/services/network/tests/data_source_private_link_endpoint_connection_test.go deleted file mode 100644 index ede0b0744a080..0000000000000 --- a/azurerm/internal/services/network/tests/data_source_private_link_endpoint_connection_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package tests - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMPrivateLinkEndpointConnection_complete(t *testing.T) { - data := acceptance.BuildTestData(t, "data.azurerm_private_link_endpoint_connection", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourcePrivateLinkEndpointConnection_complete(data), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(data.ResourceName, "private_service_connection.0.status", "Approved"), - ), - }, - }, - }) -} - -func testAccDataSourcePrivateLinkEndpointConnection_complete(data acceptance.TestData) string { - return fmt.Sprintf(` -%s - -data "azurerm_private_link_endpoint_connection" "test" { - name = azurerm_private_link_endpoint.test.name - resource_group_name = azurerm_resource_group.test.name -} -`, testAccAzureRMPrivateLinkEndpoint_basic(data)) -} diff --git a/azurerm/internal/services/network/tests/data_source_public_ip_prefix_test.go b/azurerm/internal/services/network/tests/data_source_public_ip_prefix_test.go index ca697c199dcab..35886a8ef1e32 100644 --- a/azurerm/internal/services/network/tests/data_source_public_ip_prefix_test.go +++ b/azurerm/internal/services/network/tests/data_source_public_ip_prefix_test.go @@ -36,6 +36,10 @@ func TestAccDataSourceAzureRMPublicIPPrefix_basic(t *testing.T) { func testAccDataSourceAzureRMPublicIPPrefixBasic(name string, resourceGroupName string, data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "%s" location = "%s" diff --git a/azurerm/internal/services/network/tests/data_source_public_ip_test.go b/azurerm/internal/services/network/tests/data_source_public_ip_test.go index 58fb3ac2bb955..5e4aaaca6d38b 100644 --- a/azurerm/internal/services/network/tests/data_source_public_ip_test.go +++ b/azurerm/internal/services/network/tests/data_source_public_ip_test.go @@ -67,6 +67,10 @@ func TestAccDataSourceAzureRMPublicIP_dynamic(t *testing.T) { func testAccDataSourceAzureRMPublicIP_static(name string, resourceGroupName string, data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "%s" location = "%s" @@ -74,8 +78,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" domain_name_label = "acctest-%d" idle_timeout_in_minutes = 30 @@ -86,14 +90,18 @@ resource "azurerm_public_ip" "test" { } data "azurerm_public_ip" "test" { - name = "${azurerm_public_ip.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_public_ip.test.name + resource_group_name = azurerm_resource_group.test.name } `, resourceGroupName, data.Locations.Primary, name, data.RandomInteger) } func testAccDataSourceAzureRMPublicIP_dynamic(data acceptance.TestData, ipVersion string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -101,8 +109,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" ip_version = "%s" @@ -113,8 +121,8 @@ resource "azurerm_public_ip" "test" { } data "azurerm_public_ip" "test" { - name = "${azurerm_public_ip.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_public_ip.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, ipVersion) } diff --git a/azurerm/internal/services/network/tests/data_source_public_ips_test.go b/azurerm/internal/services/network/tests/data_source_public_ips_test.go index 33102ed2129c4..8cd0a13a0cb3c 100644 --- a/azurerm/internal/services/network/tests/data_source_public_ips_test.go +++ b/azurerm/internal/services/network/tests/data_source_public_ips_test.go @@ -89,6 +89,10 @@ func TestAccDataSourceAzureRMPublicIPs_allocationType(t *testing.T) { func testAccDataSourceAzureRMPublicIPs_attached(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -97,8 +101,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { count = 7 name = "acctestpip%s-${count.index}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" idle_timeout_in_minutes = 30 @@ -110,12 +114,12 @@ resource "azurerm_public_ip" "test" { resource "azurerm_lb" "test" { count = 3 name = "acctestlb-${count.index}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "frontend" - public_ip_address_id = "${element(azurerm_public_ip.test.*.id, count.index)}" + public_ip_address_id = element(azurerm_public_ip.test.*.id, count.index) } } `, data.RandomInteger, data.Locations.Primary, data.RandomString) @@ -127,12 +131,12 @@ func testAccDataSourceAzureRMPublicIPs_attachedDataSource(data acceptance.TestDa %s data "azurerm_public_ips" "unattached" { - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name attached = false } data "azurerm_public_ips" "attached" { - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name attached = true } `, resources) @@ -140,6 +144,10 @@ data "azurerm_public_ips" "attached" { func testAccDataSourceAzureRMPublicIPs_prefix(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -148,8 +156,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { count = 2 name = "acctestpipb%s-${count.index}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" idle_timeout_in_minutes = 30 @@ -161,8 +169,8 @@ resource "azurerm_public_ip" "test" { resource "azurerm_public_ip" "test2" { count = 2 name = "acctestpipa%s-${count.index}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" idle_timeout_in_minutes = 30 @@ -179,7 +187,7 @@ func testAccDataSourceAzureRMPublicIPs_prefixDataSource(data acceptance.TestData %s data "azurerm_public_ips" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name name_prefix = "acctestpipa" } `, prefixed) @@ -187,6 +195,10 @@ data "azurerm_public_ips" "test" { func testAccDataSourceAzureRMPublicIPs_allocationType(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -195,8 +207,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "dynamic" { count = 4 name = "acctestpipd%s-${count.index}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" idle_timeout_in_minutes = 30 @@ -208,8 +220,8 @@ resource "azurerm_public_ip" "dynamic" { resource "azurerm_public_ip" "static" { count = 3 name = "acctestpips%s-${count.index}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" idle_timeout_in_minutes = 30 @@ -226,12 +238,12 @@ func testAccDataSourceAzureRMPublicIPs_allocationTypeDataSources(data acceptance %s data "azurerm_public_ips" "dynamic" { - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name allocation_type = "Dynamic" } data "azurerm_public_ips" "static" { - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name allocation_type = "Static" } `, allocationType) diff --git a/azurerm/internal/services/network/tests/data_source_route_table_test.go b/azurerm/internal/services/network/tests/data_source_route_table_test.go index 371c2cac59d1b..f728c0af0714a 100644 --- a/azurerm/internal/services/network/tests/data_source_route_table_test.go +++ b/azurerm/internal/services/network/tests/data_source_route_table_test.go @@ -80,8 +80,8 @@ func testAccDataSourceAzureRMRouteTable_basic(data acceptance.TestData) string { %s data "azurerm_route_table" "test" { - name = "${azurerm_route_table.test.name}" - resource_group_name = "${azurerm_route_table.test.resource_group_name}" + name = azurerm_route_table.test.name + resource_group_name = azurerm_route_table.test.resource_group_name } `, r) } @@ -92,8 +92,8 @@ func testAccDataSourceAzureRMRouteTable_singleRoute(data acceptance.TestData) st %s data "azurerm_route_table" "test" { - name = "${azurerm_route_table.test.name}" - resource_group_name = "${azurerm_route_table.test.resource_group_name}" + name = azurerm_route_table.test.name + resource_group_name = azurerm_route_table.test.resource_group_name } `, r) } @@ -104,8 +104,8 @@ func testAccDataSourceAzureRMRouteTable_multipleRoutes(data acceptance.TestData) %s data "azurerm_route_table" "test" { - name = "${azurerm_route_table.test.name}" - resource_group_name = "${azurerm_route_table.test.resource_group_name}" + name = azurerm_route_table.test.name + resource_group_name = azurerm_route_table.test.resource_group_name } `, r) } diff --git a/azurerm/internal/services/network/tests/data_source_subnet_test.go b/azurerm/internal/services/network/tests/data_source_subnet_test.go index 89440f431cfa2..a18b1f9309fe7 100644 --- a/azurerm/internal/services/network/tests/data_source_subnet_test.go +++ b/azurerm/internal/services/network/tests/data_source_subnet_test.go @@ -8,7 +8,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) -func TestAccDataSourceAzureRMSubnet_basic(t *testing.T) { +func TestAccDataSourceSubnet_basic(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ @@ -16,7 +16,7 @@ func TestAccDataSourceAzureRMSubnet_basic(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMSubnet_basic(data), + Config: testAccDataSourceSubnet_basic(data), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(data.ResourceName, "name"), resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), @@ -30,7 +30,7 @@ func TestAccDataSourceAzureRMSubnet_basic(t *testing.T) { }) } -func TestAccDataSourceAzureRMSubnet_networkSecurityGroup(t *testing.T) { +func TestAccDataSourceSubnet_networkSecurityGroup(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ @@ -38,7 +38,11 @@ func TestAccDataSourceAzureRMSubnet_networkSecurityGroup(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMSubnet_networkSecurityGroup(data), + // since the network security group association is a separate resource this forces it + Config: testAccDataSourceSubnet_networkSecurityGroupDependencies(data), + }, + { + Config: testAccDataSourceSubnet_networkSecurityGroup(data), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(data.ResourceName, "name"), resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), @@ -52,7 +56,7 @@ func TestAccDataSourceAzureRMSubnet_networkSecurityGroup(t *testing.T) { }) } -func TestAccDataSourceAzureRMSubnet_routeTable(t *testing.T) { +func TestAccDataSourceSubnet_routeTable(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ @@ -60,21 +64,25 @@ func TestAccDataSourceAzureRMSubnet_routeTable(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMSubnet_routeTable(data), + // since the route table association is a separate resource this forces it + Config: testAccDataSourceSubnet_routeTableDependencies(data), + }, + { + Config: testAccDataSourceSubnet_routeTable(data), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(data.ResourceName, "name"), resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_network_name"), resource.TestCheckResourceAttrSet(data.ResourceName, "address_prefix"), - resource.TestCheckResourceAttr(data.ResourceName, "network_security_group_id", ""), resource.TestCheckResourceAttrSet(data.ResourceName, "route_table_id"), + resource.TestCheckResourceAttr(data.ResourceName, "network_security_group_id", ""), ), }, }, }) } -func TestAccDataSourceAzureRMSubnet_serviceEndpoints(t *testing.T) { +func TestAccDataSourceSubnet_serviceEndpoints(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ @@ -82,7 +90,7 @@ func TestAccDataSourceAzureRMSubnet_serviceEndpoints(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMSubnet_serviceEndpoints(data), + Config: testAccDataSourceSubnet_serviceEndpoint(data), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(data.ResourceName, "name"), resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), @@ -99,46 +107,35 @@ func TestAccDataSourceAzureRMSubnet_serviceEndpoints(t *testing.T) { }) } -func testAccDataSourceAzureRMSubnet_basic(data acceptance.TestData) string { +func testAccDataSourceSubnet_basic(data acceptance.TestData) string { + template := testAccDataSourceSubnet_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctest%d-rg" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctest%d-vn" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "acctest%d-private" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.0.0/24" -} +%s data "azurerm_subnet" "test" { - name = "${azurerm_subnet.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + name = azurerm_subnet.test.name + virtual_network_name = azurerm_subnet.test.virtual_network_name + resource_group_name = azurerm_subnet.test.resource_group_name } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, template) } -func testAccDataSourceAzureRMSubnet_networkSecurityGroup(data acceptance.TestData) string { +func testAccDataSourceSubnet_networkSecurityGroupDependencies(data acceptance.TestData) string { + template := testAccDataSourceSubnet_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctest%d-rg" - location = "%s" +%s + +resource "azurerm_subnet" "test" { + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.0.0/24" } resource "azurerm_network_security_group" "test" { name = "acctestnsg%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name security_rule { name = "test123" @@ -153,98 +150,100 @@ resource "azurerm_network_security_group" "test" { } } -resource "azurerm_virtual_network" "test" { - name = "acctest%d-vn" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" +resource "azurerm_subnet_network_security_group_association" "test" { + subnet_id = azurerm_subnet.test.id + network_security_group_id = azurerm_network_security_group.test.id } - -resource "azurerm_subnet" "test" { - name = "acctest%d-private" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.0.0/24" - network_security_group_id = "${azurerm_network_security_group.test.id}" +`, template, data.RandomInteger) } +func testAccDataSourceSubnet_networkSecurityGroup(data acceptance.TestData) string { + template := testAccDataSourceSubnet_networkSecurityGroupDependencies(data) + return fmt.Sprintf(` +%s + data "azurerm_subnet" "test" { - name = "${azurerm_subnet.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + name = azurerm_subnet.test.name + virtual_network_name = azurerm_subnet.test.virtual_network_name + resource_group_name = azurerm_subnet.test.resource_group_name } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template) } -func testAccDataSourceAzureRMSubnet_routeTable(data acceptance.TestData) string { +func testAccDataSourceSubnet_routeTableDependencies(data acceptance.TestData) string { + template := testAccDataSourceSubnet_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +%s + +resource "azurerm_subnet" "test" { + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.0.0/24" } resource "azurerm_route_table" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "acctestrt-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name route { - name = "acctest-%d" + name = "first" address_prefix = "10.100.0.0/14" next_hop_type = "VirtualAppliance" next_hop_in_ip_address = "10.10.1.1" } } -resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" +resource "azurerm_subnet_route_table_association" "test" { + subnet_id = azurerm_subnet.test.id + route_table_id = azurerm_route_table.test.id +} +`, template, data.RandomInteger) } -resource "azurerm_subnet" "test" { - name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" - route_table_id = "${azurerm_route_table.test.id}" +func testAccDataSourceSubnet_routeTable(data acceptance.TestData) string { + template := testAccDataSourceSubnet_routeTableDependencies(data) + return fmt.Sprintf(` +%s + +data "azurerm_subnet" "test" { + name = azurerm_subnet.test.name + virtual_network_name = azurerm_subnet.test.virtual_network_name + resource_group_name = azurerm_subnet.test.resource_group_name +} +`, template) } +func testAccDataSourceSubnet_serviceEndpoint(data acceptance.TestData) string { + template := testAccAzureRMSubnet_serviceEndpointsUpdated(data) + return fmt.Sprintf(` +%s + data "azurerm_subnet" "test" { - name = "${azurerm_subnet.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + name = azurerm_subnet.test.name + virtual_network_name = azurerm_subnet.test.virtual_network_name + resource_group_name = azurerm_subnet.test.resource_group_name } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template) } -func testAccDataSourceAzureRMSubnet_serviceEndpoints(data acceptance.TestData) string { +func testAccDataSourceSubnet_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" + name = "acctest%d-rg" location = "%s" } resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" + name = "acctest%d-vn" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" - service_endpoints = ["Microsoft.Sql", "Microsoft.Storage"] -} - -data "azurerm_subnet" "test" { - name = "${azurerm_subnet.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/data_source_virtual_network_gateway_connection_test.go b/azurerm/internal/services/network/tests/data_source_virtual_network_gateway_connection_test.go index ea94063794c04..ba6934082eb46 100644 --- a/azurerm/internal/services/network/tests/data_source_virtual_network_gateway_connection_test.go +++ b/azurerm/internal/services/network/tests/data_source_virtual_network_gateway_connection_test.go @@ -100,62 +100,62 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" sku = "Basic" ip_configuration { name = "vnetGatewayConfig" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } resource "azurerm_local_network_gateway" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name gateway_address = "168.62.225.23" address_space = ["10.1.1.0/24"] } resource "azurerm_virtual_network_gateway_connection" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "IPsec" - virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test.id}" - local_network_gateway_id = "${azurerm_local_network_gateway.test.id}" + virtual_network_gateway_id = azurerm_virtual_network_gateway.test.id + local_network_gateway_id = azurerm_local_network_gateway.test.id shared_key = "4-v3ry-53cr37-1p53c-5h4r3d-k3y" } data "azurerm_virtual_network_gateway_connection" "test" { - name = "${azurerm_virtual_network_gateway_connection.test.name}" - resource_group_name = "${azurerm_virtual_network_gateway_connection.test.resource_group_name}" + name = azurerm_virtual_network_gateway_connection.test.name + resource_group_name = azurerm_virtual_network_gateway_connection.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary) } @@ -181,29 +181,29 @@ resource "azurerm_resource_group" "test_1" { resource "azurerm_virtual_network" "test_1" { name = "acctestvn-${var.random1}" - location = "${azurerm_resource_group.test_1.location}" - resource_group_name = "${azurerm_resource_group.test_1.name}" + location = azurerm_resource_group.test_1.location + resource_group_name = azurerm_resource_group.test_1.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test_1" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test_1.name}" - virtual_network_name = "${azurerm_virtual_network.test_1.name}" + resource_group_name = azurerm_resource_group.test_1.name + virtual_network_name = azurerm_virtual_network.test_1.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test_1" { name = "acctest-${var.random1}" - location = "${azurerm_resource_group.test_1.location}" - resource_group_name = "${azurerm_resource_group.test_1.name}" + location = azurerm_resource_group.test_1.location + resource_group_name = azurerm_resource_group.test_1.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test_1" { name = "acctest-${var.random1}" - location = "${azurerm_resource_group.test_1.location}" - resource_group_name = "${azurerm_resource_group.test_1.name}" + location = azurerm_resource_group.test_1.location + resource_group_name = azurerm_resource_group.test_1.name type = "Vpn" vpn_type = "RouteBased" @@ -211,22 +211,22 @@ resource "azurerm_virtual_network_gateway" "test_1" { ip_configuration { name = "vnetGatewayConfig" - public_ip_address_id = "${azurerm_public_ip.test_1.id}" + public_ip_address_id = azurerm_public_ip.test_1.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test_1.id}" + subnet_id = azurerm_subnet.test_1.id } } resource "azurerm_virtual_network_gateway_connection" "test_1" { name = "acctest-${var.random1}" - location = "${azurerm_resource_group.test_1.location}" - resource_group_name = "${azurerm_resource_group.test_1.name}" + location = azurerm_resource_group.test_1.location + resource_group_name = azurerm_resource_group.test_1.name type = "Vnet2Vnet" - virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test_1.id}" - peer_virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test_2.id}" + virtual_network_gateway_id = azurerm_virtual_network_gateway.test_1.id + peer_virtual_network_gateway_id = azurerm_virtual_network_gateway.test_2.id - shared_key = "${var.shared_key}" + shared_key = var.shared_key } resource "azurerm_resource_group" "test_2" { @@ -236,29 +236,29 @@ resource "azurerm_resource_group" "test_2" { resource "azurerm_virtual_network" "test_2" { name = "acctest-${var.random2}" - location = "${azurerm_resource_group.test_2.location}" - resource_group_name = "${azurerm_resource_group.test_2.name}" + location = azurerm_resource_group.test_2.location + resource_group_name = azurerm_resource_group.test_2.name address_space = ["10.1.0.0/16"] } resource "azurerm_subnet" "test_2" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test_2.name}" - virtual_network_name = "${azurerm_virtual_network.test_2.name}" + resource_group_name = azurerm_resource_group.test_2.name + virtual_network_name = azurerm_virtual_network.test_2.name address_prefix = "10.1.1.0/24" } resource "azurerm_public_ip" "test_2" { name = "acctest-${var.random2}" - location = "${azurerm_resource_group.test_2.location}" - resource_group_name = "${azurerm_resource_group.test_2.name}" + location = azurerm_resource_group.test_2.location + resource_group_name = azurerm_resource_group.test_2.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test_2" { name = "acctest-${var.random2}" - location = "${azurerm_resource_group.test_2.location}" - resource_group_name = "${azurerm_resource_group.test_2.name}" + location = azurerm_resource_group.test_2.location + resource_group_name = azurerm_resource_group.test_2.name type = "Vpn" vpn_type = "RouteBased" @@ -266,32 +266,32 @@ resource "azurerm_virtual_network_gateway" "test_2" { ip_configuration { name = "vnetGatewayConfig" - public_ip_address_id = "${azurerm_public_ip.test_2.id}" + public_ip_address_id = azurerm_public_ip.test_2.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test_2.id}" + subnet_id = azurerm_subnet.test_2.id } } resource "azurerm_virtual_network_gateway_connection" "test_2" { name = "acctest-${var.random2}" - location = "${azurerm_resource_group.test_2.location}" - resource_group_name = "${azurerm_resource_group.test_2.name}" + location = azurerm_resource_group.test_2.location + resource_group_name = azurerm_resource_group.test_2.name type = "Vnet2Vnet" - virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test_2.id}" - peer_virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test_1.id}" + virtual_network_gateway_id = azurerm_virtual_network_gateway.test_2.id + peer_virtual_network_gateway_id = azurerm_virtual_network_gateway.test_1.id - shared_key = "${var.shared_key}" + shared_key = var.shared_key } data "azurerm_virtual_network_gateway_connection" "test_1" { - name = "${azurerm_virtual_network_gateway_connection.test_1.name}" - resource_group_name = "${azurerm_virtual_network_gateway_connection.test_1.resource_group_name}" + name = azurerm_virtual_network_gateway_connection.test_1.name + resource_group_name = azurerm_virtual_network_gateway_connection.test_1.resource_group_name } data "azurerm_virtual_network_gateway_connection" "test_2" { - name = "${azurerm_virtual_network_gateway_connection.test_2.name}" - resource_group_name = "${azurerm_virtual_network_gateway_connection.test_2.resource_group_name}" + name = azurerm_virtual_network_gateway_connection.test_2.name + resource_group_name = azurerm_virtual_network_gateway_connection.test_2.resource_group_name } `, data.RandomInteger, rInt2, sharedKey, data.Locations.Primary, data.Locations.Secondary) } @@ -309,56 +309,56 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" sku = "VpnGw1" ip_configuration { name = "vnetGatewayConfig" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } resource "azurerm_local_network_gateway" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name gateway_address = "168.62.225.23" address_space = ["10.1.1.0/24"] } resource "azurerm_virtual_network_gateway_connection" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "IPsec" - virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test.id}" - local_network_gateway_id = "${azurerm_local_network_gateway.test.id}" + virtual_network_gateway_id = azurerm_virtual_network_gateway.test.id + local_network_gateway_id = azurerm_local_network_gateway.test.id use_policy_based_traffic_selectors = true routing_weight = 20 @@ -377,8 +377,8 @@ resource "azurerm_virtual_network_gateway_connection" "test" { } data "azurerm_virtual_network_gateway_connection" "test" { - name = "${azurerm_virtual_network_gateway_connection.test.name}" - resource_group_name = "${azurerm_virtual_network_gateway_connection.test.resource_group_name}" + name = azurerm_virtual_network_gateway_connection.test.name + resource_group_name = azurerm_virtual_network_gateway_connection.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/network/tests/data_source_virtual_network_gateway_test.go b/azurerm/internal/services/network/tests/data_source_virtual_network_gateway_test.go index 7ecd9af8bbb82..13a2763c319a2 100644 --- a/azurerm/internal/services/network/tests/data_source_virtual_network_gateway_test.go +++ b/azurerm/internal/services/network/tests/data_source_virtual_network_gateway_test.go @@ -28,6 +28,10 @@ func TestAccAzureRMDataSourceVirtualNetworkGateway_basic(t *testing.T) { func testAccAzureRMDataSourceVirtualNetworkGateway_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -35,44 +39,44 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctestvng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" sku = "Basic" ip_configuration { - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } data "azurerm_virtual_network_gateway" "test" { - name = "${azurerm_virtual_network_gateway.test.name}" - resource_group_name = "${azurerm_virtual_network_gateway.test.resource_group_name}" + name = azurerm_virtual_network_gateway.test.name + resource_group_name = azurerm_virtual_network_gateway.test.resource_group_name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/data_source_virtual_network_test.go b/azurerm/internal/services/network/tests/data_source_virtual_network_test.go index a4f9ee3167840..5b4081364f674 100644 --- a/azurerm/internal/services/network/tests/data_source_virtual_network_test.go +++ b/azurerm/internal/services/network/tests/data_source_virtual_network_test.go @@ -58,6 +58,10 @@ func TestAccDataSourceArmVirtualNetwork_peering(t *testing.T) { func testAccDataSourceArmVirtualNetwork_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctest%d-rg" location = "%s" @@ -66,8 +70,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvnet-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name dns_servers = ["10.0.0.4"] subnet { @@ -77,14 +81,18 @@ resource "azurerm_virtual_network" "test" { } data "azurerm_virtual_network" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + name = azurerm_virtual_network.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccDataSourceArmVirtualNetwork_peering(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctest%d-rg" location = "%s" @@ -93,28 +101,32 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test1" { name = "acctestvnet-1-%d" address_space = ["10.0.1.0/24"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_virtual_network" "test2" { name = "acctestvnet-2-%d" address_space = ["10.0.2.0/24"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_virtual_network_peering" "test1" { name = "peer-1to2" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test1.name}" - remote_virtual_network_id = "${azurerm_virtual_network.test2.id}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test1.name + remote_virtual_network_id = azurerm_virtual_network.test2.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testAccDataSourceArmVirtualNetwork_peeringWithDataSource(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctest%d-rg" location = "%s" @@ -123,27 +135,27 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test1" { name = "acctestvnet-1-%d" address_space = ["10.0.1.0/24"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_virtual_network" "test2" { name = "acctestvnet-2-%d" address_space = ["10.0.2.0/24"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_virtual_network_peering" "test1" { name = "peer-1to2" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test1.name}" - remote_virtual_network_id = "${azurerm_virtual_network.test2.id}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test1.name + remote_virtual_network_id = azurerm_virtual_network.test2.id } data "azurerm_virtual_network" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - name = "${azurerm_virtual_network.test1.name}" + resource_group_name = azurerm_resource_group.test.name + name = azurerm_virtual_network.test1.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_network_interface_application_security_group_association_test.go b/azurerm/internal/services/network/tests/network_interface_application_security_group_association_resource_test.go similarity index 53% rename from azurerm/internal/services/network/tests/resource_arm_network_interface_application_security_group_association_test.go rename to azurerm/internal/services/network/tests/network_interface_application_security_group_association_resource_test.go index 563976476bbf9..83743b4ef32d5 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_interface_application_security_group_association_test.go +++ b/azurerm/internal/services/network/tests/network_interface_application_security_group_association_resource_test.go @@ -27,6 +27,26 @@ func TestAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(t * testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationExists(data.ResourceName), ), }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_multipleIPConfigurations(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_interface_application_security_group_association", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + // intentional as this is a Virtual Resource + CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_multipleIPConfigurations(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), }, }) } @@ -79,6 +99,32 @@ func TestAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_deleted(t }) } +func TestAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_updateNIC(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_interface_application_security_group_association", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + // intentional as this is a Virtual Resource + CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_updateNIC(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + func testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).Network.InterfacesClient @@ -98,25 +144,20 @@ func testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationExists(r nicName := nicID.Path["networkInterfaces"] resourceGroup := nicID.ResourceGroup applicationSecurityGroupId := rs.Primary.Attributes["application_security_group_id"] - ipConfigurationName := rs.Primary.Attributes["ip_configuration_name"] read, err := client.Get(ctx, resourceGroup, nicName, "") if err != nil { return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", nicName, resourceGroup, err) } - c := azure.FindNetworkInterfaceIPConfiguration(read.InterfacePropertiesFormat.IPConfigurations, ipConfigurationName) - if c == nil { - return fmt.Errorf("IP Configuration %q wasn't found for Network Interface %q (Resource Group %q)", ipConfigurationName, nicName, resourceGroup) - } - config := *c - found := false - if config.InterfaceIPConfigurationPropertiesFormat.ApplicationSecurityGroups != nil { - for _, group := range *config.InterfaceIPConfigurationPropertiesFormat.ApplicationSecurityGroups { - if *group.ID == applicationSecurityGroupId { - found = true - break + for _, config := range *read.InterfacePropertiesFormat.IPConfigurations { + if config.ApplicationSecurityGroups != nil { + for _, group := range *config.ApplicationSecurityGroups { + if *group.ID == applicationSecurityGroupId { + found = true + break + } } } } @@ -148,28 +189,26 @@ func testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationDisappea nicName := nicID.Path["networkInterfaces"] resourceGroup := nicID.ResourceGroup applicationSecurityGroupId := rs.Primary.Attributes["application_security_group_id"] - ipConfigurationName := rs.Primary.Attributes["ip_configuration_name"] read, err := client.Get(ctx, resourceGroup, nicName, "") if err != nil { return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", nicName, resourceGroup, err) } - c := azure.FindNetworkInterfaceIPConfiguration(read.InterfacePropertiesFormat.IPConfigurations, ipConfigurationName) - if c == nil { - return fmt.Errorf("IP Configuration %q wasn't found for Network Interface %q (Resource Group %q)", ipConfigurationName, nicName, resourceGroup) - } - config := *c - - updatedGroups := make([]network.ApplicationSecurityGroup, 0) - if config.InterfaceIPConfigurationPropertiesFormat.ApplicationSecurityGroups != nil { - for _, group := range *config.InterfaceIPConfigurationPropertiesFormat.ApplicationSecurityGroups { - if *group.ID != applicationSecurityGroupId { - updatedGroups = append(updatedGroups, group) + configs := *read.InterfacePropertiesFormat.IPConfigurations + for _, config := range configs { + if config.ApplicationSecurityGroups != nil { + groups := make([]network.ApplicationSecurityGroup, 0) + for _, group := range *config.ApplicationSecurityGroups { + if *group.ID != applicationSecurityGroupId { + groups = append(groups, group) + } } + config.ApplicationSecurityGroups = &groups } } - config.InterfaceIPConfigurationPropertiesFormat.ApplicationSecurityGroups = &updatedGroups + + read.InterfacePropertiesFormat.IPConfigurations = &configs future, err := client.CreateOrUpdate(ctx, resourceGroup, nicName, read) if err != nil { @@ -185,62 +224,132 @@ func testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationDisappea } func testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} +%s -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + ip_configuration { + name = "testconfiguration1" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + } } -resource "azurerm_subnet" "test" { - name = "internal" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.1.0/24" +resource "azurerm_network_interface_application_security_group_association" "test" { + network_interface_id = azurerm_network_interface.test.id + application_security_group_id = azurerm_application_security_group.test.id +} +`, template, data.RandomInteger) } -resource "azurerm_application_security_group" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" +func testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface_application_security_group_association" "import" { + network_interface_id = azurerm_network_interface_application_security_group_association.test.network_interface_id + application_security_group_id = azurerm_network_interface_application_security_group_association.test.application_security_group_id +} +`, template) } +func testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_multipleIPConfigurations(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_template(data) + return fmt.Sprintf(` +%s + resource "azurerm_network_interface" "test" { name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + ip_configuration { + name = "testconfiguration1" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + primary = true + } ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - application_security_group_ids = ["${azurerm_application_security_group.test.id}"] + name = "testconfiguration2" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" } } resource "azurerm_network_interface_application_security_group_association" "test" { - network_interface_id = "${azurerm_network_interface.test.id}" - ip_configuration_name = "testconfiguration1" - application_security_group_id = "${azurerm_application_security_group.test.id}" + network_interface_id = azurerm_network_interface.test.id + application_security_group_id = azurerm_application_security_group.test.id } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger) } -func testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(data) +func testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_updateNIC(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_template(data) return fmt.Sprintf(` %s -resource "azurerm_network_interface_application_security_group_association" "import" { - network_interface_id = "${azurerm_network_interface_application_security_group_association.test.network_interface_id}" - ip_configuration_name = "${azurerm_network_interface_application_security_group_association.test.ip_configuration_name}" - application_security_group_id = "${azurerm_network_interface_application_security_group_association.test.application_security_group_id}" +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + ip_configuration { + name = "testconfiguration1" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + primary = true + } + + ip_configuration { + name = "testconfiguration2" + private_ip_address_version = "IPv6" + private_ip_address_allocation = "dynamic" + } } -`, template) + +resource "azurerm_network_interface_application_security_group_association" "test" { + network_interface_id = azurerm_network_interface.test.id + application_security_group_id = azurerm_application_security_group.test.id +} +`, template, data.RandomInteger) +} + +func testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctestvn-%d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_subnet" "test" { + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.1.0/24" +} + +resource "azurerm_application_security_group" "test" { + name = "acctest-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/network_interface_network_security_group_association_resource_test.go b/azurerm/internal/services/network/tests/network_interface_network_security_group_association_resource_test.go new file mode 100644 index 0000000000000..464b9356fafd6 --- /dev/null +++ b/azurerm/internal/services/network/tests/network_interface_network_security_group_association_resource_test.go @@ -0,0 +1,285 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/azuresdkhacks" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" +) + +func TestAccAzureRMNetworkInterfaceSecurityGroupAssociation_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_interface_security_group_association", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + // intentional as this is a Virtual Resource + CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkInterfaceSecurityGroupAssociation_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceSecurityGroupAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMNetworkInterfaceSecurityGroupAssociation_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + + data := acceptance.BuildTestData(t, "azurerm_network_interface_security_group_association", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + // intentional as this is a Virtual Resource + CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkInterfaceSecurityGroupAssociation_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceSecurityGroupAssociationExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMNetworkInterfaceSecurityGroupAssociation_requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_network_interface_security_group_association"), + }, + }, + }) +} + +func TestAccAzureRMNetworkInterfaceSecurityGroupAssociation_deleted(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_interface_security_group_association", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + // intentional as this is a Virtual Resource + CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkInterfaceSecurityGroupAssociation_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceSecurityGroupAssociationExists(data.ResourceName), + testCheckAzureRMNetworkInterfaceSecurityGroupAssociationDisappears(data.ResourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func TestAccAzureRMNetworkInterfaceSecurityGroupAssociation_updateNIC(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_interface_security_group_association", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + // intentional as this is a Virtual Resource + CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkInterfaceSecurityGroupAssociation_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceSecurityGroupAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetworkInterfaceSecurityGroupAssociation_updateNIC(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceSecurityGroupAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMNetworkInterfaceSecurityGroupAssociationExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Network.InterfacesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + nicID, err := azure.ParseAzureResourceID(rs.Primary.Attributes["network_interface_id"]) + if err != nil { + return err + } + + nicName := nicID.Path["networkInterfaces"] + resourceGroup := nicID.ResourceGroup + networkSecurityGroupId := rs.Primary.Attributes["network_security_group_id"] + + read, err := client.Get(ctx, resourceGroup, nicName, "") + if err != nil { + return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", nicName, resourceGroup, err) + } + + found := false + if read.InterfacePropertiesFormat != nil { + if read.InterfacePropertiesFormat.NetworkSecurityGroup != nil && read.InterfacePropertiesFormat.NetworkSecurityGroup.ID != nil { + found = *read.InterfacePropertiesFormat.NetworkSecurityGroup.ID == networkSecurityGroupId + } + } + if !found { + return fmt.Errorf("Association between NIC %q and Network Security Group %q was not found!", nicName, networkSecurityGroupId) + } + + return nil + } +} + +func testCheckAzureRMNetworkInterfaceSecurityGroupAssociationDisappears(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Network.InterfacesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + nicID, err := azure.ParseAzureResourceID(rs.Primary.Attributes["network_interface_id"]) + if err != nil { + return err + } + + nicName := nicID.Path["networkInterfaces"] + resourceGroup := nicID.ResourceGroup + + read, err := client.Get(ctx, resourceGroup, nicName, "") + if err != nil { + return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", nicName, resourceGroup, err) + } + + read.InterfacePropertiesFormat.NetworkSecurityGroup = nil + + future, err := azuresdkhacks.UpdateNetworkInterfaceAllowingRemovalOfNSG(ctx, client, resourceGroup, nicName, read) + if err != nil { + return fmt.Errorf("Error removing Network Security Group Association for Network Interface %q (Resource Group %q): %+v", nicName, resourceGroup, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for removal of Network Security Group Association for NIC %q (Resource Group %q): %+v", nicName, resourceGroup, err) + } + + return nil + } +} + +func testAccAzureRMNetworkInterfaceSecurityGroupAssociation_basic(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceSecurityGroupAssociation_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + ip_configuration { + name = "testconfiguration1" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_network_interface_security_group_association" "test" { + network_interface_id = azurerm_network_interface.test.id + network_security_group_id = azurerm_network_security_group.test.id +} +`, template, data.RandomInteger) +} + +func testAccAzureRMNetworkInterfaceSecurityGroupAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceSecurityGroupAssociation_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface_security_group_association" "import" { + network_interface_id = azurerm_network_interface_security_group_association.test.network_interface_id + network_security_group_id = azurerm_network_interface_security_group_association.test.network_security_group_id +} +`, template) +} + +func testAccAzureRMNetworkInterfaceSecurityGroupAssociation_updateNIC(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceSecurityGroupAssociation_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + ip_configuration { + name = "testconfiguration1" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + primary = true + } + + ip_configuration { + name = "testconfiguration2" + private_ip_address_version = "IPv6" + private_ip_address_allocation = "dynamic" + } +} + +resource "azurerm_network_interface_security_group_association" "test" { + network_interface_id = azurerm_network_interface.test.id + network_security_group_id = azurerm_network_security_group.test.id +} +`, template, data.RandomInteger) +} + +func testAccAzureRMNetworkInterfaceSecurityGroupAssociation_template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctestvn-%d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_subnet" "test" { + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.1.0/24" +} + +resource "azurerm_network_security_group" "test" { + name = "acctestnsg-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} diff --git a/azurerm/internal/services/network/tests/resource_arm_application_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_application_gateway_test.go index 23f8163487fbf..9721bb2c227b8 100644 --- a/azurerm/internal/services/network/tests/resource_arm_application_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_application_gateway_test.go @@ -817,26 +817,6 @@ func TestAccAzureRMApplicationGateway_sslPolicy_disabledProtocols(t *testing.T) }) } -func TestAccAzureRMApplicationGateway_disabledSslProtocols(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMApplicationGateway_disabledSslProtocols(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "disabled_ssl_protocols.0", "TLSv1_0"), - resource.TestCheckResourceAttr(data.ResourceName, "disabled_ssl_protocols.1", "TLSv1_1"), - ), - }, - }, - }) -} - func TestAccAzureRMApplicationGateway_cookieAffinity(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") @@ -911,6 +891,28 @@ func TestAccAzureRMApplicationGateway_UserAssignedIdentity(t *testing.T) { }) } +func TestAccAzureRMApplicationGateway_V2SKUCapacity(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApplicationGateway_v2SKUCapacity(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Standard_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "124"), + ), + }, + data.ImportStep(), + }, + }) +} + func testCheckAzureRMApplicationGatewayExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).Network.ApplicationGatewaysClient @@ -985,8 +987,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -996,25 +998,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -1022,18 +1024,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -1055,24 +1057,24 @@ locals { } resource "azurerm_user_assigned_identity" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location name = "acctest%s" } resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_v2" @@ -1081,30 +1083,30 @@ resource "azurerm_application_gateway" "test" { } identity { - identity_ids = ["${azurerm_user_assigned_identity.test.id}"] + identity_ids = [azurerm_user_assigned_identity.test.id] } gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -1112,18 +1114,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomString, data.RandomInteger, data.RandomInteger) @@ -1146,16 +1148,16 @@ locals { resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location zones = ["1", "2"] sku { @@ -1166,25 +1168,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -1192,18 +1194,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger, data.RandomInteger) @@ -1226,16 +1228,16 @@ locals { resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_v2" @@ -1249,25 +1251,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -1275,18 +1277,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger, data.RandomInteger, minCapacity, maxCapacity) @@ -1309,16 +1311,16 @@ locals { resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_v2" @@ -1331,25 +1333,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -1357,18 +1359,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger, data.RandomInteger) @@ -1391,8 +1393,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -1402,25 +1404,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" path = "/path1/" port = 80 @@ -1429,18 +1431,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -1463,8 +1465,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location enable_http2 = true sku { @@ -1475,25 +1477,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -1501,18 +1503,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -1524,9 +1526,9 @@ func testAccAzureRMApplicationGateway_requiresImport(data acceptance.TestData) s %s resource "azurerm_application_gateway" "import" { - name = "${azurerm_application_gateway.test.name}" - resource_group_name = "${azurerm_application_gateway.test.resource_group_name}" - location = "${azurerm_application_gateway.test.location}" + name = azurerm_application_gateway.test.name + resource_group_name = azurerm_application_gateway.test.resource_group_name + location = azurerm_application_gateway.test.location sku { name = "Standard_Small" @@ -1536,25 +1538,25 @@ resource "azurerm_application_gateway" "import" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -1562,18 +1564,18 @@ resource "azurerm_application_gateway" "import" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template) @@ -1597,8 +1599,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -1608,53 +1610,53 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 443 protocol = "Https" request_timeout = 1 authentication_certificate { - name = "${local.auth_cert_name}" + name = local.auth_cert_name } } authentication_certificate { - name = "${local.auth_cert_name}" - data = "${file("testdata/application_gateway_test.cer")}" + name = local.auth_cert_name + data = file("testdata/application_gateway_test.cer") } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -1706,7 +1708,7 @@ resource "azurerm_key_vault" "test" { access_policy { tenant_id = "${data.azurerm_client_config.test.tenant_id}" - object_id = "${data.azurerm_client_config.test.service_principal_object_id}" + object_id = "${data.azurerm_client_config.test.object_id}" secret_permissions = ["delete", "get", "set"] certificate_permissions = ["create", "delete", "get", "import"] } @@ -1831,16 +1833,16 @@ locals { resource "azurerm_public_ip" "teststd" { name = "acctest-PubIpStd-%[2]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_application_gateway" "test" { name = "acctestag-%[2]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "WAF_v2" @@ -1850,52 +1852,52 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.teststd.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.teststd.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 443 protocol = "Https" request_timeout = 1 pick_host_name_from_backend_address = true - trusted_root_certificate_names = ["${local.auth_cert_name}"] + trusted_root_certificate_names = [local.auth_cert_name] } trusted_root_certificate { - name = "${local.auth_cert_name}" - data = "${file("testdata/application_gateway_test.cer")}" + name = local.auth_cert_name + data = file("testdata/application_gateway_test.cer") } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -1919,8 +1921,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%[2]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -1930,53 +1932,53 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 443 protocol = "Https" request_timeout = 1 authentication_certificate { - name = "${local.auth_cert_name}" + name = local.auth_cert_name } } authentication_certificate { - name = "${local.auth_cert_name}" - data = "${file("testdata/application_gateway_test_2.crt")}" + name = local.auth_cert_name + data = file("testdata/application_gateway_test_2.crt") } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -2000,17 +2002,16 @@ locals { resource "azurerm_public_ip" "teststd" { name = "acctest-PubIpStd-%[2]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } - resource "azurerm_application_gateway" "test" { name = "acctestag-%[2]d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "WAF_v2" @@ -2020,52 +2021,52 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.teststd.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.teststd.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 443 protocol = "Https" request_timeout = 1 pick_host_name_from_backend_address = true - trusted_root_certificate_names = ["${local.auth_cert_name}"] + trusted_root_certificate_names = [local.auth_cert_name] } trusted_root_certificate { - name = "${local.auth_cert_name}" - data = "${file("testdata/application_gateway_test_2.crt")}" + name = local.auth_cert_name + data = file("testdata/application_gateway_test_2.crt") } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -2090,8 +2091,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -2101,25 +2102,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -2127,28 +2128,28 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "PathBasedRouting" - url_path_map_name = "${local.url_path_map_name}" - http_listener_name = "${local.listener_name}" + url_path_map_name = local.url_path_map_name + http_listener_name = local.listener_name } url_path_map { - name = "${local.url_path_map_name}" - default_backend_address_pool_name = "${local.backend_address_pool_name}" - default_backend_http_settings_name = "${local.http_setting_name}" + name = local.url_path_map_name + default_backend_address_pool_name = local.backend_address_pool_name + default_backend_http_settings_name = local.http_setting_name path_rule { - name = "${local.path_rule_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + name = local.path_rule_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name paths = [ "/test", @@ -2181,8 +2182,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -2192,30 +2193,30 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_port { - name = "${local.frontend_port_name2}" + name = local.frontend_port_name2 port = 8888 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -2223,30 +2224,30 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } http_listener { - name = "${local.target_listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name2}" + name = local.target_listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name2 protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - redirect_configuration_name = "${local.redirect_configuration_name}" + http_listener_name = local.listener_name + redirect_configuration_name = local.redirect_configuration_name } redirect_configuration { - name = "${local.redirect_configuration_name}" + name = local.redirect_configuration_name redirect_type = "Temporary" - target_listener_name = "${local.target_listener_name}" + target_listener_name = local.target_listener_name include_path = true include_query_string = false } @@ -2276,8 +2277,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -2287,30 +2288,30 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_port { - name = "${local.frontend_port_name2}" + name = local.frontend_port_name2 port = 8888 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -2318,31 +2319,31 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } http_listener { - name = "${local.target_listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name2}" + name = local.target_listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name2 protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - redirect_configuration_name = "${local.redirect_configuration_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + redirect_configuration_name = local.redirect_configuration_name } redirect_configuration { - name = "${local.redirect_configuration_name}" + name = local.redirect_configuration_name redirect_type = "Temporary" - target_listener_name = "${local.target_listener_name}" + target_listener_name = local.target_listener_name include_path = true include_query_string = false } @@ -2375,8 +2376,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -2386,30 +2387,30 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_port { - name = "${local.frontend_port_name2}" + name = local.frontend_port_name2 port = 8888 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -2417,34 +2418,34 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } http_listener { - name = "${local.target_listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name2}" + name = local.target_listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name2 protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "PathBasedRouting" - url_path_map_name = "${local.url_path_map_name}" - http_listener_name = "${local.listener_name}" + url_path_map_name = local.url_path_map_name + http_listener_name = local.listener_name } url_path_map { - name = "${local.url_path_map_name}" - default_backend_address_pool_name = "${local.backend_address_pool_name}" - default_backend_http_settings_name = "${local.http_setting_name}" + name = local.url_path_map_name + default_backend_address_pool_name = local.backend_address_pool_name + default_backend_http_settings_name = local.http_setting_name path_rule { - name = "${local.path_rule_name}" - redirect_configuration_name = "${local.redirect_configuration_name}" + name = local.path_rule_name + redirect_configuration_name = local.redirect_configuration_name paths = [ "/test", @@ -2452,8 +2453,8 @@ resource "azurerm_application_gateway" "test" { } path_rule { - name = "${local.path_rule_name2}" - redirect_configuration_name = "${local.redirect_configuration_name2}" + name = local.path_rule_name2 + redirect_configuration_name = local.redirect_configuration_name2 paths = [ "/test2", @@ -2462,16 +2463,16 @@ resource "azurerm_application_gateway" "test" { } redirect_configuration { - name = "${local.redirect_configuration_name}" + name = local.redirect_configuration_name redirect_type = "Found" - target_url = "${local.target_url}" + target_url = local.target_url include_query_string = true } redirect_configuration { - name = "${local.redirect_configuration_name2}" + name = local.redirect_configuration_name2 redirect_type = "Permanent" - target_listener_name = "${local.target_listener_name}" + target_listener_name = local.target_listener_name include_path = false include_query_string = false } @@ -2498,8 +2499,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -2509,28 +2510,28 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 - probe_name = "${local.probe1_name}" + probe_name = local.probe1_name protocol = "Http" request_timeout = 1 } @@ -2539,13 +2540,13 @@ resource "azurerm_application_gateway" "test" { name = "${local.http_setting_name}-2" cookie_based_affinity = "Disabled" port = 8080 - probe_name = "${local.probe2_name}" + probe_name = local.probe2_name protocol = "Http" request_timeout = 1 } probe { - name = "${local.probe1_name}" + name = local.probe1_name protocol = "Http" path = "/test" host = "azure.com" @@ -2555,7 +2556,7 @@ resource "azurerm_application_gateway" "test" { } probe { - name = "${local.probe2_name}" + name = local.probe2_name protocol = "Http" path = "/other" host = "azure.com" @@ -2565,18 +2566,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -2601,8 +2602,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -2612,28 +2613,28 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 - probe_name = "${local.probe1_name}" + probe_name = local.probe1_name protocol = "Http" request_timeout = 1 } @@ -2642,13 +2643,13 @@ resource "azurerm_application_gateway" "test" { name = "${local.http_setting_name}-2" cookie_based_affinity = "Disabled" port = 8080 - probe_name = "${local.probe2_name}" + probe_name = local.probe2_name protocol = "Http" request_timeout = 1 } probe { - name = "${local.probe1_name}" + name = local.probe1_name protocol = "Http" path = "/test" host = "azure.com" @@ -2658,7 +2659,7 @@ resource "azurerm_application_gateway" "test" { } probe { - name = "${local.probe2_name}" + name = local.probe2_name protocol = "Http" path = "/other" host = "azure.com" @@ -2671,18 +2672,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -2706,8 +2707,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -2717,35 +2718,35 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" pick_host_name_from_backend_address = true port = 80 - probe_name = "${local.probe_name}" + probe_name = local.probe_name protocol = "Http" request_timeout = 1 } probe { - name = "${local.probe_name}" + name = local.probe_name protocol = "Http" path = "/test" timeout = 120 @@ -2755,18 +2756,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -2789,8 +2790,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -2800,25 +2801,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" host_name = "%s" port = 80 @@ -2828,18 +2829,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger, hostName, pick) @@ -2862,8 +2863,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -2873,25 +2874,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" pick_host_name_from_backend_address = true port = 80 @@ -2900,18 +2901,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -2935,8 +2936,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -2946,25 +2947,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 443 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -2972,24 +2973,24 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Https" - ssl_certificate_name = "${local.ssl_certificate_name}" + ssl_certificate_name = local.ssl_certificate_name } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } ssl_certificate { - name = "${local.ssl_certificate_name}" - data = "${filebase64("testdata/application_gateway_test.pfx")}" + name = local.ssl_certificate_name + data = filebase64("testdata/application_gateway_test.pfx") password = "terraform" } } @@ -3014,8 +3015,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -3025,25 +3026,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 443 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -3051,24 +3052,24 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Https" - ssl_certificate_name = "${local.ssl_certificate_name}" + ssl_certificate_name = local.ssl_certificate_name } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } ssl_certificate { - name = "${local.ssl_certificate_name}" - data = "${filebase64("testdata/application_gateway_test_2.pfx")}" + name = local.ssl_certificate_name + data = filebase64("testdata/application_gateway_test_2.pfx") password = "hello-world" } } @@ -3101,10 +3102,6 @@ resource "azurerm_application_gateway" "test" { capacity = 1 } - disabled_ssl_protocols = [ - "TLSv1_0", - ] - waf_configuration { enabled = true firewall_mode = "Detection" @@ -3177,8 +3174,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location enable_http2 = true sku { @@ -3189,25 +3186,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -3220,18 +3217,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -3253,16 +3250,16 @@ locals { resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "WAF_v2" @@ -3296,25 +3293,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -3322,18 +3319,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger, data.RandomInteger) @@ -3356,16 +3353,16 @@ locals { resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "WAF_v2" @@ -3394,25 +3391,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -3420,18 +3417,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger, data.RandomInteger) @@ -3454,16 +3451,16 @@ locals { resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "WAF_v2" @@ -3511,25 +3508,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -3537,18 +3534,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger, data.RandomInteger) @@ -3570,16 +3567,16 @@ locals { resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "WAF_v2" @@ -3605,25 +3602,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -3631,18 +3628,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger, data.RandomInteger) @@ -3664,16 +3661,16 @@ locals { resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_v2" @@ -3688,25 +3685,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -3714,18 +3711,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger, data.RandomInteger) @@ -3747,16 +3744,16 @@ locals { resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_v2" @@ -3772,25 +3769,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -3798,18 +3795,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger, data.RandomInteger) @@ -3831,16 +3828,16 @@ locals { resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_v2" @@ -3854,25 +3851,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -3880,105 +3877,29 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_disabledSslProtocols(data acceptance.TestData) string { - template := testAccAzureRMApplicationGateway_template(data) +func testAccAzureRMApplicationGateway_template(data acceptance.TestData) string { return fmt.Sprintf(` -%s -# since these variables are re-used - a locals block makes this more maintainable -locals { - backend_address_pool_name = "${azurerm_virtual_network.test.name}-beap" - frontend_port_name = "${azurerm_virtual_network.test.name}-feport" - frontend_ip_configuration_name = "${azurerm_virtual_network.test.name}-feip" - http_setting_name = "${azurerm_virtual_network.test.name}-be-htst" - listener_name = "${azurerm_virtual_network.test.name}-httplstn" - request_routing_rule_name = "${azurerm_virtual_network.test.name}-rqrt" +provider "azurerm" { + features {} } -resource "azurerm_public_ip" "test_standard" { - name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Standard" - allocation_method = "Static" -} - -resource "azurerm_application_gateway" "test" { - name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - - sku { - name = "Standard_v2" - tier = "Standard_v2" - capacity = 1 - } - - disabled_ssl_protocols = ["TLSv1_0", "TLSv1_1"] - - gateway_ip_configuration { - name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" - } - - frontend_port { - name = "${local.frontend_port_name}" - port = 80 - } - - frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" - } - - backend_address_pool { - name = "${local.backend_address_pool_name}" - } - - backend_http_settings { - name = "${local.http_setting_name}" - cookie_based_affinity = "Disabled" - port = 80 - protocol = "Http" - request_timeout = 1 - } - - http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" - protocol = "Http" - } - - request_routing_rule { - name = "${local.request_routing_rule_name}" - rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" - } -} -`, template, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMApplicationGateway_template(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -3986,22 +3907,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctest-vnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location } resource "azurerm_subnet" "test" { name = "subnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.0.0/24" } resource "azurerm_public_ip" "test" { name = "acctest-pubip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -4026,8 +3947,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -4037,25 +3958,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -4063,9 +3984,9 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" custom_error_configuration { @@ -4090,11 +4011,11 @@ resource "azurerm_application_gateway" "test" { } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -4119,16 +4040,16 @@ locals { resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_v2" @@ -4138,25 +4059,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -4164,26 +4085,26 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" - rewrite_rule_set_name = "${local.rewrite_rule_set_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name + rewrite_rule_set_name = local.rewrite_rule_set_name } rewrite_rule_set { - name = "${local.rewrite_rule_set_name}" + name = local.rewrite_rule_set_name rewrite_rule { - name = "${local.rewrite_rule_name}" + name = local.rewrite_rule_name rule_sequence = 1 condition { @@ -4223,16 +4144,16 @@ locals { resource "azurerm_public_ip" "test_standard" { name = "acctest-pubip-%d-standard" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" allocation_method = "Static" } resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_v2" @@ -4242,30 +4163,30 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_port { - name = "${local.frontend_port_name2}" + name = local.frontend_port_name2 port = 8888 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test_standard.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test_standard.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -4273,32 +4194,32 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } http_listener { - name = "${local.target_listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name2}" + name = local.target_listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name2 protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - redirect_configuration_name = "${local.redirect_configuration_name}" - rewrite_rule_set_name = "${local.rewrite_rule_set_name}" + http_listener_name = local.listener_name + redirect_configuration_name = local.redirect_configuration_name + rewrite_rule_set_name = local.rewrite_rule_set_name } rewrite_rule_set { - name = "${local.rewrite_rule_set_name}" + name = local.rewrite_rule_set_name rewrite_rule { - name = "${local.rewrite_rule_name}" + name = local.rewrite_rule_name rule_sequence = 1 condition { @@ -4314,9 +4235,9 @@ resource "azurerm_application_gateway" "test" { } redirect_configuration { - name = "${local.redirect_configuration_name}" + name = local.redirect_configuration_name redirect_type = "Temporary" - target_listener_name = "${local.target_listener_name}" + target_listener_name = local.target_listener_name include_path = true include_query_string = false } @@ -4341,8 +4262,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -4352,25 +4273,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Enabled" affinity_cookie_name = "testCookieName" port = 80 @@ -4379,18 +4300,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -4413,8 +4334,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -4424,25 +4345,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Enabled" port = 80 protocol = "Http" @@ -4450,18 +4371,18 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } `, template, data.RandomInteger) @@ -4474,8 +4395,8 @@ func testAccAzureRMApplicationGateway_gatewayIPUpdated(data acceptance.TestData) resource "azurerm_subnet" "test1" { name = "subnet1-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } @@ -4491,8 +4412,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "acctestag-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -4502,7 +4423,86 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.test1.id}" + subnet_id = azurerm_subnet.test1.id + } + + frontend_port { + name = local.frontend_port_name + port = 80 + } + + frontend_ip_configuration { + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id + } + + backend_address_pool { + name = local.backend_address_pool_name + } + + backend_http_settings { + name = local.http_setting_name + cookie_based_affinity = "Disabled" + port = 80 + protocol = "Http" + request_timeout = 1 + } + + http_listener { + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name + protocol = "Http" + } + + request_routing_rule { + name = local.request_routing_rule_name + rule_type = "Basic" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name + } +} +`, template, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMApplicationGateway_v2SKUCapacity(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) + return fmt.Sprintf(` +%s + +# since these variables are re-used - a locals block makes this more maintainable +locals { + backend_address_pool_name = "${azurerm_virtual_network.test.name}-beap" + frontend_port_name = "${azurerm_virtual_network.test.name}-feport" + frontend_ip_configuration_name = "${azurerm_virtual_network.test.name}-feip" + http_setting_name = "${azurerm_virtual_network.test.name}-be-htst" + listener_name = "${azurerm_virtual_network.test.name}-httplstn" + request_routing_rule_name = "${azurerm_virtual_network.test.name}-rqrt" +} + +resource "azurerm_public_ip" "test_standard" { + name = "acctest-pubip-%d-standard" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "Standard" + allocation_method = "Static" +} + +resource "azurerm_application_gateway" "test" { + name = "acctestag-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + + sku { + name = "Standard_v2" + tier = "Standard_v2" + capacity = 124 + } + + gateway_ip_configuration { + name = "my-gateway-ip-configuration" + subnet_id = "${azurerm_subnet.test.id}" } frontend_port { @@ -4512,7 +4512,7 @@ resource "azurerm_application_gateway" "test" { frontend_ip_configuration { name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = "${azurerm_public_ip.test_standard.id}" } backend_address_pool { diff --git a/azurerm/internal/services/network/tests/resource_arm_application_security_group_test.go b/azurerm/internal/services/network/tests/resource_arm_application_security_group_test.go index c952052c94f9b..094911c7c36a3 100644 --- a/azurerm/internal/services/network/tests/resource_arm_application_security_group_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_application_security_group_test.go @@ -166,6 +166,10 @@ func testCheckAzureRMApplicationSecurityGroupExists(resourceName string) resourc func testAccAzureRMApplicationSecurityGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -173,8 +177,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_security_group" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -185,15 +189,19 @@ func testAccAzureRMApplicationSecurityGroup_requiresImport(data acceptance.TestD %s resource "azurerm_application_security_group" "import" { - name = "${azurerm_application_security_group.test.name}" - location = "${azurerm_application_security_group.test.location}" - resource_group_name = "${azurerm_application_security_group.test.resource_group_name}" + name = azurerm_application_security_group.test.name + location = azurerm_application_security_group.test.location + resource_group_name = azurerm_application_security_group.test.resource_group_name } `, template) } func testAccAzureRMApplicationSecurityGroup_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -201,8 +209,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_security_group" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { Hello = "World" diff --git a/azurerm/internal/services/network/tests/resource_arm_bastion_host_test.go b/azurerm/internal/services/network/tests/resource_arm_bastion_host_test.go index 9b4d2640a7f25..a3cc414c6962c 100644 --- a/azurerm/internal/services/network/tests/resource_arm_bastion_host_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_bastion_host_test.go @@ -80,6 +80,10 @@ func TestAccAzureRMBastionHost_requiresImport(t *testing.T) { func testAccAzureRMBastionHost_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-bastion-%d" location = "%s" @@ -88,34 +92,34 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestVNet%s" address_space = ["192.168.1.0/24"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "AzureBastionSubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "192.168.1.224/27" } resource "azurerm_public_ip" "test" { name = "acctestBastionPIP%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_bastion_host" "test" { name = "acctestBastion%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + subnet_id = azurerm_subnet.test.id + public_ip_address_id = azurerm_public_ip.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomString) @@ -123,6 +127,10 @@ resource "azurerm_bastion_host" "test" { func testAccAzureRMBastionHost_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-bastion-%d" location = "%s" @@ -131,34 +139,34 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestVNet%s" address_space = ["192.168.1.0/24"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "AzureBastionSubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "192.168.1.224/27" } resource "azurerm_public_ip" "test" { name = "acctestBastionPIP%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_bastion_host" "test" { name = "acctestBastion%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + subnet_id = azurerm_subnet.test.id + public_ip_address_id = azurerm_public_ip.test.id } tags = { @@ -173,14 +181,14 @@ func testAccAzureRMBastionHost_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s resource "azurerm_bastion_host" "import" { - name = "${azurerm_bastion_host.test.name}" - resource_group_name = "${azurerm_bastion_host.test.resource_group_name}" - location = "${azurerm_bastion_host.test.location}" + name = azurerm_bastion_host.test.name + resource_group_name = azurerm_bastion_host.test.resource_group_name + location = azurerm_bastion_host.test.location ip_configuration { name = "ip-configuration" - subnet_id = "${azurerm_subnet.test.id}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + subnet_id = azurerm_subnet.test.id + public_ip_address_id = azurerm_public_ip.test.id } } `, template) diff --git a/azurerm/internal/services/network/tests/resource_arm_connection_monitor_test.go b/azurerm/internal/services/network/tests/resource_arm_connection_monitor_test.go deleted file mode 100644 index 04240aa2f761e..0000000000000 --- a/azurerm/internal/services/network/tests/resource_arm_connection_monitor_test.go +++ /dev/null @@ -1,648 +0,0 @@ -package tests - -import ( - "fmt" - "net/http" - "regexp" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" -) - -func testAccAzureRMConnectionMonitor_addressBasic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMConnectionMonitor_basicAddressConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), - resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), - resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "60"), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMConnectionMonitor_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - - data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMConnectionMonitor_basicAddressConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMConnectionMonitor_requiresImportConfig(data), - ExpectError: acceptance.RequiresImportError("azurerm_connection_monitor"), - }, - }, - }) -} - -func testAccAzureRMConnectionMonitor_addressComplete(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - - autoStart := "false" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMConnectionMonitor_completeAddressConfig(data, autoStart), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "30"), - resource.TestCheckResourceAttr(data.ResourceName, "source.0.port", "20020"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMConnectionMonitor_addressUpdate(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - - autoStart := "true" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMConnectionMonitor_basicAddressConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMConnectionMonitor_completeAddressConfig(data, autoStart), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "30"), - resource.TestCheckResourceAttr(data.ResourceName, "source.0.port", "20020"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMConnectionMonitor_vmBasic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMConnectionMonitor_basicVmConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), - resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), - resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "60"), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMConnectionMonitor_vmComplete(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - - autoStart := "false" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMConnectionMonitor_completeVmConfig(data, autoStart), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "30"), - resource.TestCheckResourceAttr(data.ResourceName, "source.0.port", "20020"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMConnectionMonitor_vmUpdate(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMConnectionMonitor_basicVmConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMConnectionMonitor_completeVmConfig(data, "true"), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "30"), - resource.TestCheckResourceAttr(data.ResourceName, "source.0.port", "20020"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMConnectionMonitor_destinationUpdate(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMConnectionMonitor_basicAddressConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "destination.0.address"), - ), - }, - { - Config: testAccAzureRMConnectionMonitor_basicVmConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "destination.0.virtual_machine_id"), - ), - }, - { - Config: testAccAzureRMConnectionMonitor_basicAddressConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "destination.0.address"), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMConnectionMonitor_missingDestination(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMConnectionMonitor_missingDestinationConfig(data), - ExpectError: regexp.MustCompile("Error: either `destination.virtual_machine_id` or `destination.address` must be specified"), - }, - }, - }) -} - -func testAccAzureRMConnectionMonitor_conflictingDestinations(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMConnectionMonitor_conflictingDestinationsConfig(data), - ExpectError: regexp.MustCompile("conflicts with destination.0.address"), - }, - }, - }) -} - -func testCheckAzureRMConnectionMonitorExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.ConnectionMonitorsClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - resourceGroup := rs.Primary.Attributes["resource_group_name"] - watcherName := rs.Primary.Attributes["network_watcher_name"] - connectionMonitorName := rs.Primary.Attributes["name"] - - resp, err := client.Get(ctx, resourceGroup, watcherName, connectionMonitorName) - if err != nil { - return fmt.Errorf("Bad: Get on connectionMonitorsClient: %s", err) - } - - if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Connection Monitor does not exist: %s", connectionMonitorName) - } - - return nil - } -} - -func testCheckAzureRMConnectionMonitorDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.ConnectionMonitorsClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_connection_monitor" { - continue - } - - resourceGroup := rs.Primary.Attributes["resource_group_name"] - watcherName := rs.Primary.Attributes["network_watcher_name"] - connectionMonitorName := rs.Primary.Attributes["name"] - - resp, err := client.Get(ctx, resourceGroup, watcherName, connectionMonitorName) - - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("Connection Monitor still exists:%s", *resp.Name) - } - } - - return nil -} - -func testAccAzureRMConnectionMonitor_baseConfig(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_network_watcher" "test" { - name = "acctnw-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_virtual_network" "test" { - name = "acctvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "internal" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} - -resource "azurerm_network_interface" "src" { - name = "acctni-src%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - } -} - -resource "azurerm_virtual_machine" "src" { - name = "acctvm-src%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.src.id}"] - vm_size = "Standard_D1_v2" - - storage_image_reference { - publisher = "Canonical" - offer = "UbuntuServer" - sku = "16.04-LTS" - version = "latest" - } - - storage_os_disk { - name = "osdisk-src%d" - caching = "ReadWrite" - create_option = "FromImage" - managed_disk_type = "Standard_LRS" - } - - os_profile { - computer_name = "hostname%d" - admin_username = "testadmin" - admin_password = "Password1234!" - } - - os_profile_linux_config { - disable_password_authentication = false - } -} - -resource "azurerm_virtual_machine_extension" "src" { - name = "network-watcher" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_machine_name = "${azurerm_virtual_machine.src.name}" - publisher = "Microsoft.Azure.NetworkWatcher" - type = "NetworkWatcherAgentLinux" - type_handler_version = "1.4" - auto_upgrade_minor_version = true -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMConnectionMonitor_baseWithDestConfig(data acceptance.TestData) string { - config := testAccAzureRMConnectionMonitor_baseConfig(data) - return fmt.Sprintf(` -%s - -resource "azurerm_network_interface" "dest" { - name = "acctni-dest%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - } -} - -resource "azurerm_virtual_machine" "dest" { - name = "acctvm-dest%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.dest.id}"] - vm_size = "Standard_D1_v2" - - storage_image_reference { - publisher = "Canonical" - offer = "UbuntuServer" - sku = "16.04-LTS" - version = "latest" - } - - storage_os_disk { - name = "osdisk-dest%d" - caching = "ReadWrite" - create_option = "FromImage" - managed_disk_type = "Standard_LRS" - } - - os_profile { - computer_name = "hostname%d" - admin_username = "testadmin" - admin_password = "Password1234!" - } - - os_profile_linux_config { - disable_password_authentication = false - } -} -`, config, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMConnectionMonitor_basicAddressConfig(data acceptance.TestData) string { - config := testAccAzureRMConnectionMonitor_baseConfig(data) - return fmt.Sprintf(` -%s - -resource "azurerm_connection_monitor" "test" { - name = "acctestcm-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_network_watcher.test.location}" - - source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" - } - - destination { - address = "terraform.io" - port = 80 - } - - depends_on = ["azurerm_virtual_machine_extension.src"] -} -`, config, data.RandomInteger) -} - -func testAccAzureRMConnectionMonitor_completeAddressConfig(data acceptance.TestData, autoStart string) string { - config := testAccAzureRMConnectionMonitor_baseConfig(data) - return fmt.Sprintf(` -%s - -resource "azurerm_connection_monitor" "test" { - name = "acctestcm-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_network_watcher.test.location}" - - auto_start = %s - interval_in_seconds = 30 - - source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" - port = 20020 - } - - destination { - address = "terraform.io" - port = 443 - } - - tags = { - env = "test" - } - - depends_on = ["azurerm_virtual_machine_extension.src"] -} -`, config, data.RandomInteger, autoStart) -} - -func testAccAzureRMConnectionMonitor_basicVmConfig(data acceptance.TestData) string { - config := testAccAzureRMConnectionMonitor_baseWithDestConfig(data) - return fmt.Sprintf(` -%s - -resource "azurerm_connection_monitor" "test" { - name = "acctestcm-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_network_watcher.test.location}" - - source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" - } - - destination { - virtual_machine_id = "${azurerm_virtual_machine.dest.id}" - port = 80 - } - - depends_on = ["azurerm_virtual_machine_extension.src"] -} -`, config, data.RandomInteger) -} - -func testAccAzureRMConnectionMonitor_completeVmConfig(data acceptance.TestData, autoStart string) string { - config := testAccAzureRMConnectionMonitor_baseWithDestConfig(data) - return fmt.Sprintf(` -%s - -resource "azurerm_connection_monitor" "test" { - name = "acctestcm-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_network_watcher.test.location}" - - auto_start = %s - interval_in_seconds = 30 - - source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" - port = 20020 - } - - destination { - virtual_machine_id = "${azurerm_virtual_machine.dest.id}" - port = 443 - } - - tags = { - env = "test" - } - - depends_on = ["azurerm_virtual_machine_extension.src"] -} -`, config, data.RandomInteger, autoStart) -} - -func testAccAzureRMConnectionMonitor_missingDestinationConfig(data acceptance.TestData) string { - config := testAccAzureRMConnectionMonitor_baseConfig(data) - return fmt.Sprintf(` -%s - -resource "azurerm_connection_monitor" "test" { - name = "acctestcm-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_network_watcher.test.location}" - - source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" - } - - destination { - port = 80 - } - - depends_on = ["azurerm_virtual_machine_extension.src"] -} -`, config, data.RandomInteger) -} - -func testAccAzureRMConnectionMonitor_conflictingDestinationsConfig(data acceptance.TestData) string { - config := testAccAzureRMConnectionMonitor_baseConfig(data) - return fmt.Sprintf(` -%s - -resource "azurerm_connection_monitor" "test" { - name = "acctestcm-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_network_watcher.test.location}" - - source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" - } - - destination { - address = "terraform.io" - virtual_machine_id = "${azurerm_virtual_machine.src.id}" - port = 80 - } - - depends_on = ["azurerm_virtual_machine_extension.src"] -} -`, config, data.RandomInteger) -} - -func testAccAzureRMConnectionMonitor_requiresImportConfig(data acceptance.TestData) string { - config := testAccAzureRMConnectionMonitor_basicAddressConfig(data) - return fmt.Sprintf(` -%s - -resource "azurerm_connection_monitor" "import" { - name = "${azurerm_connection_monitor.test.name}" - network_watcher_name = "${azurerm_connection_monitor.test.network_watcher_name}" - resource_group_name = "${azurerm_connection_monitor.test.resource_group_name}" - location = "${azurerm_connection_monitor.test.location}" - - source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" - } - - destination { - address = "terraform.io" - port = 80 - } - - depends_on = ["azurerm_virtual_machine_extension.src"] -} -`, config) -} diff --git a/azurerm/internal/services/network/tests/resource_arm_ddos_protection_plan_test.go b/azurerm/internal/services/network/tests/resource_arm_ddos_protection_plan_test.go deleted file mode 100644 index ef8045b066b18..0000000000000 --- a/azurerm/internal/services/network/tests/resource_arm_ddos_protection_plan_test.go +++ /dev/null @@ -1,264 +0,0 @@ -package tests - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func testAccAzureRMDDoSProtectionPlan_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_ddos_protection_plan", "test") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDDoSProtectionPlanDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDDoSProtectionPlan_basicConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDDoSProtectionPlanExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_network_ids.#"), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMDDoSProtectionPlan_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - - data := acceptance.BuildTestData(t, "azurerm_ddos_protection_plan", "test") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDDoSProtectionPlanDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDDoSProtectionPlan_basicConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDDoSProtectionPlanExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMDDoSProtectionPlan_requiresImportConfig(data), - ExpectError: acceptance.RequiresImportError("azurerm_ddos_protection_plan"), - }, - }, - }) -} - -func testAccAzureRMDDoSProtectionPlan_withTags(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_ddos_protection_plan", "test") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDDoSProtectionPlanDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDDoSProtectionPlan_withTagsConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDDoSProtectionPlanExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), - ), - }, - { - Config: testAccAzureRMDDoSProtectionPlan_withUpdatedTagsConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDDoSProtectionPlanExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Staging"), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMDDoSProtectionPlan_disappears(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_ddos_protection_plan", "test") - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDDoSProtectionPlanDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDDoSProtectionPlan_basicConfig(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDDoSProtectionPlanExists(data.ResourceName), - testCheckAzureRMDDoSProtectionPlanDisappears(data.ResourceName), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func testCheckAzureRMDDoSProtectionPlanExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.DDOSProtectionPlansClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // Ensure we have enough information in state to look up in API - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - name := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for DDoS Protection Plan: %q", name) - } - - resp, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: DDoS Protection Plan %q (Resource Group: %q) does not exist", name, resourceGroup) - } - - return fmt.Errorf("Bad: Get on ddosProtectionPlanClient: %+v", err) - } - - return nil - } -} - -func testCheckAzureRMDDoSProtectionPlanDisappears(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.DDOSProtectionPlansClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // Ensure we have enough information in state to look up in API - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - name := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for DDoS Protection Plan: %q", name) - } - - future, err := client.Delete(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("Bad: Delete on ddosProtectionPlanClient: %+v", err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Bad: waiting for Deletion on ddosProtectionPlanClient: %+v", err) - } - - return nil - } -} - -func testCheckAzureRMDDoSProtectionPlanDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.DDOSProtectionPlansClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_ddos_protection_plan" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := client.Get(ctx, resourceGroup, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return nil - } - - return err - } - - return fmt.Errorf("DDoS Protection Plan still exists:\n%#v", resp.DdosProtectionPlanPropertiesFormat) - } - - return nil -} - -func testAccAzureRMDDoSProtectionPlan_basicConfig(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_ddos_protection_plan" "test" { - name = "acctestddospplan-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMDDoSProtectionPlan_requiresImportConfig(data acceptance.TestData) string { - basicConfig := testAccAzureRMDDoSProtectionPlan_basicConfig(data) - return fmt.Sprintf(` -%s - -resource "azurerm_ddos_protection_plan" "import" { - name = "${azurerm_ddos_protection_plan.test.name}" - location = "${azurerm_ddos_protection_plan.test.location}" - resource_group_name = "${azurerm_ddos_protection_plan.test.resource_group_name}" -} -`, basicConfig) -} - -func testAccAzureRMDDoSProtectionPlan_withTagsConfig(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_ddos_protection_plan" "test" { - name = "acctestddospplan-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - tags = { - environment = "Production" - cost_center = "MSFT" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMDDoSProtectionPlan_withUpdatedTagsConfig(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_ddos_protection_plan" "test" { - name = "acctestddospplan-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - tags = { - environment = "Staging" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} diff --git a/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_authorization_test.go b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_authorization_test.go index 84f141bc68835..ddad0d26b7102 100644 --- a/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_authorization_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_authorization_test.go @@ -142,6 +142,10 @@ func testCheckAzureRMExpressRouteCircuitAuthorizationDestroy(s *terraform.State) func testAccAzureRMExpressRouteCircuitAuthorization_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -149,8 +153,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_express_route_circuit" "test" { name = "acctest-erc-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name service_provider_name = "Equinix" peering_location = "Silicon Valley" bandwidth_in_mbps = 50 @@ -170,8 +174,8 @@ resource "azurerm_express_route_circuit" "test" { resource "azurerm_express_route_circuit_authorization" "test" { name = "acctestauth%d" - express_route_circuit_name = "${azurerm_express_route_circuit.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + express_route_circuit_name = azurerm_express_route_circuit.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } @@ -182,15 +186,19 @@ func testAccAzureRMExpressRouteCircuitAuthorization_requiresImportConfig(data ac %s resource "azurerm_express_route_circuit_authorization" "import" { - name = "${azurerm_express_route_circuit_authorization.test.name}" - express_route_circuit_name = "${azurerm_express_route_circuit_authorization.test.express_route_circuit_name}" - resource_group_name = "${azurerm_express_route_circuit_authorization.test.resource_group_name}" + name = azurerm_express_route_circuit_authorization.test.name + express_route_circuit_name = azurerm_express_route_circuit_authorization.test.express_route_circuit_name + resource_group_name = azurerm_express_route_circuit_authorization.test.resource_group_name } `, template) } func testAccAzureRMExpressRouteCircuitAuthorization_multipleConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -198,8 +206,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_express_route_circuit" "test" { name = "acctest-erc-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name service_provider_name = "Equinix" peering_location = "Silicon Valley" bandwidth_in_mbps = 50 @@ -219,14 +227,14 @@ resource "azurerm_express_route_circuit" "test" { resource "azurerm_express_route_circuit_authorization" "test1" { name = "acctestauth1%d" - express_route_circuit_name = "${azurerm_express_route_circuit.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + express_route_circuit_name = azurerm_express_route_circuit.test.name + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_express_route_circuit_authorization" "test2" { name = "acctestauth2%d" - express_route_circuit_name = "${azurerm_express_route_circuit.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + express_route_circuit_name = azurerm_express_route_circuit.test.name + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_peering_test.go b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_peering_test.go index 1a6dab56dc1d9..c6f5f3b6e088d 100644 --- a/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_peering_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_peering_test.go @@ -29,7 +29,7 @@ func testAccAzureRMExpressRouteCircuitPeering_azurePrivatePeering(t *testing.T) resource.TestCheckResourceAttr(data.ResourceName, "microsoft_peering_config.#", "0"), ), }, - data.ImportStep("shared_key"), //is not returned by the API + data.ImportStep("shared_key"), // is not returned by the API }, }) } @@ -103,7 +103,7 @@ func testAccAzureRMExpressRouteCircuitPeering_azurePrivatePeeringWithCircuitUpda resource.TestCheckResourceAttr(data.ResourceName, "microsoft_peering_config.#", "0"), ), }, - data.ImportStep("shared_key"), //is not returned by the API + data.ImportStep("shared_key"), // is not returned by the API }, }) } @@ -167,6 +167,10 @@ func testCheckAzureRMExpressRouteCircuitPeeringDestroy(s *terraform.State) error func testAccAzureRMExpressRouteCircuitPeering_privatePeering(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -174,8 +178,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_express_route_circuit" "test" { name = "acctest-erc-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name service_provider_name = "Equinix" peering_location = "Silicon Valley" bandwidth_in_mbps = 50 @@ -193,8 +197,8 @@ resource "azurerm_express_route_circuit" "test" { resource "azurerm_express_route_circuit_peering" "test" { peering_type = "AzurePrivatePeering" - express_route_circuit_name = "${azurerm_express_route_circuit.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + express_route_circuit_name = azurerm_express_route_circuit.test.name + resource_group_name = azurerm_resource_group.test.name shared_key = "SSSSsssssshhhhhItsASecret" peer_asn = 100 primary_peer_address_prefix = "192.168.1.0/30" @@ -210,20 +214,24 @@ func testAccAzureRMExpressRouteCircuitPeering_requiresImportConfig(data acceptan %s resource "azurerm_express_route_circuit_peering" "import" { - peering_type = "${azurerm_express_route_circuit_peering.test.peering_type}" - express_route_circuit_name = "${azurerm_express_route_circuit_peering.test.express_route_circuit_name}" - resource_group_name = "${azurerm_express_route_circuit_peering.test.resource_group_name}" - shared_key = "${azurerm_express_route_circuit_peering.test.shared_key}" - peer_asn = "${azurerm_express_route_circuit_peering.test.peer_asn}" - primary_peer_address_prefix = "${azurerm_express_route_circuit_peering.test.primary_peer_address_prefix}" - secondary_peer_address_prefix = "${azurerm_express_route_circuit_peering.test.secondary_peer_address_prefix}" - vlan_id = "${azurerm_express_route_circuit_peering.test.vlan_id}" + peering_type = azurerm_express_route_circuit_peering.test.peering_type + express_route_circuit_name = azurerm_express_route_circuit_peering.test.express_route_circuit_name + resource_group_name = azurerm_express_route_circuit_peering.test.resource_group_name + shared_key = azurerm_express_route_circuit_peering.test.shared_key + peer_asn = azurerm_express_route_circuit_peering.test.peer_asn + primary_peer_address_prefix = azurerm_express_route_circuit_peering.test.primary_peer_address_prefix + secondary_peer_address_prefix = azurerm_express_route_circuit_peering.test.secondary_peer_address_prefix + vlan_id = azurerm_express_route_circuit_peering.test.vlan_id } `, template) } func testAccAzureRMExpressRouteCircuitPeering_msPeering(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -231,8 +239,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_express_route_circuit" "test" { name = "acctest-erc-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name service_provider_name = "Equinix" peering_location = "Silicon Valley" bandwidth_in_mbps = 50 @@ -250,8 +258,8 @@ resource "azurerm_express_route_circuit" "test" { resource "azurerm_express_route_circuit_peering" "test" { peering_type = "MicrosoftPeering" - express_route_circuit_name = "${azurerm_express_route_circuit.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + express_route_circuit_name = azurerm_express_route_circuit.test.name + resource_group_name = azurerm_resource_group.test.name peer_asn = 100 primary_peer_address_prefix = "192.168.1.0/30" secondary_peer_address_prefix = "192.168.2.0/30" @@ -266,6 +274,10 @@ resource "azurerm_express_route_circuit_peering" "test" { func testAccAzureRMExpressRouteCircuitPeering_privatePeeringWithCircuitUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -273,8 +285,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_express_route_circuit" "test" { name = "acctest-erc-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name service_provider_name = "Equinix" peering_location = "Silicon Valley" bandwidth_in_mbps = 50 @@ -292,8 +304,8 @@ resource "azurerm_express_route_circuit" "test" { resource "azurerm_express_route_circuit_peering" "test" { peering_type = "AzurePrivatePeering" - express_route_circuit_name = "${azurerm_express_route_circuit.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + express_route_circuit_name = azurerm_express_route_circuit.test.name + resource_group_name = azurerm_resource_group.test.name shared_key = "SSSSsssssshhhhhItsASecret" peer_asn = 100 primary_peer_address_prefix = "192.168.1.0/30" diff --git a/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_test.go b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_test.go index 82f6bab218bd4..700dc98f6a5a1 100644 --- a/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_test.go @@ -309,6 +309,10 @@ func testCheckAzureRMExpressRouteCircuitDestroy(s *terraform.State) error { func testAccAzureRMExpressRouteCircuit_basicMeteredConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -316,8 +320,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_express_route_circuit" "test" { name = "acctest-erc-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name service_provider_name = "Equinix" peering_location = "Silicon Valley" bandwidth_in_mbps = 50 @@ -343,9 +347,9 @@ func testAccAzureRMExpressRouteCircuit_requiresImportConfig(data acceptance.Test %s resource "azurerm_express_route_circuit" "import" { - name = "${azurerm_express_route_circuit.test.name}" - location = "${azurerm_express_route_circuit.test.location}" - resource_group_name = "${azurerm_express_route_circuit.test.resource_group_name}" + name = azurerm_express_route_circuit.test.name + location = azurerm_express_route_circuit.test.location + resource_group_name = azurerm_express_route_circuit.test.resource_group_name service_provider_name = "Equinix" peering_location = "Silicon Valley" bandwidth_in_mbps = 50 @@ -367,6 +371,10 @@ resource "azurerm_express_route_circuit" "import" { func testAccAzureRMExpressRouteCircuit_basicUnlimitedConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -374,8 +382,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_express_route_circuit" "test" { name = "acctest-erc-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name service_provider_name = "Equinix" peering_location = "Silicon Valley" bandwidth_in_mbps = 50 @@ -397,6 +405,10 @@ resource "azurerm_express_route_circuit" "test" { func testAccAzureRMExpressRouteCircuit_sku(data acceptance.TestData, tier string, family string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -404,8 +416,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_express_route_circuit" "test" { name = "acctest-erc-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name service_provider_name = "Equinix" peering_location = "Silicon Valley" bandwidth_in_mbps = 50 @@ -427,6 +439,10 @@ resource "azurerm_express_route_circuit" "test" { func testAccAzureRMExpressRouteCircuit_allowClassicOperations(data acceptance.TestData, allowClassicOperations string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -434,8 +450,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_express_route_circuit" "test" { name = "acctest-erc-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name service_provider_name = "Equinix" peering_location = "Silicon Valley" bandwidth_in_mbps = 50 diff --git a/azurerm/internal/services/network/tests/resource_arm_express_route_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_express_route_gateway_test.go new file mode 100644 index 0000000000000..32388509d215a --- /dev/null +++ b/azurerm/internal/services/network/tests/resource_arm_express_route_gateway_test.go @@ -0,0 +1,217 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMExpressRouteGateway_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_express_route_gateway", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMExpressRouteGatewayDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMExpressRouteGateway_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMExpressRouteGatewayExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMExpressRouteGateway_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + + data := acceptance.BuildTestData(t, "azurerm_express_route_gateway", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMExpressRouteGatewayDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMExpressRouteGateway_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMExpressRouteGatewayExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMExpressRouteGateway_requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_express_route_gateway"), + }, + }, + }) +} + +func TestAccAzureRMExpressRouteGateway_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_express_route_gateway", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMExpressRouteGatewayDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMExpressRouteGateway_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMExpressRouteGatewayExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMExpressRouteGateway_complete(data, 2), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMExpressRouteGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "scale_units", "2"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMExpressRouteGateway_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMExpressRouteGatewayExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMExpressRouteGatewayExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Network.ExpressRouteGatewaysClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("ExpressRoute Gateway not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + if resp, err := client.Get(ctx, resourceGroup, name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: ExpressRoute Gateway %q (Resource Group %q) does not exist", name, resourceGroup) + } + return fmt.Errorf("Bad: Get on network.ExpressRouteGatewaysClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMExpressRouteGatewayDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Network.ExpressRouteGatewaysClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_express_route_gateway" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + if resp, err := client.Get(ctx, resourceGroup, name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on network.ExpressRouteGatewaysClient: %+v", err) + } + } + + return nil + } + + return nil +} + +func testAccAzureRMExpressRouteGateway_basic(data acceptance.TestData) string { + template := testAccAzureRMExpressRouteGateway_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_express_route_gateway" "test" { + name = "acctestER-gateway-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + virtual_hub_id = azurerm_virtual_hub.test.id + scale_units = 1 +} +`, template, data.RandomInteger) +} + +func testAccAzureRMExpressRouteGateway_complete(data acceptance.TestData, scaleUnits int) string { + template := testAccAzureRMExpressRouteGateway_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_express_route_gateway" "test" { + name = "acctestER-gateway-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + virtual_hub_id = azurerm_virtual_hub.test.id + scale_units = %d + + tags = { + Hello = "World" + } +} +`, template, data.RandomInteger, scaleUnits) +} + +func testAccAzureRMExpressRouteGateway_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMExpressRouteGateway_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_express_route_gateway" "import" { + name = azurerm_express_route_gateway.test.name + resource_group_name = azurerm_express_route_gateway.test.name + location = azurerm_express_route_gateway.test.location + virtual_hub_id = azurerm_express_route_gateway.test.virtual_hub_id + scale_units = azurerm_express_route_gateway.test.scale_units +} +`, template) +} + +func testAccAzureRMExpressRouteGateway_template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-express-%d" + location = "%s" +} + +resource "azurerm_virtual_wan" "test" { + name = "acctest-VWAN-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_virtual_hub" "test" { + name = "acctest-VHUB-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + virtual_wan_id = azurerm_virtual_wan.test.id + address_prefix = "10.0.1.0/24" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} diff --git a/azurerm/internal/services/network/tests/resource_arm_firewall_application_rule_collection_test.go b/azurerm/internal/services/network/tests/resource_arm_firewall_application_rule_collection_test.go index ca3a6a29254ae..d2371d67996c9 100644 --- a/azurerm/internal/services/network/tests/resource_arm_firewall_application_rule_collection_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_firewall_application_rule_collection_test.go @@ -495,8 +495,8 @@ func testAccAzureRMFirewallApplicationRuleCollection_basic(data acceptance.TestD resource "azurerm_firewall_application_rule_collection" "test" { name = "acctestarc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Allow" @@ -526,9 +526,9 @@ func testAccAzureRMFirewallApplicationRuleCollection_requiresImport(data accepta %s resource "azurerm_firewall_application_rule_collection" "import" { - name = "${azurerm_firewall_application_rule_collection.test.name}" - azure_firewall_name = "${azurerm_firewall_application_rule_collection.test.azure_firewall_name}" - resource_group_name = "${azurerm_firewall_application_rule_collection.test.resource_group_name}" + name = azurerm_firewall_application_rule_collection.test.name + azure_firewall_name = azurerm_firewall_application_rule_collection.test.azure_firewall_name + resource_group_name = azurerm_firewall_application_rule_collection.test.resource_group_name priority = 100 action = "Allow" @@ -559,8 +559,8 @@ func testAccAzureRMFirewallApplicationRuleCollection_updatedName(data acceptance resource "azurerm_firewall_application_rule_collection" "test" { name = "acctestarc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Allow" @@ -591,8 +591,8 @@ func testAccAzureRMFirewallApplicationRuleCollection_multiple(data acceptance.Te resource "azurerm_firewall_application_rule_collection" "test" { name = "acctestarc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Allow" @@ -616,8 +616,8 @@ resource "azurerm_firewall_application_rule_collection" "test" { resource "azurerm_firewall_application_rule_collection" "test_add" { name = "acctestarc_add" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 200 action = "Deny" @@ -648,8 +648,8 @@ func testAccAzureRMFirewallApplicationRuleCollection_multipleUpdate(data accepta resource "azurerm_firewall_application_rule_collection" "test" { name = "acctestarc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 300 action = "Deny" @@ -673,8 +673,8 @@ resource "azurerm_firewall_application_rule_collection" "test" { resource "azurerm_firewall_application_rule_collection" "test_add" { name = "acctestarc_add" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 400 action = "Allow" @@ -705,8 +705,8 @@ func testAccAzureRMFirewallApplicationRuleCollection_multipleRules(data acceptan resource "azurerm_firewall_application_rule_collection" "test" { name = "acctestarc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Allow" @@ -754,8 +754,8 @@ func testAccAzureRMFirewallApplicationRuleCollection_multipleProtocols(data acce resource "azurerm_firewall_application_rule_collection" "test" { name = "acctestarc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Allow" @@ -791,8 +791,8 @@ func testAccAzureRMFirewallApplicationRuleCollection_multipleProtocolsUpdate(dat resource "azurerm_firewall_application_rule_collection" "test" { name = "acctestarc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Allow" @@ -828,8 +828,8 @@ func testAccAzureRMFirewallApplicationRuleCollection_updateFirewallTags(data acc resource "azurerm_firewall_application_rule_collection" "test" { name = "acctestarc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Allow" diff --git a/azurerm/internal/services/network/tests/resource_arm_firewall_nat_rule_collection_test.go b/azurerm/internal/services/network/tests/resource_arm_firewall_nat_rule_collection_test.go index dbc42459c57c2..e248e73cd343d 100644 --- a/azurerm/internal/services/network/tests/resource_arm_firewall_nat_rule_collection_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_firewall_nat_rule_collection_test.go @@ -343,8 +343,8 @@ func testAccAzureRMFirewallNatRuleCollection_basic(data acceptance.TestData) str resource "azurerm_firewall_nat_rule_collection" "test" { name = "acctestnrc-%d" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Dnat" @@ -360,7 +360,7 @@ resource "azurerm_firewall_nat_rule_collection" "test" { ] destination_addresses = [ - "${azurerm_public_ip.test.ip_address}", + azurerm_public_ip.test.ip_address, ] protocols = [ @@ -380,9 +380,9 @@ func testAccAzureRMFirewallNatRuleCollection_requiresImport(data acceptance.Test %s resource "azurerm_firewall_nat_rule_collection" "import" { - name = "${azurerm_firewall_nat_rule_collection.test.name}" - azure_firewall_name = "${azurerm_firewall_nat_rule_collection.test.azure_firewall_name}" - resource_group_name = "${azurerm_firewall_nat_rule_collection.test.resource_group_name}" + name = azurerm_firewall_nat_rule_collection.test.name + azure_firewall_name = azurerm_firewall_nat_rule_collection.test.azure_firewall_name + resource_group_name = azurerm_firewall_nat_rule_collection.test.resource_group_name priority = 100 action = "Dnat" @@ -398,7 +398,7 @@ resource "azurerm_firewall_nat_rule_collection" "import" { ] destination_addresses = [ - "${azurerm_public_ip.test.ip_address}", + azurerm_public_ip.test.ip_address, ] protocols = [ @@ -419,8 +419,8 @@ func testAccAzureRMFirewallNatRuleCollection_updatedName(data acceptance.TestDat resource "azurerm_firewall_nat_rule_collection" "test" { name = "acctestnrc-%d" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Dnat" @@ -436,7 +436,7 @@ resource "azurerm_firewall_nat_rule_collection" "test" { ] destination_addresses = [ - "${azurerm_public_ip.test.ip_address}", + azurerm_public_ip.test.ip_address, ] protocols = [ @@ -457,8 +457,8 @@ func testAccAzureRMFirewallNatRuleCollection_multiple(data acceptance.TestData) resource "azurerm_firewall_nat_rule_collection" "test" { name = "acctestnrc-%d" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Dnat" @@ -474,7 +474,7 @@ resource "azurerm_firewall_nat_rule_collection" "test" { ] destination_addresses = [ - "${azurerm_public_ip.test.ip_address}", + azurerm_public_ip.test.ip_address, ] protocols = [ @@ -488,8 +488,8 @@ resource "azurerm_firewall_nat_rule_collection" "test" { resource "azurerm_firewall_nat_rule_collection" "test_add" { name = "acctestnrc_add-%d" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 200 action = "Dnat" @@ -505,7 +505,7 @@ resource "azurerm_firewall_nat_rule_collection" "test_add" { ] destination_addresses = [ - "${azurerm_public_ip.test.ip_address}", + azurerm_public_ip.test.ip_address, ] protocols = [ @@ -526,8 +526,8 @@ func testAccAzureRMFirewallNatRuleCollection_multipleUpdate(data acceptance.Test resource "azurerm_firewall_nat_rule_collection" "test" { name = "acctestnrc-%d" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 300 action = "Dnat" @@ -543,7 +543,7 @@ resource "azurerm_firewall_nat_rule_collection" "test" { ] destination_addresses = [ - "${azurerm_public_ip.test.ip_address}", + azurerm_public_ip.test.ip_address, ] protocols = [ @@ -557,8 +557,8 @@ resource "azurerm_firewall_nat_rule_collection" "test" { resource "azurerm_firewall_nat_rule_collection" "test_add" { name = "acctestnrc_add-%d" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 400 action = "Dnat" @@ -574,7 +574,7 @@ resource "azurerm_firewall_nat_rule_collection" "test_add" { ] destination_addresses = [ - "${azurerm_public_ip.test.ip_address}", + azurerm_public_ip.test.ip_address, ] protocols = [ @@ -595,8 +595,8 @@ func testAccAzureRMFirewallNatRuleCollection_multipleRules(data acceptance.TestD resource "azurerm_firewall_nat_rule_collection" "test" { name = "acctestnrc-%d" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Dnat" @@ -612,7 +612,7 @@ resource "azurerm_firewall_nat_rule_collection" "test" { ] destination_addresses = [ - "${azurerm_public_ip.test.ip_address}", + azurerm_public_ip.test.ip_address, ] protocols = [ @@ -635,7 +635,7 @@ resource "azurerm_firewall_nat_rule_collection" "test" { ] destination_addresses = [ - "${azurerm_public_ip.test.ip_address}", + azurerm_public_ip.test.ip_address, ] protocols = [ @@ -656,8 +656,8 @@ func testAccAzureRMFirewallNatRuleCollection_updateFirewallTags(data acceptance. resource "azurerm_firewall_nat_rule_collection" "test" { name = "acctestnrc-%d" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Dnat" @@ -673,7 +673,7 @@ resource "azurerm_firewall_nat_rule_collection" "test" { ] destination_addresses = [ - "${azurerm_public_ip.test.ip_address}", + azurerm_public_ip.test.ip_address, ] protocols = [ diff --git a/azurerm/internal/services/network/tests/resource_arm_firewall_network_rule_collection_test.go b/azurerm/internal/services/network/tests/resource_arm_firewall_network_rule_collection_test.go index 8335797a7d16c..bbf799dab135c 100644 --- a/azurerm/internal/services/network/tests/resource_arm_firewall_network_rule_collection_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_firewall_network_rule_collection_test.go @@ -401,8 +401,8 @@ func testAccAzureRMFirewallNetworkRuleCollection_basic(data acceptance.TestData) resource "azurerm_firewall_network_rule_collection" "test" { name = "acctestnrc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Allow" @@ -435,9 +435,9 @@ func testAccAzureRMFirewallNetworkRuleCollection_requiresImport(data acceptance. %s resource "azurerm_firewall_network_rule_collection" "import" { - name = "${azurerm_firewall_network_rule_collection.test.name}" - azure_firewall_name = "${azurerm_firewall_network_rule_collection.test.azure_firewall_name}" - resource_group_name = "${azurerm_firewall_network_rule_collection.test.resource_group_name}" + name = azurerm_firewall_network_rule_collection.test.name + azure_firewall_name = azurerm_firewall_network_rule_collection.test.azure_firewall_name + resource_group_name = azurerm_firewall_network_rule_collection.test.resource_group_name priority = 100 action = "Allow" @@ -471,8 +471,8 @@ func testAccAzureRMFirewallNetworkRuleCollection_updatedName(data acceptance.Tes resource "azurerm_firewall_network_rule_collection" "test" { name = "acctestnrc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Allow" @@ -506,8 +506,8 @@ func testAccAzureRMFirewallNetworkRuleCollection_multiple(data acceptance.TestDa resource "azurerm_firewall_network_rule_collection" "test" { name = "acctestnrc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Allow" @@ -534,8 +534,8 @@ resource "azurerm_firewall_network_rule_collection" "test" { resource "azurerm_firewall_network_rule_collection" "test_add" { name = "acctestnrc_add" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 200 action = "Deny" @@ -569,8 +569,8 @@ func testAccAzureRMFirewallNetworkRuleCollection_multipleUpdate(data acceptance. resource "azurerm_firewall_network_rule_collection" "test" { name = "acctestnrc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 300 action = "Deny" @@ -597,8 +597,8 @@ resource "azurerm_firewall_network_rule_collection" "test" { resource "azurerm_firewall_network_rule_collection" "test_add" { name = "acctestnrc_add" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 400 action = "Allow" @@ -632,8 +632,8 @@ func testAccAzureRMFirewallNetworkRuleCollection_multipleRules(data acceptance.T resource "azurerm_firewall_network_rule_collection" "test" { name = "acctestnrc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Allow" @@ -687,8 +687,8 @@ func testAccAzureRMFirewallNetworkRuleCollection_updateFirewallTags(data accepta resource "azurerm_firewall_network_rule_collection" "test" { name = "acctestnrc" - azure_firewall_name = "${azurerm_firewall.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + azure_firewall_name = azurerm_firewall.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 action = "Allow" diff --git a/azurerm/internal/services/network/tests/resource_arm_firewall_test.go b/azurerm/internal/services/network/tests/resource_arm_firewall_test.go index 67772e4550fb3..3e4b5cbd51841 100644 --- a/azurerm/internal/services/network/tests/resource_arm_firewall_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_firewall_test.go @@ -50,35 +50,6 @@ func TestValidateFirewallName(t *testing.T) { } } -func TestAccAzureRMFirewall_basicOld(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_firewall", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMFirewallDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMFirewall_basicOld(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.name", "configuration"), - resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.private_ip_address"), - ), - }, - { - Config: testAccAzureRMFirewall_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.name", "configuration"), - resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.private_ip_address"), - ), - }, - data.ImportStep(), - }, - }) -} - func TestAccAzureRMFirewall_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_firewall", "test") @@ -318,51 +289,12 @@ func testCheckAzureRMFirewallDestroy(s *terraform.State) error { return nil } -func testAccAzureRMFirewall_basicOld(data acceptance.TestData) string { +func testAccAzureRMFirewall_basic(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" +provider "azurerm" { + features {} } -resource "azurerm_subnet" "test" { - name = "AzureFirewallSubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.1.0/24" -} - -resource "azurerm_public_ip" "test" { - name = "acctestpip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - allocation_method = "Static" - sku = "Standard" -} - -resource "azurerm_firewall" "test" { - name = "acctestfirewall%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "configuration" - subnet_id = "${azurerm_subnet.test.id}" - internal_public_ip_address_id = "${azurerm_public_ip.test.id}" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMFirewall_basic(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -371,34 +303,34 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "AzureFirewallSubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_firewall" "test" { name = "acctestfirewall%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "configuration" - subnet_id = "${azurerm_subnet.test.id}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + subnet_id = azurerm_subnet.test.id + public_ip_address_id = azurerm_public_ip.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -406,6 +338,10 @@ resource "azurerm_firewall" "test" { func testAccAzureRMFirewall_multiplePublicIps(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -414,47 +350,47 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "AzureFirewallSubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_public_ip" "test_2" { name = "acctestpip2%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_firewall" "test" { name = "acctestfirewall%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "configuration" - subnet_id = "${azurerm_subnet.test.id}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + subnet_id = azurerm_subnet.test.id + public_ip_address_id = azurerm_public_ip.test.id } ip_configuration { name = "configuration_2" - public_ip_address_id = "${azurerm_public_ip.test_2.id}" + public_ip_address_id = azurerm_public_ip.test_2.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -466,14 +402,14 @@ func testAccAzureRMFirewall_requiresImport(data acceptance.TestData) string { %s resource "azurerm_firewall" "import" { - name = "${azurerm_firewall.test.name}" - location = "${azurerm_firewall.test.location}" - resource_group_name = "${azurerm_firewall.test.resource_group_name}" + name = azurerm_firewall.test.name + location = azurerm_firewall.test.location + resource_group_name = azurerm_firewall.test.resource_group_name ip_configuration { name = "configuration" - subnet_id = "${azurerm_subnet.test.id}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + subnet_id = azurerm_subnet.test.id + public_ip_address_id = azurerm_public_ip.test.id } } `, template) @@ -481,6 +417,10 @@ resource "azurerm_firewall" "import" { func testAccAzureRMFirewall_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -489,34 +429,34 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "AzureFirewallSubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_firewall" "test" { name = "acctestfirewall%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "configuration" - subnet_id = "${azurerm_subnet.test.id}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + subnet_id = azurerm_subnet.test.id + public_ip_address_id = azurerm_public_ip.test.id } tags = { @@ -529,6 +469,10 @@ resource "azurerm_firewall" "test" { func testAccAzureRMFirewall_withUpdatedTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -537,34 +481,34 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "AzureFirewallSubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_firewall" "test" { name = "acctestfirewall%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "configuration" - subnet_id = "${azurerm_subnet.test.id}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + subnet_id = azurerm_subnet.test.id + public_ip_address_id = azurerm_public_ip.test.id } tags = { @@ -577,6 +521,10 @@ resource "azurerm_firewall" "test" { func testAccAzureRMFirewall_withZones(data acceptance.TestData, zones []string) string { zoneString := strings.Join(zones, ",") return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -585,34 +533,34 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "AzureFirewallSubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_firewall" "test" { name = "acctestfirewall%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "configuration" - subnet_id = "${azurerm_subnet.test.id}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + subnet_id = azurerm_subnet.test.id + public_ip_address_id = azurerm_public_ip.test.id } zones = [%s] diff --git a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_backend_address_pool_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_backend_address_pool_test.go index a41442d0d2142..4e7d0da09b52f 100644 --- a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_backend_address_pool_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_backend_address_pool_test.go @@ -44,8 +44,6 @@ func TestAccAzureRMLoadBalancerBackEndAddressPool_basic(t *testing.T) { ResourceName: "azurerm_lb.test", ImportState: true, ImportStateVerify: true, - // location is deprecated and was never actually used - ImportStateVerifyIgnore: []string{"location"}, }, }, }) @@ -190,6 +188,10 @@ func testCheckAzureRMLoadBalancerBackEndAddressPoolDisappears(addressPoolName st func testAccAzureRMLoadBalancerBackEndAddressPool_basic(data acceptance.TestData, addressPoolName string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -197,26 +199,25 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_lb_backend_address_pool" "test" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, addressPoolName) @@ -228,16 +229,19 @@ func testAccAzureRMLoadBalancerBackEndAddressPool_requiresImport(data acceptance %s resource "azurerm_lb_backend_address_pool" "import" { - name = "${azurerm_lb_backend_address_pool.test.name}" - loadbalancer_id = "${azurerm_lb_backend_address_pool.test.loadbalancer_id}" - location = "${azurerm_lb_backend_address_pool.test.location}" - resource_group_name = "${azurerm_lb_backend_address_pool.test.resource_group_name}" + name = azurerm_lb_backend_address_pool.test.name + loadbalancer_id = azurerm_lb_backend_address_pool.test.loadbalancer_id + resource_group_name = azurerm_lb_backend_address_pool.test.resource_group_name } `, template) } func testAccAzureRMLoadBalancerBackEndAddressPool_removal(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -245,19 +249,19 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) diff --git a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_pool_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_pool_test.go index fc3cab1156c0f..a46e74c659474 100644 --- a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_pool_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_pool_test.go @@ -44,8 +44,6 @@ func TestAccAzureRMLoadBalancerNatPool_basic(t *testing.T) { ResourceName: "azurerm_lb.test", ImportState: true, ImportStateVerify: true, - // location is deprecated and was never actually used - ImportStateVerifyIgnore: []string{"location"}, }, }, }) @@ -234,6 +232,10 @@ func testCheckAzureRMLoadBalancerNatPoolDisappears(natPoolName string, lb *netwo func testAccAzureRMLoadBalancerNatPool_basic(data acceptance.TestData, natPoolName string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -241,26 +243,25 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_lb_nat_pool" "test" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" protocol = "Tcp" frontend_port_start = 80 @@ -277,11 +278,10 @@ func testAccAzureRMLoadBalancerNatPool_requiresImport(data acceptance.TestData, %s resource "azurerm_lb_nat_pool" "import" { - name = "${azurerm_lb_nat_pool.test.name}" - loadbalancer_id = "${azurerm_lb_nat_pool.test.loadbalancer_id}" - location = "${azurerm_lb_nat_pool.test.location}" - resource_group_name = "${azurerm_lb_nat_pool.test.resource_group_name}" - frontend_ip_configuration_name = "${azurerm_lb_nat_pool.test.frontend_ip_configuration_name}" + name = azurerm_lb_nat_pool.test.name + loadbalancer_id = azurerm_lb_nat_pool.test.loadbalancer_id + resource_group_name = azurerm_lb_nat_pool.test.resource_group_name + frontend_ip_configuration_name = azurerm_lb_nat_pool.test.frontend_ip_configuration_name protocol = "Tcp" frontend_port_start = 80 frontend_port_end = 81 @@ -292,6 +292,10 @@ resource "azurerm_lb_nat_pool" "import" { func testAccAzureRMLoadBalancerNatPool_removal(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -299,19 +303,19 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -319,6 +323,10 @@ resource "azurerm_lb" "test" { func testAccAzureRMLoadBalancerNatPool_multiplePools(data acceptance.TestData, natPoolName, natPool2Name string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -326,27 +334,26 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_lb_nat_pool" "test" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" protocol = "Tcp" frontend_port_start = 80 @@ -357,9 +364,8 @@ resource "azurerm_lb_nat_pool" "test" { } resource "azurerm_lb_nat_pool" "test2" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" protocol = "Tcp" frontend_port_start = 82 @@ -373,6 +379,10 @@ resource "azurerm_lb_nat_pool" "test2" { func testAccAzureRMLoadBalancerNatPool_multiplePoolsUpdate(data acceptance.TestData, natPoolName, natPool2Name string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -380,26 +390,25 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_lb_nat_pool" "test" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" protocol = "Tcp" frontend_port_start = 80 @@ -409,9 +418,8 @@ resource "azurerm_lb_nat_pool" "test" { } resource "azurerm_lb_nat_pool" "test2" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" protocol = "Tcp" frontend_port_start = 82 diff --git a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_rule_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_rule_test.go index 175c35b16ef8f..d94d22f7b8f8a 100644 --- a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_rule_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_rule_test.go @@ -39,7 +39,7 @@ func TestAccAzureRMLoadBalancerNatRule_basic(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "id", natRuleId), ), }, - data.ImportStep("location"), // todo remove location in 2.0 + data.ImportStep(), }, }) } @@ -68,7 +68,7 @@ func TestAccAzureRMLoadBalancerNatRule_complete(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "id", natRuleId), ), }, - data.ImportStep("location"), + data.ImportStep(), }, }) } @@ -97,7 +97,7 @@ func TestAccAzureRMLoadBalancerNatRule_update(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "id", natRuleId), ), }, - data.ImportStep("location"), + data.ImportStep(), { Config: testAccAzureRMLoadBalancerNatRule_complete(data, natRuleName), Check: resource.ComposeTestCheckFunc( @@ -107,7 +107,7 @@ func TestAccAzureRMLoadBalancerNatRule_update(t *testing.T) { "azurerm_lb_nat_rule.test", "id", natRuleId), ), }, - data.ImportStep("location"), + data.ImportStep(), { Config: testAccAzureRMLoadBalancerNatRule_basic(data, natRuleName, "Standard"), Check: resource.ComposeTestCheckFunc( @@ -116,7 +116,7 @@ func TestAccAzureRMLoadBalancerNatRule_update(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "id", natRuleId), ), }, - data.ImportStep("location"), + data.ImportStep(), }, }) } @@ -303,6 +303,10 @@ func testCheckAzureRMLoadBalancerNatRuleDisappears(natRuleName string, lb *netwo func testAccAzureRMLoadBalancerNatRule_template(data acceptance.TestData, sku string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-lb-%[1]d" location = "%[2]s" @@ -310,21 +314,21 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "%[3]s" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "%[3]s" frontend_ip_configuration { name = "one-%[1]d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } `, data.RandomInteger, data.Locations.Primary, sku) @@ -335,7 +339,6 @@ func testAccAzureRMLoadBalancerNatRule_basic(data acceptance.TestData, natRuleNa %s resource "azurerm_lb_nat_rule" "test" { - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" name = "%s" @@ -353,7 +356,6 @@ func testAccAzureRMLoadBalancerNatRule_complete(data acceptance.TestData, natRul resource "azurerm_lb_nat_rule" "test" { name = "%s" - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" @@ -376,11 +378,10 @@ func testAccAzureRMLoadBalancerNatRule_requiresImport(data acceptance.TestData, %s resource "azurerm_lb_nat_rule" "import" { - name = "${azurerm_lb_nat_rule.test.name}" - loadbalancer_id = "${azurerm_lb_nat_rule.test.loadbalancer_id}" - location = "${azurerm_lb_nat_rule.test.location}" - resource_group_name = "${azurerm_lb_nat_rule.test.resource_group_name}" - frontend_ip_configuration_name = "${azurerm_lb_nat_rule.test.frontend_ip_configuration_name}" + name = azurerm_lb_nat_rule.test.name + loadbalancer_id = azurerm_lb_nat_rule.test.loadbalancer_id + resource_group_name = azurerm_lb_nat_rule.test.resource_group_name + frontend_ip_configuration_name = azurerm_lb_nat_rule.test.frontend_ip_configuration_name protocol = "Tcp" frontend_port = 3389 backend_port = 3389 @@ -393,7 +394,6 @@ func testAccAzureRMLoadBalancerNatRule_multipleRules(data acceptance.TestData, n %s resource "azurerm_lb_nat_rule" "test" { - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" name = "%s" @@ -404,7 +404,6 @@ resource "azurerm_lb_nat_rule" "test" { } resource "azurerm_lb_nat_rule" "test2" { - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" name = "%s" @@ -420,7 +419,6 @@ func testAccAzureRMLoadBalancerNatRule_multipleRulesUpdate(data acceptance.TestD return fmt.Sprintf(` %s resource "azurerm_lb_nat_rule" "test" { - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" name = "%s" @@ -431,7 +429,6 @@ resource "azurerm_lb_nat_rule" "test" { } resource "azurerm_lb_nat_rule" "test2" { - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" name = "%s" diff --git a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_outbound_rule_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_outbound_rule_test.go index 6dcdd638eb508..c7fe563ff46de 100644 --- a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_outbound_rule_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_outbound_rule_test.go @@ -268,6 +268,10 @@ func testCheckAzureRMLoadBalancerOutboundRuleDisappears(ruleName string, lb *net func testAccAzureRMLoadBalancerOutboundRule_basic(data acceptance.TestData, outboundRuleName string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -275,35 +279,35 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_lb_backend_address_pool" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "be-%d" } resource "azurerm_lb_outbound_rule" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" - backend_address_pool_id = "${azurerm_lb_backend_address_pool.test.id}" + backend_address_pool_id = azurerm_lb_backend_address_pool.test.id protocol = "All" frontend_ip_configuration { @@ -319,14 +323,14 @@ func testAccAzureRMLoadBalancerOutboundRule_requiresImport(data acceptance.TestD %s resource "azurerm_lb_outbound_rule" "import" { - name = "${azurerm_lb_outbound_rule.test.name}" - resource_group_name = "${azurerm_lb_outbound_rule.test.resource_group_name}" - loadbalancer_id = "${azurerm_lb_outbound_rule.test.loadbalancer_id}" - backend_address_pool_id = "${azurerm_lb_backend_address_pool.test.id}" + name = azurerm_lb_outbound_rule.test.name + resource_group_name = azurerm_lb_outbound_rule.test.resource_group_name + loadbalancer_id = azurerm_lb_outbound_rule.test.loadbalancer_id + backend_address_pool_id = azurerm_lb_backend_address_pool.test.id protocol = "All" frontend_ip_configuration { - name = "${azurerm_lb_outbound_rule.test.frontend_ip_configuration.0.name}" + name = azurerm_lb_outbound_rule.test.frontend_ip_configuration[0].name } } `, template) @@ -334,6 +338,10 @@ resource "azurerm_lb_outbound_rule" "import" { func testAccAzureRMLoadBalancerOutboundRule_removal(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -341,27 +349,27 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_lb_backend_address_pool" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "be-%d" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -369,6 +377,10 @@ resource "azurerm_lb" "test" { func testAccAzureRMLoadBalancerOutboundRule_multipleRules(data acceptance.TestData, outboundRuleName, outboundRule2Name string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -376,49 +388,49 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test1" { name = "test-ip-1-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_public_ip" "test2" { name = "test-ip-2-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" frontend_ip_configuration { name = "fe1-%d" - public_ip_address_id = "${azurerm_public_ip.test1.id}" + public_ip_address_id = azurerm_public_ip.test1.id } frontend_ip_configuration { name = "fe2-%d" - public_ip_address_id = "${azurerm_public_ip.test2.id}" + public_ip_address_id = azurerm_public_ip.test2.id } } resource "azurerm_lb_backend_address_pool" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "be-%d" } resource "azurerm_lb_outbound_rule" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" protocol = "Tcp" - backend_address_pool_id = "${azurerm_lb_backend_address_pool.test.id}" + backend_address_pool_id = azurerm_lb_backend_address_pool.test.id frontend_ip_configuration { name = "fe1-%d" @@ -426,11 +438,11 @@ resource "azurerm_lb_outbound_rule" "test" { } resource "azurerm_lb_outbound_rule" "test2" { - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" protocol = "Udp" - backend_address_pool_id = "${azurerm_lb_backend_address_pool.test.id}" + backend_address_pool_id = azurerm_lb_backend_address_pool.test.id frontend_ip_configuration { name = "fe2-%d" @@ -441,6 +453,10 @@ resource "azurerm_lb_outbound_rule" "test2" { func testAccAzureRMLoadBalancerOutboundRule_multipleRulesUpdate(data acceptance.TestData, outboundRuleName, outboundRule2Name string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -448,49 +464,49 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test1" { name = "test-ip-1-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_public_ip" "test2" { name = "test-ip-2-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" frontend_ip_configuration { name = "fe1-%d" - public_ip_address_id = "${azurerm_public_ip.test1.id}" + public_ip_address_id = azurerm_public_ip.test1.id } frontend_ip_configuration { name = "fe2-%d" - public_ip_address_id = "${azurerm_public_ip.test2.id}" + public_ip_address_id = azurerm_public_ip.test2.id } } resource "azurerm_lb_backend_address_pool" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "be-%d" } resource "azurerm_lb_outbound_rule" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" protocol = "All" - backend_address_pool_id = "${azurerm_lb_backend_address_pool.test.id}" + backend_address_pool_id = azurerm_lb_backend_address_pool.test.id frontend_ip_configuration { name = "fe1-%d" @@ -498,11 +514,11 @@ resource "azurerm_lb_outbound_rule" "test" { } resource "azurerm_lb_outbound_rule" "test2" { - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" protocol = "All" - backend_address_pool_id = "${azurerm_lb_backend_address_pool.test.id}" + backend_address_pool_id = azurerm_lb_backend_address_pool.test.id frontend_ip_configuration { name = "fe2-%d" @@ -513,6 +529,10 @@ resource "azurerm_lb_outbound_rule" "test2" { func testAccAzureRMLoadBalancerOutboundRule_withPublicIPPrefix(data acceptance.TestData, outboundRuleName string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -520,34 +540,34 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip_prefix" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name prefix_length = 31 } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" frontend_ip_configuration { name = "one-%d" - public_ip_prefix_id = "${azurerm_public_ip_prefix.test.id}" + public_ip_prefix_id = azurerm_public_ip_prefix.test.id } } resource "azurerm_lb_backend_address_pool" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "be-%d" } resource "azurerm_lb_outbound_rule" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" - backend_address_pool_id = "${azurerm_lb_backend_address_pool.test.id}" + backend_address_pool_id = azurerm_lb_backend_address_pool.test.id protocol = "All" frontend_ip_configuration { diff --git a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_probe_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_probe_test.go index bbc310957bcb4..083a7e869fff0 100644 --- a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_probe_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_probe_test.go @@ -40,13 +40,7 @@ func TestAccAzureRMLoadBalancerProbe_basic(t *testing.T) { "azurerm_lb_probe.test", "id", probeId), ), }, - { - ResourceName: "azurerm_lb.test", - ImportState: true, - ImportStateVerify: true, - // location is deprecated and was never actually used - ImportStateVerifyIgnore: []string{"location"}, - }, + data.ImportStep(), }, }) } @@ -265,6 +259,10 @@ func testCheckAzureRMLoadBalancerProbeDisappears(addressPoolName string, lb *net func testAccAzureRMLoadBalancerProbe_basic(data acceptance.TestData, probeName string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -272,26 +270,25 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_lb_probe" "test" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" port = 22 } @@ -304,10 +301,9 @@ func testAccAzureRMLoadBalancerProbe_requiresImport(data acceptance.TestData, na %s resource "azurerm_lb_probe" "import" { - name = "${azurerm_lb_probe.test.name}" - loadbalancer_id = "${azurerm_lb_probe.test.loadbalancer_id}" - location = "${azurerm_lb_probe.test.location}" - resource_group_name = "${azurerm_lb_probe.test.resource_group_name}" + name = azurerm_lb_probe.test.name + loadbalancer_id = azurerm_lb_probe.test.loadbalancer_id + resource_group_name = azurerm_lb_probe.test.resource_group_name port = 22 } `, template) @@ -315,6 +311,10 @@ resource "azurerm_lb_probe" "import" { func testAccAzureRMLoadBalancerProbe_removal(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -322,19 +322,19 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -342,6 +342,10 @@ resource "azurerm_lb" "test" { func testAccAzureRMLoadBalancerProbe_multipleProbes(data acceptance.TestData, probeName, probe2Name string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -349,34 +353,32 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_lb_probe" "test" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" port = 22 } resource "azurerm_lb_probe" "test2" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" port = 80 } @@ -385,6 +387,10 @@ resource "azurerm_lb_probe" "test2" { func testAccAzureRMLoadBalancerProbe_multipleProbesUpdate(data acceptance.TestData, probeName, probe2Name string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -392,34 +398,32 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_lb_probe" "test" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" port = 22 } resource "azurerm_lb_probe" "test2" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" port = 8080 } @@ -428,6 +432,10 @@ resource "azurerm_lb_probe" "test2" { func testAccAzureRMLoadBalancerProbe_updateProtocolBefore(data acceptance.TestData, probeName string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -435,26 +443,25 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_lb_probe" "test" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" protocol = "Http" request_path = "/" @@ -465,6 +472,10 @@ resource "azurerm_lb_probe" "test" { func testAccAzureRMLoadBalancerProbe_updateProtocolAfter(data acceptance.TestData, probeName string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -472,26 +483,25 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_lb_probe" "test" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "%s" protocol = "Tcp" port = 80 diff --git a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_rule_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_rule_test.go index 202f83f150a2f..4f157c924d681 100644 --- a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_rule_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_rule_test.go @@ -96,7 +96,7 @@ func TestAccAzureRMLoadBalancerRule_basic(t *testing.T) { "azurerm_lb_rule.test", "id", lbRule_id), ), }, - data.ImportStep("location"), // todo remove location in 2.0 + data.ImportStep(), }, }) } @@ -125,7 +125,7 @@ func TestAccAzureRMLoadBalancerRule_complete(t *testing.T) { "azurerm_lb_rule.test", "id", lbRule_id), ), }, - data.ImportStep("location"), // todo remove location in 2.0 + data.ImportStep(), }, }) } @@ -154,7 +154,7 @@ func TestAccAzureRMLoadBalancerRule_update(t *testing.T) { "azurerm_lb_rule.test", "id", lbRule_id), ), }, - data.ImportStep("location"), // todo remove location in 2.0 + data.ImportStep(), { Config: testAccAzureRMLoadBalancerRule_complete(data, lbRuleName), Check: resource.ComposeTestCheckFunc( @@ -164,7 +164,7 @@ func TestAccAzureRMLoadBalancerRule_update(t *testing.T) { "azurerm_lb_rule.test", "id", lbRule_id), ), }, - data.ImportStep("location"), // todo remove location in 2.0 + data.ImportStep(), { Config: testAccAzureRMLoadBalancerRule_basic(data, lbRuleName, "Basic"), Check: resource.ComposeTestCheckFunc( @@ -174,7 +174,7 @@ func TestAccAzureRMLoadBalancerRule_update(t *testing.T) { "azurerm_lb_rule.test", "id", lbRule_id), ), }, - data.ImportStep("location"), // todo remove location in 2.0 + data.ImportStep(), }, }) } @@ -304,7 +304,7 @@ func TestAccAzureRMLoadBalancerRule_updateMultipleRules(t *testing.T) { resource.TestCheckResourceAttr("azurerm_lb_rule.test2", "backend_port", "3390"), ), }, - data.ImportStep("location"), // todo remove location in 2.0 + data.ImportStep(), { Config: testAccAzureRMLoadBalancerRule_multipleRulesUpdate(data, lbRuleName, lbRule2Name), Check: resource.ComposeTestCheckFunc( @@ -317,7 +317,7 @@ func TestAccAzureRMLoadBalancerRule_updateMultipleRules(t *testing.T) { resource.TestCheckResourceAttr("azurerm_lb_rule.test2", "backend_port", "3391"), ), }, - data.ImportStep("location"), // todo remove location in 2.0 + data.ImportStep(), }, }) } @@ -403,6 +403,10 @@ func testCheckAzureRMLoadBalancerRuleDisappears(ruleName string, lb *network.Loa func testAccAzureRMLoadBalancerRule_template(data acceptance.TestData, sku string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-lb-%[1]d" location = "%[2]s" @@ -410,21 +414,21 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "%[3]s" } resource "azurerm_lb" "test" { name = "arm-test-loadbalancer-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "%[3]s" frontend_ip_configuration { name = "one-%[1]d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } `, data.RandomInteger, data.Locations.Primary, sku) @@ -435,7 +439,6 @@ func testAccAzureRMLoadBalancerRule_basic(data acceptance.TestData, lbRuleName, %s resource "azurerm_lb_rule" "test" { - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" name = "%s" @@ -453,7 +456,6 @@ func testAccAzureRMLoadBalancerRule_complete(data acceptance.TestData, lbRuleNam resource "azurerm_lb_rule" "test" { name = "%s" - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" @@ -477,11 +479,10 @@ func testAccAzureRMLoadBalancerRule_requiresImport(data acceptance.TestData, nam %s resource "azurerm_lb_rule" "import" { - name = "${azurerm_lb_rule.test.name}" - location = "${azurerm_lb_rule.test.location}" - resource_group_name = "${azurerm_lb_rule.test.resource_group_name}" - loadbalancer_id = "${azurerm_lb_rule.test.loadbalancer_id}" - frontend_ip_configuration_name = "${azurerm_lb_rule.test.frontend_ip_configuration_name}" + name = azurerm_lb_rule.test.name + resource_group_name = azurerm_lb_rule.test.resource_group_name + loadbalancer_id = azurerm_lb_rule.test.loadbalancer_id + frontend_ip_configuration_name = azurerm_lb_rule.test.frontend_ip_configuration_name protocol = "Tcp" frontend_port = 3389 backend_port = 3389 @@ -496,14 +497,12 @@ func testAccAzureRMLoadBalancerRule_inconsistentRead(data acceptance.TestData, b resource "azurerm_lb_backend_address_pool" "teset" { name = "%s" - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" } resource "azurerm_lb_probe" "test" { name = "%s" - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" protocol = "Tcp" @@ -512,7 +511,6 @@ resource "azurerm_lb_probe" "test" { resource "azurerm_lb_rule" "test" { name = "%s" - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" protocol = "Tcp" @@ -528,7 +526,6 @@ func testAccAzureRMLoadBalancerRule_multipleRules(data acceptance.TestData, lbRu %s resource "azurerm_lb_rule" "test" { - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" name = "%s" @@ -539,7 +536,6 @@ resource "azurerm_lb_rule" "test" { } resource "azurerm_lb_rule" "test2" { - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" name = "%s" @@ -556,7 +552,6 @@ func testAccAzureRMLoadBalancerRule_multipleRulesUpdate(data acceptance.TestData %s resource "azurerm_lb_rule" "test" { - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" name = "%s" @@ -567,7 +562,6 @@ resource "azurerm_lb_rule" "test" { } resource "azurerm_lb_rule" "test2" { - location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" loadbalancer_id = "${azurerm_lb.test.id}" name = "%s" diff --git a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_test.go index a5ae096cd4054..d1d77189f4340 100644 --- a/azurerm/internal/services/network/tests/resource_arm_loadbalancer_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_test.go @@ -256,6 +256,10 @@ func testCheckAzureRMLoadBalancerDestroy(s *terraform.State) error { func testAccAzureRMLoadBalancer_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -263,8 +267,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_lb" "test" { name = "acctest-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { Environment = "production" @@ -280,9 +284,9 @@ func testAccAzureRMLoadBalancer_requiresImport(data acceptance.TestData) string %s resource "azurerm_lb" "import" { - name = "${azurerm_lb.test.name}" - location = "${azurerm_lb.test.location}" - resource_group_name = "${azurerm_lb.test.resource_group_name}" + name = azurerm_lb.test.name + location = azurerm_lb.test.location + resource_group_name = azurerm_lb.test.resource_group_name tags = { Environment = "production" @@ -294,6 +298,10 @@ resource "azurerm_lb" "import" { func testAccAzureRMLoadBalancer_standard(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -301,8 +309,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_lb" "test" { name = "acctest-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" tags = { @@ -315,6 +323,10 @@ resource "azurerm_lb" "test" { func testAccAzureRMLoadBalancer_updatedTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -322,8 +334,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_lb" "test" { name = "acctest-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { Purpose = "AcceptanceTests" @@ -334,6 +346,10 @@ resource "azurerm_lb" "test" { func testAccAzureRMLoadBalancer_frontEndConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -341,31 +357,31 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_public_ip" "test1" { name = "another-test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "acctest-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } frontend_ip_configuration { name = "two-%d" - public_ip_address_id = "${azurerm_public_ip.test1.id}" + public_ip_address_id = azurerm_public_ip.test1.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -373,6 +389,10 @@ resource "azurerm_lb" "test" { func testAccAzureRMLoadBalancer_frontEndConfigRemovalWithIP(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -380,26 +400,26 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_public_ip" "test1" { name = "another-test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "acctest-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -407,6 +427,10 @@ resource "azurerm_lb" "test" { func testAccAzureRMLoadBalancer_frontEndConfigPublicIPPrefix(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -414,20 +438,20 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip_prefix" "test" { name = "test-ip-prefix-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name prefix_length = 31 } resource "azurerm_lb" "test" { name = "acctest-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" frontend_ip_configuration { name = "prefix-%d" - public_ip_prefix_id = "${azurerm_public_ip_prefix.test.id}" + public_ip_prefix_id = azurerm_public_ip_prefix.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -435,6 +459,10 @@ resource "azurerm_lb" "test" { func testAccAzureRMLoadBalancer_frontEndConfigRemoval(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -442,19 +470,19 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "acctest-loadbalancer-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "one-%d" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -462,6 +490,10 @@ resource "azurerm_lb" "test" { func testAccAzureRMLoadBalancer_emptyIPAddress(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -470,28 +502,28 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctsub-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_lb" "test" { name = "acctestlb-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku = "Basic" frontend_ip_configuration { name = "Internal" private_ip_address_allocation = "Dynamic" private_ip_address = "" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) diff --git a/azurerm/internal/services/network/tests/resource_arm_local_network_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_local_network_gateway_test.go index 75fc66947c883..1798bf6600421 100644 --- a/azurerm/internal/services/network/tests/resource_arm_local_network_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_local_network_gateway_test.go @@ -322,6 +322,10 @@ func testCheckAzureRMLocalNetworkGatewayDestroy(s *terraform.State) error { func testAccAzureRMLocalNetworkGatewayConfig_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctest-%d" location = "%s" @@ -329,8 +333,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_local_network_gateway" "test" { name = "acctestlng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name gateway_address = "127.0.0.1" address_space = ["127.0.0.0/8"] } @@ -343,9 +347,9 @@ func testAccAzureRMLocalNetworkGatewayConfig_requiresImport(data acceptance.Test %s resource "azurerm_local_network_gateway" "import" { - name = "${azurerm_local_network_gateway.test.name}" - location = "${azurerm_local_network_gateway.test.location}" - resource_group_name = "${azurerm_local_network_gateway.test.resource_group_name}" + name = azurerm_local_network_gateway.test.name + location = azurerm_local_network_gateway.test.location + resource_group_name = azurerm_local_network_gateway.test.resource_group_name gateway_address = "127.0.0.1" address_space = ["127.0.0.0/8"] } @@ -354,6 +358,10 @@ resource "azurerm_local_network_gateway" "import" { func testAccAzureRMLocalNetworkGatewayConfig_tags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctest-%d" location = "%s" @@ -361,8 +369,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_local_network_gateway" "test" { name = "acctestlng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name gateway_address = "127.0.0.1" address_space = ["127.0.0.0/8"] @@ -375,6 +383,10 @@ resource "azurerm_local_network_gateway" "test" { func testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctest-%d" location = "%s" @@ -382,8 +394,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_local_network_gateway" "test" { name = "acctestlng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name gateway_address = "127.0.0.1" address_space = ["127.0.0.0/8"] @@ -397,6 +409,10 @@ resource "azurerm_local_network_gateway" "test" { func testAccAzureRMLocalNetworkGatewayConfig_bgpSettingsComplete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctest-%d" location = "%s" @@ -404,8 +420,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_local_network_gateway" "test" { name = "acctestlng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name gateway_address = "127.0.0.1" address_space = ["127.0.0.0/8"] diff --git a/azurerm/internal/services/network/tests/resource_arm_nat_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_nat_gateway_test.go index 942a145699d4e..4da55448d34cf 100644 --- a/azurerm/internal/services/network/tests/resource_arm_nat_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_nat_gateway_test.go @@ -135,6 +135,10 @@ func testCheckAzureRMNatGatewayDestroy(s *terraform.State) error { // Using alt location because the resource currently in private preview and is only available in eastus2. func testAccAzureRMNatGateway_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-network-%d" location = "%s" @@ -142,8 +146,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_nat_gateway" "test" { name = "acctestnatGateway-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Secondary, data.RandomInteger) } @@ -151,6 +155,10 @@ resource "azurerm_nat_gateway" "test" { // Using alt location because the resource currently in private preview and is only available in eastus2. func testAccAzureRMNatGateway_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-network-%d" location = "%s" @@ -158,8 +166,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicIP-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" zones = ["1"] @@ -167,18 +175,18 @@ resource "azurerm_public_ip" "test" { resource "azurerm_public_ip_prefix" "test" { name = "acctestpublicIPPrefix-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name prefix_length = 30 zones = ["1"] } resource "azurerm_nat_gateway" "test" { name = "acctestnatGateway-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - public_ip_address_ids = ["${azurerm_public_ip.test.id}"] - public_ip_prefix_ids = ["${azurerm_public_ip_prefix.test.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + public_ip_address_ids = [azurerm_public_ip.test.id] + public_ip_prefix_ids = [azurerm_public_ip_prefix.test.id] sku_name = "Standard" idle_timeout_in_minutes = 10 zones = ["1"] diff --git a/azurerm/internal/services/network/tests/resource_arm_network_connection_monitor_test.go b/azurerm/internal/services/network/tests/resource_arm_network_connection_monitor_test.go index 8bfb3e92ca86d..3fb89251ac6ec 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_connection_monitor_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_connection_monitor_test.go @@ -323,6 +323,10 @@ func testCheckAzureRMNetworkConnectionMonitorDestroy(s *terraform.State) error { func testAccAzureRMNetworkConnectionMonitor_baseConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-watcher-%d" location = "%s" @@ -412,21 +416,21 @@ func testAccAzureRMNetworkConnectionMonitor_baseWithDestConfig(data acceptance.T resource "azurerm_network_interface" "dest" { name = "acctni-dest%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } resource "azurerm_virtual_machine" "dest" { name = "acctvm-dest%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_interface_ids = ["${azurerm_network_interface.dest.id}"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + network_interface_ids = [azurerm_network_interface.dest.id] vm_size = "Standard_D1_v2" storage_image_reference { @@ -463,12 +467,12 @@ func testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(data acceptance.T resource "azurerm_network_connection_monitor" "test" { name = "acctestcm-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_network_watcher.test.location}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_network_watcher.test.location source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" + virtual_machine_id = azurerm_virtual_machine.src.id } destination { @@ -476,7 +480,7 @@ resource "azurerm_network_connection_monitor" "test" { port = 80 } - depends_on = ["azurerm_virtual_machine_extension.src"] + depends_on = [azurerm_virtual_machine_extension.src] } `, config, data.RandomInteger) } @@ -488,15 +492,15 @@ func testAccAzureRMNetworkConnectionMonitor_completeAddressConfig(data acceptanc resource "azurerm_network_connection_monitor" "test" { name = "acctestcm-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_network_watcher.test.location}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_network_watcher.test.location auto_start = %s interval_in_seconds = 30 source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" + virtual_machine_id = azurerm_virtual_machine.src.id port = 20020 } @@ -509,7 +513,7 @@ resource "azurerm_network_connection_monitor" "test" { env = "test" } - depends_on = ["azurerm_virtual_machine_extension.src"] + depends_on = [azurerm_virtual_machine_extension.src] } `, config, data.RandomInteger, autoStart) } @@ -521,20 +525,20 @@ func testAccAzureRMNetworkConnectionMonitor_basicVmConfig(data acceptance.TestDa resource "azurerm_network_connection_monitor" "test" { name = "acctestcm-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_network_watcher.test.location}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_network_watcher.test.location source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" + virtual_machine_id = azurerm_virtual_machine.src.id } destination { - virtual_machine_id = "${azurerm_virtual_machine.dest.id}" + virtual_machine_id = azurerm_virtual_machine.dest.id port = 80 } - depends_on = ["azurerm_virtual_machine_extension.src"] + depends_on = [azurerm_virtual_machine_extension.src] } `, config, data.RandomInteger) } @@ -546,20 +550,20 @@ func testAccAzureRMNetworkConnectionMonitor_completeVmConfig(data acceptance.Tes resource "azurerm_network_connection_monitor" "test" { name = "acctestcm-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_network_watcher.test.location}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_network_watcher.test.location auto_start = %s interval_in_seconds = 30 source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" + virtual_machine_id = azurerm_virtual_machine.src.id port = 20020 } destination { - virtual_machine_id = "${azurerm_virtual_machine.dest.id}" + virtual_machine_id = azurerm_virtual_machine.dest.id port = 443 } @@ -567,7 +571,7 @@ resource "azurerm_network_connection_monitor" "test" { env = "test" } - depends_on = ["azurerm_virtual_machine_extension.src"] + depends_on = [azurerm_virtual_machine_extension.src] } `, config, data.RandomInteger, autoStart) } @@ -579,19 +583,19 @@ func testAccAzureRMNetworkConnectionMonitor_missingDestinationConfig(data accept resource "azurerm_network_connection_monitor" "test" { name = "acctestcm-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_network_watcher.test.location}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_network_watcher.test.location source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" + virtual_machine_id = azurerm_virtual_machine.src.id } destination { port = 80 } - depends_on = ["azurerm_virtual_machine_extension.src"] + depends_on = [azurerm_virtual_machine_extension.src] } `, config, data.RandomInteger) } @@ -603,21 +607,21 @@ func testAccAzureRMNetworkConnectionMonitor_conflictingDestinationsConfig(data a resource "azurerm_network_connection_monitor" "test" { name = "acctestcm-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_network_watcher.test.location}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_network_watcher.test.location source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" + virtual_machine_id = azurerm_virtual_machine.src.id } destination { address = "terraform.io" - virtual_machine_id = "${azurerm_virtual_machine.src.id}" + virtual_machine_id = azurerm_virtual_machine.src.id port = 80 } - depends_on = ["azurerm_virtual_machine_extension.src"] + depends_on = [azurerm_virtual_machine_extension.src] } `, config, data.RandomInteger) } @@ -628,13 +632,13 @@ func testAccAzureRMNetworkConnectionMonitor_requiresImportConfig(data acceptance %s resource "azurerm_network_connection_monitor" "import" { - name = "${azurerm_network_connection_monitor.test.name}" - network_watcher_name = "${azurerm_network_connection_monitor.test.network_watcher_name}" - resource_group_name = "${azurerm_network_connection_monitor.test.resource_group_name}" - location = "${azurerm_network_connection_monitor.test.location}" + name = azurerm_network_connection_monitor.test.name + network_watcher_name = azurerm_network_connection_monitor.test.network_watcher_name + resource_group_name = azurerm_network_connection_monitor.test.resource_group_name + location = azurerm_network_connection_monitor.test.location source { - virtual_machine_id = "${azurerm_virtual_machine.src.id}" + virtual_machine_id = azurerm_virtual_machine.src.id } destination { @@ -642,7 +646,7 @@ resource "azurerm_network_connection_monitor" "import" { port = 80 } - depends_on = ["azurerm_virtual_machine_extension.src"] + depends_on = [azurerm_virtual_machine_extension.src] } `, config) } diff --git a/azurerm/internal/services/network/tests/resource_arm_network_ddos_protection_plan_test.go b/azurerm/internal/services/network/tests/resource_arm_network_ddos_protection_plan_test.go index a246d3c33d1b4..39e15faee6e6b 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_ddos_protection_plan_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_ddos_protection_plan_test.go @@ -25,12 +25,6 @@ func TestAccAzureRMNetworkDDoSProtectionPlan(t *testing.T) { "datasource": { "basic": testAccAzureRMNetworkDDoSProtectionPlanDataSource_basic, }, - "deprecated": { - "basic": testAccAzureRMDDoSProtectionPlan_basic, - "requiresImport": testAccAzureRMDDoSProtectionPlan_requiresImport, - "withTags": testAccAzureRMDDoSProtectionPlan_withTags, - "disappears": testAccAzureRMDDoSProtectionPlan_disappears, - }, } for group, steps := range testCases { @@ -230,6 +224,10 @@ func testCheckAzureRMNetworkDDoSProtectionPlanDestroy(s *terraform.State) error func testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -237,8 +235,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_ddos_protection_plan" "test" { name = "acctestddospplan-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -249,15 +247,19 @@ func testAccAzureRMNetworkDDoSProtectionPlan_requiresImportConfig(data acceptanc %s resource "azurerm_network_ddos_protection_plan" "import" { - name = "${azurerm_network_ddos_protection_plan.test.name}" - location = "${azurerm_network_ddos_protection_plan.test.location}" - resource_group_name = "${azurerm_network_ddos_protection_plan.test.resource_group_name}" + name = azurerm_network_ddos_protection_plan.test.name + location = azurerm_network_ddos_protection_plan.test.location + resource_group_name = azurerm_network_ddos_protection_plan.test.resource_group_name } `, basicConfig) } func testAccAzureRMNetworkDDoSProtectionPlan_withTagsConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -265,8 +267,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_ddos_protection_plan" "test" { name = "acctestddospplan-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { environment = "Production" @@ -278,6 +280,10 @@ resource "azurerm_network_ddos_protection_plan" "test" { func testAccAzureRMNetworkDDoSProtectionPlan_withUpdatedTagsConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -285,8 +291,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_ddos_protection_plan" "test" { name = "acctestddospplan-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { environment = "Staging" diff --git a/azurerm/internal/services/network/tests/resource_arm_network_interface_application_gateway_association_test.go b/azurerm/internal/services/network/tests/resource_arm_network_interface_application_gateway_association_test.go index 3fc2b0d855eb1..152914c722c7f 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_interface_application_gateway_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_interface_application_gateway_association_test.go @@ -27,6 +27,7 @@ func TestAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociati testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationExists(data.ResourceName), ), }, + data.ImportStep(), }, }) } @@ -79,6 +80,32 @@ func TestAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociati }) } +func TestAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_updateNIC(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_interface_application_gateway_backend_address_pool_association", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + // intentional as this is a Virtual Resource + CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_updateNIC(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + func testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).Network.InterfacesClient @@ -185,7 +212,81 @@ func testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssocia } func testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.backend.id}" + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_network_interface_application_gateway_backend_address_pool_association" "test" { + network_interface_id = azurerm_network_interface.test.id + ip_configuration_name = "testconfiguration1" + backend_address_pool_id = azurerm_application_gateway.test.backend_address_pool.0.id +} +`, template, data.RandomInteger) +} + +func testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface_application_gateway_backend_address_pool_association" "import" { + network_interface_id = azurerm_network_interface_application_gateway_backend_address_pool_association.test.network_interface_id + ip_configuration_name = azurerm_network_interface_application_gateway_backend_address_pool_association.test.ip_configuration_name + backend_address_pool_id = azurerm_network_interface_application_gateway_backend_address_pool_association.test.backend_address_pool_id +} +`, template) +} + +func testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_updateNIC(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.backend.id}" + private_ip_address_allocation = "Dynamic" + primary = true + } + + ip_configuration { + name = "testconfiguration2" + private_ip_address_version = "IPv6" + private_ip_address_allocation = "dynamic" + } +} + +resource "azurerm_network_interface_application_gateway_backend_address_pool_association" "test" { + network_interface_id = azurerm_network_interface.test.id + ip_configuration_name = "testconfiguration1" + backend_address_pool_id = azurerm_application_gateway.test.backend_address_pool.0.id +} +`, template, data.RandomInteger) +} + +func testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -194,28 +295,28 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "frontend" { name = "frontend" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_subnet" "backend" { name = "backend" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.4.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } @@ -231,8 +332,8 @@ locals { resource "azurerm_application_gateway" "test" { name = "apptestag%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location sku { name = "Standard_Small" @@ -242,25 +343,25 @@ resource "azurerm_application_gateway" "test" { gateway_ip_configuration { name = "my-gateway-ip-configuration" - subnet_id = "${azurerm_subnet.frontend.id}" + subnet_id = azurerm_subnet.frontend.id } frontend_port { - name = "${local.frontend_port_name}" + name = local.frontend_port_name port = 80 } frontend_ip_configuration { - name = "${local.frontend_ip_configuration_name}" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = local.frontend_ip_configuration_name + public_ip_address_id = azurerm_public_ip.test.id } backend_address_pool { - name = "${local.backend_address_pool_name}" + name = local.backend_address_pool_name } backend_http_settings { - name = "${local.http_setting_name}" + name = local.http_setting_name cookie_based_affinity = "Disabled" port = 80 protocol = "Http" @@ -268,50 +369,19 @@ resource "azurerm_application_gateway" "test" { } http_listener { - name = "${local.listener_name}" - frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" - frontend_port_name = "${local.frontend_port_name}" + name = local.listener_name + frontend_ip_configuration_name = local.frontend_ip_configuration_name + frontend_port_name = local.frontend_port_name protocol = "Http" } request_routing_rule { - name = "${local.request_routing_rule_name}" + name = local.request_routing_rule_name rule_type = "Basic" - http_listener_name = "${local.listener_name}" - backend_address_pool_name = "${local.backend_address_pool_name}" - backend_http_settings_name = "${local.http_setting_name}" + http_listener_name = local.listener_name + backend_address_pool_name = local.backend_address_pool_name + backend_http_settings_name = local.http_setting_name } } - -resource "azurerm_network_interface" "test" { - name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.frontend.id}" - private_ip_address_allocation = "Dynamic" - } -} - -resource "azurerm_network_interface_application_gateway_backend_address_pool_association" "test" { - network_interface_id = "${azurerm_network_interface.test.id}" - ip_configuration_name = "testconfiguration1" - backend_address_pool_id = "${azurerm_application_gateway.test.backend_address_pool.0.id}" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(data) - return fmt.Sprintf(` -%s - -resource "azurerm_network_interface_application_gateway_backend_address_pool_association" "import" { - network_interface_id = "${azurerm_network_interface_application_gateway_backend_address_pool_association.test.network_interface_id}" - ip_configuration_name = "${azurerm_network_interface_application_gateway_backend_address_pool_association.test.ip_configuration_name}" - backend_address_pool_id = "${azurerm_network_interface_application_gateway_backend_address_pool_association.test.backend_address_pool_id}" -} -`, template) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_network_interface_backend_address_pool_association_test.go b/azurerm/internal/services/network/tests/resource_arm_network_interface_backend_address_pool_association_test.go index 635796cfc4267..1c5b2058c5808 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_interface_backend_address_pool_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_interface_backend_address_pool_association_test.go @@ -27,6 +27,7 @@ func TestAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(t *testin testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationExists(data.ResourceName), ), }, + data.ImportStep(), }, }) } @@ -79,6 +80,32 @@ func TestAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_deleted(t *test }) } +func TestAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_updateNIC(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_interface_backend_address_pool_association", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + // intentional as this is a Virtual Resource + CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_updateNIC(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + func testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).Network.InterfacesClient @@ -185,7 +212,81 @@ func testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationDisappears(res } func testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + ip_configuration { + name = "testconfiguration1" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_network_interface_backend_address_pool_association" "test" { + network_interface_id = azurerm_network_interface.test.id + ip_configuration_name = "testconfiguration1" + backend_address_pool_id = azurerm_lb_backend_address_pool.test.id +} +`, template, data.RandomInteger) +} + +func testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface_backend_address_pool_association" "import" { + network_interface_id = azurerm_network_interface_backend_address_pool_association.test.network_interface_id + ip_configuration_name = azurerm_network_interface_backend_address_pool_association.test.ip_configuration_name + backend_address_pool_id = azurerm_network_interface_backend_address_pool_association.test.backend_address_pool_id +} +`, template) +} + +func testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_updateNIC(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + ip_configuration { + name = "testconfiguration1" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + primary = true + } + + ip_configuration { + name = "testconfiguration2" + private_ip_address_version = "IPv6" + private_ip_address_allocation = "dynamic" + } +} + +resource "azurerm_network_interface_backend_address_pool_association" "test" { + network_interface_id = azurerm_network_interface.test.id + ip_configuration_name = "testconfiguration1" + backend_address_pool_id = azurerm_lb_backend_address_pool.test.id +} +`, template, data.RandomInteger) +} + +func testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -194,71 +295,39 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "acctestlb-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "primary" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_lb_backend_address_pool" "test" { - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "acctestpool" } - -resource "azurerm_network_interface" "test" { - name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - } -} - -resource "azurerm_network_interface_backend_address_pool_association" "test" { - network_interface_id = "${azurerm_network_interface.test.id}" - ip_configuration_name = "testconfiguration1" - backend_address_pool_id = "${azurerm_lb_backend_address_pool.test.id}" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(data) - return fmt.Sprintf(` -%s - -resource "azurerm_network_interface_backend_address_pool_association" "import" { - network_interface_id = "${azurerm_network_interface_backend_address_pool_association.test.network_interface_id}" - ip_configuration_name = "${azurerm_network_interface_backend_address_pool_association.test.ip_configuration_name}" - backend_address_pool_id = "${azurerm_network_interface_backend_address_pool_association.test.backend_address_pool_id}" -} -`, template) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_network_interface_nat_rule_association_test.go b/azurerm/internal/services/network/tests/resource_arm_network_interface_nat_rule_association_test.go index e10f617bfe017..f1f9edaa4e74b 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_interface_nat_rule_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_interface_nat_rule_association_test.go @@ -27,6 +27,7 @@ func TestAccAzureRMNetworkInterfaceNATRuleAssociation_basic(t *testing.T) { testCheckAzureRMNetworkInterfaceNATRuleAssociationExists(data.ResourceName), ), }, + data.ImportStep(), }, }) } @@ -79,6 +80,32 @@ func TestAccAzureRMNetworkInterfaceNATRuleAssociation_deleted(t *testing.T) { }) } +func TestAccAzureRMNetworkInterfaceNATRuleAssociation_updateNIC(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_interface_nat_rule_association", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + // intentional as this is a Virtual Resource + CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceNATRuleAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetworkInterfaceNATRuleAssociation_updateNIC(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceNATRuleAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + func testCheckAzureRMNetworkInterfaceNATRuleAssociationExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).Network.InterfacesClient @@ -185,7 +212,81 @@ func testCheckAzureRMNetworkInterfaceNATRuleAssociationDisappears(resourceName s } func testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceNATRuleAssociation_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + ip_configuration { + name = "testconfiguration1" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_network_interface_nat_rule_association" "test" { + network_interface_id = azurerm_network_interface.test.id + ip_configuration_name = "testconfiguration1" + nat_rule_id = azurerm_lb_nat_rule.test.id +} +`, template, data.RandomInteger) +} + +func testAccAzureRMNetworkInterfaceNATRuleAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface_nat_rule_association" "import" { + network_interface_id = azurerm_network_interface_nat_rule_association.test.network_interface_id + ip_configuration_name = azurerm_network_interface_nat_rule_association.test.ip_configuration_name + nat_rule_id = azurerm_network_interface_nat_rule_association.test.nat_rule_id +} +`, template) +} + +func testAccAzureRMNetworkInterfaceNATRuleAssociation_updateNIC(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceNATRuleAssociation_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + ip_configuration { + name = "testconfiguration1" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + primary = true + } + + ip_configuration { + name = "testconfiguration2" + private_ip_address_version = "IPv6" + private_ip_address_allocation = "dynamic" + } +} + +resource "azurerm_network_interface_nat_rule_association" "test" { + network_interface_id = azurerm_network_interface.test.id + ip_configuration_name = "testconfiguration1" + nat_rule_id = azurerm_lb_nat_rule.test.id +} +`, template, data.RandomInteger) +} + +func testAccAzureRMNetworkInterfaceNATRuleAssociation_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -194,74 +295,43 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } resource "azurerm_public_ip" "test" { name = "test-ip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } resource "azurerm_lb" "test" { name = "acctestlb-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name frontend_ip_configuration { name = "primary" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_lb_nat_rule" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.test.id}" + resource_group_name = azurerm_resource_group.test.name + loadbalancer_id = azurerm_lb.test.id name = "RDPAccess" protocol = "Tcp" frontend_port = 3389 backend_port = 3389 frontend_ip_configuration_name = "primary" } - -resource "azurerm_network_interface" "test" { - name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - } -} - -resource "azurerm_network_interface_nat_rule_association" "test" { - network_interface_id = "${azurerm_network_interface.test.id}" - ip_configuration_name = "testconfiguration1" - nat_rule_id = "${azurerm_lb_nat_rule.test.id}" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMNetworkInterfaceNATRuleAssociation_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(data) - return fmt.Sprintf(` -%s - -resource "azurerm_network_interface_nat_rule_association" "import" { - network_interface_id = "${azurerm_network_interface_nat_rule_association.test.network_interface_id}" - ip_configuration_name = "${azurerm_network_interface_nat_rule_association.test.ip_configuration_name}" - nat_rule_id = "${azurerm_network_interface_nat_rule_association.test.nat_rule_id}" -} -`, template) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_network_interface_test.go b/azurerm/internal/services/network/tests/resource_arm_network_interface_test.go index 468f031e32375..ca083a43dc299 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_interface_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_interface_test.go @@ -12,7 +12,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAccAzureRMNetworkInterface_disappears(t *testing.T) { +func TestAccAzureRMNetworkInterface_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,20 +23,14 @@ func TestAccAzureRMNetworkInterface_disappears(t *testing.T) { Config: testAccAzureRMNetworkInterface_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - testCheckAzureRMNetworkInterfaceDisappears(data.ResourceName), ), - ExpectNonEmptyPlan: true, }, + data.ImportStep(), }, }) } -func TestAccAzureRMNetworkInterface_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - +func TestAccAzureRMNetworkInterface_disappears(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -47,17 +41,15 @@ func TestAccAzureRMNetworkInterface_requiresImport(t *testing.T) { Config: testAccAzureRMNetworkInterface_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + testCheckAzureRMNetworkInterfaceDisappears(data.ResourceName), ), - }, - { - Config: testAccAzureRMNetworkInterface_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_network_interface"), + ExpectNonEmptyPlan: true, }, }, }) } -func TestAccAzureRMNetworkInterface_basic(t *testing.T) { +func TestAccAzureRMNetworkInterface_dnsServers(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -65,7 +57,14 @@ func TestAccAzureRMNetworkInterface_basic(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_basic(data), + Config: testAccAzureRMNetworkInterface_dnsServers(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetworkInterface_dnsServersUpdated(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), ), @@ -75,108 +74,102 @@ func TestAccAzureRMNetworkInterface_basic(t *testing.T) { }) } -func TestAccAzureRMNetworkInterface_setNetworkSecurityGroupId(t *testing.T) { +func TestAccAzureRMNetworkInterface_enableAcceleratedNetworking(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_basic(data), + // Enabled + Config: testAccAzureRMNetworkInterface_enableAcceleratedNetworking(data, true), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), ), }, + data.ImportStep(), { - Config: testAccAzureRMNetworkInterface_basicWithNetworkSecurityGroup(data), + // Disabled + Config: testAccAzureRMNetworkInterface_enableAcceleratedNetworking(data, false), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), ), }, + data.ImportStep(), + { + // Enabled + Config: testAccAzureRMNetworkInterface_enableAcceleratedNetworking(data, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + ), + }, + data.ImportStep(), }, }) } -func TestAccAzureRMNetworkInterface_removeNetworkSecurityGroupId(t *testing.T) { +func TestAccAzureRMNetworkInterface_enableIPForwarding(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_basicWithNetworkSecurityGroup(data), + // Enabled + Config: testAccAzureRMNetworkInterface_enableIPForwarding(data, true), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), ), }, + data.ImportStep(), { - Config: testAccAzureRMNetworkInterface_basic(data), + // Disabled + Config: testAccAzureRMNetworkInterface_enableIPForwarding(data, false), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "network_security_group_id", ""), ), }, - }, - }) -} - -func TestAccAzureRMNetworkInterface_multipleSubnets(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, - Steps: []resource.TestStep{ + data.ImportStep(), { - Config: testAccAzureRMNetworkInterface_multipleSubnets(data), + // Enabled + Config: testAccAzureRMNetworkInterface_enableIPForwarding(data, true), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.#", "2"), ), }, + data.ImportStep(), }, }) } -func TestAccAzureRMNetworkInterface_multipleSubnetsPrimary(t *testing.T) { +func TestAccAzureRMNetworkInterface_internalDomainNameLabel(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_multipleSubnets(data), + Config: testAccAzureRMNetworkInterface_internalDomainNameLabel(data, "1"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.primary", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.name", "testconfiguration1"), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.1.primary", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.1.name", "testconfiguration2"), ), }, + data.ImportStep(), { - Config: testAccAzureRMNetworkInterface_multipleSubnetsUpdatedPrimary(data), + Config: testAccAzureRMNetworkInterface_internalDomainNameLabel(data, "2"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.primary", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.name", "testconfiguration2"), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.1.primary", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.1.name", "testconfiguration1"), ), }, + data.ImportStep(), }, }) } -func TestAccAzureRMNetworkInterface_enableIPForwarding(t *testing.T) { +func TestAccAzureRMNetworkInterface_ipv6(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -184,17 +177,19 @@ func TestAccAzureRMNetworkInterface_enableIPForwarding(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_ipForwarding(data), + Config: testAccAzureRMNetworkInterface_ipv6(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enable_ip_forwarding", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.private_ip_address_version", "IPv4"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.1.private_ip_address_version", "IPv6"), ), }, + data.ImportStep(), }, }) } -func TestAccAzureRMNetworkInterface_enableAcceleratedNetworking(t *testing.T) { +func TestAccAzureRMNetworkInterface_multipleIPConfigurations(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -202,36 +197,35 @@ func TestAccAzureRMNetworkInterface_enableAcceleratedNetworking(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_acceleratedNetworking(data), + Config: testAccAzureRMNetworkInterface_multipleIPConfigurations(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enable_accelerated_networking", "true"), ), }, + data.ImportStep(), }, }) } -func TestAccAzureRMNetworkInterface_multipleLoadBalancers(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_network_interface", "test1") - +func TestAccAzureRMNetworkInterface_multipleIPConfigurationsSecondaryAsPrimary(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_multipleLoadBalancers(data), + Config: testAccAzureRMNetworkInterface_multipleIPConfigurationsSecondaryAsPrimary(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test1"), - testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test2"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), ), }, + data.ImportStep(), }, }) } -func TestAccAzureRMNetworkInterface_applicationGateway(t *testing.T) { +func TestAccAzureRMNetworkInterface_publicIP(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -239,45 +233,36 @@ func TestAccAzureRMNetworkInterface_applicationGateway(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_applicationGatewayBackendPool(data), + Config: testAccAzureRMNetworkInterface_publicIP(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test"), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.application_gateway_backend_address_pools_ids.#", "1"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), ), }, - }, - }) -} - -func TestAccAzureRMNetworkInterface_withTags(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, - Steps: []resource.TestStep{ + data.ImportStep(), { - Config: testAccAzureRMNetworkInterface_withTags(data), + Config: testAccAzureRMNetworkInterface_publicIPRemoved(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, + data.ImportStep(), { - Config: testAccAzureRMNetworkInterface_withTagsUpdate(data), + Config: testAccAzureRMNetworkInterface_publicIP(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, + data.ImportStep(), }, }) } -func TestAccAzureRMNetworkInterface_IPAddressesBug1286(t *testing.T) { +func TestAccAzureRMNetworkInterface_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -285,93 +270,81 @@ func TestAccAzureRMNetworkInterface_IPAddressesBug1286(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_withIPAddresses(data), + Config: testAccAzureRMNetworkInterface_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.private_ip_address"), - resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.public_ip_address_id"), ), }, { - Config: testAccAzureRMNetworkInterface_withIPAddressesUpdate(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.private_ip_address"), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.public_ip_address_id", ""), - ), + Config: testAccAzureRMNetworkInterface_requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_network_interface"), }, }, }) } -func TestAccAzureRMNetworkInterface_IPAddressesFeature2543(t *testing.T) { +func TestAccAzureRMNetworkInterface_static(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_withIPv6Addresses(data), + Config: testAccAzureRMNetworkInterface_static(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.private_ip_address_version", "IPv4"), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.1.private_ip_address_version", "IPv6"), - resource.TestCheckResourceAttrSet(data.ResourceName, "private_ip_address"), ), }, + data.ImportStep(), }, }) } -func TestAccAzureRMNetworkInterface_bug7986(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_network_interface", "test1") - +func TestAccAzureRMNetworkInterface_tags(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_bug7986(data), + Config: testAccAzureRMNetworkInterface_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test1"), - testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test2"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), ), }, - }, - }) -} - -func TestAccAzureRMNetworkInterface_applicationSecurityGroups(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, - Steps: []resource.TestStep{ + data.ImportStep(), { - Config: testAccAzureRMNetworkInterface_applicationSecurityGroup(data), + Config: testAccAzureRMNetworkInterface_tagsUpdated(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.application_security_group_ids.#", "1"), ), }, + data.ImportStep(), }, }) } -func TestAccAzureRMNetworkInterface_importPublicIP(t *testing.T) { +func TestAccAzureRMNetworkInterface_update(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_publicIP(data), + Config: testAccAzureRMNetworkInterface_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetworkInterface_multipleIPConfigurations(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + ), }, data.ImportStep(), }, @@ -390,11 +363,7 @@ func testCheckAzureRMNetworkInterfaceExists(resourceName string) resource.TestCh } name := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for availability set: %q", name) - } - + resourceGroup := rs.Primary.Attributes["resource_group_name"] resp, err := client.Get(ctx, resourceGroup, name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { @@ -420,10 +389,7 @@ func testCheckAzureRMNetworkInterfaceDisappears(resourceName string) resource.Te } name := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for availability set: %q", name) - } + resourceGroup := rs.Primary.Attributes["resource_group_name"] future, err := client.Delete(ctx, resourceGroup, name) if err != nil { @@ -466,868 +432,355 @@ func testCheckAzureRMNetworkInterfaceDestroy(s *terraform.State) error { } func testAccAzureRMNetworkInterface_basic(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} +%s resource "azurerm_network_interface" "test" { name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger) } -func testAccAzureRMNetworkInterface_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMNetworkInterface_basic(data) +func testAccAzureRMNetworkInterface_dnsServers(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_template(data) return fmt.Sprintf(` %s -resource "azurerm_network_interface" "import" { - name = "${azurerm_network_interface.test.name}" - location = "${azurerm_network_interface.test.location}" - resource_group_name = "${azurerm_network_interface.test.resource_group_name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - } -} -`, template) -} - -func testAccAzureRMNetworkInterface_basicWithNetworkSecurityGroup(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} - -resource "azurerm_network_security_group" "test" { - name = "acctestnsg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - resource "azurerm_network_interface" "test" { - name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - network_security_group_id = "${azurerm_network_security_group.test.id}" + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + dns_servers = [ + "10.0.0.5", + "10.0.0.6" + ] ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger) } -func testAccAzureRMNetworkInterface_multipleSubnets(data acceptance.TestData) string { +func testAccAzureRMNetworkInterface_dnsServersUpdated(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} +%s resource "azurerm_network_interface" "test" { name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - primary = true - } + dns_servers = [ + "10.0.0.6", + "10.0.0.5" + ] ip_configuration { - name = "testconfiguration2" - subnet_id = "${azurerm_subnet.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger) } -func testAccAzureRMNetworkInterface_multipleSubnetsUpdatedPrimary(data acceptance.TestData) string { +func testAccAzureRMNetworkInterface_enableAcceleratedNetworking(data acceptance.TestData, enabled bool) string { + template := testAccAzureRMNetworkInterface_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} +%s resource "azurerm_network_interface" "test" { - name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration2" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - primary = true - } + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + enable_accelerated_networking = %t ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger, enabled) } -func testAccAzureRMNetworkInterface_ipForwarding(data acceptance.TestData) string { +func testAccAzureRMNetworkInterface_enableIPForwarding(data acceptance.TestData, enabled bool) string { + template := testAccAzureRMNetworkInterface_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} +%s resource "azurerm_network_interface" "test" { name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - enable_ip_forwarding = true + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + enable_ip_forwarding = %t ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger, enabled) } -func testAccAzureRMNetworkInterface_acceleratedNetworking(data acceptance.TestData) string { +func testAccAzureRMNetworkInterface_internalDomainNameLabel(data acceptance.TestData, suffix string) string { + template := testAccAzureRMNetworkInterface_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} +%s resource "azurerm_network_interface" "test" { - name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - enable_ip_forwarding = false - enable_accelerated_networking = true + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + internal_dns_name_label = "acctestni-%s-%s" ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger, suffix, data.RandomString) } -func testAccAzureRMNetworkInterface_withTags(data acceptance.TestData) string { +func testAccAzureRMNetworkInterface_ipv6(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} +%s resource "azurerm_network_interface" "test" { name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" + primary = true } - tags = { - environment = "Production" - cost_center = "MSFT" + ip_configuration { + name = "secondary" + private_ip_address_allocation = "Dynamic" + private_ip_address_version = "IPv6" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger) } -func testAccAzureRMNetworkInterface_withTagsUpdate(data acceptance.TestData) string { +func testAccAzureRMNetworkInterface_multipleIPConfigurations(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} +%s resource "azurerm_network_interface" "test" { name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" + primary = true } - tags = { - environment = "staging" + ip_configuration { + name = "secondary" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger) } -func testAccAzureRMNetworkInterface_withIPAddresses(data acceptance.TestData) string { +func testAccAzureRMNetworkInterface_multipleIPConfigurationsSecondaryAsPrimary(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} - -resource "azurerm_public_ip" "test" { - name = "test-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - allocation_method = "Static" - domain_name_label = "${azurerm_resource_group.test.name}" -} +%s resource "azurerm_network_interface" "test" { name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Static" - private_ip_address = "10.0.2.9" - public_ip_address_id = "${azurerm_public_ip.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMNetworkInterface_withIPAddressesUpdate(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + ip_configuration { + name = "secondary" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + primary = true + } } - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" +`, template, data.RandomInteger) } -resource "azurerm_public_ip" "test" { - name = "test-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - allocation_method = "Static" - domain_name_label = "${azurerm_resource_group.test.name}" -} +func testAccAzureRMNetworkInterface_publicIP(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_publicIPTemplate(data) + return fmt.Sprintf(` +%s resource "azurerm_network_interface" "test" { name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" + public_ip_address_id = azurerm_public_ip.test.id } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger) } -func testAccAzureRMNetworkInterface_withIPv6Addresses(data acceptance.TestData) string { +func testAccAzureRMNetworkInterface_publicIPRemoved(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_publicIPTemplate(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} - -resource "azurerm_public_ip" "test" { - name = "test-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - allocation_method = "Static" - domain_name_label = "${azurerm_resource_group.test.name}" -} +%s resource "azurerm_network_interface" "test" { name = "acctestni-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "dynamic" - primary = true - } + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { - name = "testconfiguration2" - private_ip_address_version = "IPv6" - private_ip_address_allocation = "dynamic" + name = "primary" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger) } -func testAccAzureRMNetworkInterface_multipleLoadBalancers(data acceptance.TestData) string { +func testAccAzureRMNetworkInterface_publicIPTemplate(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} - -resource "azurerm_public_ip" "testext" { - name = "acctestpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - allocation_method = "Static" -} - -resource "azurerm_lb" "testext" { - name = "acctestlb-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - frontend_ip_configuration { - name = "publicipext" - public_ip_address_id = "${azurerm_public_ip.testext.id}" - } -} - -resource "azurerm_lb_backend_address_pool" "testext" { - name = "testbackendpoolext" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.testext.id}" -} - -resource "azurerm_lb_nat_rule" "testext" { - name = "testnatruleext" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.testext.id}" - protocol = "Tcp" - frontend_port = 3389 - backend_port = 3390 - frontend_ip_configuration_name = "publicipext" -} +%s -resource "azurerm_public_ip" "testint" { - name = "testpublicipint" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" +resource "azurerm_public_ip" "test" { + name = "acctestpublicip-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } - -resource "azurerm_lb" "testint" { - name = "testlbint" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - frontend_ip_configuration { - name = "publicipint" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - } -} - -resource "azurerm_lb_backend_address_pool" "testint" { - name = "testbackendpoolint" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.testint.id}" -} - -resource "azurerm_lb_nat_rule" "testint" { - name = "testnatruleint" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - loadbalancer_id = "${azurerm_lb.testint.id}" - protocol = "Tcp" - frontend_port = 3389 - backend_port = 3391 - frontend_ip_configuration_name = "publicipint" +`, template, data.RandomInteger) } -resource "azurerm_network_interface" "test1" { - name = "acctestnic1-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - enable_ip_forwarding = true - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - - load_balancer_backend_address_pools_ids = [ - "${azurerm_lb_backend_address_pool.testext.id}", - "${azurerm_lb_backend_address_pool.testint.id}", - ] - } -} +func testAccAzureRMNetworkInterface_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_basic(data) + return fmt.Sprintf(` +%s -resource "azurerm_network_interface" "test2" { - name = "acctestnic2-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - enable_ip_forwarding = true +resource "azurerm_network_interface" "import" { + name = azurerm_network_interface.test.name + location = azurerm_network_interface.test.location + resource_group_name = azurerm_network_interface.test.resource_group_name ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" - - load_balancer_inbound_nat_rules_ids = [ - "${azurerm_lb_nat_rule.testext.id}", - "${azurerm_lb_nat_rule.testint.id}", - ] } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template) } -func testAccAzureRMNetworkInterface_applicationGatewayBackendPool(data acceptance.TestData) string { +func testAccAzureRMNetworkInterface_static(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctest-vnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - address_space = ["10.254.0.0/16"] - location = "${azurerm_resource_group.test.location}" -} - -resource "azurerm_subnet" "gateway" { - name = "subnet-gateway-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.254.0.0/24" -} - -resource "azurerm_subnet" "test" { - name = "subnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.254.1.0/24" -} - -resource "azurerm_public_ip" "test" { - name = "acctest-pubip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - allocation_method = "Dynamic" -} - -resource "azurerm_application_gateway" "test" { - name = "acctestgw-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "Standard_Medium" - tier = "Standard" - capacity = 1 - } - - gateway_ip_configuration { - name = "gw-ip-config1" - subnet_id = "${azurerm_subnet.gateway.id}" - } - - frontend_port { - name = "port-8080" - port = 8080 - } - - frontend_ip_configuration { - name = "ip-config-public" - public_ip_address_id = "${azurerm_public_ip.test.id}" - } - - backend_address_pool { - name = "pool-1" - } - - backend_http_settings { - name = "backend-http-1" - port = 8080 - protocol = "Http" - cookie_based_affinity = "Enabled" - request_timeout = 30 - } - - http_listener { - name = "listener-1" - frontend_ip_configuration_name = "ip-config-public" - frontend_port_name = "port-8080" - protocol = "Http" - } - - request_routing_rule { - name = "rule-basic-1" - rule_type = "Basic" - http_listener_name = "listener-1" - backend_address_pool_name = "pool-1" - backend_http_settings_name = "backend-http-1" - } - - tags = { - environment = "tf01" - } -} +%s resource "azurerm_network_interface" "test" { - name = "acctestnic-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - enable_ip_forwarding = true + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - - application_gateway_backend_address_pools_ids = [ - "${azurerm_application_gateway.test.backend_address_pool.0.id}", - ] + name = "primary" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Static" + private_ip_address = "10.0.2.15" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger) } -func testAccAzureRMNetworkInterface_bug7986(data acceptance.TestData) string { +func testAccAzureRMNetworkInterface_tags(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctest-%d" - location = "%s" -} - -resource "azurerm_network_security_group" "test" { - name = "acctest-%d-nsg" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - tags = { - environment = "Production" - } -} - -resource "azurerm_network_security_rule" "test1" { - name = "test1" - priority = 101 - direction = "Outbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "*" - source_address_prefix = "*" - destination_address_prefix = "*" - resource_group_name = "${azurerm_resource_group.test.name}" - network_security_group_name = "${azurerm_network_security_group.test.name}" -} - -resource "azurerm_network_security_rule" "test2" { - name = "test2" - priority = 102 - direction = "Outbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "*" - source_address_prefix = "*" - destination_address_prefix = "*" - resource_group_name = "${azurerm_resource_group.test.name}" - network_security_group_name = "${azurerm_network_security_group.test.name}" -} - -resource "azurerm_public_ip" "test" { - name = "acctest-%d-pip" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - allocation_method = "Dynamic" - - tags = { - environment = "Production" - } -} - -resource "azurerm_virtual_network" "test" { - name = "acctest-%d-vn" - address_space = ["10.0.0.0/16"] - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" -} - -resource "azurerm_subnet" "test" { - name = "first" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} +%s -resource "azurerm_network_interface" "test1" { - name = "acctest-%d-nic1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } tags = { - environment = "staging" + Hello = "World" } } +`, template, data.RandomInteger) +} + +func testAccAzureRMNetworkInterface_tagsUpdated(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_template(data) + return fmt.Sprintf(` +%s -resource "azurerm_network_interface" "test2" { - name = "acctest-%d-nic2" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" +resource "azurerm_network_interface" "test" { + name = "acctestni-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" + name = "primary" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" } tags = { - environment = "staging" + Hello = "World" + Elephants = "Five" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template, data.RandomInteger) } -func testAccAzureRMNetworkInterface_publicIP(data acceptance.TestData) string { +func testAccAzureRMNetworkInterface_template(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" -} - -resource "azurerm_public_ip" "testext" { - name = "acctestip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - allocation_method = "Static" +provider "azurerm" { + features {} } -resource "azurerm_network_interface" "test" { - name = "acctestnic-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.testext.id}" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMNetworkInterface_applicationSecurityGroup(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1335,35 +788,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" } resource "azurerm_subnet" "test" { - name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } - -resource "azurerm_application_security_group" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_network_interface" "test" { - name = "acctestnic-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "testconfiguration1" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - application_security_group_ids = ["${azurerm_application_security_group.test.id}"] - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_network_packet_capture_test.go b/azurerm/internal/services/network/tests/resource_arm_network_packet_capture_test.go index 9a559313b8286..3f2a6a32cada5 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_packet_capture_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_packet_capture_test.go @@ -170,6 +170,10 @@ func testCheckAzureRMNetworkPacketCaptureDestroy(s *terraform.State) error { func testAzureRMNetworkPacketCapture_base(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-watcher-%d" location = "%s" @@ -259,15 +263,15 @@ func testAzureRMNetworkPacketCapture_localDiskConfig(data acceptance.TestData) s resource "azurerm_network_packet_capture" "test" { name = "acctestpc-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - target_resource_id = "${azurerm_virtual_machine.test.id}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + target_resource_id = azurerm_virtual_machine.test.id storage_location { file_path = "/var/captures/packet.cap" } - depends_on = ["azurerm_virtual_machine_extension.test"] + depends_on = [azurerm_virtual_machine_extension.test] } `, config, data.RandomInteger) } @@ -278,16 +282,16 @@ func testAzureRMNetworkPacketCapture_localDiskConfig_requiresImport(data accepta %s resource "azurerm_network_packet_capture" "import" { - name = "${azurerm_network_packet_capture.test.name}" - network_watcher_name = "${azurerm_network_packet_capture.test.network_watcher_name}" - resource_group_name = "${azurerm_network_packet_capture.test.resource_group_name}" - target_resource_id = "${azurerm_network_packet_capture.test.target_resource_id}" + name = azurerm_network_packet_capture.test.name + network_watcher_name = azurerm_network_packet_capture.test.network_watcher_name + resource_group_name = azurerm_network_packet_capture.test.resource_group_name + target_resource_id = azurerm_network_packet_capture.test.target_resource_id storage_location { file_path = "/var/captures/packet.cap" } - depends_on = ["azurerm_virtual_machine_extension.test"] + depends_on = [azurerm_virtual_machine_extension.test] } `, config) } @@ -299,9 +303,9 @@ func testAzureRMNetworkPacketCapture_localDiskConfigWithFilters(data acceptance. resource "azurerm_network_packet_capture" "test" { name = "acctestpc-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - target_resource_id = "${azurerm_virtual_machine.test.id}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + target_resource_id = azurerm_virtual_machine.test.id storage_location { file_path = "/var/captures/packet.cap" @@ -319,7 +323,7 @@ resource "azurerm_network_packet_capture" "test" { protocol = "UDP" } - depends_on = ["azurerm_virtual_machine_extension.test"] + depends_on = [azurerm_virtual_machine_extension.test] } `, config, data.RandomInteger) } @@ -331,23 +335,23 @@ func testAzureRMNetworkPacketCapture_storageAccountConfig(data acceptance.TestDa resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_network_packet_capture" "test" { name = "acctestpc-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - target_resource_id = "${azurerm_virtual_machine.test.id}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + target_resource_id = azurerm_virtual_machine.test.id storage_location { - storage_account_id = "${azurerm_storage_account.test.id}" + storage_account_id = azurerm_storage_account.test.id } - depends_on = ["azurerm_virtual_machine_extension.test"] + depends_on = [azurerm_virtual_machine_extension.test] } `, config, data.RandomString, data.RandomInteger) } @@ -359,24 +363,24 @@ func testAzureRMNetworkPacketCapture_storageAccountAndLocalDiskConfig(data accep resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_network_packet_capture" "test" { name = "acctestpc-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - target_resource_id = "${azurerm_virtual_machine.test.id}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + target_resource_id = azurerm_virtual_machine.test.id storage_location { file_path = "/var/captures/packet.cap" - storage_account_id = "${azurerm_storage_account.test.id}" + storage_account_id = azurerm_storage_account.test.id } - depends_on = ["azurerm_virtual_machine_extension.test"] + depends_on = [azurerm_virtual_machine_extension.test] } `, config, data.RandomString, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_network_profile_test.go b/azurerm/internal/services/network/tests/resource_arm_network_profile_test.go index c8c31f7a74376..be3e006446a2f 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_profile_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_profile_test.go @@ -193,6 +193,10 @@ func testCheckAzureRMNetworkProfileDestroy(s *terraform.State) error { func testAccAzureRMNetworkProfile_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -200,15 +204,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.1.0.0/16"] } resource "azurerm_subnet" "test" { name = "acctestsubnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.1.0.0/24" delegation { @@ -223,15 +227,15 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_profile" "test" { name = "acctestnetprofile-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name container_network_interface { name = "acctesteth-%d" ip_configuration { name = "acctestipconfig-%d" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } } @@ -244,16 +248,16 @@ func testAccAzureRMNetworkProfile_requiresImport(data acceptance.TestData) strin %s resource "azurerm_network_profile" "import" { - name = "${azurerm_network_profile.test.name}" - location = "${azurerm_network_profile.test.location}" - resource_group_name = "${azurerm_network_profile.test.resource_group_name}" + name = azurerm_network_profile.test.name + location = azurerm_network_profile.test.location + resource_group_name = azurerm_network_profile.test.resource_group_name container_network_interface { - name = "${azurerm_network_profile.test.container_network_interface.0.name}" + name = azurerm_network_profile.test.container_network_interface[0].name ip_configuration { - name = "${azurerm_network_profile.test.container_network_interface.0.ip_configuration.0.name}" - subnet_id = "${azurerm_subnet.test.id}" + name = azurerm_network_profile.test.container_network_interface[0].ip_configuration[0].name + subnet_id = azurerm_subnet.test.id } } } @@ -262,6 +266,10 @@ resource "azurerm_network_profile" "import" { func testAccAzureRMNetworkProfile_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -269,15 +277,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.1.0.0/16"] } resource "azurerm_subnet" "test" { name = "acctestsubnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.1.0.0/24" delegation { @@ -292,15 +300,15 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_profile" "test" { name = "acctestnetprofile-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name container_network_interface { name = "acctesteth-%d" ip_configuration { name = "acctestipconfig-%d" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } @@ -314,6 +322,10 @@ resource "azurerm_network_profile" "test" { func testAccAzureRMNetworkProfile_withUpdatedTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -321,15 +333,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.1.0.0/16"] } resource "azurerm_subnet" "test" { name = "acctestsubnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.1.0.0/24" delegation { @@ -344,15 +356,15 @@ resource "azurerm_subnet" "test" { resource "azurerm_network_profile" "test" { name = "acctestnetprofile-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name container_network_interface { name = "acctesteth-%d" ip_configuration { name = "acctestipconfig-%d" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } diff --git a/azurerm/internal/services/network/tests/resource_arm_network_security_group_test.go b/azurerm/internal/services/network/tests/resource_arm_network_security_group_test.go index 35a3320bf182d..3f0674aec5782 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_security_group_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_security_group_test.go @@ -316,6 +316,10 @@ func testCheckAzureRMNetworkSecurityGroupDestroy(s *terraform.State) error { func testAccAzureRMNetworkSecurityGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -323,8 +327,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_security_group" "test" { name = "acceptanceTestSecurityGroup1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary) } @@ -335,15 +339,19 @@ func testAccAzureRMNetworkSecurityGroup_requiresImport(data acceptance.TestData) %s resource "azurerm_network_security_group" "test" { - name = "${azurerm_network_security_group.test.name}" - location = "${azurerm_network_security_group.test.location}" - resource_group_name = "${azurerm_network_security_group.test.resource_group_name}" + name = azurerm_network_security_group.test.name + location = azurerm_network_security_group.test.location + resource_group_name = azurerm_network_security_group.test.resource_group_name } `, template) } func testAccAzureRMNetworkSecurityGroup_rulesExplicitZero(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -351,8 +359,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_security_group" "test" { name = "acceptanceTestSecurityGroup1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name security_rule = [] } @@ -361,6 +369,10 @@ resource "azurerm_network_security_group" "test" { func testAccAzureRMNetworkSecurityGroup_singleRule(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -368,8 +380,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_security_group" "test" { name = "acceptanceTestSecurityGroup1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name security_rule { name = "test123" @@ -388,6 +400,10 @@ resource "azurerm_network_security_group" "test" { func testAccAzureRMNetworkSecurityGroup_anotherRule(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -395,8 +411,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_security_group" "test" { name = "acceptanceTestSecurityGroup1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name security_rule { name = "test123" @@ -427,6 +443,10 @@ resource "azurerm_network_security_group" "test" { func testAccAzureRMNetworkSecurityGroup_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -434,8 +454,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_security_group" "test" { name = "acceptanceTestSecurityGroup1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name security_rule { name = "test123" @@ -459,6 +479,10 @@ resource "azurerm_network_security_group" "test" { func testAccAzureRMNetworkSecurityGroup_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -466,8 +490,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_security_group" "test" { name = "acceptanceTestSecurityGroup1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name security_rule { name = "test123" @@ -490,6 +514,10 @@ resource "azurerm_network_security_group" "test" { func testAccAzureRMNetworkSecurityGroup_augmented(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -497,8 +525,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_security_group" "test" { name = "acceptanceTestSecurityGroup1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name security_rule { name = "test123" @@ -517,6 +545,10 @@ resource "azurerm_network_security_group" "test" { func testAccAzureRMNetworkSecurityGroup_applicationSecurityGroup(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -524,20 +556,20 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_security_group" "first" { name = "acctest-first%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_application_security_group" "second" { name = "acctest-second%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_network_security_group" "test" { name = "acctestnsg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name security_rule { name = "test123" @@ -545,8 +577,8 @@ resource "azurerm_network_security_group" "test" { direction = "Inbound" access = "Allow" protocol = "Tcp" - source_application_security_group_ids = ["${azurerm_application_security_group.first.id}"] - destination_application_security_group_ids = ["${azurerm_application_security_group.second.id}"] + source_application_security_group_ids = [azurerm_application_security_group.first.id] + destination_application_security_group_ids = [azurerm_application_security_group.second.id] source_port_ranges = ["10000-40000"] destination_port_ranges = ["80", "443", "8080", "8190"] } diff --git a/azurerm/internal/services/network/tests/resource_arm_network_security_rule_test.go b/azurerm/internal/services/network/tests/resource_arm_network_security_rule_test.go index c5f252c65b370..f4ccae96b4d85 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_security_rule_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_security_rule_test.go @@ -226,6 +226,10 @@ func testCheckAzureRMNetworkSecurityRuleDestroy(s *terraform.State) error { func testAccAzureRMNetworkSecurityRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -233,14 +237,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_security_group" "test" { name = "acceptanceTestSecurityGroup1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_network_security_rule" "test" { name = "test123" - network_security_group_name = "${azurerm_network_security_group.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + network_security_group_name = azurerm_network_security_group.test.name + resource_group_name = azurerm_resource_group.test.name priority = 100 direction = "Outbound" access = "Allow" @@ -259,23 +263,27 @@ func testAccAzureRMNetworkSecurityRule_requiresImport(data acceptance.TestData) %s resource "azurerm_network_security_rule" "import" { - name = "${azurerm_network_security_rule.test.name}" - network_security_group_name = "${azurerm_network_security_rule.test.network_security_group_name}" - resource_group_name = "${azurerm_network_security_rule.test.resource_group_name}" - priority = "${azurerm_network_security_rule.test.priority}" - direction = "${azurerm_network_security_rule.test.direction}" - access = "${azurerm_network_security_rule.test.access}" - protocol = "${azurerm_network_security_rule.test.protocol}" - source_port_range = "${azurerm_network_security_rule.test.source_port_range}" - destination_port_range = "${azurerm_network_security_rule.test.destination_port_range}" - source_address_prefix = "${azurerm_network_security_rule.test.source_address_prefix}" - destination_address_prefix = "${azurerm_network_security_rule.test.destination_address_prefix}" + name = azurerm_network_security_rule.test.name + network_security_group_name = azurerm_network_security_rule.test.network_security_group_name + resource_group_name = azurerm_network_security_rule.test.resource_group_name + priority = azurerm_network_security_rule.test.priority + direction = azurerm_network_security_rule.test.direction + access = azurerm_network_security_rule.test.access + protocol = azurerm_network_security_rule.test.protocol + source_port_range = azurerm_network_security_rule.test.source_port_range + destination_port_range = azurerm_network_security_rule.test.destination_port_range + source_address_prefix = azurerm_network_security_rule.test.source_address_prefix + destination_address_prefix = azurerm_network_security_rule.test.destination_address_prefix } `, template) } func testAccAzureRMNetworkSecurityRule_updateBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test1" { name = "acctestRG-%d" location = "%s" @@ -283,8 +291,8 @@ resource "azurerm_resource_group" "test1" { resource "azurerm_network_security_group" "test1" { name = "acceptanceTestSecurityGroup2" - location = "${azurerm_resource_group.test1.location}" - resource_group_name = "${azurerm_resource_group.test1.name}" + location = azurerm_resource_group.test1.location + resource_group_name = azurerm_resource_group.test1.name } resource "azurerm_network_security_rule" "test1" { @@ -297,14 +305,18 @@ resource "azurerm_network_security_rule" "test1" { destination_port_range = "*" source_address_prefix = "*" destination_address_prefix = "*" - resource_group_name = "${azurerm_resource_group.test1.name}" - network_security_group_name = "${azurerm_network_security_group.test1.name}" + resource_group_name = azurerm_resource_group.test1.name + network_security_group_name = azurerm_network_security_group.test1.name } `, data.RandomInteger, data.Locations.Primary) } func testAccAzureRMNetworkSecurityRule_updateExtraRule(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test1" { name = "acctestRG-%d" location = "%s" @@ -312,8 +324,8 @@ resource "azurerm_resource_group" "test1" { resource "azurerm_network_security_group" "test1" { name = "acceptanceTestSecurityGroup2" - location = "${azurerm_resource_group.test1.location}" - resource_group_name = "${azurerm_resource_group.test1.name}" + location = azurerm_resource_group.test1.location + resource_group_name = azurerm_resource_group.test1.name } resource "azurerm_network_security_rule" "test1" { @@ -326,8 +338,8 @@ resource "azurerm_network_security_rule" "test1" { destination_port_range = "*" source_address_prefix = "*" destination_address_prefix = "*" - resource_group_name = "${azurerm_resource_group.test1.name}" - network_security_group_name = "${azurerm_network_security_group.test1.name}" + resource_group_name = azurerm_resource_group.test1.name + network_security_group_name = azurerm_network_security_group.test1.name } resource "azurerm_network_security_rule" "test2" { @@ -340,14 +352,18 @@ resource "azurerm_network_security_rule" "test2" { destination_port_range = "*" source_address_prefix = "*" destination_address_prefix = "*" - resource_group_name = "${azurerm_resource_group.test1.name}" - network_security_group_name = "${azurerm_network_security_group.test1.name}" + resource_group_name = azurerm_resource_group.test1.name + network_security_group_name = azurerm_network_security_group.test1.name } `, data.RandomInteger, data.Locations.Primary) } func testAccAzureRMNetworkSecurityRule_augmented(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test1" { name = "acctestRG-%d" location = "%s" @@ -355,8 +371,8 @@ resource "azurerm_resource_group" "test1" { resource "azurerm_network_security_group" "test1" { name = "acceptanceTestSecurityGroup2" - location = "${azurerm_resource_group.test1.location}" - resource_group_name = "${azurerm_resource_group.test1.name}" + location = azurerm_resource_group.test1.location + resource_group_name = azurerm_resource_group.test1.name } resource "azurerm_network_security_rule" "test1" { @@ -369,14 +385,18 @@ resource "azurerm_network_security_rule" "test1" { destination_port_ranges = ["80", "443", "8080", "8190"] source_address_prefixes = ["10.0.0.0/8", "192.168.0.0/16"] destination_address_prefixes = ["172.16.0.0/20", "8.8.8.8"] - resource_group_name = "${azurerm_resource_group.test1.name}" - network_security_group_name = "${azurerm_network_security_group.test1.name}" + resource_group_name = azurerm_resource_group.test1.name + network_security_group_name = azurerm_network_security_group.test1.name } `, data.RandomInteger, data.Locations.Primary) } func testAccAzureRMNetworkSecurityRule_applicationSecurityGroups(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -384,32 +404,32 @@ resource "azurerm_resource_group" "test" { resource "azurerm_application_security_group" "first" { name = "acctest-first%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_application_security_group" "second" { name = "acctest-second%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_network_security_group" "test" { name = "acctestnsg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_network_security_rule" "test1" { name = "test123" - resource_group_name = "${azurerm_resource_group.test.name}" - network_security_group_name = "${azurerm_network_security_group.test.name}" + resource_group_name = azurerm_resource_group.test.name + network_security_group_name = azurerm_network_security_group.test.name priority = 100 direction = "Outbound" access = "Allow" protocol = "Tcp" - source_application_security_group_ids = ["${azurerm_application_security_group.first.id}"] - destination_application_security_group_ids = ["${azurerm_application_security_group.second.id}"] + source_application_security_group_ids = [azurerm_application_security_group.first.id] + destination_application_security_group_ids = [azurerm_application_security_group.second.id] source_port_ranges = ["10000-40000"] destination_port_ranges = ["80", "443", "8080", "8190"] } diff --git a/azurerm/internal/services/network/tests/resource_arm_network_watcher_flow_log_test.go b/azurerm/internal/services/network/tests/resource_arm_network_watcher_flow_log_test.go index b774ebc38511e..091bcbc7a390f 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_watcher_flow_log_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_watcher_flow_log_test.go @@ -228,6 +228,7 @@ func testAccAzureRMNetworkWatcherFlowLog_trafficAnalytics(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), ), }, + data.ImportStep(), { Config: testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsEnabledConfig(data), Check: resource.ComposeTestCheckFunc( @@ -242,6 +243,28 @@ func testAccAzureRMNetworkWatcherFlowLog_trafficAnalytics(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), resource.TestCheckResourceAttr(data.ResourceName, "traffic_analytics.#", "1"), resource.TestCheckResourceAttr(data.ResourceName, "traffic_analytics.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_analytics.0.interval_in_minutes", "60"), + resource.TestCheckResourceAttrSet(data.ResourceName, "traffic_analytics.0.workspace_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "traffic_analytics.0.workspace_region"), + resource.TestCheckResourceAttrSet(data.ResourceName, "traffic_analytics.0.workspace_resource_id"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsUpdateInterval(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.days", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_analytics.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_analytics.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_analytics.0.interval_in_minutes", "10"), resource.TestCheckResourceAttrSet(data.ResourceName, "traffic_analytics.0.workspace_id"), resource.TestCheckResourceAttrSet(data.ResourceName, "traffic_analytics.0.workspace_region"), resource.TestCheckResourceAttrSet(data.ResourceName, "traffic_analytics.0.workspace_resource_id"), @@ -332,33 +355,37 @@ func testCheckAzureRMNetworkWatcherFlowLogExists(name string) resource.TestCheck } func testAccAzureRMNetworkWatcherFlowLog_prerequisites(data acceptance.TestData) string { - return fmt.Sprintf(` + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { - name = "acctestRG-watcher-%d" - location = "%s" + name = "acctestRG-watcher-%d" + location = "%s" } resource "azurerm_network_security_group" "test" { - name = "acctestNSG%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "acctestNSG%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" } resource "azurerm_network_watcher" "test" { - name = "acctest-NW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = "acctest-NW-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" } resource "azurerm_storage_account" "test" { - name = "acctestsa%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + name = "acctestsa%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" - account_kind = "StorageV2" - account_replication_type = "LRS" - enable_https_traffic_only = true + account_tier = "Standard" + account_kind = "StorageV2" + account_replication_type = "LRS" + enable_https_traffic_only = true } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger%1000000) } @@ -368,11 +395,11 @@ func testAccAzureRMNetworkWatcherFlowLog_basicConfig(data acceptance.TestData) s %s resource "azurerm_network_watcher_flow_log" "test" { - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name - network_security_group_id = "${azurerm_network_security_group.test.id}" - storage_account_id = "${azurerm_storage_account.test.id}" + network_security_group_id = azurerm_network_security_group.test.id + storage_account_id = azurerm_storage_account.test.id enabled = true retention_policy { @@ -388,11 +415,11 @@ func testAccAzureRMNetworkWatcherFlowLog_retentionPolicyConfig(data acceptance.T %s resource "azurerm_network_watcher_flow_log" "test" { - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name - network_security_group_id = "${azurerm_network_security_group.test.id}" - storage_account_id = "${azurerm_storage_account.test.id}" + network_security_group_id = azurerm_network_security_group.test.id + storage_account_id = azurerm_storage_account.test.id enabled = true retention_policy { @@ -409,8 +436,8 @@ func testAccAzureRMNetworkWatcherFlowLog_retentionPolicyConfigUpdateStorageAccou resource "azurerm_storage_account" "testb" { name = "acctestsab%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_kind = "StorageV2" @@ -419,11 +446,11 @@ resource "azurerm_storage_account" "testb" { } resource "azurerm_network_watcher_flow_log" "test" { - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name - network_security_group_id = "${azurerm_network_security_group.test.id}" - storage_account_id = "${azurerm_storage_account.testb.id}" + network_security_group_id = azurerm_network_security_group.test.id + storage_account_id = azurerm_storage_account.testb.id enabled = true retention_policy { @@ -439,11 +466,11 @@ func testAccAzureRMNetworkWatcherFlowLog_disabledConfig(data acceptance.TestData %s resource "azurerm_network_watcher_flow_log" "test" { - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name - network_security_group_id = "${azurerm_network_security_group.test.id}" - storage_account_id = "${azurerm_storage_account.test.id}" + network_security_group_id = azurerm_network_security_group.test.id + storage_account_id = azurerm_storage_account.test.id enabled = false retention_policy { @@ -458,6 +485,40 @@ func testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsEnabledConfig(data acce return fmt.Sprintf(` %s +resource "azurerm_log_analytics_workspace" "test" { + name = "acctestLAW-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku = "PerGB2018" +} + +resource "azurerm_network_watcher_flow_log" "test" { + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + + network_security_group_id = azurerm_network_security_group.test.id + storage_account_id = azurerm_storage_account.test.id + enabled = true + + retention_policy { + enabled = true + days = 7 + } + + traffic_analytics { + enabled = true + workspace_id = azurerm_log_analytics_workspace.test.workspace_id + workspace_region = azurerm_log_analytics_workspace.test.location + workspace_resource_id = azurerm_log_analytics_workspace.test.id + } +} +`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(data), data.RandomInteger) +} + +func testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsUpdateInterval(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + resource "azurerm_log_analytics_workspace" "test" { name = "acctestLAW-%d" location = "${azurerm_resource_group.test.location}" @@ -483,6 +544,7 @@ resource "azurerm_network_watcher_flow_log" "test" { workspace_id = "${azurerm_log_analytics_workspace.test.workspace_id}" workspace_region = "${azurerm_log_analytics_workspace.test.location}" workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" + interval_in_minutes = 10 } } `, testAccAzureRMNetworkWatcherFlowLog_prerequisites(data), data.RandomInteger) @@ -494,17 +556,17 @@ func testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsDisabledConfig(data acc resource "azurerm_log_analytics_workspace" "test" { name = "acctestLAW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" } resource "azurerm_network_watcher_flow_log" "test" { - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name - network_security_group_id = "${azurerm_network_security_group.test.id}" - storage_account_id = "${azurerm_storage_account.test.id}" + network_security_group_id = azurerm_network_security_group.test.id + storage_account_id = azurerm_storage_account.test.id enabled = true retention_policy { @@ -514,9 +576,9 @@ resource "azurerm_network_watcher_flow_log" "test" { traffic_analytics { enabled = false - workspace_id = "${azurerm_log_analytics_workspace.test.workspace_id}" - workspace_region = "${azurerm_log_analytics_workspace.test.location}" - workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" + workspace_id = azurerm_log_analytics_workspace.test.workspace_id + workspace_region = azurerm_log_analytics_workspace.test.location + workspace_resource_id = azurerm_log_analytics_workspace.test.id } } `, testAccAzureRMNetworkWatcherFlowLog_prerequisites(data), data.RandomInteger) @@ -528,17 +590,17 @@ func testAccAzureRMNetworkWatcherFlowLog_versionConfig(data acceptance.TestData, resource "azurerm_log_analytics_workspace" "test" { name = "acctestLAW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "PerGB2018" } resource "azurerm_network_watcher_flow_log" "test" { - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name - network_security_group_id = "${azurerm_network_security_group.test.id}" - storage_account_id = "${azurerm_storage_account.test.id}" + network_security_group_id = azurerm_network_security_group.test.id + storage_account_id = azurerm_storage_account.test.id enabled = true version = %d @@ -549,9 +611,9 @@ resource "azurerm_network_watcher_flow_log" "test" { traffic_analytics { enabled = true - workspace_id = "${azurerm_log_analytics_workspace.test.workspace_id}" - workspace_region = "${azurerm_log_analytics_workspace.test.location}" - workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" + workspace_id = azurerm_log_analytics_workspace.test.workspace_id + workspace_region = azurerm_log_analytics_workspace.test.location + workspace_resource_id = azurerm_log_analytics_workspace.test.id } } `, testAccAzureRMNetworkWatcherFlowLog_prerequisites(data), data.RandomInteger, version) diff --git a/azurerm/internal/services/network/tests/resource_arm_network_watcher_test.go b/azurerm/internal/services/network/tests/resource_arm_network_watcher_test.go index 855f58eec3365..4d88fd28255d9 100644 --- a/azurerm/internal/services/network/tests/resource_arm_network_watcher_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_watcher_test.go @@ -28,18 +28,6 @@ func TestAccAzureRMNetworkWatcher(t *testing.T) { "DataSource": { "basic": testAccDataSourceAzureRMNetworkWatcher_basic, }, - "ConnectionMonitorOld": { - "addressBasic": testAccAzureRMConnectionMonitor_addressBasic, - "addressComplete": testAccAzureRMConnectionMonitor_addressComplete, - "addressUpdate": testAccAzureRMConnectionMonitor_addressUpdate, - "vmBasic": testAccAzureRMConnectionMonitor_vmBasic, - "vmComplete": testAccAzureRMConnectionMonitor_vmComplete, - "vmUpdate": testAccAzureRMConnectionMonitor_vmUpdate, - "destinationUpdate": testAccAzureRMConnectionMonitor_destinationUpdate, - "missingDestinationInvalid": testAccAzureRMConnectionMonitor_missingDestination, - "bothDestinationsInvalid": testAccAzureRMConnectionMonitor_conflictingDestinations, - "requiresImport": testAccAzureRMConnectionMonitor_requiresImport, - }, "PacketCaptureOld": { "localDisk": testAccAzureRMPacketCapture_localDisk, "storageAccount": testAccAzureRMPacketCapture_storageAccount, @@ -282,6 +270,10 @@ func testCheckAzureRMNetworkWatcherDestroy(s *terraform.State) error { func testAccAzureRMNetworkWatcher_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-watcher-%d" location = "%s" @@ -289,8 +281,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_watcher" "test" { name = "acctestNW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -301,15 +293,19 @@ func testAccAzureRMNetworkWatcher_requiresImportConfig(data acceptance.TestData) %s resource "azurerm_network_watcher" "import" { - name = "${azurerm_network_watcher.test.name}" - location = "${azurerm_network_watcher.test.location}" - resource_group_name = "${azurerm_network_watcher.test.resource_group_name}" + name = azurerm_network_watcher.test.name + location = azurerm_network_watcher.test.location + resource_group_name = azurerm_network_watcher.test.resource_group_name } `, template) } func testAccAzureRMNetworkWatcher_completeConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-watcher-%d" location = "%s" @@ -317,8 +313,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_network_watcher" "test" { name = "acctestNW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { "Source" = "AccTests" diff --git a/azurerm/internal/services/network/tests/resource_arm_packet_capture_test.go b/azurerm/internal/services/network/tests/resource_arm_packet_capture_test.go index e1db9e6e681c6..b7452b739236a 100644 --- a/azurerm/internal/services/network/tests/resource_arm_packet_capture_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_packet_capture_test.go @@ -170,6 +170,10 @@ func testCheckAzureRMPacketCaptureDestroy(s *terraform.State) error { func testAzureRMPacketCapture_base(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -259,15 +263,15 @@ func testAzureRMPacketCapture_localDiskConfig(data acceptance.TestData) string { resource "azurerm_packet_capture" "test" { name = "acctestpc-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - target_resource_id = "${azurerm_virtual_machine.test.id}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + target_resource_id = azurerm_virtual_machine.test.id storage_location { file_path = "/var/captures/packet.cap" } - depends_on = ["azurerm_virtual_machine_extension.test"] + depends_on = [azurerm_virtual_machine_extension.test] } `, config, data.RandomInteger) } @@ -278,16 +282,16 @@ func testAzureRMPacketCapture_localDiskConfig_requiresImport(data acceptance.Tes %s resource "azurerm_packet_capture" "import" { - name = "${azurerm_packet_capture.test.name}" - network_watcher_name = "${azurerm_packet_capture.test.network_watcher_name}" - resource_group_name = "${azurerm_packet_capture.test.resource_group_name}" - target_resource_id = "${azurerm_packet_capture.test.target_resource_id}" + name = azurerm_packet_capture.test.name + network_watcher_name = azurerm_packet_capture.test.network_watcher_name + resource_group_name = azurerm_packet_capture.test.resource_group_name + target_resource_id = azurerm_packet_capture.test.target_resource_id storage_location { file_path = "/var/captures/packet.cap" } - depends_on = ["azurerm_virtual_machine_extension.test"] + depends_on = [azurerm_virtual_machine_extension.test] } `, config) } @@ -299,9 +303,9 @@ func testAzureRMPacketCapture_localDiskConfigWithFilters(data acceptance.TestDat resource "azurerm_packet_capture" "test" { name = "acctestpc-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - target_resource_id = "${azurerm_virtual_machine.test.id}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + target_resource_id = azurerm_virtual_machine.test.id storage_location { file_path = "/var/captures/packet.cap" @@ -319,7 +323,7 @@ resource "azurerm_packet_capture" "test" { protocol = "UDP" } - depends_on = ["azurerm_virtual_machine_extension.test"] + depends_on = [azurerm_virtual_machine_extension.test] } `, config, data.RandomInteger) } @@ -331,23 +335,23 @@ func testAzureRMPacketCapture_storageAccountConfig(data acceptance.TestData) str resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_packet_capture" "test" { name = "acctestpc-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - target_resource_id = "${azurerm_virtual_machine.test.id}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + target_resource_id = azurerm_virtual_machine.test.id storage_location { - storage_account_id = "${azurerm_storage_account.test.id}" + storage_account_id = azurerm_storage_account.test.id } - depends_on = ["azurerm_virtual_machine_extension.test"] + depends_on = [azurerm_virtual_machine_extension.test] } `, config, data.RandomString, data.RandomInteger) } @@ -359,24 +363,24 @@ func testAzureRMPacketCapture_storageAccountAndLocalDiskConfig(data acceptance.T resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_packet_capture" "test" { name = "acctestpc-%d" - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - target_resource_id = "${azurerm_virtual_machine.test.id}" + network_watcher_name = azurerm_network_watcher.test.name + resource_group_name = azurerm_resource_group.test.name + target_resource_id = azurerm_virtual_machine.test.id storage_location { file_path = "/var/captures/packet.cap" - storage_account_id = "${azurerm_storage_account.test.id}" + storage_account_id = azurerm_storage_account.test.id } - depends_on = ["azurerm_virtual_machine_extension.test"] + depends_on = [azurerm_virtual_machine_extension.test] } `, config, data.RandomString, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_point_to_site_vpn_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_point_to_site_vpn_gateway_test.go index 10ed5cccc6d9f..b5d779365de7f 100644 --- a/azurerm/internal/services/network/tests/resource_arm_point_to_site_vpn_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_point_to_site_vpn_gateway_test.go @@ -250,6 +250,10 @@ resource "azurerm_point_to_site_vpn_gateway" "test" { func testAccAzureRMAzureRMPointToSiteVPNGateway_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/network/tests/resource_arm_private_endpoint_test.go b/azurerm/internal/services/network/tests/resource_arm_private_endpoint_test.go index 0357699e654a8..7e47dbbcc38e4 100644 --- a/azurerm/internal/services/network/tests/resource_arm_private_endpoint_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_private_endpoint_test.go @@ -24,6 +24,7 @@ func TestAccAzureRMPrivateEndpoint_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMPrivateEndpointExists(data.ResourceName), resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "private_service_connection.0.private_ip_address"), ), }, data.ImportStep(), @@ -115,6 +116,10 @@ func testCheckAzureRMPrivateEndpointDestroy(s *terraform.State) error { func testAccAzureRMPrivateEndpointTemplate_template(data acceptance.TestData, seviceCfg string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_subscription" "current" {} resource "azurerm_resource_group" "test" { @@ -172,6 +177,10 @@ resource "azurerm_lb" "test" { func testAccAzureRMPrivateEndpoint_serviceAutoApprove(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_private_link_service" "test" { name = "acctestPLS-%d" location = azurerm_resource_group.test.location @@ -194,6 +203,10 @@ resource "azurerm_private_link_service" "test" { func testAccAzureRMPrivateEndpoint_serviceManualApprove(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_private_link_service" "test" { name = "acctestPLS-%d" location = azurerm_resource_group.test.location diff --git a/azurerm/internal/services/network/tests/resource_arm_private_link_endpoint_test.go b/azurerm/internal/services/network/tests/resource_arm_private_link_endpoint_test.go deleted file mode 100644 index 60749548ec854..0000000000000 --- a/azurerm/internal/services/network/tests/resource_arm_private_link_endpoint_test.go +++ /dev/null @@ -1,102 +0,0 @@ -package tests - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccAzureRMPrivateLinkEndpoint_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_private_link_endpoint", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMPrivateEndpointDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMPrivateLinkEndpoint_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateEndpointExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), - ), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMPrivateLinkEndpoint_requestMessage(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_private_link_endpoint", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMPrivateEndpointDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMPrivateLinkEndpoint_requestMessage(data, "CATS: ALL YOUR BASE ARE BELONG TO US."), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateEndpointExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), - resource.TestCheckResourceAttr(data.ResourceName, "private_service_connection.0.request_message", "CATS: ALL YOUR BASE ARE BELONG TO US."), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMPrivateLinkEndpoint_requestMessage(data, "CAPTAIN: WHAT YOU SAY!!"), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateEndpointExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), - resource.TestCheckResourceAttr(data.ResourceName, "private_service_connection.0.request_message", "CAPTAIN: WHAT YOU SAY!!"), - ), - }, - data.ImportStep(), - }, - }) -} - -// The update and complete test cases had to be totally removed since there is a bug with tags and the support for -// tags has been removed, all other attributes are ForceNew. -// API Issue "Unable to remove Tags from Private Link Endpoint": https://github.com/Azure/azure-sdk-for-go/issues/6467 - -func testAccAzureRMPrivateLinkEndpoint_basic(data acceptance.TestData) string { - return fmt.Sprintf(` -%s - -resource "azurerm_private_link_endpoint" "test" { - name = "acctest-privatelink-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - subnet_id = azurerm_subnet.endpoint.id - - private_service_connection { - name = azurerm_private_link_service.test.name - is_manual_connection = false - private_connection_resource_id = azurerm_private_link_service.test.id - } -} -`, testAccAzureRMPrivateEndpointTemplate_template(data, testAccAzureRMPrivateEndpoint_serviceAutoApprove(data)), data.RandomInteger) -} - -func testAccAzureRMPrivateLinkEndpoint_requestMessage(data acceptance.TestData, msg string) string { - return fmt.Sprintf(` -%s - -resource "azurerm_private_link_endpoint" "test" { - name = "acctest-privatelink-%d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - subnet_id = azurerm_subnet.endpoint.id - - private_service_connection { - name = azurerm_private_link_service.test.name - is_manual_connection = true - private_connection_resource_id = azurerm_private_link_service.test.id - request_message = %q - } -} -`, testAccAzureRMPrivateEndpointTemplate_template(data, testAccAzureRMPrivateEndpoint_serviceManualApprove(data)), data.RandomInteger, msg) -} diff --git a/azurerm/internal/services/network/tests/resource_arm_private_link_service_test.go b/azurerm/internal/services/network/tests/resource_arm_private_link_service_test.go index 68c18f96538b4..dda198ea10da3 100644 --- a/azurerm/internal/services/network/tests/resource_arm_private_link_service_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_private_link_service_test.go @@ -816,6 +816,10 @@ resource "azurerm_private_link_service" "test" { func testAccAzureRMPrivateLinkService_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_subscription" "current" {} resource "azurerm_resource_group" "test" { diff --git a/azurerm/internal/services/network/tests/resource_arm_public_ip_prefix_test.go b/azurerm/internal/services/network/tests/resource_arm_public_ip_prefix_test.go index 69da829f4f740..3a8146ab82ea9 100644 --- a/azurerm/internal/services/network/tests/resource_arm_public_ip_prefix_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_public_ip_prefix_test.go @@ -190,6 +190,10 @@ func TestAccAzureRMPublicIpPrefix_disappears(t *testing.T) { func testAccAzureRMPublicIPPrefix_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -197,14 +201,18 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip_prefix" "test" { name = "acctestpublicipprefix-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccAzureRMPublicIPPrefix_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -212,8 +220,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip_prefix" "test" { name = "acctestpublicipprefix-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { environment = "Production" @@ -225,6 +233,10 @@ resource "azurerm_public_ip_prefix" "test" { func testAccAzureRMPublicIPPrefix_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -232,8 +244,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip_prefix" "test" { name = "acctestpublicipprefix-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name tags = { environment = "staging" @@ -244,6 +256,10 @@ resource "azurerm_public_ip_prefix" "test" { func testAccAzureRMPublicIPPrefix_prefixLength(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -251,8 +267,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip_prefix" "test" { name = "acctestpublicipprefix-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name prefix_length = 31 } diff --git a/azurerm/internal/services/network/tests/resource_arm_public_ip_test.go b/azurerm/internal/services/network/tests/resource_arm_public_ip_test.go index 837ad33717494..24ae135fb1190 100644 --- a/azurerm/internal/services/network/tests/resource_arm_public_ip_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_public_ip_test.go @@ -66,37 +66,6 @@ func TestAccAzureRMPublicIpStatic_requiresImport(t *testing.T) { }) } -func TestAccAzureRMPublicIpStatic_basicOld(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMPublicIpDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMPublicIPStatic_basicOld(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), - resource.TestCheckResourceAttr(data.ResourceName, "public_ip_address_allocation", "Static"), - resource.TestCheckResourceAttr(data.ResourceName, "ip_version", "IPv4"), - ), - }, - { - Config: testAccAzureRMPublicIPStatic_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), - resource.TestCheckResourceAttr(data.ResourceName, "allocation_method", "Static"), - resource.TestCheckResourceAttr(data.ResourceName, "ip_version", "IPv4"), - ), - }, - data.ImportStep(), - }, - }) -} - func TestAccAzureRMPublicIpStatic_zones(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") @@ -531,6 +500,10 @@ func testCheckAzureRMPublicIpDestroy(s *terraform.State) error { func testAccAzureRMPublicIPStatic_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -538,8 +511,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -550,32 +523,20 @@ func testAccAzureRMPublicIPStatic_requiresImport(data acceptance.TestData) strin %s resource "azurerm_public_ip" "import" { - name = "${azurerm_public_ip.test.name}" - location = "${azurerm_public_ip.test.location}" - resource_group_name = "${azurerm_public_ip.test.resource_group_name}" - allocation_method = "${azurerm_public_ip.test.allocation_method}" + name = azurerm_public_ip.test.name + location = azurerm_public_ip.test.location + resource_group_name = azurerm_public_ip.test.resource_group_name + allocation_method = azurerm_public_ip.test.allocation_method } `, testAccAzureRMPublicIPStatic_basic(data)) } -func testAccAzureRMPublicIPStatic_basicOld(data acceptance.TestData) string { +func testAccAzureRMPublicIPStatic_withZone(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_public_ip" "test" { - name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - public_ip_address_allocation = "Static" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMPublicIPStatic_withZone(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -583,8 +544,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" zones = ["1"] } @@ -593,6 +554,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPStatic_basic_withDNSLabel(data acceptance.TestData, dnsNameLabel string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -600,8 +565,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" domain_name_label = "%s" } @@ -610,6 +575,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPStatic_basic_withIPVersion(data acceptance.TestData, ipVersion string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -617,8 +586,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" ip_version = "%s" } @@ -627,6 +596,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPStatic_standard(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -634,8 +607,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" } @@ -644,6 +617,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPStatic_standardPrefix(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -651,23 +628,27 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip_prefix" "test" { name = "acctestpublicipprefix-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" - public_ip_prefix_id = "${azurerm_public_ip_prefix.test.id}" + public_ip_prefix_id = azurerm_public_ip_prefix.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testAccAzureRMPublicIPStatic_standardPrefixWithTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -675,17 +656,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip_prefix" "test" { name = "acctestpublicipprefix-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" - public_ip_prefix_id = "${azurerm_public_ip_prefix.test.id}" + public_ip_prefix_id = azurerm_public_ip_prefix.test.id tags = { environment = "Production" @@ -697,6 +678,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPStatic_standardPrefixWithTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -704,17 +689,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip_prefix" "test" { name = "acctestpublicipprefix-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" sku = "Standard" - public_ip_prefix_id = "${azurerm_public_ip_prefix.test.id}" + public_ip_prefix_id = azurerm_public_ip_prefix.test.id tags = { environment = "staging" @@ -725,6 +710,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPStatic_standard_withIPVersion(data acceptance.TestData, ipVersion string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -732,8 +721,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" ip_version = "%s" sku = "Standard" @@ -743,6 +732,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPStatic_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -750,8 +743,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" domain_name_label = "acctest-%d" } @@ -760,6 +753,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPStatic_idleTimeout(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -767,8 +764,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" idle_timeout_in_minutes = 30 } @@ -777,6 +774,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPDynamic_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -784,8 +785,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -793,6 +794,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPDynamic_basic_withIPVersion(data acceptance.TestData, ipVersion string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -800,8 +805,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" ip_version = "%s" @@ -811,6 +816,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPStatic_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -818,8 +827,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" tags = { @@ -832,6 +841,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPStatic_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -839,8 +852,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" tags = { @@ -852,6 +865,10 @@ resource "azurerm_public_ip" "test" { func testAccAzureRMPublicIPStatic_canLabelBe63(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -859,8 +876,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" domain_name_label = "k2345678-1-2345678-2-2345678-3-2345678-4-2345678-5-2345678-6-23" diff --git a/azurerm/internal/services/network/tests/resource_arm_route_table_test.go b/azurerm/internal/services/network/tests/resource_arm_route_table_test.go index e69d34553a312..05f29aef80625 100644 --- a/azurerm/internal/services/network/tests/resource_arm_route_table_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_route_table_test.go @@ -265,34 +265,6 @@ func TestAccAzureRMRouteTable_multipleRoutes(t *testing.T) { }) } -func TestAccAzureRMRouteTable_withTagsSubnet(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_route_table", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteTable_withTagsSubnet(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists("azurerm_route_table.test"), - testCheckAzureRMSubnetExists("azurerm_subnet.subnet1"), - resource.TestCheckResourceAttrSet("azurerm_subnet.subnet1", "route_table_id"), - ), - }, - { - Config: testAccAzureRMRouteTable_withAddTagsSubnet(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists("azurerm_route_table.test"), - testCheckAzureRMSubnetExists("azurerm_subnet.subnet1"), - resource.TestCheckResourceAttrSet("azurerm_subnet.subnet1", "route_table_id"), - ), - }, - }, - }) -} - func testCheckAzureRMRouteTableExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] @@ -382,6 +354,10 @@ func testCheckAzureRMRouteTableDestroy(s *terraform.State) error { func testAccAzureRMRouteTable_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -389,8 +365,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_route_table" "test" { name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -400,15 +376,19 @@ func testAccAzureRMRouteTable_requiresImport(data acceptance.TestData) string { %s resource "azurerm_route_table" "import" { - name = "${azurerm_route_table.test.name}" - location = "${azurerm_route_table.test.location}" - resource_group_name = "${azurerm_route_table.test.resource_group_name}" + name = azurerm_route_table.test.name + location = azurerm_route_table.test.location + resource_group_name = azurerm_route_table.test.resource_group_name } `, testAccAzureRMRouteTable_basic(data)) } func testAccAzureRMRouteTable_basicAppliance(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -416,8 +396,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_route_table" "test" { name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name route { name = "route1" @@ -431,6 +411,10 @@ resource "azurerm_route_table" "test" { func testAccAzureRMRouteTable_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -438,8 +422,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_route_table" "test" { name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name route { name = "acctestRoute" @@ -454,6 +438,10 @@ resource "azurerm_route_table" "test" { func testAccAzureRMRouteTable_singleRoute(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -461,8 +449,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_route_table" "test" { name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name route { name = "route1" @@ -475,6 +463,10 @@ resource "azurerm_route_table" "test" { func testAccAzureRMRouteTable_noRouteBlocks(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -482,14 +474,18 @@ resource "azurerm_resource_group" "test" { resource "azurerm_route_table" "test" { name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccAzureRMRouteTable_singleRouteRemoved(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -497,8 +493,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_route_table" "test" { name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name route = [] } @@ -507,6 +503,10 @@ resource "azurerm_route_table" "test" { func testAccAzureRMRouteTable_multipleRoutes(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -514,8 +514,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_route_table" "test" { name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name route { name = "route1" @@ -534,6 +534,10 @@ resource "azurerm_route_table" "test" { func testAccAzureRMRouteTable_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -541,8 +545,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_route_table" "test" { name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name route { name = "route1" @@ -560,63 +564,19 @@ resource "azurerm_route_table" "test" { func testAccAzureRMRouteTable_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_route_table" "test" { - name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - route { - name = "route1" - address_prefix = "10.1.0.0/16" - next_hop_type = "vnetlocal" - } - - tags = { - environment = "staging" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -func testAccAzureRMRouteTable_withTagsSubnet(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" - - tags = { - environment = "staging" - } -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - address_space = ["10.0.0.0/16"] - - tags = { - environment = "staging" - } -} - -resource "azurerm_subnet" "subnet1" { - name = "subnet1" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.1.0/24" - route_table_id = "${azurerm_route_table.test.id}" } resource "azurerm_route_table" "test" { name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name route { name = "route1" @@ -628,56 +588,5 @@ resource "azurerm_route_table" "test" { environment = "staging" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMRouteTable_withAddTagsSubnet(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" - - tags = { - environment = "staging" - cloud = "Azure" - } -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - address_space = ["10.0.0.0/16"] - - tags = { - environment = "staging" - cloud = "Azure" - } -} - -resource "azurerm_subnet" "subnet1" { - name = "subnet1" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.1.0/24" - route_table_id = "${azurerm_route_table.test.id}" -} - -resource "azurerm_route_table" "test" { - name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - route { - name = "route1" - address_prefix = "10.1.0.0/16" - next_hop_type = "vnetlocal" - } - - tags = { - environment = "staging" - cloud = "Azure" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_route_test.go b/azurerm/internal/services/network/tests/resource_arm_route_test.go index bb771b300d716..a560ad376c2d9 100644 --- a/azurerm/internal/services/network/tests/resource_arm_route_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_route_test.go @@ -228,6 +228,10 @@ func testCheckAzureRMRouteDestroy(s *terraform.State) error { func testAccAzureRMRoute_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -235,14 +239,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_route_table" "test" { name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_route" "test" { name = "acctestroute%d" - resource_group_name = "${azurerm_resource_group.test.name}" - route_table_name = "${azurerm_route_table.test.name}" + resource_group_name = azurerm_resource_group.test.name + route_table_name = azurerm_route_table.test.name address_prefix = "10.1.0.0/16" next_hop_type = "vnetlocal" @@ -254,18 +258,22 @@ func testAccAzureRMRoute_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s resource "azurerm_route" "import" { - name = "${azurerm_route.test.name}" - resource_group_name = "${azurerm_route.test.resource_group_name}" - route_table_name = "${azurerm_route.test.route_table_name}" + name = azurerm_route.test.name + resource_group_name = azurerm_route.test.resource_group_name + route_table_name = azurerm_route.test.route_table_name - address_prefix = "${azurerm_route.test.address_prefix}" - next_hop_type = "${azurerm_route.test.next_hop_type}" + address_prefix = azurerm_route.test.address_prefix + next_hop_type = azurerm_route.test.next_hop_type } `, testAccAzureRMRoute_basic(data)) } func testAccAzureRMRoute_basicAppliance(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -273,14 +281,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_route_table" "test" { name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_route" "test" { name = "acctestroute%d" - resource_group_name = "${azurerm_resource_group.test.name}" - route_table_name = "${azurerm_route_table.test.name}" + resource_group_name = azurerm_resource_group.test.name + route_table_name = azurerm_route_table.test.name address_prefix = "10.1.0.0/16" next_hop_type = "VirtualAppliance" @@ -291,6 +299,10 @@ resource "azurerm_route" "test" { func testAccAzureRMRoute_multipleRoutes(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -298,14 +310,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_route_table" "test" { name = "acctestrt%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_route" "test1" { name = "acctestroute%d" - resource_group_name = "${azurerm_resource_group.test.name}" - route_table_name = "${azurerm_route_table.test.name}" + resource_group_name = azurerm_resource_group.test.name + route_table_name = azurerm_route_table.test.name address_prefix = "10.2.0.0/16" next_hop_type = "none" diff --git a/azurerm/internal/services/network/tests/resource_arm_subnet_nat_gateway_association_test.go b/azurerm/internal/services/network/tests/resource_arm_subnet_nat_gateway_association_test.go index 86ff7f597aca1..107fa815a441e 100644 --- a/azurerm/internal/services/network/tests/resource_arm_subnet_nat_gateway_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_subnet_nat_gateway_association_test.go @@ -55,7 +55,7 @@ func TestAccAzureRMSubnetNatGatewayAssociation_requiresImport(t *testing.T) { }, { Config: testAccAzureRMSubnetNatGatewayAssociation_requiresImport(data), - ExpectError: acceptance.RequiresImportError(""), + ExpectError: acceptance.RequiresImportError(data.ResourceType), }, }, }) @@ -83,6 +83,33 @@ func TestAccAzureRMSubnetNatGatewayAssociation_deleted(t *testing.T) { }) } +func TestAccAzureRMSubnetNatGatewayAssociation_updateSubnet(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_subnet_nat_gateway_association", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + // intentional since this is a virtual resource + CheckDestroy: testCheckAzureRMSubnetDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMSubnetNatGatewayAssociation_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSubnetNatGatewayAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMSubnetNatGatewayAssociation_updateSubnet(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSubnetNatGatewayAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + func testCheckAzureRMSubnetNatGatewayAssociationExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).Network.SubnetsClient @@ -207,37 +234,22 @@ func testCheckAzureRMSubnetHasNoNatGateways(resourceName string) resource.TestCh } func testAccAzureRMSubnetNatGatewayAssociation_basic(data acceptance.TestData) string { + template := testAccAzureRMSubnetNatGatewayAssociation_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-network-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} +%s resource "azurerm_subnet" "test" { - name = "acctestsubnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } -resource "azurerm_nat_gateway" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - resource "azurerm_subnet_nat_gateway_association" "test" { - subnet_id = "${azurerm_subnet.test.id}" - nat_gateway_id = "${azurerm_nat_gateway.test.id}" + subnet_id = azurerm_subnet.test.id + nat_gateway_id = azurerm_nat_gateway.test.id } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template) } func testAccAzureRMSubnetNatGatewayAssociation_requiresImport(data acceptance.TestData) string { @@ -246,8 +258,55 @@ func testAccAzureRMSubnetNatGatewayAssociation_requiresImport(data acceptance.Te %s resource "azurerm_subnet_nat_gateway_association" "import" { - subnet_id = "${azurerm_subnet_nat_gateway_association.test.subnet_id}" - nat_gateway_id = "${azurerm_subnet_nat_gateway_association.test.nat_gateway_id}" + subnet_id = azurerm_subnet_nat_gateway_association.test.subnet_id + nat_gateway_id = azurerm_subnet_nat_gateway_association.test.nat_gateway_id +} +`, template) +} + +func testAccAzureRMSubnetNatGatewayAssociation_updateSubnet(data acceptance.TestData) string { + template := testAccAzureRMSubnetNatGatewayAssociation_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_subnet" "test" { + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.2.0/24" + + enforce_private_link_endpoint_network_policies = true +} + +resource "azurerm_subnet_nat_gateway_association" "test" { + subnet_id = azurerm_subnet.test.id + nat_gateway_id = azurerm_nat_gateway.test.id } `, template) } + +func testAccAzureRMSubnetNatGatewayAssociation_template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-network-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctestvn-%d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_nat_gateway" "test" { + name = "acctest-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} diff --git a/azurerm/internal/services/network/tests/resource_arm_subnet_network_security_group_association_test.go b/azurerm/internal/services/network/tests/resource_arm_subnet_network_security_group_association_test.go index 016a9e30c9610..48363fa4bee3a 100644 --- a/azurerm/internal/services/network/tests/resource_arm_subnet_network_security_group_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_subnet_network_security_group_association_test.go @@ -61,6 +61,33 @@ func TestAccAzureRMSubnetNetworkSecurityGroupAssociation_requiresImport(t *testi }) } +func TestAccAzureRMSubnetNetworkSecurityGroupAssociation_updateSubnet(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_subnet_network_security_group_association", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + // intentional as this is a Virtual Resource + CheckDestroy: testCheckAzureRMSubnetDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSubnetNetworkSecurityGroupAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMSubnetNetworkSecurityGroupAssociation_updateSubnet(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSubnetNetworkSecurityGroupAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMSubnetNetworkSecurityGroupAssociation_deleted(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_subnet_network_security_group_association", "test") @@ -212,7 +239,63 @@ func testCheckAzureRMSubnetHasNoNetworkSecurityGroup(resourceName string) resour } func testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(data acceptance.TestData) string { + template := testAccAzureRMSubnetNetworkSecurityGroupAssociation_template(data) return fmt.Sprintf(` +%s + +resource "azurerm_subnet" "test" { + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_subnet_network_security_group_association" "test" { + subnet_id = azurerm_subnet.test.id + network_security_group_id = azurerm_network_security_group.test.id +} +`, template) +} + +func testAccAzureRMSubnetNetworkSecurityGroupAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_subnet_network_security_group_association" "internal" { + subnet_id = azurerm_subnet_network_security_group_association.test.subnet_id + network_security_group_id = azurerm_subnet_network_security_group_association.test.network_security_group_id +} +`, template) +} + +func testAccAzureRMSubnetNetworkSecurityGroupAssociation_updateSubnet(data acceptance.TestData) string { + template := testAccAzureRMSubnetNetworkSecurityGroupAssociation_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_subnet" "test" { + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.2.0/24" + + enforce_private_link_endpoint_network_policies = true +} + +resource "azurerm_subnet_network_security_group_association" "test" { + subnet_id = azurerm_subnet.test.id + network_security_group_id = azurerm_network_security_group.test.id +} +`, template) +} + +func testAccAzureRMSubnetNetworkSecurityGroupAssociation_template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -221,22 +304,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" - network_security_group_id = "${azurerm_network_security_group.test.id}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_network_security_group" "test" { name = "acctestnsg%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name security_rule { name = "test123" @@ -250,18 +325,5 @@ resource "azurerm_network_security_group" "test" { destination_address_prefix = "*" } } - -resource "azurerm_subnet_network_security_group_association" "test" { - subnet_id = "${azurerm_subnet.test.id}" - network_security_group_id = "${azurerm_network_security_group.test.id}" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMSubnetNetworkSecurityGroupAssociation_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(data) - return fmt.Sprintf(` -%s - -`, template) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_subnet_route_table_association_test.go b/azurerm/internal/services/network/tests/resource_arm_subnet_route_table_association_test.go index b6602d29c7f6e..66f38365b4f88 100644 --- a/azurerm/internal/services/network/tests/resource_arm_subnet_route_table_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_subnet_route_table_association_test.go @@ -32,6 +32,7 @@ func TestAccAzureRMSubnetRouteTableAssociation_basic(t *testing.T) { }, }) } + func TestAccAzureRMSubnetRouteTableAssociation_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -54,8 +55,35 @@ func TestAccAzureRMSubnetRouteTableAssociation_requiresImport(t *testing.T) { }, { Config: testAccAzureRMSubnetRouteTableAssociation_requiresImport(data), - ExpectError: acceptance.RequiresImportError(""), + ExpectError: acceptance.RequiresImportError("azurerm_subnet_route_table_association"), + }, + }, + }) +} + +func TestAccAzureRMSubnetRouteTableAssociation_updateSubnet(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_subnet_route_table_association", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + // intentional since this is a Virtual Resource + CheckDestroy: testCheckAzureRMSubnetDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMSubnetRouteTableAssociation_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSubnetRouteTableAssociationExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMSubnetRouteTableAssociation_updateSubnet(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSubnetRouteTableAssociationExists(data.ResourceName), + ), }, + data.ImportStep(), }, }) } @@ -211,45 +239,22 @@ func testCheckAzureRMSubnetHasNoRouteTable(resourceName string) resource.TestChe } func testAccAzureRMSubnetRouteTableAssociation_basic(data acceptance.TestData) string { + template := testAccAzureRMSubnetRouteTableAssociation_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} +%s resource "azurerm_subnet" "test" { - name = "acctestsubnet%d" + name = "internal" resource_group_name = "${azurerm_resource_group.test.name}" virtual_network_name = "${azurerm_virtual_network.test.name}" address_prefix = "10.0.2.0/24" - route_table_id = "${azurerm_route_table.test.id}" -} - -resource "azurerm_route_table" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - route { - name = "acctest-%d" - address_prefix = "10.100.0.0/14" - next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "10.10.1.1" - } } resource "azurerm_subnet_route_table_association" "test" { - subnet_id = "${azurerm_subnet.test.id}" - route_table_id = "${azurerm_route_table.test.id}" + subnet_id = azurerm_subnet.test.id + route_table_id = azurerm_route_table.test.id } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template) } func testAccAzureRMSubnetRouteTableAssociation_requiresImport(data acceptance.TestData) string { @@ -258,8 +263,61 @@ func testAccAzureRMSubnetRouteTableAssociation_requiresImport(data acceptance.Te %s resource "azurerm_subnet_route_table_association" "import" { - subnet_id = "${azurerm_subnet_route_table_association.test.subnet_id}" - route_table_id = "${azurerm_subnet_route_table_association.test.route_table_id}" + subnet_id = azurerm_subnet_route_table_association.test.subnet_id + route_table_id = azurerm_subnet_route_table_association.test.route_table_id } `, template) } + +func testAccAzureRMSubnetRouteTableAssociation_updateSubnet(data acceptance.TestData) string { + template := testAccAzureRMSubnetRouteTableAssociation_template(data) + return fmt.Sprintf(` +%s +resource "azurerm_subnet" "test" { + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.2.0/24" + + enforce_private_link_endpoint_network_policies = true +} + +resource "azurerm_subnet_route_table_association" "test" { + subnet_id = azurerm_subnet.test.id + route_table_id = azurerm_route_table.test.id +} +`, template) +} + +func testAccAzureRMSubnetRouteTableAssociation_template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctestvirtnet%d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_route_table" "test" { + name = "acctest-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + route { + name = "first" + address_prefix = "10.100.0.0/14" + next_hop_type = "VirtualAppliance" + next_hop_in_ip_address = "10.10.1.1" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} diff --git a/azurerm/internal/services/network/tests/resource_arm_subnet_test.go b/azurerm/internal/services/network/tests/resource_arm_subnet_test.go index d2334f1eecb29..527dfa9c0e715 100644 --- a/azurerm/internal/services/network/tests/resource_arm_subnet_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_subnet_test.go @@ -3,7 +3,6 @@ package tests import ( "fmt" "log" - "strings" "testing" "github.com/hashicorp/go-azure-helpers/response" @@ -61,7 +60,7 @@ func TestAccAzureRMSubnet_requiresImport(t *testing.T) { }) } -func TestAccAzureRMSubnet_delegation(t *testing.T) { +func TestAccAzureRMSubnet_disappears(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ @@ -70,17 +69,18 @@ func TestAccAzureRMSubnet_delegation(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnet_delegation(data), + Config: testAccAzureRMSubnet_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSubnetExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "delegation.#", "1"), + testCheckAzureRMSubnetDisappears(data.ResourceName), ), + ExpectNonEmptyPlan: true, }, }, }) } -func TestAccAzureRMSubnet_delegationComputedActions(t *testing.T) { +func TestAccAzureRMSubnet_delegation(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ @@ -89,42 +89,38 @@ func TestAccAzureRMSubnet_delegationComputedActions(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnet_delegationComputedActions(data), + Config: testAccAzureRMSubnet_delegation(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSubnetExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "delegation.#", "1"), ), }, - }, - }) -} - -func TestAccAzureRMSubnet_routeTableUpdate(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_subnet", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSubnetDestroy, - Steps: []resource.TestStep{ + data.ImportStep(), { - Config: testAccAzureRMSubnet_routeTable(data), + Config: testAccAzureRMSubnet_delegationUpdated(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSubnetExists(data.ResourceName), ), }, - + data.ImportStep(), { - Config: testAccAzureRMSubnet_updatedRouteTable(data), + Config: testAccAzureRMSubnet_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetRouteTableExists(data.ResourceName, fmt.Sprintf("acctest-%d", data.RandomInteger)), + testCheckAzureRMSubnetExists(data.ResourceName), ), }, + data.ImportStep(), + { + Config: testAccAzureRMSubnet_delegation(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSubnetExists(data.ResourceName), + ), + }, + data.ImportStep(), }, }) } -func TestAccAzureRMSubnet_routeTableRemove(t *testing.T) { +func TestAccAzureRMSubnet_enforcePrivateLinkEndpointNetworkPolicies(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ @@ -133,17 +129,23 @@ func TestAccAzureRMSubnet_routeTableRemove(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnet_routeTable(data), + Config: testAccAzureRMSubnet_enforcePrivateLinkEndpointNetworkPolicies(data, true), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSubnetExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "route_table_id"), ), }, + data.ImportStep(), + { + Config: testAccAzureRMSubnet_enforcePrivateLinkEndpointNetworkPolicies(data, false), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSubnetExists(data.ResourceName), + ), + }, + data.ImportStep(), { - Config: testAccAzureRMSubnet_routeTableUnlinked(data), + Config: testAccAzureRMSubnet_enforcePrivateLinkEndpointNetworkPolicies(data, true), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSubnetExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "route_table_id", ""), ), }, data.ImportStep(), @@ -151,7 +153,7 @@ func TestAccAzureRMSubnet_routeTableRemove(t *testing.T) { }) } -func TestAccAzureRMSubnet_removeNetworkSecurityGroup(t *testing.T) { +func TestAccAzureRMSubnet_enforcePrivateLinkServiceNetworkPolicies(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ @@ -160,44 +162,31 @@ func TestAccAzureRMSubnet_removeNetworkSecurityGroup(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnet_networkSecurityGroup(data), + Config: testAccAzureRMSubnet_enforcePrivateLinkServiceNetworkPolicies(data, true), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSubnetExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), ), }, + data.ImportStep(), { - Config: testAccAzureRMSubnet_networkSecurityGroupDetached(data), + Config: testAccAzureRMSubnet_enforcePrivateLinkServiceNetworkPolicies(data, false), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSubnetExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "network_security_group_id", ""), ), }, data.ImportStep(), - }, - }) -} - -func TestAccAzureRMSubnet_bug7986(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_subnet", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSubnetDestroy, - Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnet_bug7986(data), + Config: testAccAzureRMSubnet_enforcePrivateLinkServiceNetworkPolicies(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists("azurerm_subnet.first"), - testCheckAzureRMSubnetExists("azurerm_subnet.second"), + testCheckAzureRMSubnetExists(data.ResourceName), ), }, + data.ImportStep(), }, }) } -func TestAccAzureRMSubnet_bug15204(t *testing.T) { +func TestAccAzureRMSubnet_serviceEndpoints(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ @@ -206,55 +195,39 @@ func TestAccAzureRMSubnet_bug15204(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnet_bug15204(data), + Config: testAccAzureRMSubnet_serviceEndpoints(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSubnetExists(data.ResourceName), ), }, - }, - }) -} - -func TestAccAzureRMSubnet_disappears(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_subnet", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSubnetDestroy, - Steps: []resource.TestStep{ + data.ImportStep(), { + Config: testAccAzureRMSubnet_serviceEndpointsUpdated(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSubnetExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + // remove them Config: testAccAzureRMSubnet_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSubnetExists(data.ResourceName), - testCheckAzureRMSubnetDisappears(data.ResourceName), ), - ExpectNonEmptyPlan: true, }, - }, - }) -} - -func TestAccAzureRMSubnet_serviceEndpoints(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_subnet", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSubnetDestroy, - Steps: []resource.TestStep{ + data.ImportStep(), { Config: testAccAzureRMSubnet_serviceEndpoints(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists("azurerm_subnet.test"), - resource.TestCheckResourceAttr(data.ResourceName, "service_endpoints.#", "2"), + testCheckAzureRMSubnetExists(data.ResourceName), ), }, + data.ImportStep(), }, }) } -func TestAccAzureRMSubnet_serviceEndpointsVNetUpdate(t *testing.T) { +func TestAccAzureRMSubnet_updateAddressPrefix(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ @@ -263,19 +236,19 @@ func TestAccAzureRMSubnet_serviceEndpointsVNetUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnet_serviceEndpoints(data), + Config: testAccAzureRMSubnet_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSubnetExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "service_endpoints.#", "2"), ), }, + data.ImportStep(), { - Config: testAccAzureRMSubnet_serviceEndpointsVNetUpdate(data), + Config: testAccAzureRMSubnet_updatedAddressPrefix(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSubnetExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "service_endpoints.#", "2"), ), }, + data.ImportStep(), }, }) } @@ -313,57 +286,6 @@ func testCheckAzureRMSubnetExists(resourceName string) resource.TestCheckFunc { } } -func testCheckAzureRMSubnetRouteTableExists(resourceName string, routeTableId string) resource.TestCheckFunc { - return func(s *terraform.State) error { - networksClient := acceptance.AzureProvider.Meta().(*clients.Client).Network.VnetClient - subnetsClient := acceptance.AzureProvider.Meta().(*clients.Client).Network.SubnetsClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // Ensure we have enough information in state to look up in API - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - log.Printf("[INFO] Checking Subnet update.") - - subnetName := rs.Primary.Attributes["name"] - vnetName := rs.Primary.Attributes["virtual_network_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for subnet: %s", subnetName) - } - - vnetResp, vnetErr := networksClient.Get(ctx, resourceGroup, vnetName, "") - if vnetErr != nil { - return fmt.Errorf("Bad: Get on vnetClient: %+v", vnetErr) - } - - if vnetResp.Subnets == nil { - return fmt.Errorf("Bad: Vnet %q (resource group: %q) does not have subnets after update", vnetName, resourceGroup) - } - - resp, err := subnetsClient.Get(ctx, resourceGroup, vnetName, subnetName, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Subnet %q (resource group: %q) does not exist", subnetName, resourceGroup) - } - - return fmt.Errorf("Bad: Get on subnetClient: %+v", err) - } - - if resp.RouteTable == nil { - return fmt.Errorf("Bad: Subnet %q (resource group: %q) does not contain route tables after update", subnetName, resourceGroup) - } - - if !strings.Contains(*resp.RouteTable.ID, routeTableId) { - return fmt.Errorf("Bad: Subnet %q (resource group: %q) does not have route table %q", subnetName, resourceGroup, routeTableId) - } - - return nil - } -} - func testCheckAzureRMSubnetDisappears(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).Network.SubnetsClient @@ -423,452 +345,167 @@ func testCheckAzureRMSubnetDestroy(s *terraform.State) error { } func testAccAzureRMSubnet_basic(data acceptance.TestData) string { + template := testAccAzureRMSubnet_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} +%s resource "azurerm_subnet" "test" { - name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMSubnet_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMSubnet_basic(data) - return fmt.Sprintf(` -%s - -resource "azurerm_subnet" "import" { - name = "${azurerm_subnet.test.name}" - resource_group_name = "${azurerm_subnet.test.resource_group_name}" - virtual_network_name = "${azurerm_subnet.test.virtual_network_name}" - address_prefix = "${azurerm_subnet.test.address_prefix}" -} `, template) } func testAccAzureRMSubnet_delegation(data acceptance.TestData) string { + template := testAccAzureRMSubnet_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} +%s resource "azurerm_subnet" "test" { - name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" delegation { - name = "acctestdelegation" + name = "first" service_delegation { - name = "Microsoft.ContainerInstance/containerGroups" - actions = ["Microsoft.Network/virtualNetworks/subnets/action"] + name = "Microsoft.ContainerInstance/containerGroups" + actions = [ + "Microsoft.Network/virtualNetworks/subnets/action", + ] } } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, template) } -func testAccAzureRMSubnet_delegationComputedActions(data acceptance.TestData) string { +func testAccAzureRMSubnet_delegationUpdated(data acceptance.TestData) string { + template := testAccAzureRMSubnet_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} +%s resource "azurerm_subnet" "test" { - name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" delegation { - name = "acctestdelegation" + name = "first" service_delegation { - name = "Microsoft.Sql/managedInstances" + name = "Microsoft.Databricks/workspaces" + actions = [ + "Microsoft.Network/virtualNetworks/subnets/join/action", + "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action", + "Microsoft.Network/virtualNetworks/subnets/unprepareNetworkPolicies/action", + ] } } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, template) } -func testAccAzureRMSubnet_routeTable(data acceptance.TestData) string { +func testAccAzureRMSubnet_enforcePrivateLinkEndpointNetworkPolicies(data acceptance.TestData, enabled bool) string { + template := testAccAzureRMSubnet_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} +%s resource "azurerm_subnet" "test" { - name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" - route_table_id = "${azurerm_route_table.test.id}" -} -resource "azurerm_route_table" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - route { - name = "acctest-%d" - address_prefix = "10.100.0.0/14" - next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "10.10.1.1" - } + enforce_private_link_endpoint_network_policies = %t } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template, enabled) } -func testAccAzureRMSubnet_routeTableUnlinked(data acceptance.TestData) string { +func testAccAzureRMSubnet_enforcePrivateLinkServiceNetworkPolicies(data acceptance.TestData, enabled bool) string { + template := testAccAzureRMSubnet_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} +%s resource "azurerm_subnet" "test" { - name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" - route_table_id = "" -} - -resource "azurerm_route_table" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - route { - name = "acctest-%d" - address_prefix = "10.100.0.0/14" - next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "10.10.1.1" - } + enforce_private_link_service_network_policies = %t } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template, enabled) } -func testAccAzureRMSubnet_updatedRouteTable(data acceptance.TestData) string { +func testAccAzureRMSubnet_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMSubnet_basic(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" - - tags = { - environment = "Testing" - } -} - -resource "azurerm_network_security_group" "test_secgroup" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - security_rule { - name = "acctest-%d" - priority = 100 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "*" - source_address_prefix = "*" - destination_address_prefix = "*" - } - - tags = { - environment = "Testing" - } -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - tags = { - environment = "Testing" - } -} - -resource "azurerm_subnet" "test" { - name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" - route_table_id = "${azurerm_route_table.test.id}" -} - -resource "azurerm_route_table" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - route { - name = "acctest-%d" - address_prefix = "10.100.0.0/14" - next_hop_type = "VirtualAppliance" - next_hop_in_ip_address = "10.10.1.1" - } +%s - tags = { - environment = "Testing" - } +resource "azurerm_subnet" "import" { + name = azurerm_subnet.test.name + resource_group_name = azurerm_subnet.test.resource_group_name + virtual_network_name = azurerm_subnet.test.virtual_network_name + address_prefix = azurerm_subnet.test.address_prefix } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template) } -func testAccAzureRMSubnet_networkSecurityGroup(data acceptance.TestData) string { +func testAccAzureRMSubnet_serviceEndpoints(data acceptance.TestData) string { + template := testAccAzureRMSubnet_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctest%d-rg" - location = "%s" -} - -resource "azurerm_network_security_group" "test" { - name = "acctestnsg%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - security_rule { - name = "test123" - priority = 100 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "*" - source_address_prefix = "*" - destination_address_prefix = "*" - } -} - -resource "azurerm_virtual_network" "test" { - name = "acctest%d-vn" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} +%s resource "azurerm_subnet" "test" { - name = "acctest%d-private" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.0.0/24" - network_security_group_id = "${azurerm_network_security_group.test.id}" + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.2.0/24" + service_endpoints = ["Microsoft.Sql"] } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template) } -func testAccAzureRMSubnet_networkSecurityGroupDetached(data acceptance.TestData) string { +func testAccAzureRMSubnet_serviceEndpointsUpdated(data acceptance.TestData) string { + template := testAccAzureRMSubnet_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctest%d-rg" - location = "%s" -} - -resource "azurerm_network_security_group" "test" { - name = "acctestnsg%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - security_rule { - name = "test123" - priority = 100 - direction = "Inbound" - access = "Allow" - protocol = "Tcp" - source_port_range = "*" - destination_port_range = "*" - source_address_prefix = "*" - destination_address_prefix = "*" - } -} - -resource "azurerm_virtual_network" "test" { - name = "acctest%d-vn" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} +%s resource "azurerm_subnet" "test" { - name = "acctest%d-private" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.0.0/24" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMSubnet_bug7986(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctest%d-rg" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctest%d-vn" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_route_table" "first" { - name = "acctest%d-private-1" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - route { - name = "acctest%d-private-1" - address_prefix = "0.0.0.0/0" - next_hop_type = "None" - } -} - -resource "azurerm_subnet" "first" { - name = "acctest%d-private-1" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.0.0/24" - route_table_id = "${azurerm_route_table.first.id}" -} - -resource "azurerm_route_table" "second" { - name = "acctest%d-private-2" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - route { - name = "acctest%d-private-2" - address_prefix = "0.0.0.0/0" - next_hop_type = "None" - } -} - -resource "azurerm_subnet" "second" { - name = "acctest%d-private-2" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.1.0/24" - route_table_id = "${azurerm_route_table.second.id}" + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.2.0/24" + service_endpoints = ["Microsoft.Sql", "Microsoft.Storage"] } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template) } -func testAccAzureRMSubnet_bug15204(data acceptance.TestData) string { +func testAccAzureRMSubnet_updatedAddressPrefix(data acceptance.TestData) string { + template := testAccAzureRMSubnet_template(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctest-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "acctestvn-%d" - address_space = ["10.85.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_network_security_group" "test" { - name = "acctestnsg-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_route_table" "test" { - name = "acctestrt-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} +%s resource "azurerm_subnet" "test" { - name = "acctestsubnet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.85.9.0/24" - route_table_id = "${azurerm_route_table.test.id}" - network_security_group_id = "${azurerm_network_security_group.test.id}" + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.3.0/24" } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, template) } -func testAccAzureRMSubnet_serviceEndpoints(data acceptance.TestData) string { +func testAccAzureRMSubnet_template(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_virtual_network" "test" { - name = "acctestvirtnet%d" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" - service_endpoints = ["Microsoft.Sql", "Microsoft.Storage"] -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMSubnet_serviceEndpointsVNetUpdate(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -877,20 +514,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - tags = { - Environment = "Staging" - } -} - -resource "azurerm_subnet" "test" { - name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" - service_endpoints = ["Microsoft.Sql", "Microsoft.Storage"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_virtual_hub_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_hub_test.go index 7f609ad2adca2..b3254f5340fd3 100644 --- a/azurerm/internal/services/network/tests/resource_arm_virtual_hub_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_hub_test.go @@ -282,6 +282,10 @@ resource "azurerm_virtual_hub" "test" { func testAccAzureRMVirtualHub_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_connection_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_connection_test.go index ab4f266b44a19..1273176bf70e4 100644 --- a/azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_connection_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_connection_test.go @@ -219,29 +219,29 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" @@ -249,16 +249,16 @@ resource "azurerm_virtual_network_gateway" "test" { ip_configuration { name = "vnetGatewayConfig" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } resource "azurerm_local_network_gateway" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name gateway_address = "168.62.225.23" address_space = ["10.1.1.0/24"] @@ -266,12 +266,12 @@ resource "azurerm_local_network_gateway" "test" { resource "azurerm_virtual_network_gateway_connection" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "IPsec" - virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test.id}" - local_network_gateway_id = "${azurerm_local_network_gateway.test.id}" + virtual_network_gateway_id = azurerm_virtual_network_gateway.test.id + local_network_gateway_id = azurerm_local_network_gateway.test.id shared_key = "4-v3ry-53cr37-1p53c-5h4r3d-k3y" } @@ -284,13 +284,13 @@ func testAccAzureRMVirtualNetworkGatewayConnection_requiresImport(data acceptanc %s resource "azurerm_virtual_network_gateway_connection" "import" { - name = "${azurerm_virtual_network_gateway_connection.test.name}" - location = "${azurerm_virtual_network_gateway_connection.test.location}" - resource_group_name = "${azurerm_virtual_network_gateway_connection.test.resource_group_name}" - type = "${azurerm_virtual_network_gateway_connection.test.type}" - virtual_network_gateway_id = "${azurerm_virtual_network_gateway_connection.test.virtual_network_gateway_id}" - local_network_gateway_id = "${azurerm_virtual_network_gateway_connection.test.local_network_gateway_id}" - shared_key = "${azurerm_virtual_network_gateway_connection.test.shared_key}" + name = azurerm_virtual_network_gateway_connection.test.name + location = azurerm_virtual_network_gateway_connection.test.location + resource_group_name = azurerm_virtual_network_gateway_connection.test.resource_group_name + type = azurerm_virtual_network_gateway_connection.test.type + virtual_network_gateway_id = azurerm_virtual_network_gateway_connection.test.virtual_network_gateway_id + local_network_gateway_id = azurerm_virtual_network_gateway_connection.test.local_network_gateway_id + shared_key = azurerm_virtual_network_gateway_connection.test.shared_key } `, template) } @@ -316,29 +316,29 @@ resource "azurerm_resource_group" "test_1" { resource "azurerm_virtual_network" "test_1" { name = "acctestvn-${var.random1}" - location = "${azurerm_resource_group.test_1.location}" - resource_group_name = "${azurerm_resource_group.test_1.name}" + location = azurerm_resource_group.test_1.location + resource_group_name = azurerm_resource_group.test_1.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test_1" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test_1.name}" - virtual_network_name = "${azurerm_virtual_network.test_1.name}" + resource_group_name = azurerm_resource_group.test_1.name + virtual_network_name = azurerm_virtual_network.test_1.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test_1" { name = "acctest-${var.random1}" - location = "${azurerm_resource_group.test_1.location}" - resource_group_name = "${azurerm_resource_group.test_1.name}" + location = azurerm_resource_group.test_1.location + resource_group_name = azurerm_resource_group.test_1.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test_1" { name = "acctest-${var.random1}" - location = "${azurerm_resource_group.test_1.location}" - resource_group_name = "${azurerm_resource_group.test_1.name}" + location = azurerm_resource_group.test_1.location + resource_group_name = azurerm_resource_group.test_1.name type = "Vpn" vpn_type = "RouteBased" @@ -346,22 +346,22 @@ resource "azurerm_virtual_network_gateway" "test_1" { ip_configuration { name = "vnetGatewayConfig" - public_ip_address_id = "${azurerm_public_ip.test_1.id}" + public_ip_address_id = azurerm_public_ip.test_1.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test_1.id}" + subnet_id = azurerm_subnet.test_1.id } } resource "azurerm_virtual_network_gateway_connection" "test_1" { name = "acctest-${var.random1}" - location = "${azurerm_resource_group.test_1.location}" - resource_group_name = "${azurerm_resource_group.test_1.name}" + location = azurerm_resource_group.test_1.location + resource_group_name = azurerm_resource_group.test_1.name type = "Vnet2Vnet" - virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test_1.id}" - peer_virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test_2.id}" + virtual_network_gateway_id = azurerm_virtual_network_gateway.test_1.id + peer_virtual_network_gateway_id = azurerm_virtual_network_gateway.test_2.id - shared_key = "${var.shared_key}" + shared_key = var.shared_key } resource "azurerm_resource_group" "test_2" { @@ -371,29 +371,29 @@ resource "azurerm_resource_group" "test_2" { resource "azurerm_virtual_network" "test_2" { name = "acctest-${var.random2}" - location = "${azurerm_resource_group.test_2.location}" - resource_group_name = "${azurerm_resource_group.test_2.name}" + location = azurerm_resource_group.test_2.location + resource_group_name = azurerm_resource_group.test_2.name address_space = ["10.1.0.0/16"] } resource "azurerm_subnet" "test_2" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test_2.name}" - virtual_network_name = "${azurerm_virtual_network.test_2.name}" + resource_group_name = azurerm_resource_group.test_2.name + virtual_network_name = azurerm_virtual_network.test_2.name address_prefix = "10.1.1.0/24" } resource "azurerm_public_ip" "test_2" { name = "acctest-${var.random2}" - location = "${azurerm_resource_group.test_2.location}" - resource_group_name = "${azurerm_resource_group.test_2.name}" + location = azurerm_resource_group.test_2.location + resource_group_name = azurerm_resource_group.test_2.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test_2" { name = "acctest-${var.random2}" - location = "${azurerm_resource_group.test_2.location}" - resource_group_name = "${azurerm_resource_group.test_2.name}" + location = azurerm_resource_group.test_2.location + resource_group_name = azurerm_resource_group.test_2.name type = "Vpn" vpn_type = "RouteBased" @@ -401,22 +401,22 @@ resource "azurerm_virtual_network_gateway" "test_2" { ip_configuration { name = "vnetGatewayConfig" - public_ip_address_id = "${azurerm_public_ip.test_2.id}" + public_ip_address_id = azurerm_public_ip.test_2.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test_2.id}" + subnet_id = azurerm_subnet.test_2.id } } resource "azurerm_virtual_network_gateway_connection" "test_2" { name = "acctest-${var.random2}" - location = "${azurerm_resource_group.test_2.location}" - resource_group_name = "${azurerm_resource_group.test_2.name}" + location = azurerm_resource_group.test_2.location + resource_group_name = azurerm_resource_group.test_2.name type = "Vnet2Vnet" - virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test_2.id}" - peer_virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test_1.id}" + virtual_network_gateway_id = azurerm_virtual_network_gateway.test_2.id + peer_virtual_network_gateway_id = azurerm_virtual_network_gateway.test_1.id - shared_key = "${var.shared_key}" + shared_key = var.shared_key } `, data.RandomInteger, rInt2, sharedKey, data.Locations.Primary, data.Locations.Secondary) } @@ -434,29 +434,29 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" @@ -464,16 +464,16 @@ resource "azurerm_virtual_network_gateway" "test" { ip_configuration { name = "vnetGatewayConfig" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } resource "azurerm_local_network_gateway" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name gateway_address = "168.62.225.23" address_space = ["10.1.1.0/24"] @@ -481,12 +481,12 @@ resource "azurerm_local_network_gateway" "test" { resource "azurerm_virtual_network_gateway_connection" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "IPsec" - virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test.id}" - local_network_gateway_id = "${azurerm_local_network_gateway.test.id}" + virtual_network_gateway_id = azurerm_virtual_network_gateway.test.id + local_network_gateway_id = azurerm_local_network_gateway.test.id use_policy_based_traffic_selectors = true routing_weight = 20 @@ -520,29 +520,29 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" @@ -550,16 +550,16 @@ resource "azurerm_virtual_network_gateway" "test" { ip_configuration { name = "vnetGatewayConfig" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } resource "azurerm_local_network_gateway" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name gateway_address = "168.62.225.23" address_space = ["10.1.1.0/24"] @@ -567,12 +567,12 @@ resource "azurerm_local_network_gateway" "test" { resource "azurerm_virtual_network_gateway_connection" "test" { name = "acctest-${var.random}" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "IPsec" - virtual_network_gateway_id = "${azurerm_virtual_network_gateway.test.id}" - local_network_gateway_id = "${azurerm_local_network_gateway.test.id}" + virtual_network_gateway_id = azurerm_virtual_network_gateway.test.id + local_network_gateway_id = azurerm_local_network_gateway.test.id connection_protocol = "IKEv1" diff --git a/azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_test.go index 423d3ba92cbbb..3a8303fe2fa57 100644 --- a/azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_test.go @@ -324,6 +324,10 @@ func testCheckAzureRMVirtualNetworkGatewayDestroy(s *terraform.State) error { func testAccAzureRMVirtualNetworkGateway_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -331,38 +335,38 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctestvng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" sku = "Basic" ip_configuration { - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -374,17 +378,17 @@ func testAccAzureRMVirtualNetworkGateway_requiresImport(data acceptance.TestData %s resource "azurerm_virtual_network_gateway" "import" { - name = "${azurerm_virtual_network_gateway.test.name}" - location = "${azurerm_virtual_network_gateway.test.location}" - resource_group_name = "${azurerm_virtual_network_gateway.test.resource_group_name}" - type = "${azurerm_virtual_network_gateway.test.type}" - vpn_type = "${azurerm_virtual_network_gateway.test.vpn_type}" - sku = "${azurerm_virtual_network_gateway.test.sku}" + name = azurerm_virtual_network_gateway.test.name + location = azurerm_virtual_network_gateway.test.location + resource_group_name = azurerm_virtual_network_gateway.test.resource_group_name + type = azurerm_virtual_network_gateway.test.type + vpn_type = azurerm_virtual_network_gateway.test.vpn_type + sku = azurerm_virtual_network_gateway.test.sku ip_configuration { - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } `, template) @@ -392,6 +396,10 @@ resource "azurerm_virtual_network_gateway" "import" { func testAccAzureRMVirtualNetworkGateway_lowerCaseSubnetName(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -399,38 +407,38 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "gatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctestvng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" sku = "Basic" ip_configuration { - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -438,6 +446,10 @@ resource "azurerm_virtual_network_gateway" "test" { func testAccAzureRMVirtualNetworkGateway_vpnGw1(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -445,38 +457,38 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctestvng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" sku = "VpnGw1" ip_configuration { - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -484,6 +496,10 @@ resource "azurerm_virtual_network_gateway" "test" { func testAccAzureRMVirtualNetworkGateway_activeActive(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -491,38 +507,41 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "first" { name = "acctestpip1-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_public_ip" "second" { name = "acctestpip2-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { - depends_on = ["azurerm_public_ip.first", "azurerm_public_ip.second"] + depends_on = [ + azurerm_public_ip.first, + azurerm_public_ip.second, + ] name = "acctestvng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" @@ -533,17 +552,17 @@ resource "azurerm_virtual_network_gateway" "test" { ip_configuration { name = "gw-ip1" - public_ip_address_id = "${azurerm_public_ip.first.id}" + public_ip_address_id = azurerm_public_ip.first.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } ip_configuration { name = "gw-ip2" - public_ip_address_id = "${azurerm_public_ip.second.id}" + public_ip_address_id = azurerm_public_ip.second.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } bgp_settings { @@ -555,6 +574,10 @@ resource "azurerm_virtual_network_gateway" "test" { func testAccAzureRMVirtualNetworkGateway_vpnClientConfig(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -562,39 +585,39 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { - depends_on = ["azurerm_public_ip.test"] + depends_on = [azurerm_public_ip.test] name = "acctestvng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" sku = "VpnGw1" ip_configuration { - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } vpn_client_configuration { @@ -610,6 +633,10 @@ resource "azurerm_virtual_network_gateway" "test" { func testAccAzureRMVirtualNetworkGateway_vpnClientConfigOpenVPN(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -617,39 +644,39 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { - depends_on = ["azurerm_public_ip.test"] + depends_on = [azurerm_public_ip.test] name = "acctestvng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" sku = "VpnGw1" ip_configuration { - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } vpn_client_configuration { @@ -662,6 +689,10 @@ resource "azurerm_virtual_network_gateway" "test" { func testAccAzureRMVirtualNetworkGateway_sku(data acceptance.TestData, sku string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -669,38 +700,38 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctestvng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" sku = "%s" ip_configuration { - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, sku) @@ -708,6 +739,10 @@ resource "azurerm_virtual_network_gateway" "test" { func testAccAzureRMVirtualNetworkGateway_enableBgp(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -715,29 +750,29 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip1-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctestvng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" @@ -745,9 +780,9 @@ resource "azurerm_virtual_network_gateway" "test" { enable_bgp = true ip_configuration { - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -755,6 +790,10 @@ resource "azurerm_virtual_network_gateway" "test" { func testAccAzureRMVirtualNetworkGateway_expressRoute(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -762,38 +801,38 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip1-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctestvng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "ExpressRoute" vpn_type = "PolicyBased" sku = "Standard" ip_configuration { - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -801,6 +840,10 @@ resource "azurerm_virtual_network_gateway" "test" { func testAccAzureRMVirtualNetworkGateway_generation(data acceptance.TestData, generation string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -808,29 +851,29 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "test" { name = "GatewaySubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_public_ip" "test" { name = "acctestpip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" } resource "azurerm_virtual_network_gateway" "test" { name = "acctestvng-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name type = "Vpn" vpn_type = "RouteBased" @@ -838,9 +881,9 @@ resource "azurerm_virtual_network_gateway" "test" { generation = "%s" ip_configuration { - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id private_ip_address_allocation = "Dynamic" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, generation) diff --git a/azurerm/internal/services/network/tests/resource_arm_virtual_network_peering_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_network_peering_test.go index 5a5cddd555a4d..3ec0418b2a07d 100644 --- a/azurerm/internal/services/network/tests/resource_arm_virtual_network_peering_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_network_peering_test.go @@ -213,6 +213,10 @@ func testCheckAzureRMVirtualNetworkPeeringDestroy(s *terraform.State) error { func testAccAzureRMVirtualNetworkPeering_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -220,31 +224,31 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test1" { name = "acctestvirtnet-1-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.1.0/24"] - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location } resource "azurerm_virtual_network" "test2" { name = "acctestvirtnet-2-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.2.0/24"] - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location } resource "azurerm_virtual_network_peering" "test1" { name = "acctestpeer-1-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test1.name}" - remote_virtual_network_id = "${azurerm_virtual_network.test2.id}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test1.name + remote_virtual_network_id = azurerm_virtual_network.test2.id allow_virtual_network_access = true } resource "azurerm_virtual_network_peering" "test2" { name = "acctestpeer-2-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test2.name}" - remote_virtual_network_id = "${azurerm_virtual_network.test1.id}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test2.name + remote_virtual_network_id = azurerm_virtual_network.test1.id allow_virtual_network_access = true } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) @@ -256,17 +260,21 @@ func testAccAzureRMVirtualNetworkPeering_requiresImport(data acceptance.TestData %s resource "azurerm_virtual_network_peering" "import" { - name = "${azurerm_virtual_network_peering.test1.name}" - resource_group_name = "${azurerm_virtual_network_peering.test1.resource_group_name}" - virtual_network_name = "${azurerm_virtual_network_peering.test1.virtual_network_name}" - remote_virtual_network_id = "${azurerm_virtual_network_peering.test1.remote_virtual_network_id}" - allow_virtual_network_access = "${azurerm_virtual_network_peering.test1.allow_virtual_network_access}" + name = azurerm_virtual_network_peering.test1.name + resource_group_name = azurerm_virtual_network_peering.test1.resource_group_name + virtual_network_name = azurerm_virtual_network_peering.test1.virtual_network_name + remote_virtual_network_id = azurerm_virtual_network_peering.test1.remote_virtual_network_id + allow_virtual_network_access = azurerm_virtual_network_peering.test1.allow_virtual_network_access } `, template) } func testAccAzureRMVirtualNetworkPeering_basicUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -274,32 +282,32 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test1" { name = "acctestvirtnet-1-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.1.0/24"] - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location } resource "azurerm_virtual_network" "test2" { name = "acctestvirtnet-2-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name address_space = ["10.0.2.0/24"] - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location } resource "azurerm_virtual_network_peering" "test1" { name = "acctestpeer-1-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test1.name}" - remote_virtual_network_id = "${azurerm_virtual_network.test2.id}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test1.name + remote_virtual_network_id = azurerm_virtual_network.test2.id allow_forwarded_traffic = true allow_virtual_network_access = true } resource "azurerm_virtual_network_peering" "test2" { name = "acctestpeer-2-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test2.name}" - remote_virtual_network_id = "${azurerm_virtual_network.test1.id}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test2.name + remote_virtual_network_id = azurerm_virtual_network.test1.id allow_forwarded_traffic = true allow_virtual_network_access = true } diff --git a/azurerm/internal/services/network/tests/resource_arm_virtual_network_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_network_test.go index 353cda16a364c..e309026ee7195 100644 --- a/azurerm/internal/services/network/tests/resource_arm_virtual_network_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_network_test.go @@ -163,24 +163,6 @@ func TestAccAzureRMVirtualNetwork_withTags(t *testing.T) { }) } -func TestAccAzureRMVirtualNetwork_bug373(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_virtual_network", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMVirtualNetworkDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMVirtualNetwork_bug373(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkExists(data.ResourceName), - ), - }, - }, - }) -} - func testCheckAzureRMVirtualNetworkExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).Network.VnetClient @@ -270,6 +252,10 @@ func testCheckAzureRMVirtualNetworkDestroy(s *terraform.State) error { func testAccAzureRMVirtualNetwork_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -278,8 +264,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name subnet { name = "subnet1" @@ -291,6 +277,10 @@ resource "azurerm_virtual_network" "test" { func testAccAzureRMVirtualNetwork_basicUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -299,8 +289,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16", "10.10.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name subnet { name = "subnet1" @@ -321,9 +311,9 @@ func testAccAzureRMVirtualNetwork_requiresImport(data acceptance.TestData) strin %s resource "azurerm_virtual_network" "import" { - name = "${azurerm_virtual_network.test.name}" - location = "${azurerm_virtual_network.test.location}" - resource_group_name = "${azurerm_virtual_network.test.resource_group_name}" + name = azurerm_virtual_network.test.name + location = azurerm_virtual_network.test.location + resource_group_name = azurerm_virtual_network.test.resource_group_name address_space = ["10.0.0.0/16"] subnet { @@ -336,25 +326,29 @@ resource "azurerm_virtual_network" "import" { func testAccAzureRMVirtualNetwork_ddosProtectionPlan(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" } -resource "azurerm_ddos_protection_plan" "test" { +resource "azurerm_network_ddos_protection_plan" "test" { name = "acctestddospplan-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ddos_protection_plan { - id = "${azurerm_ddos_protection_plan.test.id}" + id = azurerm_network_ddos_protection_plan.test.id enable = true } @@ -368,6 +362,10 @@ resource "azurerm_virtual_network" "test" { func testAccAzureRMVirtualNetwork_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -376,8 +374,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name subnet { name = "subnet1" @@ -394,6 +392,10 @@ resource "azurerm_virtual_network" "test" { func testAccAzureRMVirtualNetwork_withTagsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -402,8 +404,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name subnet { name = "subnet1" @@ -416,69 +418,3 @@ resource "azurerm_virtual_network" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } - -func testAccAzureRMVirtualNetwork_bug373(data acceptance.TestData) string { - return fmt.Sprintf(` -variable "environment" { - default = "TestVirtualNetworkBug373" -} - -variable "network_cidr" { - default = "10.0.0.0/16" -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "${azurerm_resource_group.test.name}-vnet" - resource_group_name = "${azurerm_resource_group.test.name}" - address_space = ["${var.network_cidr}"] - location = "${azurerm_resource_group.test.location}" - - tags = { - environment = "${var.environment}" - } -} - -resource "azurerm_subnet" "public" { - name = "${azurerm_resource_group.test.name}-subnet-public" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.1.0/24" - network_security_group_id = "${azurerm_network_security_group.test.id}" -} - -resource "azurerm_subnet" "private" { - name = "${azurerm_resource_group.test.name}-subnet-private" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" - network_security_group_id = "${azurerm_network_security_group.test.id}" -} - -resource "azurerm_network_security_group" "test" { - name = "default-network-sg" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - security_rule { - name = "default-allow-all" - priority = 100 - direction = "Inbound" - access = "Allow" - protocol = "*" - source_port_range = "*" - destination_port_range = "*" - source_address_prefix = "${var.network_cidr}" - destination_address_prefix = "*" - } - - tags = { - environment = "${var.environment}" - } -} -`, data.RandomInteger, data.Locations.Primary) -} diff --git a/azurerm/internal/services/network/tests/resource_arm_virtual_wan_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_wan_test.go index 81d1499709de6..29879bae5bc0d 100644 --- a/azurerm/internal/services/network/tests/resource_arm_virtual_wan_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_wan_test.go @@ -137,6 +137,10 @@ func testCheckAzureRMVirtualWanExists(resourceName string) resource.TestCheckFun func testAccAzureRMVirtualWan_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -165,6 +169,10 @@ resource "azurerm_virtual_wan" "import" { func testAccAzureRMVirtualWan_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -179,6 +187,7 @@ resource "azurerm_virtual_wan" "test" { allow_branch_to_branch_traffic = true allow_vnet_to_vnet_traffic = true office365_local_breakout_category = "All" + type = "Standard" tags = { Hello = "There" diff --git a/azurerm/internal/services/network/tests/resource_arm_vpn_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_vpn_gateway_test.go index 0fc7c91c9c22d..71b1ed8cbbc48 100644 --- a/azurerm/internal/services/network/tests/resource_arm_vpn_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_vpn_gateway_test.go @@ -289,6 +289,10 @@ resource "azurerm_vpn_gateway" "test" { func testAccAzureRMVPNGateway_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/network/tests/resource_arm_vpn_server_configuration_test.go b/azurerm/internal/services/network/tests/resource_arm_vpn_server_configuration_test.go index 6c877048add32..eb58bb2536be9 100644 --- a/azurerm/internal/services/network/tests/resource_arm_vpn_server_configuration_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_vpn_server_configuration_test.go @@ -441,6 +441,10 @@ EOF func testAccAzureRMAzureRMVPNServerConfiguration_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/network/tests/resource_arm_web_application_firewall_policy_test.go b/azurerm/internal/services/network/tests/resource_arm_web_application_firewall_policy_test.go index f1593f57ba69c..576c91e87635d 100644 --- a/azurerm/internal/services/network/tests/resource_arm_web_application_firewall_policy_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_web_application_firewall_policy_test.go @@ -186,6 +186,10 @@ func testCheckAzureRMWebApplicationFirewallPolicyDestroy(s *terraform.State) err func testAccAzureRMWebApplicationFirewallPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -193,14 +197,18 @@ resource "azurerm_resource_group" "test" { resource "azurerm_web_application_firewall_policy" "test" { name = "acctestwafpolicy-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccAzureRMWebApplicationFirewallPolicy_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -208,8 +216,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_web_application_firewall_policy" "test" { name = "acctestwafpolicy-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location custom_rules { name = "Rule1" diff --git a/azurerm/internal/services/network/validate/subnet.go b/azurerm/internal/services/network/validate/subnet.go new file mode 100644 index 0000000000000..625f730148247 --- /dev/null +++ b/azurerm/internal/services/network/validate/subnet.go @@ -0,0 +1,23 @@ +package validate + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/parse" +) + +// SubnetID validates that the specified ID is a valid Subnet ID +func SubnetID(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) + return + } + + if _, err := parse.SubnetID(v); err != nil { + errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err)) + return + } + + return warnings, errors +} diff --git a/azurerm/internal/services/network/validate/virtual_network.go b/azurerm/internal/services/network/validate/virtual_network.go new file mode 100644 index 0000000000000..03b10e31f2efe --- /dev/null +++ b/azurerm/internal/services/network/validate/virtual_network.go @@ -0,0 +1,23 @@ +package validate + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/parse" +) + +// VirtualNetworkID validates that the specified ID is a valid Virtual Network ID +func VirtualNetworkID(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) + return + } + + if _, err := parse.VirtualNetworkID(v); err != nil { + errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err)) + return + } + + return warnings, errors +} diff --git a/azurerm/internal/services/notificationhub/registration.go b/azurerm/internal/services/notificationhub/registration.go index 0d5cf5c6db60f..0859e9c37df25 100644 --- a/azurerm/internal/services/notificationhub/registration.go +++ b/azurerm/internal/services/notificationhub/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Notification Hub" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Messaging", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/notificationhub/resource_arm_notification_hub.go b/azurerm/internal/services/notificationhub/resource_arm_notification_hub.go index fb8533ea59bb6..3b29b6ad97fd4 100644 --- a/azurerm/internal/services/notificationhub/resource_arm_notification_hub.go +++ b/azurerm/internal/services/notificationhub/resource_arm_notification_hub.go @@ -137,7 +137,7 @@ func resourceArmNotificationHub() *schema.Resource { // NOTE: skipping tags as there's a bug in the API where the Keys for Tags are returned in lower-case // Azure Rest API Specs issue: https://github.com/Azure/azure-sdk-for-go/issues/2239 - //"tags": tags.Schema(), + // "tags": tags.Schema(), }, } } diff --git a/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace.go b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace.go index b7f8a05b2580e..894852a5fe277 100644 --- a/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace.go +++ b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace.go @@ -80,7 +80,7 @@ func resourceArmNotificationHubNamespace() *schema.Resource { // NOTE: skipping tags as there's a bug in the API where the Keys for Tags are returned in lower-case // Azure Rest API Specs issue: https://github.com/Azure/azure-sdk-for-go/issues/2239 - //"tags": tags.Schema(), + // "tags": tags.Schema(), "servicebus_endpoint": { Type: schema.TypeString, diff --git a/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_namespace_test.go b/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_namespace_test.go index 2c210fb3bc63b..b0a9b9871aae9 100644 --- a/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_namespace_test.go +++ b/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_namespace_test.go @@ -32,8 +32,8 @@ func testAccDataSourceAzureRMNotificationHubNamespaceFree(data acceptance.TestDa %s data "azurerm_notification_hub_namespace" "test" { - name = "${azurerm_notification_hub_namespace.test.name}" - resource_group_name = "${azurerm_notification_hub_namespace.test.resource_group_name}" + name = azurerm_notification_hub_namespace.test.name + resource_group_name = azurerm_notification_hub_namespace.test.resource_group_name } `, template) } diff --git a/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_test.go b/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_test.go index a50725388c6ee..bbd7c64e31116 100644 --- a/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_test.go +++ b/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_test.go @@ -32,9 +32,9 @@ func testAccDataSourceAzureRMNotificationHubBasic(data acceptance.TestData) stri %s data "azurerm_notification_hub" "test" { - name = "${azurerm_notification_hub.test.name}" - namespace_name = "${azurerm_notification_hub_namespace.test.name}" - resource_group_name = "${azurerm_notification_hub_namespace.test.resource_group_name}" + name = azurerm_notification_hub.test.name + namespace_name = azurerm_notification_hub_namespace.test.name + resource_group_name = azurerm_notification_hub_namespace.test.resource_group_name } `, template) } diff --git a/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_authorization_rule_test.go b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_authorization_rule_test.go index d354ab07c668f..6777862a3de11 100644 --- a/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_authorization_rule_test.go +++ b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_authorization_rule_test.go @@ -252,9 +252,9 @@ func testAzureRMNotificationHubAuthorizationRule_listen(data acceptance.TestData resource "azurerm_notification_hub_authorization_rule" "test" { name = "acctestrule-%d" - notification_hub_name = "${azurerm_notification_hub.test.name}" - namespace_name = "${azurerm_notification_hub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + notification_hub_name = azurerm_notification_hub.test.name + namespace_name = azurerm_notification_hub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name listen = true } `, template, data.RandomInteger) @@ -266,11 +266,11 @@ func testAzureRMNotificationHubAuthorizationRule_requiresImport(data acceptance. %s resource "azurerm_notification_hub_authorization_rule" "import" { - name = "${azurerm_notification_hub_authorization_rule.test.name}" - notification_hub_name = "${azurerm_notification_hub_authorization_rule.test.notification_hub_name}" - namespace_name = "${azurerm_notification_hub_authorization_rule.test.namespace_name}" - resource_group_name = "${azurerm_notification_hub_authorization_rule.test.resource_group_name}" - listen = "${azurerm_notification_hub_authorization_rule.test.listen}" + name = azurerm_notification_hub_authorization_rule.test.name + notification_hub_name = azurerm_notification_hub_authorization_rule.test.notification_hub_name + namespace_name = azurerm_notification_hub_authorization_rule.test.namespace_name + resource_group_name = azurerm_notification_hub_authorization_rule.test.resource_group_name + listen = azurerm_notification_hub_authorization_rule.test.listen } `, template) } @@ -282,9 +282,9 @@ func testAzureRMNotificationHubAuthorizationRule_send(data acceptance.TestData) resource "azurerm_notification_hub_authorization_rule" "test" { name = "acctestrule-%d" - notification_hub_name = "${azurerm_notification_hub.test.name}" - namespace_name = "${azurerm_notification_hub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + notification_hub_name = azurerm_notification_hub.test.name + namespace_name = azurerm_notification_hub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name send = true listen = true } @@ -298,31 +298,30 @@ func testAzureRMNotificationHubAuthorizationRule_multi(data acceptance.TestData) resource "azurerm_notification_hub_authorization_rule" "test1" { name = "acctestruleone-%d" - notification_hub_name = "${azurerm_notification_hub.test.name}" - namespace_name = "${azurerm_notification_hub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + notification_hub_name = azurerm_notification_hub.test.name + namespace_name = azurerm_notification_hub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name send = true listen = true } resource "azurerm_notification_hub_authorization_rule" "test2" { name = "acctestruletwo-%d" - notification_hub_name = "${azurerm_notification_hub.test.name}" - namespace_name = "${azurerm_notification_hub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + notification_hub_name = azurerm_notification_hub.test.name + namespace_name = azurerm_notification_hub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name send = true listen = true } resource "azurerm_notification_hub_authorization_rule" "test3" { name = "acctestrulethree-%d" - notification_hub_name = "${azurerm_notification_hub.test.name}" - namespace_name = "${azurerm_notification_hub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + notification_hub_name = azurerm_notification_hub.test.name + namespace_name = azurerm_notification_hub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name send = true listen = true } - `, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } @@ -333,9 +332,9 @@ func testAzureRMNotificationHubAuthorizationRule_manage(data acceptance.TestData resource "azurerm_notification_hub_authorization_rule" "test" { name = "acctestrule-%d" - notification_hub_name = "${azurerm_notification_hub.test.name}" - namespace_name = "${azurerm_notification_hub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + notification_hub_name = azurerm_notification_hub.test.name + namespace_name = azurerm_notification_hub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name manage = true send = true listen = true @@ -345,6 +344,10 @@ resource "azurerm_notification_hub_authorization_rule" "test" { func testAzureRMNotificationHubAuthorizationRule_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -352,17 +355,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_notification_hub_namespace" "test" { name = "acctestnhn-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location namespace_type = "NotificationHub" sku_name = "Free" } resource "azurerm_notification_hub" "test" { name = "acctestnh-%d" - namespace_name = "${azurerm_notification_hub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + namespace_name = azurerm_notification_hub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_namespace_test.go b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_namespace_test.go index fae8ccae7d72b..e511870cde39e 100644 --- a/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_namespace_test.go +++ b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_namespace_test.go @@ -106,6 +106,10 @@ func testCheckAzureRMNotificationHubNamespaceDestroy(s *terraform.State) error { func testAccAzureRMNotificationHubNamespace_free(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -113,8 +117,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_notification_hub_namespace" "test" { name = "acctestnhn-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location namespace_type = "NotificationHub" sku_name = "Free" @@ -128,10 +132,10 @@ func testAccAzureRMNotificationHubNamespace_requiresImport(data acceptance.TestD %s resource "azurerm_notification_hub_namespace" "import" { - name = "${azurerm_notification_hub_namespace.test.name}" - resource_group_name = "${azurerm_notification_hub_namespace.test.resource_group_name}" - location = "${azurerm_notification_hub_namespace.test.location}" - namespace_type = "${azurerm_notification_hub_namespace.test.namespace_type}" + name = azurerm_notification_hub_namespace.test.name + resource_group_name = azurerm_notification_hub_namespace.test.resource_group_name + location = azurerm_notification_hub_namespace.test.location + namespace_type = azurerm_notification_hub_namespace.test.namespace_type sku_name = "Free" } diff --git a/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_test.go b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_test.go index 7daae627df7ff..ab1c71f9f104b 100644 --- a/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_test.go +++ b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_test.go @@ -113,6 +113,10 @@ func testCheckAzureRMNotificationHubDestroy(s *terraform.State) error { func testAccAzureRMNotificationHub_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRGpol-%d" location = "%s" @@ -120,17 +124,17 @@ resource "azurerm_resource_group" "test" { resource "azurerm_notification_hub_namespace" "test" { name = "acctestnhn-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location namespace_type = "NotificationHub" sku_name = "Free" } resource "azurerm_notification_hub" "test" { name = "acctestnh-%d" - namespace_name = "${azurerm_notification_hub_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + namespace_name = azurerm_notification_hub_namespace.test.name + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/policy/registration.go b/azurerm/internal/services/policy/registration.go index 1b78e83734118..3fde20e4468b7 100644 --- a/azurerm/internal/services/policy/registration.go +++ b/azurerm/internal/services/policy/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Policy" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Policy", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/policy/resource_arm_policy_definition.go b/azurerm/internal/services/policy/resource_arm_policy_definition.go index aa03c8994460c..9d5ff49a7dead 100644 --- a/azurerm/internal/services/policy/resource_arm_policy_definition.go +++ b/azurerm/internal/services/policy/resource_arm_policy_definition.go @@ -334,7 +334,7 @@ func resourceArmPolicyDefinitionImport(d *schema.ResourceData, meta interface{}) return []*schema.ResourceData{d}, nil } - //import a subscription based policy as before + // import a subscription based policy as before return schema.ImportStatePassthrough(d, meta) } diff --git a/azurerm/internal/services/policy/tests/data_source_policy_definition_test.go b/azurerm/internal/services/policy/tests/data_source_policy_definition_test.go index cfa7a800d3eba..ca1b76bfcb168 100644 --- a/azurerm/internal/services/policy/tests/data_source_policy_definition_test.go +++ b/azurerm/internal/services/policy/tests/data_source_policy_definition_test.go @@ -68,6 +68,10 @@ func TestAccDataSourceAzureRMPolicyDefinition_custom(t *testing.T) { func testAccDataSourceBuiltInPolicyDefinition(name string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + data "azurerm_policy_definition" "test" { display_name = "%s" } @@ -76,17 +80,26 @@ data "azurerm_policy_definition" "test" { func testAccDataSourceBuiltInPolicyDefinitionAtManagementGroup(name string) string { return fmt.Sprintf(` -data "azurerm_client_config" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" { +} data "azurerm_policy_definition" "test" { display_name = "%s" - management_group_id = "${data.azurerm_client_config.current.tenant_id}" + management_group_id = data.azurerm_client_config.current.tenant_id } `, name) } func testAccDataSourceCustomPolicyDefinition(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_policy_definition" "test_policy" { name = "acctestpol-%d" policy_type = "Custom" @@ -107,6 +120,7 @@ resource "azurerm_policy_definition" "test_policy" { } POLICY_RULE + parameters = < 1048576 { - return fmt.Errorf("basic pricing tier only supports upto 1,048,576 MB (1TB) of storage") - } - - return nil - }, } } @@ -288,17 +199,9 @@ func resourceArmPostgreSQLServerCreate(d *schema.ResourceData, meta interface{}) } } - var sku *postgresql.Sku - if b, ok := d.GetOk("sku_name"); ok { - var err error - sku, err = expandServerSkuName(b.(string)) - if err != nil { - return fmt.Errorf("error expanding sku_name for PostgreSQL Server %s (Resource Group %q): %v", name, resourceGroup, err) - } - } else if _, ok := d.GetOk("sku"); ok { - sku = expandAzureRmPostgreSQLServerSku(d) - } else { - return fmt.Errorf("One of `sku` or `sku_name` must be set for PostgreSQL Server %q (Resource Group %q)", name, resourceGroup) + sku, err := expandServerSkuName(d.Get("sku_name").(string)) + if err != nil { + return fmt.Errorf("error expanding `sku_name` for PostgreSQL Server %s (Resource Group %q): %v", name, resourceGroup, err) } properties := postgresql.ServerForCreate{ @@ -348,17 +251,9 @@ func resourceArmPostgreSQLServerUpdate(d *schema.ResourceData, meta interface{}) name := d.Get("name").(string) resourceGroup := d.Get("resource_group_name").(string) - var sku *postgresql.Sku - if b, ok := d.GetOk("sku_name"); ok { - var err error - sku, err = expandServerSkuName(b.(string)) - if err != nil { - return fmt.Errorf("error expanding sku_name for PostgreSQL Server %q (Resource Group %q): %v", name, resourceGroup, err) - } - } else if _, ok := d.GetOk("sku"); ok { - sku = expandAzureRmPostgreSQLServerSku(d) - } else { - return fmt.Errorf("One of `sku` or `sku_name` must be set for PostgreSQL Server %q (Resource Group %q)", name, resourceGroup) + sku, err := expandServerSkuName(d.Get("sku_name").(string)) + if err != nil { + return fmt.Errorf("error expanding `sku_name` for PostgreSQL Server %s (Resource Group %q): %v", name, resourceGroup, err) } properties := postgresql.ServerUpdateParameters{ @@ -428,9 +323,6 @@ func resourceArmPostgreSQLServerRead(d *schema.ResourceData, meta interface{}) e d.Set("version", string(resp.Version)) d.Set("ssl_enforcement", string(resp.SslEnforcement)) - if err := d.Set("sku", flattenPostgreSQLServerSku(resp.Sku)); err != nil { - return fmt.Errorf("Error setting `sku`: %+v", err) - } if sku := resp.Sku; sku != nil { d.Set("sku_name", sku.Name) } @@ -508,23 +400,6 @@ func expandServerSkuName(skuName string) (*postgresql.Sku, error) { }, nil } -func expandAzureRmPostgreSQLServerSku(d *schema.ResourceData) *postgresql.Sku { - skus := d.Get("sku").([]interface{}) - sku := skus[0].(map[string]interface{}) - - name := sku["name"].(string) - capacity := sku["capacity"].(int) - tier := sku["tier"].(string) - family := sku["family"].(string) - - return &postgresql.Sku{ - Name: utils.String(name), - Tier: postgresql.SkuTier(tier), - Capacity: utils.Int32(int32(capacity)), - Family: utils.String(family), - } -} - func expandAzureRmPostgreSQLStorageProfile(d *schema.ResourceData) *postgresql.StorageProfile { storageprofiles := d.Get("storage_profile").([]interface{}) storageprofile := storageprofiles[0].(map[string]interface{}) @@ -542,26 +417,6 @@ func expandAzureRmPostgreSQLStorageProfile(d *schema.ResourceData) *postgresql.S } } -func flattenPostgreSQLServerSku(resp *postgresql.Sku) []interface{} { - values := map[string]interface{}{} - - if name := resp.Name; name != nil { - values["name"] = *name - } - - if capacity := resp.Capacity; capacity != nil { - values["capacity"] = *capacity - } - - values["tier"] = string(resp.Tier) - - if family := resp.Family; family != nil { - values["family"] = *family - } - - return []interface{}{values} -} - func flattenPostgreSQLStorageProfile(resp *postgresql.StorageProfile) []interface{} { values := map[string]interface{}{} diff --git a/azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule.go b/azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule.go index ba39d406f9371..807775b8b0e73 100644 --- a/azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule.go +++ b/azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule.go @@ -226,7 +226,7 @@ func postgreSQLVirtualNetworkStateStatusCodeRefreshFunc(ctx context.Context, cli return resp, string(props.State), nil } - //Valid response was returned but VirtualNetworkRuleProperties was nil. Basically the rule exists, but with no properties for some reason. Assume Unknown instead of returning error. + // Valid response was returned but VirtualNetworkRuleProperties was nil. Basically the rule exists, but with no properties for some reason. Assume Unknown instead of returning error. log.Printf("[DEBUG] Retrieving PostgreSQL Virtual Network Rule %q (PostgreSQL Server: %q, Resource Group: %q) returned empty VirtualNetworkRuleProperties", resourceGroup, serverName, name) return resp, "Unknown", nil } diff --git a/azurerm/internal/services/postgres/tests/data_source_postgresql_server_test.go b/azurerm/internal/services/postgres/tests/data_source_postgresql_server_test.go index 259ab7507e43c..b221ba0631ccf 100644 --- a/azurerm/internal/services/postgres/tests/data_source_postgresql_server_test.go +++ b/azurerm/internal/services/postgres/tests/data_source_postgresql_server_test.go @@ -37,8 +37,8 @@ func testAccDataSourceAzureRMPostgreSqlServer_basic(data acceptance.TestData, ve %s data "azurerm_postgresql_server" "test" { - name = "${azurerm_postgresql_server.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + name = azurerm_postgresql_server.test.name + resource_group_name = azurerm_resource_group.test.name } `, testAccAzureRMPostgreSQLServer_basic(data, version)) } diff --git a/azurerm/internal/services/postgres/tests/resource_arm_postgresql_configuration_test.go b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_configuration_test.go index 68a5cbd193e4d..cfef6c8e4a896 100644 --- a/azurerm/internal/services/postgres/tests/resource_arm_postgresql_configuration_test.go +++ b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_configuration_test.go @@ -193,8 +193,8 @@ func testAccAzureRMPostgreSQLConfiguration_template(data acceptance.TestData, na resource "azurerm_postgresql_configuration" "test" { name = "%s" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_postgresql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_postgresql_server.test.name value = "%s" } `, testAccAzureRMPostgreSQLConfiguration_empty(data), name, value) @@ -202,6 +202,10 @@ resource "azurerm_postgresql_configuration" "test" { func testAccAzureRMPostgreSQLConfiguration_empty(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -209,8 +213,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" diff --git a/azurerm/internal/services/postgres/tests/resource_arm_postgresql_database_test.go b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_database_test.go index 88898da9717b4..83462b6ae8e6b 100644 --- a/azurerm/internal/services/postgres/tests/resource_arm_postgresql_database_test.go +++ b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_database_test.go @@ -174,6 +174,10 @@ func testCheckAzureRMPostgreSQLDatabaseDestroy(s *terraform.State) error { func testAccAzureRMPostgreSQLDatabase_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -181,8 +185,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -200,8 +204,8 @@ resource "azurerm_postgresql_server" "test" { resource "azurerm_postgresql_database" "test" { name = "acctest_PSQL_db_%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_postgresql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_postgresql_server.test.name charset = "UTF8" collation = "English_United States.1252" } @@ -214,17 +218,21 @@ func testAccAzureRMPostgreSQLDatabase_requiresImport(data acceptance.TestData) s %s resource "azurerm_postgresql_database" "import" { - name = "${azurerm_postgresql_database.test.name}" - resource_group_name = "${azurerm_postgresql_database.test.resource_group_name}" - server_name = "${azurerm_postgresql_database.test.server_name}" - charset = "${azurerm_postgresql_database.test.charset}" - collation = "${azurerm_postgresql_database.test.collation}" + name = azurerm_postgresql_database.test.name + resource_group_name = azurerm_postgresql_database.test.resource_group_name + server_name = azurerm_postgresql_database.test.server_name + charset = azurerm_postgresql_database.test.charset + collation = azurerm_postgresql_database.test.collation } `, template) } func testAccAzureRMPostgreSQLDatabase_collationWithHyphen(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -232,8 +240,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -251,8 +259,8 @@ resource "azurerm_postgresql_server" "test" { resource "azurerm_postgresql_database" "test" { name = "acctest_PSQL_db_%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_postgresql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_postgresql_server.test.name charset = "UTF8" collation = "En-US" } @@ -261,6 +269,10 @@ resource "azurerm_postgresql_database" "test" { func testAccAzureRMPostgreSQLDatabase_charsetLowercase(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -268,8 +280,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -287,8 +299,8 @@ resource "azurerm_postgresql_server" "test" { resource "azurerm_postgresql_database" "test" { name = "acctest_PSQL_db_%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_postgresql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_postgresql_server.test.name charset = "utf8" collation = "English_United States.1252" } @@ -297,6 +309,10 @@ resource "azurerm_postgresql_database" "test" { func testAccAzureRMPostgreSQLDatabase_charsetMixedcase(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -304,8 +320,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -323,8 +339,8 @@ resource "azurerm_postgresql_server" "test" { resource "azurerm_postgresql_database" "test" { name = "acctest_PSQL_db_%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_postgresql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_postgresql_server.test.name charset = "Utf8" collation = "English_United States.1252" } diff --git a/azurerm/internal/services/postgres/tests/resource_arm_postgresql_firewall_rule_test.go b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_firewall_rule_test.go index b9aea371992ea..e15c3858b5582 100644 --- a/azurerm/internal/services/postgres/tests/resource_arm_postgresql_firewall_rule_test.go +++ b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_firewall_rule_test.go @@ -119,6 +119,10 @@ func testCheckAzureRMPostgreSQLFirewallRuleDestroy(s *terraform.State) error { func testAccAzureRMPostgreSQLFirewallRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -126,8 +130,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -145,8 +149,8 @@ resource "azurerm_postgresql_server" "test" { resource "azurerm_postgresql_firewall_rule" "test" { name = "acctest-PSQL-fwrule-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_postgresql_server.test.name}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_postgresql_server.test.name start_ip_address = "0.0.0.0" end_ip_address = "255.255.255.255" } @@ -159,11 +163,11 @@ func testAccAzureRMPostgreSQLFirewallRule_requiresImport(data acceptance.TestDat %s resource "azurerm_postgresql_firewall_rule" "import" { - name = "${azurerm_postgresql_firewall_rule.test.name}" - resource_group_name = "${azurerm_postgresql_firewall_rule.test.resource_group_name}" - server_name = "${azurerm_postgresql_firewall_rule.test.server_name}" - start_ip_address = "${azurerm_postgresql_firewall_rule.test.start_ip_address}" - end_ip_address = "${azurerm_postgresql_firewall_rule.test.end_ip_address}" + name = azurerm_postgresql_firewall_rule.test.name + resource_group_name = azurerm_postgresql_firewall_rule.test.resource_group_name + server_name = azurerm_postgresql_firewall_rule.test.server_name + start_ip_address = azurerm_postgresql_firewall_rule.test.start_ip_address + end_ip_address = azurerm_postgresql_firewall_rule.test.end_ip_address } `, template) } diff --git a/azurerm/internal/services/postgres/tests/resource_arm_postgresql_server_test.go b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_server_test.go index a90489d476d83..ce802d23e4335 100644 --- a/azurerm/internal/services/postgres/tests/resource_arm_postgresql_server_test.go +++ b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_server_test.go @@ -33,28 +33,6 @@ func TestAccAzureRMPostgreSQLServer_basicNinePointFive(t *testing.T) { }) } -// TODO: remove in 2.0 -func TestAccAzureRMPostgreSQLServer_basicNinePointFiveOldSku(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMPostgreSQLServer_basicNinePointFiveOldSku(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), - resource.TestCheckResourceAttr(data.ResourceName, "version", "9.5"), - resource.TestCheckResourceAttr(data.ResourceName, "ssl_enforcement", "Enabled"), - ), - }, - data.ImportStep("administrator_login_password"), - }, - }) -} - func TestAccAzureRMPostgreSQLServer_basicNinePointSix(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") resource.ParallelTest(t, resource.TestCase{ @@ -235,7 +213,7 @@ func TestAccAzureRMPostgreSQLServer_updated(t *testing.T) { Config: testAccAzureRMPostgreSQLServer_basicNinePointSix(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMPostgreSQLServerExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "GP_Gen5_2"), resource.TestCheckResourceAttr(data.ResourceName, "version", "9.6"), resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "51200"), resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.auto_grow", "Disabled"), @@ -246,7 +224,7 @@ func TestAccAzureRMPostgreSQLServer_updated(t *testing.T) { Config: testAccAzureRMPostgreSQLServer_basicNinePointSixUpdated(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMPostgreSQLServerExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_4"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "GP_Gen5_4"), resource.TestCheckResourceAttr(data.ResourceName, "version", "9.6"), resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "640000"), resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.auto_grow", "Enabled"), @@ -268,10 +246,7 @@ func TestAccAzureRMPostgreSQLServer_updateSKU(t *testing.T) { Config: testAccAzureRMPostgreSQLServer_generalPurpose(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMPostgreSQLServerExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_32"), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "32"), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "GeneralPurpose"), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "GP_Gen5_32"), resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "640000"), resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), @@ -280,10 +255,7 @@ func TestAccAzureRMPostgreSQLServer_updateSKU(t *testing.T) { Config: testAccAzureRMPostgreSQLServer_memoryOptimized(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMPostgreSQLServerExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "MO_Gen5_16"), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "16"), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "MemoryOptimized"), - resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "MO_Gen5_16"), resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "4194304"), resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), @@ -354,35 +326,10 @@ func testCheckAzureRMPostgreSQLServerDestroy(s *terraform.State) error { func testAccAzureRMPostgreSQLServer_basic(data acceptance.TestData, version string) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-psql-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_postgresql_server" "test" { - name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku_name = "GP_Gen5_2" - - storage_profile { - storage_mb = 51200 - backup_retention_days = 7 - geo_redundant_backup = "Disabled" - auto_grow = "Disabled" - } - - administrator_login = "acctestun" - administrator_login_password = "H@Sh1CoR3!" - version = "%s" - ssl_enforcement = "Enabled" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, version) -} - -func testAccAzureRMPostgreSQLServer_basicNinePointFiveOldSku(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -390,8 +337,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -407,7 +354,7 @@ resource "azurerm_postgresql_server" "test" { version = "%s" ssl_enforcement = "Enabled" } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, "9.5") +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, version) } func testAccAzureRMPostgreSQLServer_basicNinePointFive(data acceptance.TestData) string { @@ -432,9 +379,9 @@ func testAccAzureRMPostgreSQLServer_requiresImport(data acceptance.TestData) str %s resource "azurerm_postgresql_server" "import" { - name = "${azurerm_postgresql_server.test.name}" - location = "${azurerm_postgresql_server.test.location}" - resource_group_name = "${azurerm_postgresql_server.test.resource_group_name}" + name = azurerm_postgresql_server.test.name + location = azurerm_postgresql_server.test.location + resource_group_name = azurerm_postgresql_server.test.resource_group_name sku_name = "GP_Gen5_2" @@ -454,6 +401,10 @@ resource "azurerm_postgresql_server" "import" { func testAccAzureRMPostgreSQLServer_basicNinePointSixUpdatedPassword(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -461,8 +412,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -482,6 +433,10 @@ resource "azurerm_postgresql_server" "test" { func testAccAzureRMPostgreSQLServer_basicNinePointSixUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -489,8 +444,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_4" @@ -510,6 +465,10 @@ resource "azurerm_postgresql_server" "test" { func testAccAzureRMPostgreSQLServer_basicMaxStorage(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -517,8 +476,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_2" @@ -539,6 +498,10 @@ resource "azurerm_postgresql_server" "test" { func testAccAzureRMPostgreSQLServer_generalPurpose(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -546,8 +509,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "GP_Gen5_32" @@ -567,6 +530,10 @@ resource "azurerm_postgresql_server" "test" { func testAccAzureRMPostgreSQLServer_memoryOptimized(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -574,8 +541,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "MO_Gen5_16" @@ -595,6 +562,10 @@ resource "azurerm_postgresql_server" "test" { func testAccAzureRMPostgreSQLServer_memoryOptimizedGeoRedundant(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -602,15 +573,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "MO_Gen5_16" - capacity = 16 - tier = "MemoryOptimized" - family = "Gen5" - } + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + sku_name = "MO_Gen5_16" storage_profile { storage_mb = 4194304 diff --git a/azurerm/internal/services/postgres/tests/resource_arm_postgresql_virtual_network_rule_test.go b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_virtual_network_rule_test.go index bd6410dfa5d20..0c2890c19129f 100644 --- a/azurerm/internal/services/postgres/tests/resource_arm_postgresql_virtual_network_rule_test.go +++ b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_virtual_network_rule_test.go @@ -59,8 +59,8 @@ func TestAccAzureRMPostgreSQLVirtualNetworkRule_switchSubnets(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_postgresql_virtual_network_rule", "test") // Create regex strings that will ensure that one subnet name exists, but not the other - preConfigRegex := regexp.MustCompile(fmt.Sprintf("(acctest-SN1-%d)$|(acctest-SN[^2]-%d)$", data.RandomInteger, data.RandomInteger)) //subnet 1 but not 2 - postConfigRegex := regexp.MustCompile(fmt.Sprintf("(acctest-SN2-%d)$|(acctest-SN-[^1]%d)$", data.RandomInteger, data.RandomInteger)) //subnet 2 but not 1 + preConfigRegex := regexp.MustCompile(fmt.Sprintf("(acctest-SN1-%d)$|(acctest-SN[^2]-%d)$", data.RandomInteger, data.RandomInteger)) // subnet 1 but not 2 + postConfigRegex := regexp.MustCompile(fmt.Sprintf("(acctest-SN2-%d)$|(acctest-SN-[^1]%d)$", data.RandomInteger, data.RandomInteger)) // subnet 2 but not 1 resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -215,8 +215,8 @@ func testCheckAzureRMPostgreSQLVirtualNetworkRuleDisappears(resourceName string) future, err := client.Delete(ctx, resourceGroup, serverName, ruleName) if err != nil { - //If the error is that the resource we want to delete does not exist in the first - //place (404), then just return with no error. + // If the error is that the resource we want to delete does not exist in the first + // place (404), then just return with no error. if response.WasNotFound(future.Response()) { return nil } @@ -225,7 +225,7 @@ func testCheckAzureRMPostgreSQLVirtualNetworkRuleDisappears(resourceName string) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - //Same deal as before. Just in case. + // Same deal as before. Just in case. if response.WasNotFound(future.Response()) { return nil } @@ -239,6 +239,10 @@ func testCheckAzureRMPostgreSQLVirtualNetworkRuleDisappears(resourceName string) func testAccAzureRMPostgreSQLVirtualNetworkRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -247,22 +251,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctest-VNET-%d" address_space = ["10.7.29.0/29"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctest-SN-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.7.29.0/29" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name administrator_login = "acctestun" administrator_login_password = "H@Sh1CoR3!" version = "9.5" @@ -279,9 +283,9 @@ resource "azurerm_postgresql_server" "test" { resource "azurerm_postgresql_virtual_network_rule" "test" { name = "acctest-PSQL-VNET-rule-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_postgresql_server.test.name}" - subnet_id = "${azurerm_subnet.test.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_postgresql_server.test.name + subnet_id = azurerm_subnet.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } @@ -292,16 +296,20 @@ func testAccAzureRMPostgreSQLVirtualNetworkRule_requiresImport(data acceptance.T %s resource "azurerm_postgresql_virtual_network_rule" "import" { - name = "${azurerm_postgresql_virtual_network_rule.test.name}" - resource_group_name = "${azurerm_postgresql_virtual_network_rule.test.resource_group_name}" - server_name = "${azurerm_postgresql_virtual_network_rule.test.server_name}" - subnet_id = "${azurerm_postgresql_virtual_network_rule.test.subnet_id}" + name = azurerm_postgresql_virtual_network_rule.test.name + resource_group_name = azurerm_postgresql_virtual_network_rule.test.resource_group_name + server_name = azurerm_postgresql_virtual_network_rule.test.server_name + subnet_id = azurerm_postgresql_virtual_network_rule.test.subnet_id } `, template) } func testAccAzureRMPostgreSQLVirtualNetworkRule_subnetSwitchPre(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -310,30 +318,30 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctest-VNET-%d" address_space = ["10.7.29.0/24"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test1" { name = "acctest-SN1-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.7.29.0/25" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_subnet" "test2" { name = "acctest-SN2-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.7.29.128/25" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name administrator_login = "acctestun" administrator_login_password = "H@Sh1CoR3!" version = "9.5" @@ -350,15 +358,19 @@ resource "azurerm_postgresql_server" "test" { resource "azurerm_postgresql_virtual_network_rule" "test" { name = "acctest-PSQL-VNET-rule-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_postgresql_server.test.name}" - subnet_id = "${azurerm_subnet.test1.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_postgresql_server.test.name + subnet_id = azurerm_subnet.test1.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMPostgreSQLVirtualNetworkRule_subnetSwitchPost(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -367,30 +379,30 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctest-VNET-%d" address_space = ["10.7.29.0/24"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test1" { name = "acctest-SN1-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.7.29.0/25" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_subnet" "test2" { name = "acctest-SN2-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.7.29.128/25" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name administrator_login = "acctestun" administrator_login_password = "H@Sh1CoR3!" version = "9.5" @@ -407,15 +419,19 @@ resource "azurerm_postgresql_server" "test" { resource "azurerm_postgresql_virtual_network_rule" "test" { name = "acctest-PSQL-VNET-rule-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_postgresql_server.test.name}" - subnet_id = "${azurerm_subnet.test2.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_postgresql_server.test.name + subnet_id = azurerm_subnet.test2.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMPostgreSQLVirtualNetworkRule_multipleSubnets(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -424,45 +440,45 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "vnet1" { name = "acctestvnet1%d" address_space = ["10.7.29.0/24"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_virtual_network" "vnet2" { name = "acctestvnet2%d" address_space = ["10.1.29.0/29"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "vnet1_subnet1" { name = "acctestsubnet1%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.vnet1.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.vnet1.name address_prefix = "10.7.29.0/29" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_subnet" "vnet1_subnet2" { name = "acctestsubnet2%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.vnet1.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.vnet1.name address_prefix = "10.7.29.128/29" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_subnet" "vnet2_subnet1" { name = "acctestsubnet3%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.vnet2.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.vnet2.name address_prefix = "10.1.29.0/29" service_endpoints = ["Microsoft.Sql"] } resource "azurerm_postgresql_server" "test" { name = "acctest-psql-server-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name administrator_login = "acctestun" administrator_login_password = "H@Sh1CoR3!" version = "9.5" @@ -479,32 +495,36 @@ resource "azurerm_postgresql_server" "test" { resource "azurerm_postgresql_virtual_network_rule" "rule1" { name = "acctestpostgresqlvnetrule1%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_postgresql_server.test.name}" - subnet_id = "${azurerm_subnet.vnet1_subnet1.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_postgresql_server.test.name + subnet_id = azurerm_subnet.vnet1_subnet1.id ignore_missing_vnet_service_endpoint = false } resource "azurerm_postgresql_virtual_network_rule" "rule2" { name = "acctestpostgresqlvnetrule2%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_postgresql_server.test.name}" - subnet_id = "${azurerm_subnet.vnet1_subnet2.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_postgresql_server.test.name + subnet_id = azurerm_subnet.vnet1_subnet2.id ignore_missing_vnet_service_endpoint = false } resource "azurerm_postgresql_virtual_network_rule" "rule3" { name = "acctestpostgresqlvnetrule3%d" - resource_group_name = "${azurerm_resource_group.test.name}" - server_name = "${azurerm_postgresql_server.test.name}" - subnet_id = "${azurerm_subnet.vnet2_subnet1.id}" + resource_group_name = azurerm_resource_group.test.name + server_name = azurerm_postgresql_server.test.name + subnet_id = azurerm_subnet.vnet2_subnet1.id ignore_missing_vnet_service_endpoint = false } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testAccAzureRMPostgreSQLVirtualNetworkRule_ignoreEndpointValid(data acceptance.TestData) string { - return fmt.Sprintf(` + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-psql-%d" location = "%s" @@ -530,7 +550,7 @@ resource "azurerm_postgresql_server" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku_name = "GP_Gen5_2" + sku_name = "GP_Gen5_2" storage_profile { storage_mb = 51200 diff --git a/azurerm/internal/services/privatedns/registration.go b/azurerm/internal/services/privatedns/registration.go index 40421d979b0fa..37b46c37e956d 100644 --- a/azurerm/internal/services/privatedns/registration.go +++ b/azurerm/internal/services/privatedns/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Private DNS" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Private DNS", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{} diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_a_record.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_a_record.go index b85f444d95108..cc76e796619b8 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_a_record.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_a_record.go @@ -63,6 +63,11 @@ func resourceArmPrivateDnsARecord() *schema.Resource { Required: true, }, + "fqdn": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tags.Schema(), }, } @@ -149,6 +154,7 @@ func resourceArmPrivateDnsARecordRead(d *schema.ResourceData, meta interface{}) d.Set("resource_group_name", resGroup) d.Set("zone_name", zoneName) d.Set("ttl", resp.TTL) + d.Set("fqdn", resp.Fqdn) if err := d.Set("records", flattenAzureRmPrivateDnsARecords(resp.ARecords)); err != nil { return err diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record.go index 932ccee4fdfcc..ab8e0178996b2 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record.go @@ -60,6 +60,11 @@ func resourceArmPrivateDnsAaaaRecord() *schema.Resource { Required: true, }, + "fqdn": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tags.Schema(), }, } @@ -146,6 +151,7 @@ func resourceArmPrivateDnsAaaaRecordRead(d *schema.ResourceData, meta interface{ d.Set("resource_group_name", resGroup) d.Set("zone_name", zoneName) d.Set("ttl", resp.TTL) + d.Set("fqdn", resp.Fqdn) if err := d.Set("records", flattenAzureRmPrivateDnsAaaaRecords(resp.AaaaRecords)); err != nil { return err diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record.go index 6eac1023392ba..e67581c1bdd08 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record.go @@ -65,6 +65,11 @@ func resourceArmPrivateDnsCNameRecord() *schema.Resource { ValidateFunc: validation.IntBetween(1, 2147483647), }, + "fqdn": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tags.Schema(), }, } @@ -154,6 +159,7 @@ func resourceArmPrivateDnsCNameRecordRead(d *schema.ResourceData, meta interface d.Set("resource_group_name", resGroup) d.Set("zone_name", zoneName) d.Set("ttl", resp.TTL) + d.Set("fqdn", resp.Fqdn) if props := resp.RecordSetProperties; props != nil { if record := props.CnameRecord; record != nil { diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record.go index f099109f21bae..4eb08bdbc3304 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record.go @@ -81,6 +81,11 @@ func resourceArmPrivateDnsMxRecord() *schema.Resource { ValidateFunc: validation.IntBetween(1, 2147483647), }, + "fqdn": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tags.Schema(), }, } @@ -165,6 +170,7 @@ func resourceArmPrivateDnsMxRecordRead(d *schema.ResourceData, meta interface{}) d.Set("resource_group_name", resGroup) d.Set("zone_name", zoneName) d.Set("ttl", resp.TTL) + d.Set("fqdn", resp.Fqdn) if err := d.Set("record", flattenAzureRmPrivateDnsMxRecords(resp.MxRecords)); err != nil { return err diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record.go index cec024a9b510c..731e3aa1fc88d 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record.go @@ -66,6 +66,11 @@ func resourceArmPrivateDnsPtrRecord() *schema.Resource { ValidateFunc: validation.IntBetween(1, 2147483647), }, + "fqdn": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tags.Schema(), }, } @@ -152,6 +157,7 @@ func resourceArmPrivateDnsPtrRecordRead(d *schema.ResourceData, meta interface{} d.Set("resource_group_name", resGroup) d.Set("zone_name", zoneName) d.Set("ttl", resp.TTL) + d.Set("fqdn", resp.Fqdn) if props := resp.RecordSetProperties; props != nil { if err := d.Set("records", flattenAzureRmPrivateDnsPtrRecords(resp.PtrRecords)); err != nil { diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record.go index be99dbf21836f..5295f33546153 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record.go @@ -91,6 +91,11 @@ func resourceArmPrivateDnsSrvRecord() *schema.Resource { ValidateFunc: validation.IntBetween(1, 2147483647), }, + "fqdn": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tags.Schema(), }, } @@ -175,6 +180,7 @@ func resourceArmPrivateDnsSrvRecordRead(d *schema.ResourceData, meta interface{} d.Set("resource_group_name", resGroup) d.Set("zone_name", zoneName) d.Set("ttl", resp.TTL) + d.Set("fqdn", resp.Fqdn) if err := d.Set("record", flattenAzureRmPrivateDnsSrvRecords(resp.SrvRecords)); err != nil { return err diff --git a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_a_record_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_a_record_test.go index c351b83d15923..d322ad0dcc188 100644 --- a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_a_record_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_a_record_test.go @@ -25,6 +25,7 @@ func TestAccAzureRMPrivateDnsARecord_basic(t *testing.T) { Config: testAccAzureRMPrivateDnsARecord_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMPrivateDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, data.ImportStep(), @@ -168,6 +169,10 @@ func testCheckAzureRMPrivateDnsARecordDestroy(s *terraform.State) error { func testAccAzureRMPrivateDnsARecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -175,13 +180,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_a_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 records = ["1.2.3.4", "1.2.4.5"] } @@ -194,9 +199,9 @@ func testAccAzureRMPrivateDnsARecord_requiresImport(data acceptance.TestData) st %s resource "azurerm_private_dns_a_record" "import" { - name = "${azurerm_private_dns_a_record.test.name}" - resource_group_name = "${azurerm_private_dns_a_record.test.resource_group_name}" - zone_name = "${azurerm_private_dns_a_record.test.zone_name}" + name = azurerm_private_dns_a_record.test.name + resource_group_name = azurerm_private_dns_a_record.test.resource_group_name + zone_name = azurerm_private_dns_a_record.test.zone_name ttl = 300 records = ["1.2.3.4", "1.2.4.5"] } @@ -205,6 +210,10 @@ resource "azurerm_private_dns_a_record" "import" { func testAccAzureRMPrivateDnsARecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -212,13 +221,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_a_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 records = ["1.2.3.4", "1.2.4.5", "1.2.3.7"] } @@ -227,6 +236,10 @@ resource "azurerm_private_dns_a_record" "test" { func testAccAzureRMPrivateDnsARecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -234,13 +247,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_a_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 records = ["1.2.3.4", "1.2.4.5"] @@ -254,6 +267,10 @@ resource "azurerm_private_dns_a_record" "test" { func testAccAzureRMPrivateDnsARecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -261,13 +278,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_a_record" "test" { name = "myarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 records = ["1.2.3.4", "1.2.4.5"] diff --git a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_aaaa_record_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_aaaa_record_test.go index 4c8d3e3ee65a9..d89bc9bb98c5a 100644 --- a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_aaaa_record_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_aaaa_record_test.go @@ -25,6 +25,7 @@ func TestAccAzureRMPrivateDnsAaaaRecord_basic(t *testing.T) { Config: testAccAzureRMPrivateDnsAaaaRecord_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMPrivateDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, data.ImportStep(), @@ -168,6 +169,10 @@ func testCheckAzureRMPrivateDnsAaaaRecordDestroy(s *terraform.State) error { func testAccAzureRMPrivateDnsAaaaRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -175,13 +180,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_aaaa_record" "test" { name = "myaaaarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 records = ["fd5d:70bc:930e:d008:0000:0000:0000:7334", "fd5d:70bc:930e:d008::7335"] } @@ -194,9 +199,9 @@ func testAccAzureRMPrivateDnsAaaaRecord_requiresImport(data acceptance.TestData) %s resource "azurerm_private_dns_aaaa_record" "import" { - name = "${azurerm_private_dns_aaaa_record.test.name}" - resource_group_name = "${azurerm_private_dns_aaaa_record.test.resource_group_name}" - zone_name = "${azurerm_private_dns_aaaa_record.test.zone_name}" + name = azurerm_private_dns_aaaa_record.test.name + resource_group_name = azurerm_private_dns_aaaa_record.test.resource_group_name + zone_name = azurerm_private_dns_aaaa_record.test.zone_name ttl = 300 records = ["fd5d:70bc:930e:d008:0000:0000:0000:7334", "fd5d:70bc:930e:d008::7335"] } @@ -205,6 +210,10 @@ resource "azurerm_private_dns_aaaa_record" "import" { func testAccAzureRMPrivateDnsAaaaRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -212,13 +221,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_aaaa_record" "test" { name = "myaaaarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 records = ["fd5d:70bc:930e:d008:0000:0000:0000:7334", "fd5d:70bc:930e:d008::7335", "fd73:5e76:3ab5:d2e9::1"] } @@ -227,6 +236,10 @@ resource "azurerm_private_dns_aaaa_record" "test" { func testAccAzureRMPrivateDnsAaaaRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -234,13 +247,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_aaaa_record" "test" { name = "myaaaarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 records = ["fd5d:70bc:930e:d008:0000:0000:0000:7334", "fd5d:70bc:930e:d008::7335"] @@ -254,6 +267,10 @@ resource "azurerm_private_dns_aaaa_record" "test" { func testAccAzureRMPrivateDnsAaaaRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -261,13 +278,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_aaaa_record" "test" { name = "myaaaarecord%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 records = ["fd5d:70bc:930e:d008:0000:0000:0000:7334", "fd5d:70bc:930e:d008::7335"] diff --git a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_cname_record_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_cname_record_test.go index cb9d0ba813d84..84b8beb9525d5 100644 --- a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_cname_record_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_cname_record_test.go @@ -24,6 +24,7 @@ func TestAccAzureRMPrivateDnsCNameRecord_basic(t *testing.T) { Config: testAccAzureRMPrivateDnsCNameRecord_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMPrivateDnsCNameRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, data.ImportStep(), @@ -184,6 +185,10 @@ func testCheckAzureRMPrivateDnsCNameRecordDestroy(s *terraform.State) error { func testAccAzureRMPrivateDnsCNameRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -191,13 +196,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_cname_record" "test" { name = "acctestcname%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record = "contoso.com" } @@ -210,9 +215,9 @@ func testAccAzureRMPrivateDnsCNameRecord_requiresImport(data acceptance.TestData %s resource "azurerm_private_dns_cname_record" "import" { - name = "${azurerm_private_dns_cname_record.test.name}" - resource_group_name = "${azurerm_private_dns_cname_record.test.resource_group_name}" - zone_name = "${azurerm_private_dns_cname_record.test.zone_name}" + name = azurerm_private_dns_cname_record.test.name + resource_group_name = azurerm_private_dns_cname_record.test.resource_group_name + zone_name = azurerm_private_dns_cname_record.test.zone_name ttl = 300 record = "contoso.com" } @@ -221,6 +226,10 @@ resource "azurerm_private_dns_cname_record" "import" { func testAccAzureRMPrivateDnsCNameRecord_subdomain(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -228,13 +237,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_cname_record" "test" { name = "acctestcname%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record = "test.contoso.com" } @@ -243,6 +252,10 @@ resource "azurerm_private_dns_cname_record" "test" { func testAccAzureRMPrivateDnsCNameRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -250,13 +263,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_cname_record" "test" { name = "acctestcname%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record = "contoso.com" } @@ -265,6 +278,10 @@ resource "azurerm_private_dns_cname_record" "test" { func testAccAzureRMPrivateDnsCNameRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -272,13 +289,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_cname_record" "test" { name = "acctestcname%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record = "contoso.com" @@ -292,6 +309,10 @@ resource "azurerm_private_dns_cname_record" "test" { func testAccAzureRMPrivateDnsCNameRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -299,13 +320,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_cname_record" "test" { name = "acctestcname%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record = "contoso.com" diff --git a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_mx_record_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_mx_record_test.go index 4c176475d0526..204320495b42e 100644 --- a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_mx_record_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_mx_record_test.go @@ -24,6 +24,7 @@ func TestAccAzureRMPrivateDnsMxRecord_basic(t *testing.T) { Config: testAccAzureRMPrivateDnsMxRecord_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMPrivateDnsMxRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, data.ImportStep(), @@ -185,6 +186,10 @@ func testCheckAzureRMPrivateDnsMxRecordDestroy(s *terraform.State) error { func testAccAzureRMPrivateDnsMxRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-prvdns-%d" location = "%s" @@ -192,13 +197,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "testzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_mx_record" "test" { name = "testaccmx%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record { preference = 10 @@ -215,6 +220,10 @@ resource "azurerm_private_dns_mx_record" "test" { func testAccAzureRMPrivateDnsMxRecord_emptyName(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-prvdns-%d" location = "%s" @@ -222,12 +231,12 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "testzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_mx_record" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record { preference = 10 @@ -248,9 +257,9 @@ func testAccAzureRMPrivateDnsMxRecord_requiresImport(data acceptance.TestData) s %s resource "azurerm_private_dns_mx_record" "import" { - name = "${azurerm_private_dns_mx_record.test.name}" - resource_group_name = "${azurerm_private_dns_mx_record.test.resource_group_name}" - zone_name = "${azurerm_private_dns_mx_record.test.zone_name}" + name = azurerm_private_dns_mx_record.test.name + resource_group_name = azurerm_private_dns_mx_record.test.resource_group_name + zone_name = azurerm_private_dns_mx_record.test.zone_name ttl = 300 record { preference = 10 @@ -266,6 +275,10 @@ resource "azurerm_private_dns_mx_record" "import" { func testAccAzureRMPrivateDnsMxRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-prvdns-%d" location = "%s" @@ -273,13 +286,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "testzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_mx_record" "test" { name = "testaccmx%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record { preference = 10 @@ -299,6 +312,10 @@ resource "azurerm_private_dns_mx_record" "test" { func testAccAzureRMPrivateDnsMxRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-prvdns-%d" location = "%s" @@ -306,13 +323,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "testzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_mx_record" "test" { name = "testaccmx%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record { preference = 10 @@ -333,6 +350,10 @@ resource "azurerm_private_dns_mx_record" "test" { func testAccAzureRMPrivateDnsMxRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-prvdns-%d" location = "%s" @@ -340,13 +361,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "testzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_mx_record" "test" { name = "testaccmx%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record { preference = 10 diff --git a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_ptr_record_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_ptr_record_test.go index a274708f3da33..482b8b67ce8e2 100644 --- a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_ptr_record_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_ptr_record_test.go @@ -24,6 +24,7 @@ func TestAccAzureRMPrivateDnsPtrRecord_basic(t *testing.T) { Config: testAccAzureRMPrivateDnsPtrRecord_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMPrivateDnsPtrRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, data.ImportStep(), @@ -167,6 +168,10 @@ func testCheckAzureRMPrivateDnsPtrRecordDestroy(s *terraform.State) error { func testAccAzureRMPrivateDnsPtrRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -174,13 +179,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "%d.0.10.in-addr.arpa" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_ptr_record" "test" { name = "%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 records = ["test.contoso.com", "test2.contoso.com"] } @@ -193,9 +198,9 @@ func testAccAzureRMPrivateDnsPtrRecord_requiresImport(data acceptance.TestData) %s resource "azurerm_private_dns_ptr_record" "import" { - name = "${azurerm_private_dns_ptr_record.test.name}" - resource_group_name = "${azurerm_private_dns_ptr_record.test.resource_group_name}" - zone_name = "${azurerm_private_dns_ptr_record.test.zone_name}" + name = azurerm_private_dns_ptr_record.test.name + resource_group_name = azurerm_private_dns_ptr_record.test.resource_group_name + zone_name = azurerm_private_dns_ptr_record.test.zone_name ttl = 300 records = ["test.contoso.com", "test2.contoso.com"] } @@ -204,6 +209,10 @@ resource "azurerm_private_dns_ptr_record" "import" { func testAccAzureRMPrivateDnsPtrRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -211,13 +220,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "%d.0.10.in-addr.arpa" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_ptr_record" "test" { name = "%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 records = ["test.contoso.com", "test2.contoso.com", "test3.contoso.com"] } @@ -226,6 +235,10 @@ resource "azurerm_private_dns_ptr_record" "test" { func testAccAzureRMPrivateDnsPtrRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -233,13 +246,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "%d.0.10.in-addr.arpa" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_ptr_record" "test" { name = "%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 records = ["test.contoso.com", "test2.contoso.com"] @@ -253,6 +266,10 @@ resource "azurerm_private_dns_ptr_record" "test" { func testAccAzureRMPrivateDnsPtrRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -260,13 +277,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "%d.0.10.in-addr.arpa" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_ptr_record" "test" { name = "%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 records = ["test.contoso.com", "test2.contoso.com"] diff --git a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_srv_record_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_srv_record_test.go index 3712f648cacb7..ca3561faeff67 100644 --- a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_srv_record_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_srv_record_test.go @@ -24,6 +24,7 @@ func TestAccAzureRMPrivateDnsSrvRecord_basic(t *testing.T) { Config: testAccAzureRMPrivateDnsSrvRecord_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMPrivateDnsSrvRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, data.ImportStep(), @@ -167,6 +168,10 @@ func testCheckAzureRMPrivateDnsSrvRecordDestroy(s *terraform.State) error { func testAccAzureRMPrivateDnsSrvRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-prvdns-%d" location = "%s" @@ -174,13 +179,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "testzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_srv_record" "test" { name = "testaccsrv%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record { priority = 1 @@ -205,9 +210,9 @@ func testAccAzureRMPrivateDnsSrvRecord_requiresImport(data acceptance.TestData) %s resource "azurerm_private_dns_srv_record" "import" { - name = "${azurerm_private_dns_srv_record.test.name}" - resource_group_name = "${azurerm_private_dns_srv_record.test.resource_group_name}" - zone_name = "${azurerm_private_dns_srv_record.test.zone_name}" + name = azurerm_private_dns_srv_record.test.name + resource_group_name = azurerm_private_dns_srv_record.test.resource_group_name + zone_name = azurerm_private_dns_srv_record.test.zone_name ttl = 300 record { priority = 1 @@ -227,6 +232,10 @@ resource "azurerm_private_dns_srv_record" "import" { func testAccAzureRMPrivateDnsSrvRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -234,13 +243,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "testzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_srv_record" "test" { name = "test%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record { priority = 1 @@ -266,6 +275,10 @@ resource "azurerm_private_dns_srv_record" "test" { func testAccAzureRMPrivateDnsSrvRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -273,13 +286,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "testzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_srv_record" "test" { name = "test%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record { priority = 1 @@ -304,6 +317,10 @@ resource "azurerm_private_dns_srv_record" "test" { func testAccAzureRMPrivateDnsSrvRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -311,13 +328,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "testzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_private_dns_srv_record" "test" { name = "test%d" - resource_group_name = "${azurerm_resource_group.test.name}" - zone_name = "${azurerm_private_dns_zone.test.name}" + resource_group_name = azurerm_resource_group.test.name + zone_name = azurerm_private_dns_zone.test.name ttl = 300 record { priority = 1 diff --git a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_test.go index 42766e390cf2c..dca6e005e30e6 100644 --- a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_test.go @@ -138,6 +138,10 @@ func testCheckAzureRMPrivateDnsZoneDestroy(s *terraform.State) error { func testAccAzureRMPrivateDnsZone_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -145,7 +149,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -156,14 +160,18 @@ func testAccAzureRMPrivateDnsZone_requiresImport(data acceptance.TestData) strin %s resource "azurerm_private_dns_zone" "import" { - name = "${azurerm_private_dns_zone.test.name}" - resource_group_name = "${azurerm_private_dns_zone.test.resource_group_name}" + name = azurerm_private_dns_zone.test.name + resource_group_name = azurerm_private_dns_zone.test.resource_group_name } `, template) } func testAccAzureRMPrivateDnsZone_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -171,7 +179,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name tags = { environment = "Production" @@ -183,6 +191,10 @@ resource "azurerm_private_dns_zone" "test" { func testAccAzureRMPrivateDnsZone_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -190,7 +202,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name tags = { environment = "staging" diff --git a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_virtual_network_link_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_virtual_network_link_test.go index 1b82e1e592e99..7e918a835f137 100644 --- a/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_virtual_network_link_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_virtual_network_link_test.go @@ -142,6 +142,10 @@ func testCheckAzureRMPrivateDnsZoneVirtualNetworkLinkDestroy(s *terraform.State) func testAccAzureRMPrivateDnsZoneVirtualNetworkLink_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -180,16 +184,20 @@ func testAccAzureRMPrivateDnsZoneVirtualNetworkLink_requiresImport(data acceptan %s resource "azurerm_private_dns_zone_virtual_network_link" "import" { - name = "${azurerm_private_dns_zone_virtual_network_link.test.name}" - private_dns_zone_name = "${azurerm_private_dns_zone_virtual_network_link.test.private_dns_zone_name}" - virtual_network_id = "${azurerm_private_dns_zone_virtual_network_link.test.virtual_network_id}" - resource_group_name = "${azurerm_private_dns_zone_virtual_network_link.test.resource_group_name}" + name = azurerm_private_dns_zone_virtual_network_link.test.name + private_dns_zone_name = azurerm_private_dns_zone_virtual_network_link.test.private_dns_zone_name + virtual_network_id = azurerm_private_dns_zone_virtual_network_link.test.virtual_network_id + resource_group_name = azurerm_private_dns_zone_virtual_network_link.test.resource_group_name } `, template) } func testAccAzureRMPrivateDnsZoneVirtualNetworkLink_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -228,6 +236,10 @@ resource "azurerm_private_dns_zone_virtual_network_link" "test" { func testAccAzureRMPrivateDnsZoneVirtualNetworkLink_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/recoveryservices/client/client.go b/azurerm/internal/services/recoveryservices/client/client.go index 39f6742ce031b..f4a8e0fb8c29f 100644 --- a/azurerm/internal/services/recoveryservices/client/client.go +++ b/azurerm/internal/services/recoveryservices/client/client.go @@ -23,7 +23,7 @@ type Client struct { } func NewClient(o *common.ClientOptions) *Client { - vaultConfigsClient := backup.NewResourceVaultConfigsClient(o.SubscriptionId) + vaultConfigsClient := backup.NewResourceVaultConfigsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&vaultConfigsClient.Client, o.ResourceManagerAuthorizer) vaultsClient := recoveryservices.NewVaultsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) diff --git a/azurerm/internal/services/recoveryservices/data_source_recovery_services_protection_policy_vm.go b/azurerm/internal/services/recoveryservices/data_source_backup_policy_vm.go similarity index 72% rename from azurerm/internal/services/recoveryservices/data_source_recovery_services_protection_policy_vm.go rename to azurerm/internal/services/recoveryservices/data_source_backup_policy_vm.go index 401ff7fa38a9a..626a073105c99 100644 --- a/azurerm/internal/services/recoveryservices/data_source_recovery_services_protection_policy_vm.go +++ b/azurerm/internal/services/recoveryservices/data_source_backup_policy_vm.go @@ -14,9 +14,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func dataSourceArmRecoveryServicesProtectionPolicyVm() *schema.Resource { +func dataSourceArmBackupPolicyVm() *schema.Resource { return &schema.Resource{ - Read: dataSourceArmRecoveryServicesProtectionPolicyVmRead, + Read: dataSourceArmBackupPolicyVmRead, Timeouts: &schema.ResourceTimeout{ Read: schema.DefaultTimeout(5 * time.Minute), @@ -41,7 +41,7 @@ func dataSourceArmRecoveryServicesProtectionPolicyVm() *schema.Resource { } } -func dataSourceArmRecoveryServicesProtectionPolicyVmRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceArmBackupPolicyVmRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).RecoveryServices.ProtectionPoliciesClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() @@ -50,15 +50,15 @@ func dataSourceArmRecoveryServicesProtectionPolicyVmRead(d *schema.ResourceData, resourceGroup := d.Get("resource_group_name").(string) vaultName := d.Get("recovery_vault_name").(string) - log.Printf("[DEBUG] Reading Recovery Service Protection Policy %q (resource group %q)", name, resourceGroup) + log.Printf("[DEBUG] Reading Recovery Service Policy %q (resource group %q)", name, resourceGroup) protectionPolicy, err := client.Get(ctx, vaultName, resourceGroup, name) if err != nil { if utils.ResponseWasNotFound(protectionPolicy.Response) { - return fmt.Errorf("Error: Recovery Services Protection Policy %q (Resource Group %q) was not found", name, resourceGroup) + return fmt.Errorf("Error: Backup Policy %q (Resource Group %q) was not found", name, resourceGroup) } - return fmt.Errorf("Error making Read request on Recovery Service Protection Policy %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("Error making Read request on Backup Policy %q (Resource Group %q): %+v", name, resourceGroup, err) } id := strings.Replace(*protectionPolicy.ID, "Subscriptions", "subscriptions", 1) diff --git a/azurerm/internal/services/recoveryservices/registration.go b/azurerm/internal/services/recoveryservices/registration.go index c2c497c382169..4ad4baf1c1ed1 100644 --- a/azurerm/internal/services/recoveryservices/registration.go +++ b/azurerm/internal/services/recoveryservices/registration.go @@ -11,36 +11,35 @@ func (r Registration) Name() string { return "Recovery Services" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Recovery Services", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_recovery_services_vault": dataSourceArmRecoveryServicesVault(), - "azurerm_recovery_services_protection_policy_vm": dataSourceArmRecoveryServicesProtectionPolicyVm(), + "azurerm_recovery_services_vault": dataSourceArmRecoveryServicesVault(), + "azurerm_backup_policy_vm": dataSourceArmBackupPolicyVm(), } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_backup_container_storage_account": resourceArmBackupProtectionContainerStorageAccount(), - "azurerm_backup_policy_file_share": resourceArmBackupProtectionPolicyFileShare(), - "azurerm_backup_protected_file_share": resourceArmBackupProtectedFileShare(), - "azurerm_backup_protected_vm": resourceArmRecoveryServicesBackupProtectedVM(), - "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), - "azurerm_recovery_network_mapping": resourceArmRecoveryServicesNetworkMapping(), - "azurerm_recovery_replicated_vm": resourceArmRecoveryServicesReplicatedVm(), - "azurerm_recovery_services_fabric": resourceArmRecoveryServicesFabric(), - "azurerm_recovery_services_protected_vm": resourceArmRecoveryServicesProtectedVm(), - "azurerm_recovery_services_protection_container": resourceArmRecoveryServicesProtectionContainer(), - "azurerm_recovery_services_protection_container_mapping": resourceArmRecoveryServicesProtectionContainerMapping(), - "azurerm_recovery_services_protection_policy_vm": resourceArmRecoveryServicesProtectionPolicyVm(), - "azurerm_recovery_services_replication_policy": resourceArmRecoveryServicesReplicationPolicy(), - "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), - "azurerm_site_recovery_fabric": resourceArmSiteRecoveryFabric(), - "azurerm_site_recovery_network_mapping": resourceArmSiteRecoveryNetworkMapping(), - "azurerm_site_recovery_protection_container": resourceArmSiteRecoveryProtectionContainer(), - "azurerm_site_recovery_protection_container_mapping": resourceArmSiteRecoveryProtectionContainerMapping(), - "azurerm_site_recovery_replicated_vm": resourceArmSiteRecoveryReplicatedVM(), - "azurerm_site_recovery_replication_policy": resourceArmSiteRecoveryReplicationPolicy(), + "azurerm_backup_container_storage_account": resourceArmBackupProtectionContainerStorageAccount(), + "azurerm_backup_policy_file_share": resourceArmBackupProtectionPolicyFileShare(), + "azurerm_backup_protected_file_share": resourceArmBackupProtectedFileShare(), + "azurerm_backup_protected_vm": resourceArmRecoveryServicesBackupProtectedVM(), + "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), + "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), + "azurerm_site_recovery_fabric": resourceArmSiteRecoveryFabric(), + "azurerm_site_recovery_network_mapping": resourceArmSiteRecoveryNetworkMapping(), + "azurerm_site_recovery_protection_container": resourceArmSiteRecoveryProtectionContainer(), + "azurerm_site_recovery_protection_container_mapping": resourceArmSiteRecoveryProtectionContainerMapping(), + "azurerm_site_recovery_replicated_vm": resourceArmSiteRecoveryReplicatedVM(), + "azurerm_site_recovery_replication_policy": resourceArmSiteRecoveryReplicationPolicy(), } } diff --git a/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share.go index 82e0ecc20e19c..d2d0b921714e7 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share.go @@ -87,7 +87,7 @@ func resourceArmBackupProtectionPolicyFileShare() *schema.Resource { Type: schema.TypeString, Required: true, ValidateFunc: validation.StringMatch( - regexp.MustCompile("^([01][0-9]|[2][0-3]):([03][0])$"), //time must be on the hour or half past + regexp.MustCompile("^([01][0-9]|[2][0-3]):([03][0])$"), // time must be on the hour or half past "Time of day must match the format HH:mm where HH is 00-23 and mm is 00 or 30", ), }, @@ -124,7 +124,7 @@ func resourceArmBackupProtectionPolicyFileShareCreateUpdate(d *schema.ResourceDa log.Printf("[DEBUG] Creating/updating Recovery Service Protection Policy %s (resource group %q)", policyName, resourceGroup) - //getting this ready now because its shared between *everything*, time is... complicated for this resource + // getting this ready now because its shared between *everything*, time is... complicated for this resource timeOfDay := d.Get("backup.0.time").(string) dateOfDay, err := time.Parse(time.RFC3339, fmt.Sprintf("2018-07-30T%s:00Z", timeOfDay)) if err != nil { @@ -151,7 +151,7 @@ func resourceArmBackupProtectionPolicyFileShareCreateUpdate(d *schema.ResourceDa BackupManagementType: backup.BackupManagementTypeAzureStorage, WorkLoadType: backup.WorkloadTypeAzureFileShare, SchedulePolicy: expandArmBackupProtectionPolicyFileShareSchedule(d, times), - RetentionPolicy: &backup.LongTermRetentionPolicy{ //SimpleRetentionPolicy only has duration property ¯\_(ツ)_/¯ + RetentionPolicy: &backup.LongTermRetentionPolicy{ // SimpleRetentionPolicy only has duration property ¯\_(ツ)_/¯ RetentionPolicyType: backup.RetentionPolicyTypeLongTermRetentionPolicy, DailySchedule: expandArmBackupProtectionPolicyFileShareRetentionDaily(d, times), }, @@ -259,7 +259,7 @@ func expandArmBackupProtectionPolicyFileShareSchedule(d *schema.ResourceData, ti if bb, ok := d.Get("backup").([]interface{}); ok && len(bb) > 0 { block := bb[0].(map[string]interface{}) - schedule := backup.SimpleSchedulePolicy{ //LongTermSchedulePolicy has no properties + schedule := backup.SimpleSchedulePolicy{ // LongTermSchedulePolicy has no properties SchedulePolicyType: backup.SchedulePolicyTypeSimpleSchedulePolicy, ScheduleRunTimes: ×, } diff --git a/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm.go index ab6a31120502a..f0a91ba7b4ff8 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm.go @@ -17,7 +17,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/set" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" @@ -87,23 +86,23 @@ func resourceArmBackupProtectionPolicyVM() *schema.Resource { }, true), }, - "time": { //applies to all backup schedules & retention times (they all must be the same) + "time": { // applies to all backup schedules & retention times (they all must be the same) Type: schema.TypeString, Required: true, ValidateFunc: validation.StringMatch( - regexp.MustCompile("^([01][0-9]|[2][0-3]):([03][0])$"), //time must be on the hour or half past + regexp.MustCompile("^([01][0-9]|[2][0-3]):([03][0])$"), // time must be on the hour or half past "Time of day must match the format HH:mm where HH is 00-23 and mm is 00 or 30", ), }, - "weekdays": { //only for weekly + "weekdays": { // only for weekly Type: schema.TypeSet, Optional: true, Set: set.HashStringIgnoreCase, Elem: &schema.Schema{ Type: schema.TypeString, DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validate.DayOfTheWeek(true), + ValidateFunc: validation.IsDayOfTheWeek(true), }, }, }, @@ -144,7 +143,7 @@ func resourceArmBackupProtectionPolicyVM() *schema.Resource { Elem: &schema.Schema{ Type: schema.TypeString, DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validate.DayOfTheWeek(true), + ValidateFunc: validation.IsDayOfTheWeek(true), }, }, }, @@ -187,7 +186,7 @@ func resourceArmBackupProtectionPolicyVM() *schema.Resource { Elem: &schema.Schema{ Type: schema.TypeString, DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validate.DayOfTheWeek(true), + ValidateFunc: validation.IsDayOfTheWeek(true), }, }, }, @@ -213,7 +212,7 @@ func resourceArmBackupProtectionPolicyVM() *schema.Resource { Elem: &schema.Schema{ Type: schema.TypeString, DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validate.Month(true), + ValidateFunc: validation.IsMonth(true), }, }, @@ -241,7 +240,7 @@ func resourceArmBackupProtectionPolicyVM() *schema.Resource { Elem: &schema.Schema{ Type: schema.TypeString, DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validate.DayOfTheWeek(true), + ValidateFunc: validation.IsDayOfTheWeek(true), }, }, }, @@ -251,8 +250,8 @@ func resourceArmBackupProtectionPolicyVM() *schema.Resource { "tags": tags.Schema(), }, - //if daily, we need daily retention - //if weekly daily cannot be set, and we need weekly + // if daily, we need daily retention + // if weekly daily cannot be set, and we need weekly CustomizeDiff: func(diff *schema.ResourceDiff, v interface{}) error { _, hasDaily := diff.GetOk("retention_daily") _, hasWeekly := diff.GetOk("retention_weekly") @@ -295,7 +294,7 @@ func resourceArmBackupProtectionPolicyVMCreateUpdate(d *schema.ResourceData, met log.Printf("[DEBUG] Creating/updating Azure Backup Protection Policy %s (resource group %q)", policyName, resourceGroup) - //getting this ready now because its shared between *everything*, time is... complicated for this resource + // getting this ready now because its shared between *everything*, time is... complicated for this resource timeOfDay := d.Get("backup.0.time").(string) dateOfDay, err := time.Parse(time.RFC3339, fmt.Sprintf("2018-07-30T%s:00Z", timeOfDay)) if err != nil { @@ -322,7 +321,7 @@ func resourceArmBackupProtectionPolicyVMCreateUpdate(d *schema.ResourceData, met TimeZone: utils.String(d.Get("timezone").(string)), BackupManagementType: backup.BackupManagementTypeAzureIaasVM, SchedulePolicy: expandArmBackupProtectionPolicyVMSchedule(d, times), - RetentionPolicy: &backup.LongTermRetentionPolicy{ //SimpleRetentionPolicy only has duration property ¯\_(ツ)_/¯ + RetentionPolicy: &backup.LongTermRetentionPolicy{ // SimpleRetentionPolicy only has duration property ¯\_(ツ)_/¯ RetentionPolicyType: backup.RetentionPolicyTypeLongTermRetentionPolicy, DailySchedule: expandArmBackupProtectionPolicyVMRetentionDaily(d, times), WeeklySchedule: expandArmBackupProtectionPolicyVMRetentionWeekly(d, times), @@ -457,7 +456,7 @@ func expandArmBackupProtectionPolicyVMSchedule(d *schema.ResourceData, times []d if bb, ok := d.Get("backup").([]interface{}); ok && len(bb) > 0 { block := bb[0].(map[string]interface{}) - schedule := backup.SimpleSchedulePolicy{ //LongTermSchedulePolicy has no properties + schedule := backup.SimpleSchedulePolicy{ // LongTermSchedulePolicy has no properties SchedulePolicyType: backup.SchedulePolicyTypeSimpleSchedulePolicy, ScheduleRunTimes: ×, } @@ -527,8 +526,8 @@ func expandArmBackupProtectionPolicyVMRetentionMonthly(d *schema.ResourceData, t block := rb[0].(map[string]interface{}) retention := backup.MonthlyRetentionSchedule{ - RetentionScheduleFormatType: backup.RetentionScheduleFormatWeekly, //this is always weekly ¯\_(ツ)_/¯ - RetentionScheduleDaily: nil, //and this is always nil.. + RetentionScheduleFormatType: backup.RetentionScheduleFormatWeekly, // this is always weekly ¯\_(ツ)_/¯ + RetentionScheduleDaily: nil, // and this is always nil.. RetentionScheduleWeekly: expandArmBackupProtectionPolicyVMRetentionWeeklyFormat(block), RetentionTimes: ×, RetentionDuration: &backup.RetentionDuration{ @@ -548,8 +547,8 @@ func expandArmBackupProtectionPolicyVMRetentionYearly(d *schema.ResourceData, ti block := rb[0].(map[string]interface{}) retention := backup.YearlyRetentionSchedule{ - RetentionScheduleFormatType: backup.RetentionScheduleFormatWeekly, //this is always weekly ¯\_(ツ)_/¯ - RetentionScheduleDaily: nil, //and this is always nil.. + RetentionScheduleFormatType: backup.RetentionScheduleFormatWeekly, // this is always weekly ¯\_(ツ)_/¯ + RetentionScheduleDaily: nil, // and this is always nil.. RetentionScheduleWeekly: expandArmBackupProtectionPolicyVMRetentionWeeklyFormat(block), RetentionTimes: ×, RetentionDuration: &backup.RetentionDuration{ diff --git a/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share.go index 550205b18ecb7..56d8dd3fd5211 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share.go @@ -84,7 +84,7 @@ func resourceArmBackupProtectedFileShareCreateUpdate(d *schema.ResourceData, met fileShareName := d.Get("source_file_share_name").(string) policyID := d.Get("backup_policy_id").(string) - //get storage account name from id + // get storage account name from id parsedStorageAccountID, err := azure.ParseAzureResourceID(storageAccountID) if err != nil { return fmt.Errorf("[ERROR] Unable to parse source_storage_account_id '%s': %+v", storageAccountID, err) diff --git a/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm.go index 36f3c38584f8c..3bc9098f237c1 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm.go @@ -78,7 +78,7 @@ func resourceArmRecoveryServicesBackupProtectedVMCreateUpdate(d *schema.Resource vmId := d.Get("source_vm_id").(string) policyId := d.Get("backup_policy_id").(string) - //get VM name from id + // get VM name from id parsedVmId, err := azure.ParseAzureResourceID(vmId) if err != nil { return fmt.Errorf("[ERROR] Unable to parse source_vm_id '%s': %+v", vmId, err) diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_fabric.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_fabric.go deleted file mode 100644 index bb0d6e00b0b8f..0000000000000 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_fabric.go +++ /dev/null @@ -1,164 +0,0 @@ -package recoveryservices - -import ( - "fmt" - "time" - - "github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-01-10/siterecovery" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmRecoveryServicesFabric() *schema.Resource { - return &schema.Resource{ - DeprecationMessage: "`azurerm_recovery_services_fabric` resource is deprecated in favor of `azurerm_site_recovery_fabric` and will be removed in v2.0 of the AzureRM Provider", - Create: resourceArmRecoveryServicesFabricCreate, - Read: resourceArmRecoveryServicesFabricRead, - Update: nil, - Delete: resourceArmRecoveryServicesFabricDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "resource_group_name": azure.SchemaResourceGroupName(), - - "recovery_vault_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateRecoveryServicesVaultName, - }, - "location": azure.SchemaLocation(), - }, - } -} - -func resourceArmRecoveryServicesFabricCreate(d *schema.ResourceData, meta interface{}) error { - resGroup := d.Get("resource_group_name").(string) - vaultName := d.Get("recovery_vault_name").(string) - location := azure.NormalizeLocation(d.Get("location").(string)) - name := d.Get("name").(string) - - client := meta.(*clients.Client).RecoveryServices.FabricClient(resGroup, vaultName) - ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) - defer cancel() - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing rec overy services fabric %s (vault %s): %+v", name, vaultName, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_resource_group", azure.HandleAzureSdkForGoBug2824(*existing.ID)) - } - } - - parameters := siterecovery.FabricCreationInput{ - Properties: &siterecovery.FabricCreationInputProperties{ - CustomDetails: siterecovery.AzureFabricCreationInput{ - InstanceType: "Azure", - Location: &location, - }, - }, - } - - future, err := client.Create(ctx, name, parameters) - if err != nil { - return fmt.Errorf("Error creating recovery services fabric %s (vault %s): %+v", name, vaultName, err) - } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error creating recovery services fabric %s (vault %s): %+v", name, vaultName, err) - } - - resp, err := client.Get(ctx, name) - if err != nil { - return fmt.Errorf("Error retrieving recovery services fabric %s (vault %s): %+v", name, vaultName, err) - } - - d.SetId(azure.HandleAzureSdkForGoBug2824(*resp.ID)) - - return resourceArmRecoveryServicesFabricRead(d, meta) -} - -func resourceArmRecoveryServicesFabricRead(d *schema.ResourceData, meta interface{}) error { - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - resGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - name := id.Path["replicationFabrics"] - - client := meta.(*clients.Client).RecoveryServices.FabricClient(resGroup, vaultName) - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - resp, err := client.Get(ctx, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil - } - return fmt.Errorf("Error making Read request on recovery services fabric %s (vault %s): %+v", name, vaultName, err) - } - - d.Set("name", resp.Name) - d.Set("resource_group_name", resGroup) - if props := resp.Properties; props != nil { - if azureDetails, isAzureDetails := props.CustomDetails.AsAzureFabricSpecificDetails(); isAzureDetails { - d.Set("location", azureDetails.Location) - } - } - d.Set("recovery_vault_name", vaultName) - return nil -} - -func resourceArmRecoveryServicesFabricDelete(d *schema.ResourceData, meta interface{}) error { - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - resGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - name := id.Path["replicationFabrics"] - - client := meta.(*clients.Client).RecoveryServices.FabricClient(resGroup, vaultName) - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - future, err := client.Delete(ctx, name) - if err != nil { - return fmt.Errorf("Error deleting recovery services fabric %s (vault %s): %+v", name, vaultName, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for deletion of recovery services fabric %s (vault %s): %+v", name, vaultName, err) - } - - return nil -} diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_network_mapping.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_network_mapping.go deleted file mode 100644 index fc6a4d24a3ba8..0000000000000 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_network_mapping.go +++ /dev/null @@ -1,216 +0,0 @@ -package recoveryservices - -import ( - "fmt" - "time" - - "github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-01-10/siterecovery" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmRecoveryServicesNetworkMapping() *schema.Resource { - return &schema.Resource{ - DeprecationMessage: "`azurerm_recovery_network_mapping` resource is deprecated in favor of `azurerm_site_recovery_network_mapping` and will be removed in v2.0 of the AzureRM Provider", - Create: resourceArmRecoveryNetworkMappingCreate, - Read: resourceArmRecoveryNetworkMappingRead, - Delete: resourceArmRecoveryNetworkMappingDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "resource_group_name": azure.SchemaResourceGroupName(), - - "recovery_vault_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateRecoveryServicesVaultName, - }, - "source_recovery_fabric_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "target_recovery_fabric_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "source_network_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, - }, - "target_network_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, - }, - }, - } -} - -func resourceArmRecoveryNetworkMappingCreate(d *schema.ResourceData, meta interface{}) error { - resGroup := d.Get("resource_group_name").(string) - vaultName := d.Get("recovery_vault_name").(string) - fabricName := d.Get("source_recovery_fabric_name").(string) - targetFabricName := d.Get("target_recovery_fabric_name").(string) - sourceNetworkId := d.Get("source_network_id").(string) - targetNetworkId := d.Get("target_network_id").(string) - name := d.Get("name").(string) - - client := meta.(*clients.Client).RecoveryServices.NetworkMappingClient(resGroup, vaultName) - ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) - defer cancel() - - //get network name from id - parsedSourceNetworkId, err := azure.ParseAzureResourceID(sourceNetworkId) - if err != nil { - return fmt.Errorf("[ERROR] Unable to parse source_network_id '%s' (network mapping %s): %+v", sourceNetworkId, name, err) - } - sourceNetworkName, hasName := parsedSourceNetworkId.Path["virtualNetworks"] - if !hasName { - sourceNetworkName, hasName = parsedSourceNetworkId.Path["virtualnetworks"] // Handle that different APIs return different ID casings - if !hasName { - return fmt.Errorf("[ERROR] parsed source_network_id '%s' doesn't contain 'virtualnetworks'", parsedSourceNetworkId) - } - } - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, fabricName, sourceNetworkName, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing recovery services fabric %s (vault %s): %+v", name, vaultName, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_recovery_network_mapping", azure.HandleAzureSdkForGoBug2824(*existing.ID)) - } - } - - var parameters = siterecovery.CreateNetworkMappingInput{ - Properties: &siterecovery.CreateNetworkMappingInputProperties{ - RecoveryNetworkID: &targetNetworkId, - RecoveryFabricName: &targetFabricName, - FabricSpecificDetails: siterecovery.AzureToAzureCreateNetworkMappingInput{ - PrimaryNetworkID: &sourceNetworkId, - }, - }, - } - future, err := client.Create(ctx, fabricName, sourceNetworkName, name, parameters) - if err != nil { - return fmt.Errorf("Error creating recovery network mapping %s (vault %s): %+v", name, vaultName, err) - } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error creating recovery network mapping %s (vault %s): %+v", name, vaultName, err) - } - - resp, err := client.Get(ctx, fabricName, sourceNetworkName, name) - if err != nil { - return fmt.Errorf("Error retrieving recovery network mapping %s (vault %s): %+v", name, vaultName, err) - } - - d.SetId(azure.HandleAzureSdkForGoBug2824(*resp.ID)) - - return resourceArmRecoveryNetworkMappingRead(d, meta) -} - -func resourceArmRecoveryNetworkMappingRead(d *schema.ResourceData, meta interface{}) error { - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - resGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - fabricName := id.Path["replicationFabrics"] - networkName := id.Path["replicationNetworks"] - name := id.Path["replicationNetworkMappings"] - - client := meta.(*clients.Client).RecoveryServices.NetworkMappingClient(resGroup, vaultName) - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - resp, err := client.Get(ctx, fabricName, networkName, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil - } - return fmt.Errorf("Error making Read request on recovery services protection container mapping %s (vault %s): %+v", name, vaultName, err) - } - - d.Set("resource_group_name", resGroup) - d.Set("recovery_vault_name", vaultName) - d.Set("source_recovery_fabric_name", fabricName) - d.Set("name", resp.Name) - if props := resp.Properties; props != nil { - d.Set("source_network_id", props.PrimaryNetworkID) - d.Set("target_network_id", props.RecoveryNetworkID) - - targetFabricId, err := azure.ParseAzureResourceID(azure.HandleAzureSdkForGoBug2824(*resp.Properties.RecoveryFabricArmID)) - if err != nil { - return err - } - d.Set("target_recovery_fabric_name", targetFabricId.Path["replicationFabrics"]) - } - - return nil -} - -func resourceArmRecoveryNetworkMappingDelete(d *schema.ResourceData, meta interface{}) error { - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - resGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - fabricName := id.Path["replicationFabrics"] - networkName := id.Path["replicationNetworks"] - name := id.Path["replicationNetworkMappings"] - - client := meta.(*clients.Client).RecoveryServices.NetworkMappingClient(resGroup, vaultName) - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - future, err := client.Delete(ctx, fabricName, networkName, name) - if err != nil { - return fmt.Errorf("Error deleting recovery services protection container mapping %s (vault %s): %+v", name, vaultName, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for deletion of recovery services protection container mapping %s (vault %s): %+v", name, vaultName, err) - } - - return nil -} diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protected_vm.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protected_vm.go deleted file mode 100644 index 68181b97366c5..0000000000000 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protected_vm.go +++ /dev/null @@ -1,283 +0,0 @@ -package recoveryservices - -import ( - "context" - "fmt" - "log" - "strings" - "time" - - "github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2019-05-13/backup" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmRecoveryServicesProtectedVm() *schema.Resource { - return &schema.Resource{ - DeprecationMessage: "`azurerm_recovery_services_protected_vm` resource is deprecated in favor of `azurerm_backup_protected_vm` and will be removed in v2.0 of the AzureRM Provider", - Create: resourceArmRecoveryServicesProtectedVmCreateUpdate, - Read: resourceArmRecoveryServicesProtectedVmRead, - Update: resourceArmRecoveryServicesProtectedVmCreateUpdate, - Delete: resourceArmRecoveryServicesProtectedVmDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(80 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(80 * time.Minute), - Delete: schema.DefaultTimeout(80 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - - "resource_group_name": azure.SchemaResourceGroupName(), - - "recovery_vault_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateRecoveryServicesVaultName, - }, - - "source_vm_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - }, - - "backup_policy_id": { - Type: schema.TypeString, - Required: true, - ValidateFunc: azure.ValidateResourceID, - }, - - "tags": tags.Schema(), - }, - } -} - -func resourceArmRecoveryServicesProtectedVmCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).RecoveryServices.ProtectedItemsClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - resourceGroup := d.Get("resource_group_name").(string) - t := d.Get("tags").(map[string]interface{}) - - vaultName := d.Get("recovery_vault_name").(string) - vmId := d.Get("source_vm_id").(string) - policyId := d.Get("backup_policy_id").(string) - - //get VM name from id - parsedVmId, err := azure.ParseAzureResourceID(vmId) - if err != nil { - return fmt.Errorf("[ERROR] Unable to parse source_vm_id '%s': %+v", vmId, err) - } - vmName, hasName := parsedVmId.Path["virtualMachines"] - if !hasName { - return fmt.Errorf("[ERROR] parsed source_vm_id '%s' doesn't contain 'virtualMachines'", vmId) - } - - protectedItemName := fmt.Sprintf("VM;iaasvmcontainerv2;%s;%s", parsedVmId.ResourceGroup, vmName) - containerName := fmt.Sprintf("iaasvmcontainer;iaasvmcontainerv2;%s;%s", parsedVmId.ResourceGroup, vmName) - - log.Printf("[DEBUG] Creating/updating Recovery Service Protected VM %s (resource group %q)", protectedItemName, resourceGroup) - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err2 := client.Get(ctx, vaultName, resourceGroup, "Azure", containerName, protectedItemName, "") - if err2 != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing Recovery Service Protected VM %q (Resource Group %q): %+v", protectedItemName, resourceGroup, err2) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_recovery_services_protected_vm", *existing.ID) - } - } - - item := backup.ProtectedItemResource{ - Tags: tags.Expand(t), - Properties: &backup.AzureIaaSComputeVMProtectedItem{ - PolicyID: &policyId, - ProtectedItemType: backup.ProtectedItemTypeMicrosoftClassicComputevirtualMachines, - WorkloadType: backup.DataSourceTypeVM, - SourceResourceID: utils.String(vmId), - FriendlyName: utils.String(vmName), - VirtualMachineID: utils.String(vmId), - }, - } - - if _, err = client.CreateOrUpdate(ctx, vaultName, resourceGroup, "Azure", containerName, protectedItemName, item); err != nil { - return fmt.Errorf("Error creating/updating Recovery Service Protected VM %q (Resource Group %q): %+v", protectedItemName, resourceGroup, err) - } - - resp, err := resourceArmRecoveryServicesProtectedVmWaitForStateCreateUpdate(ctx, client, vaultName, resourceGroup, containerName, protectedItemName, policyId, d) - if err != nil { - return err - } - - id := strings.Replace(*resp.ID, "Subscriptions", "subscriptions", 1) // This code is a workaround for this bug https://github.com/Azure/azure-sdk-for-go/issues/2824 - d.SetId(id) - - return resourceArmRecoveryServicesProtectedVmRead(d, meta) -} - -func resourceArmRecoveryServicesProtectedVmRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).RecoveryServices.ProtectedItemsClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - protectedItemName := id.Path["protectedItems"] - vaultName := id.Path["vaults"] - resourceGroup := id.ResourceGroup - containerName := id.Path["protectionContainers"] - - log.Printf("[DEBUG] Reading Recovery Service Protected VM %q (resource group %q)", protectedItemName, resourceGroup) - - resp, err := client.Get(ctx, vaultName, resourceGroup, "Azure", containerName, protectedItemName, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil - } - - return fmt.Errorf("Error making Read request on Recovery Service Protected VM %q (Resource Group %q): %+v", protectedItemName, resourceGroup, err) - } - - d.Set("resource_group_name", resourceGroup) - d.Set("recovery_vault_name", vaultName) - - if properties := resp.Properties; properties != nil { - if vm, ok := properties.AsAzureIaaSComputeVMProtectedItem(); ok { - d.Set("source_vm_id", vm.SourceResourceID) - - if v := vm.PolicyID; v != nil { - d.Set("backup_policy_id", strings.Replace(*v, "Subscriptions", "subscriptions", 1)) - } - } - } - - return tags.FlattenAndSet(d, resp.Tags) -} - -func resourceArmRecoveryServicesProtectedVmDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).RecoveryServices.ProtectedItemsClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - protectedItemName := id.Path["protectedItems"] - resourceGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - containerName := id.Path["protectionContainers"] - - log.Printf("[DEBUG] Deleting Recovery Service Protected Item %q (resource group %q)", protectedItemName, resourceGroup) - - resp, err := client.Delete(ctx, vaultName, resourceGroup, "Azure", containerName, protectedItemName) - if err != nil { - if !utils.ResponseWasNotFound(resp) { - return fmt.Errorf("Error issuing delete request for Recovery Service Protected VM %q (Resource Group %q): %+v", protectedItemName, resourceGroup, err) - } - } - - if _, err := resourceArmRecoveryServicesProtectedVmWaitForDeletion(ctx, client, vaultName, resourceGroup, containerName, protectedItemName, "", d); err != nil { - return err - } - - return nil -} - -func resourceArmRecoveryServicesProtectedVmWaitForStateCreateUpdate(ctx context.Context, client *backup.ProtectedItemsClient, vaultName, resourceGroup, containerName, protectedItemName string, policyId string, d *schema.ResourceData) (backup.ProtectedItemResource, error) { - state := &resource.StateChangeConf{ - MinTimeout: 30 * time.Second, - Delay: 10 * time.Second, - Pending: []string{"NotFound"}, - Target: []string{"Found"}, - Refresh: resourceArmRecoveryServicesProtectedVmRefreshFunc(ctx, client, vaultName, resourceGroup, containerName, protectedItemName, policyId, true), - } - - if d.IsNewResource() { - state.Timeout = d.Timeout(schema.TimeoutCreate) - } else { - state.Timeout = d.Timeout(schema.TimeoutUpdate) - } - - resp, err := state.WaitForState() - if err != nil { - i, _ := resp.(backup.ProtectedItemResource) - return i, fmt.Errorf("Error waiting for the Recovery Service Protected VM %q to be true (Resource Group %q) to provision: %+v", protectedItemName, resourceGroup, err) - } - - return resp.(backup.ProtectedItemResource), nil -} - -func resourceArmRecoveryServicesProtectedVmWaitForDeletion(ctx context.Context, client *backup.ProtectedItemsClient, vaultName, resourceGroup, containerName, protectedItemName string, policyId string, d *schema.ResourceData) (backup.ProtectedItemResource, error) { - state := &resource.StateChangeConf{ - MinTimeout: 30 * time.Second, - Delay: 10 * time.Second, - Pending: []string{"Found"}, - Target: []string{"NotFound"}, - Refresh: resourceArmRecoveryServicesProtectedVmRefreshFunc(ctx, client, vaultName, resourceGroup, containerName, protectedItemName, policyId, false), - Timeout: d.Timeout(schema.TimeoutDelete), - } - - resp, err := state.WaitForState() - if err != nil { - i, _ := resp.(backup.ProtectedItemResource) - return i, fmt.Errorf("Error waiting for the Recovery Service Protected VM %q to be false (Resource Group %q) to provision: %+v", protectedItemName, resourceGroup, err) - } - - return resp.(backup.ProtectedItemResource), nil -} - -func resourceArmRecoveryServicesProtectedVmRefreshFunc(ctx context.Context, client *backup.ProtectedItemsClient, vaultName, resourceGroup, containerName, protectedItemName string, policyId string, newResource bool) resource.StateRefreshFunc { - // TODO: split this into two functions - return func() (interface{}, string, error) { - resp, err := client.Get(ctx, vaultName, resourceGroup, "Azure", containerName, protectedItemName, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return resp, "NotFound", nil - } - - return resp, "Error", fmt.Errorf("Error making Read request on Recovery Service Protected VM %q (Resource Group %q): %+v", protectedItemName, resourceGroup, err) - } else if !newResource && policyId != "" { - if properties := resp.Properties; properties != nil { - if vm, ok := properties.AsAzureIaaSComputeVMProtectedItem(); ok { - if v := vm.PolicyID; v != nil { - if strings.Replace(*v, "Subscriptions", "subscriptions", 1) != policyId { - return resp, "NotFound", nil - } - } else { - return resp, "Error", fmt.Errorf("Error reading policy ID attribute nil on Recovery Service Protected VM %q (Resource Group %q)", protectedItemName, resourceGroup) - } - } else { - return resp, "Error", fmt.Errorf("Error reading properties on Recovery Service Protected VM %q (Resource Group %q)", protectedItemName, resourceGroup) - } - } else { - return resp, "Error", fmt.Errorf("Error reading properties on empty Recovery Service Protected VM %q (Resource Group %q)", protectedItemName, resourceGroup) - } - } - return resp, "Found", nil - } -} diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container.go deleted file mode 100644 index f31bbd4c16266..0000000000000 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container.go +++ /dev/null @@ -1,162 +0,0 @@ -package recoveryservices - -import ( - "fmt" - "time" - - "github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-01-10/siterecovery" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmRecoveryServicesProtectionContainer() *schema.Resource { - return &schema.Resource{ - DeprecationMessage: "`azurerm_recovery_services_protection_container` resource is deprecated in favor of `azurerm_site_recovery_protection_container` and will be removed in v2.0 of the AzureRM Provider", - Create: resourceArmRecoveryServicesProtectionContainerCreate, - Read: resourceArmRecoveryServicesProtectionContainerRead, - Update: nil, - Delete: resourceArmRecoveryServicesProtectionContainerDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "resource_group_name": azure.SchemaResourceGroupName(), - - "recovery_vault_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateRecoveryServicesVaultName, - }, - "recovery_fabric_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - }, - } -} - -func resourceArmRecoveryServicesProtectionContainerCreate(d *schema.ResourceData, meta interface{}) error { - resGroup := d.Get("resource_group_name").(string) - vaultName := d.Get("recovery_vault_name").(string) - fabricName := d.Get("recovery_fabric_name").(string) - name := d.Get("name").(string) - - client := meta.(*clients.Client).RecoveryServices.ProtectionContainerClient(resGroup, vaultName) - ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) - defer cancel() - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, fabricName, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing recovery services protection container %s (fabric %s): %+v", name, fabricName, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_recovery_services_protection_container", azure.HandleAzureSdkForGoBug2824(*existing.ID)) - } - } - - parameters := siterecovery.CreateProtectionContainerInput{ - Properties: &siterecovery.CreateProtectionContainerInputProperties{}, - } - - future, err := client.Create(ctx, fabricName, name, parameters) - if err != nil { - return fmt.Errorf("Error creating recovery services protection container %s (fabric %s): %+v", name, fabricName, err) - } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error creating recovery services protection container %s (fabric %s): %+v", name, fabricName, err) - } - - resp, err := client.Get(ctx, fabricName, name) - if err != nil { - return fmt.Errorf("Error retrieving site recovery protection container %s (fabric %s): %+v", name, fabricName, err) - } - - d.SetId(azure.HandleAzureSdkForGoBug2824(*resp.ID)) - - return resourceArmRecoveryServicesProtectionContainerRead(d, meta) -} - -func resourceArmRecoveryServicesProtectionContainerRead(d *schema.ResourceData, meta interface{}) error { - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - resGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - fabricName := id.Path["replicationFabrics"] - name := id.Path["replicationProtectionContainers"] - - client := meta.(*clients.Client).RecoveryServices.ProtectionContainerClient(resGroup, vaultName) - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - resp, err := client.Get(ctx, fabricName, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil - } - return fmt.Errorf("Error making Read request on recovery services protection container %s (fabric %s): %+v", name, fabricName, err) - } - - d.Set("name", resp.Name) - d.Set("resource_group_name", resGroup) - d.Set("recovery_vault_name", vaultName) - d.Set("recovery_fabric_name", fabricName) - return nil -} - -func resourceArmRecoveryServicesProtectionContainerDelete(d *schema.ResourceData, meta interface{}) error { - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - resGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - fabricName := id.Path["replicationFabrics"] - name := id.Path["replicationProtectionContainers"] - - client := meta.(*clients.Client).RecoveryServices.ProtectionContainerClient(resGroup, vaultName) - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - future, err := client.Delete(ctx, fabricName, name) - if err != nil { - return fmt.Errorf("Error deleting recovery services protection container %s (fabric %s): %+v", name, fabricName, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for deletion of recovery services protection container %s (fabric %s): %+v", name, fabricName, err) - } - - return nil -} diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_mapping.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_mapping.go deleted file mode 100644 index cbeea35521bf9..0000000000000 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_mapping.go +++ /dev/null @@ -1,203 +0,0 @@ -package recoveryservices - -import ( - "fmt" - "time" - - "github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-01-10/siterecovery" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmRecoveryServicesProtectionContainerMapping() *schema.Resource { - return &schema.Resource{ - DeprecationMessage: "`azurerm_recovery_services_protection_container_mapping` resource is deprecated in favor of `azurerm_site_recovery_protection_container_mapping` and will be removed in v2.0 of the AzureRM Provider", - Create: resourceArmRecoveryServicesContainerMappingCreate, - Read: resourceArmRecoveryServicesContainerMappingRead, - Update: nil, - Delete: resourceArmRecoveryServicesContainerMappingDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "resource_group_name": azure.SchemaResourceGroupName(), - - "recovery_vault_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateRecoveryServicesVaultName, - }, - "recovery_fabric_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "recovery_replication_policy_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, - }, - "recovery_source_protection_container_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "recovery_target_protection_container_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, - }, - }, - } -} - -func resourceArmRecoveryServicesContainerMappingCreate(d *schema.ResourceData, meta interface{}) error { - resGroup := d.Get("resource_group_name").(string) - vaultName := d.Get("recovery_vault_name").(string) - fabricName := d.Get("recovery_fabric_name").(string) - policyId := d.Get("recovery_replication_policy_id").(string) - protectionContainerName := d.Get("recovery_source_protection_container_name").(string) - targetContainerId := d.Get("recovery_target_protection_container_id").(string) - name := d.Get("name").(string) - - client := meta.(*clients.Client).RecoveryServices.ContainerMappingClient(resGroup, vaultName) - ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) - defer cancel() - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, fabricName, protectionContainerName, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing recovery services protection container mapping %s (fabric %s, container %s): %+v", name, fabricName, protectionContainerName, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_recovery_services_protection_container_mapping", azure.HandleAzureSdkForGoBug2824(*existing.ID)) - } - } - - var parameters = siterecovery.CreateProtectionContainerMappingInput{ - Properties: &siterecovery.CreateProtectionContainerMappingInputProperties{ - TargetProtectionContainerID: &targetContainerId, - PolicyID: &policyId, - ProviderSpecificInput: siterecovery.ReplicationProviderSpecificContainerMappingInput{}, - }, - } - future, err := client.Create(ctx, fabricName, protectionContainerName, name, parameters) - if err != nil { - return fmt.Errorf("Error creating recovery services protection container mapping %s (vault %s): %+v", name, vaultName, err) - } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error creating recovery services protection container mapping %s (vault %s): %+v", name, vaultName, err) - } - - resp, err := client.Get(ctx, fabricName, protectionContainerName, name) - if err != nil { - return fmt.Errorf("Error retrieving site recovery protection container mapping %s (vault %s): %+v", name, vaultName, err) - } - - d.SetId(azure.HandleAzureSdkForGoBug2824(*resp.ID)) - - return resourceArmRecoveryServicesContainerMappingRead(d, meta) -} - -func resourceArmRecoveryServicesContainerMappingRead(d *schema.ResourceData, meta interface{}) error { - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - resGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - fabricName := id.Path["replicationFabrics"] - protectionContainerName := id.Path["replicationProtectionContainers"] - name := id.Path["replicationProtectionContainerMappings"] - - client := meta.(*clients.Client).RecoveryServices.ContainerMappingClient(resGroup, vaultName) - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - resp, err := client.Get(ctx, fabricName, protectionContainerName, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil - } - return fmt.Errorf("Error making Read request on recovery services protection container mapping %s (vault %s): %+v", name, vaultName, err) - } - - d.Set("resource_group_name", resGroup) - d.Set("recovery_vault_name", vaultName) - d.Set("recovery_fabric_name", fabricName) - d.Set("recovery_source_protection_container_name", resp.Properties.SourceProtectionContainerFriendlyName) - d.Set("name", resp.Name) - d.Set("recovery_replication_policy_id", resp.Properties.PolicyID) - d.Set("recovery_target_protection_container_id", resp.Properties.TargetProtectionContainerID) - return nil -} - -func resourceArmRecoveryServicesContainerMappingDelete(d *schema.ResourceData, meta interface{}) error { - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - resGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - fabricName := id.Path["replicationFabrics"] - protectionContainerName := id.Path["replicationProtectionContainers"] - name := id.Path["replicationProtectionContainerMappings"] - instanceType := string(siterecovery.InstanceTypeBasicReplicationProviderSpecificContainerMappingInputInstanceTypeA2A) - - client := meta.(*clients.Client).RecoveryServices.ContainerMappingClient(resGroup, vaultName) - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - input := siterecovery.RemoveProtectionContainerMappingInput{ - Properties: &siterecovery.RemoveProtectionContainerMappingInputProperties{ - ProviderSpecificInput: &siterecovery.ReplicationProviderContainerUnmappingInput{ - InstanceType: &instanceType, - }, - }, - } - - future, err := client.Delete(ctx, fabricName, protectionContainerName, name, input) - if err != nil { - return fmt.Errorf("Error deleting recovery services protection container mapping %s (vault %s): %+v", name, vaultName, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for deletion of recovery services protection container mapping %s (vault %s): %+v", name, vaultName, err) - } - - return nil -} diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_policy_vm.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_policy_vm.go deleted file mode 100644 index 9239c1d793493..0000000000000 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_policy_vm.go +++ /dev/null @@ -1,764 +0,0 @@ -package recoveryservices - -import ( - "context" - "fmt" - "log" - "regexp" - "strings" - "time" - - "github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2019-05-13/backup" - "github.com/Azure/go-autorest/autorest/date" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/set" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmRecoveryServicesProtectionPolicyVm() *schema.Resource { - return &schema.Resource{ - DeprecationMessage: "`azurerm_recovery_services_protection_policy_vm` resource is deprecated in favor of `azurerm_backup_policy_vm` and will be removed in v2.0 of the AzureRM Provider", - Create: resourceArmRecoveryServicesProtectionPolicyVmCreateUpdate, - Read: resourceArmRecoveryServicesProtectionPolicyVmRead, - Update: resourceArmRecoveryServicesProtectionPolicyVmCreateUpdate, - Delete: resourceArmRecoveryServicesProtectionPolicyVmDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringMatch( - regexp.MustCompile("^[a-zA-Z][-_!a-zA-Z0-9]{2,149}$"), - "Backup Policy name must be 3 - 150 characters long, start with a letter, contain only letters and numbers.", - ), - }, - - "resource_group_name": azure.SchemaResourceGroupName(), - - "recovery_vault_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateRecoveryServicesVaultName, - }, - - "timezone": { - Type: schema.TypeString, - Optional: true, - Default: "UTC", - }, - - "backup": { - Type: schema.TypeList, - MaxItems: 1, - Required: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - - "frequency": { - Type: schema.TypeString, - Required: true, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(backup.ScheduleRunTypeDaily), - string(backup.ScheduleRunTypeWeekly), - }, true), - }, - - "time": { //applies to all backup schedules & retention times (they all must be the same) - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringMatch( - regexp.MustCompile("^([01][0-9]|[2][0-3]):([03][0])$"), //time must be on the hour or half past - "Time of day must match the format HH:mm where HH is 00-23 and mm is 00 or 30", - ), - }, - - "weekdays": { //only for weekly - Type: schema.TypeSet, - Optional: true, - Set: set.HashStringIgnoreCase, - Elem: &schema.Schema{ - Type: schema.TypeString, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validate.DayOfTheWeek(true), - }, - }, - }, - }, - }, - - "retention_daily": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "count": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(1, 9999), - }, - }, - }, - }, - - "retention_weekly": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "count": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(1, 9999), - }, - - "weekdays": { - Type: schema.TypeSet, - Required: true, - Set: set.HashStringIgnoreCase, - Elem: &schema.Schema{ - Type: schema.TypeString, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validate.DayOfTheWeek(true), - }, - }, - }, - }, - }, - - "retention_monthly": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "count": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(1, 9999), - }, - - "weeks": { - Type: schema.TypeSet, - Required: true, - Set: set.HashStringIgnoreCase, - Elem: &schema.Schema{ - Type: schema.TypeString, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(backup.WeekOfMonthFirst), - string(backup.WeekOfMonthSecond), - string(backup.WeekOfMonthThird), - string(backup.WeekOfMonthFourth), - string(backup.WeekOfMonthLast), - }, true), - }, - }, - - "weekdays": { - Type: schema.TypeSet, - Required: true, - Set: set.HashStringIgnoreCase, - Elem: &schema.Schema{ - Type: schema.TypeString, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validate.DayOfTheWeek(true), - }, - }, - }, - }, - }, - - "retention_yearly": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "count": { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(1, 9999), - }, - - "months": { - Type: schema.TypeSet, - Required: true, - Set: set.HashStringIgnoreCase, - Elem: &schema.Schema{ - Type: schema.TypeString, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validate.Month(true), - }, - }, - - "weeks": { - Type: schema.TypeSet, - Required: true, - Set: set.HashStringIgnoreCase, - Elem: &schema.Schema{ - Type: schema.TypeString, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validation.StringInSlice([]string{ - string(backup.WeekOfMonthFirst), - string(backup.WeekOfMonthSecond), - string(backup.WeekOfMonthThird), - string(backup.WeekOfMonthFourth), - string(backup.WeekOfMonthLast), - }, true), - }, - }, - - "weekdays": { - Type: schema.TypeSet, - Required: true, - Set: set.HashStringIgnoreCase, - Elem: &schema.Schema{ - Type: schema.TypeString, - DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validate.DayOfTheWeek(true), - }, - }, - }, - }, - }, - - "tags": tags.Schema(), - }, - - //if daily, we need daily retention - //if weekly daily cannot be set, and we need weekly - CustomizeDiff: func(diff *schema.ResourceDiff, v interface{}) error { - _, hasDaily := diff.GetOk("retention_daily") - _, hasWeekly := diff.GetOk("retention_weekly") - - frequencyI, _ := diff.GetOk("backup.0.frequency") - frequency := strings.ToLower(frequencyI.(string)) - if frequency == "daily" { - if !hasDaily { - return fmt.Errorf("`retention_daily` must be set when backup.0.frequency is daily") - } - - if _, ok := diff.GetOk("backup.0.weekdays"); ok { - return fmt.Errorf("`backup.0.weekdays` should be not set when backup.0.frequency is daily") - } - } else if frequency == "weekly" { - if hasDaily { - return fmt.Errorf("`retention_daily` must be not set when backup.0.frequency is weekly") - } - if !hasWeekly { - return fmt.Errorf("`retention_weekly` must be set when backup.0.frequency is weekly") - } - } else { - return fmt.Errorf("Unrecognized value for backup.0.frequency") - } - - return nil - }, - } -} - -func resourceArmRecoveryServicesProtectionPolicyVmCreateUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).RecoveryServices.ProtectionPoliciesClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - policyName := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - vaultName := d.Get("recovery_vault_name").(string) - t := d.Get("tags").(map[string]interface{}) - - log.Printf("[DEBUG] Creating/updating Recovery Service Protection Policy %s (resource group %q)", policyName, resourceGroup) - - //getting this ready now because its shared between *everything*, time is... complicated for this resource - timeOfDay := d.Get("backup.0.time").(string) - dateOfDay, err := time.Parse(time.RFC3339, fmt.Sprintf("2018-07-30T%s:00Z", timeOfDay)) - if err != nil { - return fmt.Errorf("Error generating time from %q for policy %q (Resource Group %q): %+v", timeOfDay, policyName, resourceGroup, err) - } - times := append(make([]date.Time, 0), date.Time{Time: dateOfDay}) - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err2 := client.Get(ctx, vaultName, resourceGroup, policyName) - if err2 != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing Recovery Service Protection Policy %q (Resource Group %q): %+v", policyName, resourceGroup, err2) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_recovery_services_protection_policy_vm", *existing.ID) - } - } - - policy := backup.ProtectionPolicyResource{ - Tags: tags.Expand(t), - Properties: &backup.AzureIaaSVMProtectionPolicy{ - TimeZone: utils.String(d.Get("timezone").(string)), - BackupManagementType: backup.BackupManagementTypeAzureIaasVM, - SchedulePolicy: expandArmRecoveryServicesProtectionPolicySchedule(d, times), - RetentionPolicy: &backup.LongTermRetentionPolicy{ //SimpleRetentionPolicy only has duration property ¯\_(ツ)_/¯ - RetentionPolicyType: backup.RetentionPolicyTypeLongTermRetentionPolicy, - DailySchedule: expandArmRecoveryServicesProtectionPolicyRetentionDaily(d, times), - WeeklySchedule: expandArmRecoveryServicesProtectionPolicyRetentionWeekly(d, times), - MonthlySchedule: expandArmRecoveryServicesProtectionPolicyRetentionMonthly(d, times), - YearlySchedule: expandArmRecoveryServicesProtectionPolicyRetentionYearly(d, times), - }, - }, - } - if _, err = client.CreateOrUpdate(ctx, vaultName, resourceGroup, policyName, policy); err != nil { - return fmt.Errorf("Error creating/updating Recovery Service Protection Policy %q (Resource Group %q): %+v", policyName, resourceGroup, err) - } - - resp, err := resourceArmRecoveryServicesProtectionPolicyWaitForUpdate(ctx, client, vaultName, resourceGroup, policyName, d) - if err != nil { - return err - } - - id := strings.Replace(*resp.ID, "Subscriptions", "subscriptions", 1) - d.SetId(id) - - return resourceArmRecoveryServicesProtectionPolicyVmRead(d, meta) -} - -func resourceArmRecoveryServicesProtectionPolicyVmRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).RecoveryServices.ProtectionPoliciesClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - policyName := id.Path["backupPolicies"] - vaultName := id.Path["vaults"] - resourceGroup := id.ResourceGroup - - log.Printf("[DEBUG] Reading Recovery Service Protection Policy %q (resource group %q)", policyName, resourceGroup) - - resp, err := client.Get(ctx, vaultName, resourceGroup, policyName) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil - } - - return fmt.Errorf("Error making Read request on Recovery Service Protection Policy %q (Resource Group %q): %+v", policyName, resourceGroup, err) - } - - d.Set("name", policyName) - d.Set("resource_group_name", resourceGroup) - d.Set("recovery_vault_name", vaultName) - - if properties, ok := resp.Properties.AsAzureIaaSVMProtectionPolicy(); ok && properties != nil { - d.Set("timezone", properties.TimeZone) - - if schedule, ok := properties.SchedulePolicy.AsSimpleSchedulePolicy(); ok && schedule != nil { - if err := d.Set("backup", flattenArmRecoveryServicesProtectionPolicySchedule(schedule)); err != nil { - return fmt.Errorf("Error setting `backup`: %+v", err) - } - } - - if retention, ok := properties.RetentionPolicy.AsLongTermRetentionPolicy(); ok && retention != nil { - if s := retention.DailySchedule; s != nil { - if err := d.Set("retention_daily", flattenArmRecoveryServicesProtectionPolicyRetentionDaily(s)); err != nil { - return fmt.Errorf("Error setting `retention_daily`: %+v", err) - } - } else { - d.Set("retention_daily", nil) - } - - if s := retention.WeeklySchedule; s != nil { - if err := d.Set("retention_weekly", flattenArmRecoveryServicesProtectionPolicyRetentionWeekly(s)); err != nil { - return fmt.Errorf("Error setting `retention_weekly`: %+v", err) - } - } else { - d.Set("retention_weekly", nil) - } - - if s := retention.MonthlySchedule; s != nil { - if err := d.Set("retention_monthly", flattenArmRecoveryServicesProtectionPolicyRetentionMonthly(s)); err != nil { - return fmt.Errorf("Error setting `retention_monthly`: %+v", err) - } - } else { - d.Set("retention_monthly", nil) - } - - if s := retention.YearlySchedule; s != nil { - if err := d.Set("retention_yearly", flattenArmRecoveryServicesProtectionPolicyRetentionYearly(s)); err != nil { - return fmt.Errorf("Error setting `retention_yearly`: %+v", err) - } - } else { - d.Set("retention_yearly", nil) - } - } - } - - return tags.FlattenAndSet(d, resp.Tags) -} - -func resourceArmRecoveryServicesProtectionPolicyVmDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).RecoveryServices.ProtectionPoliciesClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - policyName := id.Path["backupPolicies"] - resourceGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - - log.Printf("[DEBUG] Deleting Recovery Service Protected Item %q (resource group %q)", policyName, resourceGroup) - - resp, err := client.Delete(ctx, vaultName, resourceGroup, policyName) - if err != nil { - if !utils.ResponseWasNotFound(resp) { - return fmt.Errorf("Error issuing delete request for Recovery Service Protection Policy %q (Resource Group %q): %+v", policyName, resourceGroup, err) - } - } - - if _, err := resourceArmRecoveryServicesProtectionPolicyWaitForDeletion(ctx, client, vaultName, resourceGroup, policyName, d); err != nil { - return err - } - - return nil -} - -func expandArmRecoveryServicesProtectionPolicySchedule(d *schema.ResourceData, times []date.Time) *backup.SimpleSchedulePolicy { - if bb, ok := d.Get("backup").([]interface{}); ok && len(bb) > 0 { - block := bb[0].(map[string]interface{}) - - schedule := backup.SimpleSchedulePolicy{ //LongTermSchedulePolicy has no properties - SchedulePolicyType: backup.SchedulePolicyTypeSimpleSchedulePolicy, - ScheduleRunTimes: ×, - } - - if v, ok := block["frequency"].(string); ok { - schedule.ScheduleRunFrequency = backup.ScheduleRunType(v) - } - - if v, ok := block["weekdays"].(*schema.Set); ok { - days := make([]backup.DayOfWeek, 0) - for _, day := range v.List() { - days = append(days, backup.DayOfWeek(day.(string))) - } - schedule.ScheduleRunDays = &days - } - - return &schedule - } - - return nil -} - -func expandArmRecoveryServicesProtectionPolicyRetentionDaily(d *schema.ResourceData, times []date.Time) *backup.DailyRetentionSchedule { - if rb, ok := d.Get("retention_daily").([]interface{}); ok && len(rb) > 0 { - block := rb[0].(map[string]interface{}) - - return &backup.DailyRetentionSchedule{ - RetentionTimes: ×, - RetentionDuration: &backup.RetentionDuration{ - Count: utils.Int32(int32(block["count"].(int))), - DurationType: backup.RetentionDurationTypeDays, - }, - } - } - - return nil -} - -func expandArmRecoveryServicesProtectionPolicyRetentionWeekly(d *schema.ResourceData, times []date.Time) *backup.WeeklyRetentionSchedule { - if rb, ok := d.Get("retention_weekly").([]interface{}); ok && len(rb) > 0 { - block := rb[0].(map[string]interface{}) - - retention := backup.WeeklyRetentionSchedule{ - RetentionTimes: ×, - RetentionDuration: &backup.RetentionDuration{ - Count: utils.Int32(int32(block["count"].(int))), - DurationType: backup.RetentionDurationTypeWeeks, - }, - } - - if v, ok := block["weekdays"].(*schema.Set); ok { - days := make([]backup.DayOfWeek, 0) - for _, day := range v.List() { - days = append(days, backup.DayOfWeek(day.(string))) - } - retention.DaysOfTheWeek = &days - } - - return &retention - } - - return nil -} - -func expandArmRecoveryServicesProtectionPolicyRetentionMonthly(d *schema.ResourceData, times []date.Time) *backup.MonthlyRetentionSchedule { - if rb, ok := d.Get("retention_monthly").([]interface{}); ok && len(rb) > 0 { - block := rb[0].(map[string]interface{}) - - retention := backup.MonthlyRetentionSchedule{ - RetentionScheduleFormatType: backup.RetentionScheduleFormatWeekly, //this is always weekly ¯\_(ツ)_/¯ - RetentionScheduleDaily: nil, //and this is always nil.. - RetentionScheduleWeekly: expandArmRecoveryServicesProtectionPolicyRetentionWeeklyFormat(block), - RetentionTimes: ×, - RetentionDuration: &backup.RetentionDuration{ - Count: utils.Int32(int32(block["count"].(int))), - DurationType: backup.RetentionDurationTypeMonths, - }, - } - - return &retention - } - - return nil -} - -func expandArmRecoveryServicesProtectionPolicyRetentionYearly(d *schema.ResourceData, times []date.Time) *backup.YearlyRetentionSchedule { - if rb, ok := d.Get("retention_yearly").([]interface{}); ok && len(rb) > 0 { - block := rb[0].(map[string]interface{}) - - retention := backup.YearlyRetentionSchedule{ - RetentionScheduleFormatType: backup.RetentionScheduleFormatWeekly, //this is always weekly ¯\_(ツ)_/¯ - RetentionScheduleDaily: nil, //and this is always nil.. - RetentionScheduleWeekly: expandArmRecoveryServicesProtectionPolicyRetentionWeeklyFormat(block), - RetentionTimes: ×, - RetentionDuration: &backup.RetentionDuration{ - Count: utils.Int32(int32(block["count"].(int))), - DurationType: backup.RetentionDurationTypeYears, - }, - } - - if v, ok := block["months"].(*schema.Set); ok { - months := make([]backup.MonthOfYear, 0) - for _, month := range v.List() { - months = append(months, backup.MonthOfYear(month.(string))) - } - retention.MonthsOfYear = &months - } - - return &retention - } - - return nil -} - -func expandArmRecoveryServicesProtectionPolicyRetentionWeeklyFormat(block map[string]interface{}) *backup.WeeklyRetentionFormat { - weekly := backup.WeeklyRetentionFormat{} - - if v, ok := block["weekdays"].(*schema.Set); ok { - days := make([]backup.DayOfWeek, 0) - for _, day := range v.List() { - days = append(days, backup.DayOfWeek(day.(string))) - } - weekly.DaysOfTheWeek = &days - } - - if v, ok := block["weeks"].(*schema.Set); ok { - weeks := make([]backup.WeekOfMonth, 0) - for _, week := range v.List() { - weeks = append(weeks, backup.WeekOfMonth(week.(string))) - } - weekly.WeeksOfTheMonth = &weeks - } - - return &weekly -} - -func flattenArmRecoveryServicesProtectionPolicySchedule(schedule *backup.SimpleSchedulePolicy) []interface{} { - block := map[string]interface{}{} - - block["frequency"] = string(schedule.ScheduleRunFrequency) - - if times := schedule.ScheduleRunTimes; times != nil && len(*times) > 0 { - block["time"] = (*times)[0].Format("15:04") - } - - if days := schedule.ScheduleRunDays; days != nil { - weekdays := make([]interface{}, 0) - for _, d := range *days { - weekdays = append(weekdays, string(d)) - } - block["weekdays"] = schema.NewSet(schema.HashString, weekdays) - } - - return []interface{}{block} -} - -func flattenArmRecoveryServicesProtectionPolicyRetentionDaily(daily *backup.DailyRetentionSchedule) []interface{} { - block := map[string]interface{}{} - - if duration := daily.RetentionDuration; duration != nil { - if v := duration.Count; v != nil { - block["count"] = *v - } - } - - return []interface{}{block} -} - -func flattenArmRecoveryServicesProtectionPolicyRetentionWeekly(weekly *backup.WeeklyRetentionSchedule) []interface{} { - block := map[string]interface{}{} - - if duration := weekly.RetentionDuration; duration != nil { - if v := duration.Count; v != nil { - block["count"] = *v - } - } - - if days := weekly.DaysOfTheWeek; days != nil { - weekdays := make([]interface{}, 0) - for _, d := range *days { - weekdays = append(weekdays, string(d)) - } - block["weekdays"] = schema.NewSet(schema.HashString, weekdays) - } - - return []interface{}{block} -} - -func flattenArmRecoveryServicesProtectionPolicyRetentionMonthly(monthly *backup.MonthlyRetentionSchedule) []interface{} { - block := map[string]interface{}{} - - if duration := monthly.RetentionDuration; duration != nil { - if v := duration.Count; v != nil { - block["count"] = *v - } - } - - if weekly := monthly.RetentionScheduleWeekly; weekly != nil { - block["weekdays"], block["weeks"] = flattenArmRecoveryServicesProtectionPolicyRetentionWeeklyFormat(weekly) - } - - return []interface{}{block} -} - -func flattenArmRecoveryServicesProtectionPolicyRetentionYearly(yearly *backup.YearlyRetentionSchedule) []interface{} { - block := map[string]interface{}{} - - if duration := yearly.RetentionDuration; duration != nil { - if v := duration.Count; v != nil { - block["count"] = *v - } - } - - if weekly := yearly.RetentionScheduleWeekly; weekly != nil { - block["weekdays"], block["weeks"] = flattenArmRecoveryServicesProtectionPolicyRetentionWeeklyFormat(weekly) - } - - if months := yearly.MonthsOfYear; months != nil { - slice := make([]interface{}, 0) - for _, d := range *months { - slice = append(slice, string(d)) - } - block["months"] = schema.NewSet(schema.HashString, slice) - } - - return []interface{}{block} -} - -func flattenArmRecoveryServicesProtectionPolicyRetentionWeeklyFormat(retention *backup.WeeklyRetentionFormat) (weekdays, weeks *schema.Set) { - if days := retention.DaysOfTheWeek; days != nil { - slice := make([]interface{}, 0) - for _, d := range *days { - slice = append(slice, string(d)) - } - weekdays = schema.NewSet(schema.HashString, slice) - } - - if days := retention.WeeksOfTheMonth; days != nil { - slice := make([]interface{}, 0) - for _, d := range *days { - slice = append(slice, string(d)) - } - weeks = schema.NewSet(schema.HashString, slice) - } - - return weekdays, weeks -} - -func resourceArmRecoveryServicesProtectionPolicyWaitForUpdate(ctx context.Context, client *backup.ProtectionPoliciesClient, vaultName, resourceGroup, policyName string, d *schema.ResourceData) (backup.ProtectionPolicyResource, error) { - state := &resource.StateChangeConf{ - MinTimeout: 30 * time.Second, - Delay: 10 * time.Second, - Pending: []string{"NotFound"}, - Target: []string{"Found"}, - Refresh: resourceArmRecoveryServicesProtectionPolicyRefreshFunc(ctx, client, vaultName, resourceGroup, policyName), - } - - if d.IsNewResource() { - state.Timeout = d.Timeout(schema.TimeoutCreate) - } else { - state.Timeout = d.Timeout(schema.TimeoutUpdate) - } - - resp, err := state.WaitForState() - if err != nil { - return resp.(backup.ProtectionPolicyResource), fmt.Errorf("Error waiting for the Recovery Service Protection Policy %q to be true (Resource Group %q) to provision: %+v", policyName, resourceGroup, err) - } - - return resp.(backup.ProtectionPolicyResource), nil -} - -func resourceArmRecoveryServicesProtectionPolicyWaitForDeletion(ctx context.Context, client *backup.ProtectionPoliciesClient, vaultName, resourceGroup, policyName string, d *schema.ResourceData) (backup.ProtectionPolicyResource, error) { - state := &resource.StateChangeConf{ - MinTimeout: 30 * time.Second, - Delay: 10 * time.Second, - Pending: []string{"Found"}, - Target: []string{"NotFound"}, - Refresh: resourceArmRecoveryServicesProtectionPolicyRefreshFunc(ctx, client, vaultName, resourceGroup, policyName), - Timeout: d.Timeout(schema.TimeoutDelete), - } - - resp, err := state.WaitForState() - if err != nil { - return resp.(backup.ProtectionPolicyResource), fmt.Errorf("Error waiting for the Recovery Service Protection Policy %q to be false (Resource Group %q) to provision: %+v", policyName, resourceGroup, err) - } - - return resp.(backup.ProtectionPolicyResource), nil -} - -func resourceArmRecoveryServicesProtectionPolicyRefreshFunc(ctx context.Context, client *backup.ProtectionPoliciesClient, vaultName, resourceGroup, policyName string) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - resp, err := client.Get(ctx, vaultName, resourceGroup, policyName) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return resp, "NotFound", nil - } - - return resp, "Error", fmt.Errorf("Error making Read request on Recovery Service Protection Policy %q (Resource Group %q): %+v", policyName, resourceGroup, err) - } - - return resp, "Found", nil - } -} diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replicated_vm.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replicated_vm.go deleted file mode 100644 index a93c4937d8d1c..0000000000000 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replicated_vm.go +++ /dev/null @@ -1,353 +0,0 @@ -package recoveryservices - -import ( - "bytes" - "fmt" - "strings" - "time" - - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" - "github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-01-10/siterecovery" - "github.com/hashicorp/terraform-plugin-sdk/helper/hashcode" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmRecoveryServicesReplicatedVm() *schema.Resource { - return &schema.Resource{ - DeprecationMessage: "`azurerm_recovery_replicated_vm` resource is deprecated in favor of `azurerm_site_recovery_replicated_vm` and will be removed in v2.0 of the AzureRM Provider", - Create: resourceArmRecoveryReplicatedItemCreate, - Read: resourceArmRecoveryReplicatedItemRead, - Delete: resourceArmRecoveryReplicatedItemDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(80 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(80 * time.Minute), - Delete: schema.DefaultTimeout(80 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "resource_group_name": azure.SchemaResourceGroupName(), - - "recovery_vault_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateRecoveryServicesVaultName, - }, - "source_recovery_fabric_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "source_vm_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, - }, - "target_recovery_fabric_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, - }, - "recovery_replication_policy_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, - }, - "source_recovery_protection_container_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "target_recovery_protection_container_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, - }, - "target_resource_group_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, - }, - "target_availability_set_id": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, - }, - "managed_disk": { - Type: schema.TypeSet, - ConfigMode: schema.SchemaConfigModeAttr, - Optional: true, - ForceNew: true, - Set: resourceArmRecoveryReplicatedVmDiskHash, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "disk_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - DiffSuppressFunc: suppress.CaseDifference, - }, - "staging_storage_account_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, - }, - "target_resource_group_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateResourceID, - DiffSuppressFunc: suppress.CaseDifference, - }, - "target_disk_type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - string(compute.StandardLRS), - string(compute.PremiumLRS), - string(compute.StandardSSDLRS), - string(compute.UltraSSDLRS), - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, - "target_replica_disk_type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - string(compute.StandardLRS), - string(compute.PremiumLRS), - string(compute.StandardSSDLRS), - string(compute.UltraSSDLRS), - }, true), - DiffSuppressFunc: suppress.CaseDifference, - }, - }, - }, - }, - }, - } -} - -func resourceArmRecoveryReplicatedItemCreate(d *schema.ResourceData, meta interface{}) error { - name := d.Get("name").(string) - resGroup := d.Get("resource_group_name").(string) - vaultName := d.Get("recovery_vault_name").(string) - fabricName := d.Get("source_recovery_fabric_name").(string) - sourceVmId := d.Get("source_vm_id").(string) - policyId := d.Get("recovery_replication_policy_id").(string) - sourceProtectionContainerName := d.Get("source_recovery_protection_container_name").(string) - targetProtectionContainerId := d.Get("target_recovery_protection_container_id").(string) - targetResourceGroupId := d.Get("target_resource_group_id").(string) - - var targetAvailabilitySetID *string - if id, isSet := d.GetOk("target_availability_set_id"); isSet { - tmp := id.(string) - targetAvailabilitySetID = &tmp - } else { - targetAvailabilitySetID = nil - } - - client := meta.(*clients.Client).RecoveryServices.ReplicationMigrationItemsClient(resGroup, vaultName) - ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) - defer cancel() - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, fabricName, sourceProtectionContainerName, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing recovery services replicated vm %s (vault %s): %+v", name, vaultName, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_recovery_replicated_vm", azure.HandleAzureSdkForGoBug2824(*existing.ID)) - } - } - - managedDisks := []siterecovery.A2AVMManagedDiskInputDetails{} - - for _, raw := range d.Get("managed_disk").(*schema.Set).List() { - diskInput := raw.(map[string]interface{}) - diskId := diskInput["disk_id"].(string) - primaryStagingAzureStorageAccountID := diskInput["staging_storage_account_id"].(string) - recoveryResourceGroupId := diskInput["target_resource_group_id"].(string) - targetReplicaDiskType := diskInput["target_replica_disk_type"].(string) - targetDiskType := diskInput["target_disk_type"].(string) - - managedDisks = append(managedDisks, siterecovery.A2AVMManagedDiskInputDetails{ - DiskID: &diskId, - PrimaryStagingAzureStorageAccountID: &primaryStagingAzureStorageAccountID, - RecoveryResourceGroupID: &recoveryResourceGroupId, - RecoveryReplicaDiskAccountType: &targetReplicaDiskType, - RecoveryTargetDiskAccountType: &targetDiskType, - }) - } - - var parameters = siterecovery.EnableProtectionInput{ - Properties: &siterecovery.EnableProtectionInputProperties{ - PolicyID: &policyId, - ProviderSpecificDetails: siterecovery.A2AEnableProtectionInput{ - FabricObjectID: &sourceVmId, - RecoveryContainerID: &targetProtectionContainerId, - RecoveryResourceGroupID: &targetResourceGroupId, - RecoveryAvailabilitySetID: targetAvailabilitySetID, - VMManagedDisks: &managedDisks, - }, - }, - } - future, err := client.Create(ctx, fabricName, sourceProtectionContainerName, name, parameters) - if err != nil { - return fmt.Errorf("Error creating replicated vm %s (vault %s): %+v", name, vaultName, err) - } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error creating replicated vm %s (vault %s): %+v", name, vaultName, err) - } - - resp, err := client.Get(ctx, fabricName, sourceProtectionContainerName, name) - if err != nil { - return fmt.Errorf("Error retrieving replicated vm %s (vault %s): %+v", name, vaultName, err) - } - - d.SetId(azure.HandleAzureSdkForGoBug2824(*resp.ID)) - - return resourceArmRecoveryReplicatedItemRead(d, meta) -} - -func resourceArmRecoveryReplicatedItemRead(d *schema.ResourceData, meta interface{}) error { - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - resGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - fabricName := id.Path["replicationFabrics"] - protectionContainerName := id.Path["replicationProtectionContainers"] - name := id.Path["replicationProtectedItems"] - - client := meta.(*clients.Client).RecoveryServices.ReplicationMigrationItemsClient(resGroup, vaultName) - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - resp, err := client.Get(ctx, fabricName, protectionContainerName, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil - } - return fmt.Errorf("Error making Read request on recovery services replicated vm %s (vault %s): %+v", name, vaultName, err) - } - - d.Set("name", name) - d.Set("resource_group_name", resGroup) - d.Set("recovery_vault_name", vaultName) - d.Set("source_recovery_fabric_name", fabricName) - d.Set("target_recovery_fabric_id", resp.Properties.RecoveryFabricID) - d.Set("recovery_replication_policy_id", resp.Properties.PolicyID) - d.Set("source_recovery_protection_container_name", protectionContainerName) - d.Set("target_recovery_protection_container_id", resp.Properties.RecoveryContainerID) - - if a2aDetails, isA2a := resp.Properties.ProviderSpecificDetails.AsA2AReplicationDetails(); isA2a { - d.Set("source_vm_id", a2aDetails.FabricObjectID) - d.Set("target_resource_group_id", a2aDetails.RecoveryAzureResourceGroupID) - d.Set("target_availability_set_id", a2aDetails.RecoveryAvailabilitySet) - if a2aDetails.ProtectedManagedDisks != nil { - disksOutput := make([]interface{}, 0) - for _, disk := range *a2aDetails.ProtectedManagedDisks { - diskOutput := make(map[string]interface{}) - diskOutput["disk_id"] = *disk.DiskID - diskOutput["staging_storage_account_id"] = *disk.PrimaryStagingAzureStorageAccountID - diskOutput["target_resource_group_id"] = *disk.RecoveryResourceGroupID - diskOutput["target_replica_disk_type"] = *disk.RecoveryReplicaDiskAccountType - diskOutput["target_disk_type"] = *disk.RecoveryTargetDiskAccountType - - disksOutput = append(disksOutput, diskOutput) - } - d.Set("managed_disk", schema.NewSet(resourceArmRecoveryReplicatedVmDiskHash, disksOutput)) - } - } - - return nil -} - -func resourceArmRecoveryReplicatedItemDelete(d *schema.ResourceData, meta interface{}) error { - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - resGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - fabricName := id.Path["replicationFabrics"] - protectionContainerName := id.Path["replicationProtectionContainers"] - name := id.Path["replicationProtectedItems"] - - disableProtectionInput := siterecovery.DisableProtectionInput{ - Properties: &siterecovery.DisableProtectionInputProperties{ - DisableProtectionReason: siterecovery.NotSpecified, - ReplicationProviderInput: siterecovery.DisableProtectionProviderSpecificInput{}, - }, - } - - client := meta.(*clients.Client).RecoveryServices.ReplicationMigrationItemsClient(resGroup, vaultName) - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - future, err := client.Delete(ctx, fabricName, protectionContainerName, name, disableProtectionInput) - if err != nil { - return fmt.Errorf("Error deleting recovery services replicated vm %s (vault %s): %+v", name, vaultName, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for deletion of recovery services replicated vm %s (vault %s): %+v", name, vaultName, err) - } - return nil -} - -func resourceArmRecoveryReplicatedVmDiskHash(v interface{}) int { - var buf bytes.Buffer - - if m, ok := v.(map[string]interface{}); ok { - if v, ok := m["disk_id"]; ok { - buf.WriteString(strings.ToLower(v.(string))) - } - } - - return hashcode.String(buf.String()) -} diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replication_policy.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replication_policy.go deleted file mode 100644 index 2288499b6ac5d..0000000000000 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replication_policy.go +++ /dev/null @@ -1,215 +0,0 @@ -package recoveryservices - -import ( - "fmt" - "time" - - "github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2018-01-10/siterecovery" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func resourceArmRecoveryServicesReplicationPolicy() *schema.Resource { - return &schema.Resource{ - DeprecationMessage: "`azurerm_recovery_services_replication_policy` resource is deprecated in favor of `azurerm_site_recovery_replication_policy` and will be removed in v2.0 of the AzureRM Provider", - Create: resourceArmRecoveryServicesReplicationPolicyCreate, - Read: resourceArmRecoveryServicesReplicationPolicyRead, - Update: resourceArmRecoveryServicesReplicationPolicyUpdate, - Delete: resourceArmRecoveryServicesReplicationPolicyDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(30 * time.Minute), - Read: schema.DefaultTimeout(5 * time.Minute), - Update: schema.DefaultTimeout(30 * time.Minute), - Delete: schema.DefaultTimeout(30 * time.Minute), - }, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "resource_group_name": azure.SchemaResourceGroupName(), - - "recovery_vault_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: azure.ValidateRecoveryServicesVaultName, - }, - "recovery_point_retention_in_minutes": { - Type: schema.TypeInt, - Required: true, - ForceNew: false, - ValidateFunc: validation.IntBetween(1, 365*24*60), - }, - "application_consistent_snapshot_frequency_in_minutes": { - Type: schema.TypeInt, - Required: true, - ForceNew: false, - ValidateFunc: validation.IntBetween(1, 365*24*60), - }, - }, - } -} - -func resourceArmRecoveryServicesReplicationPolicyCreate(d *schema.ResourceData, meta interface{}) error { - resGroup := d.Get("resource_group_name").(string) - vaultName := d.Get("recovery_vault_name").(string) - name := d.Get("name").(string) - - client := meta.(*clients.Client).RecoveryServices.ReplicationPoliciesClient(resGroup, vaultName) - ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) - defer cancel() - - if features.ShouldResourcesBeImported() && d.IsNewResource() { - existing, err := client.Get(ctx, name) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("Error checking for presence of existing recovery services replication policy %s: %+v", name, err) - } - } - - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_recovery_services_replication_policy", azure.HandleAzureSdkForGoBug2824(*existing.ID)) - } - } - - recoveryPoint := int32(d.Get("recovery_point_retention_in_minutes").(int)) - appConsitency := int32(d.Get("application_consistent_snapshot_frequency_in_minutes").(int)) - var parameters = siterecovery.CreatePolicyInput{ - Properties: &siterecovery.CreatePolicyInputProperties{ - ProviderSpecificInput: &siterecovery.A2APolicyCreationInput{ - RecoveryPointHistory: &recoveryPoint, - AppConsistentFrequencyInMinutes: &appConsitency, - MultiVMSyncStatus: siterecovery.Enable, - InstanceType: siterecovery.InstanceTypeBasicPolicyProviderSpecificInputInstanceTypeA2A, - }, - }, - } - future, err := client.Create(ctx, name, parameters) - if err != nil { - return fmt.Errorf("Error creating recovery services replication policy %s (vault %s): %+v", name, vaultName, err) - } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error creating recovery services replication policy %s (vault %s): %+v", name, vaultName, err) - } - - resp, err := client.Get(ctx, name) - if err != nil { - return fmt.Errorf("Error retrieving site recovery replication policy %s (vault %s): %+v", name, vaultName, err) - } - - d.SetId(azure.HandleAzureSdkForGoBug2824(*resp.ID)) - - return resourceArmRecoveryServicesReplicationPolicyRead(d, meta) -} - -func resourceArmRecoveryServicesReplicationPolicyUpdate(d *schema.ResourceData, meta interface{}) error { - resGroup := d.Get("resource_group_name").(string) - vaultName := d.Get("recovery_vault_name").(string) - name := d.Get("name").(string) - - client := meta.(*clients.Client).RecoveryServices.ReplicationPoliciesClient(resGroup, vaultName) - ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - recoveryPoint := int32(d.Get("recovery_point_retention_in_minutes").(int)) - appConsitency := int32(d.Get("application_consistent_snapshot_frequency_in_minutes").(int)) - var parameters = siterecovery.UpdatePolicyInput{ - Properties: &siterecovery.UpdatePolicyInputProperties{ - ReplicationProviderSettings: &siterecovery.A2APolicyCreationInput{ - RecoveryPointHistory: &recoveryPoint, - AppConsistentFrequencyInMinutes: &appConsitency, - MultiVMSyncStatus: siterecovery.Enable, - InstanceType: siterecovery.InstanceTypeBasicPolicyProviderSpecificInputInstanceTypeA2A, - }, - }, - } - future, err := client.Update(ctx, name, parameters) - if err != nil { - return fmt.Errorf("Error updating recovery services replication policy %s (vault %s): %+v", name, vaultName, err) - } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error updating recovery services replication policy %s (vault %s): %+v", name, vaultName, err) - } - - resp, err := client.Get(ctx, name) - if err != nil { - return fmt.Errorf("Error retrieving site recovery replication policy %s (vault %s): %+v", name, vaultName, err) - } - - d.SetId(azure.HandleAzureSdkForGoBug2824(*resp.ID)) - - return resourceArmRecoveryServicesReplicationPolicyRead(d, meta) -} - -func resourceArmRecoveryServicesReplicationPolicyRead(d *schema.ResourceData, meta interface{}) error { - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - resGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - name := id.Path["replicationPolicies"] - - client := meta.(*clients.Client).RecoveryServices.ReplicationPoliciesClient(resGroup, vaultName) - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - resp, err := client.Get(ctx, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil - } - return fmt.Errorf("Error making Read request on recovery services replication policy %s (vault %s): %+v", name, vaultName, err) - } - - d.Set("name", resp.Name) - d.Set("resource_group_name", resGroup) - d.Set("recovery_vault_name", vaultName) - if a2APolicyDetails, isA2A := resp.Properties.ProviderSpecificDetails.AsA2APolicyDetails(); isA2A { - d.Set("recovery_point_retention_in_minutes", a2APolicyDetails.RecoveryPointHistory) - d.Set("application_consistent_snapshot_frequency_in_minutes", a2APolicyDetails.AppConsistentFrequencyInMinutes) - } - return nil -} - -func resourceArmRecoveryServicesReplicationPolicyDelete(d *schema.ResourceData, meta interface{}) error { - id, err := azure.ParseAzureResourceID(d.Id()) - if err != nil { - return err - } - - resGroup := id.ResourceGroup - vaultName := id.Path["vaults"] - name := id.Path["replicationPolicies"] - - client := meta.(*clients.Client).RecoveryServices.ReplicationPoliciesClient(resGroup, vaultName) - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - future, err := client.Delete(ctx, name) - if err != nil { - return fmt.Errorf("Error deleting recovery services replication policy %s (vault %s): %+v", name, vaultName, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for deletion of recovery services replication policy %s (vault %s): %+v", name, vaultName, err) - } - - return nil -} diff --git a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping.go index 1deb7410705a9..94a6efdb862c3 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping.go @@ -90,7 +90,7 @@ func resourceArmSiteRecoveryNetworkMappingCreate(d *schema.ResourceData, meta in ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - //get network name from id + // get network name from id parsedSourceNetworkId, err := azure.ParseAzureResourceID(sourceNetworkId) if err != nil { return fmt.Errorf("[ERROR] Unable to parse source_network_id '%s' (network mapping %s): %+v", sourceNetworkId, name, err) diff --git a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container.go index ec0c32c3bb119..d0497ccd1f718 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container.go @@ -76,7 +76,7 @@ func resourceArmSiteRecoveryProtectionContainerCreate(d *schema.ResourceData, me } if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_recovery_services_protection_container", azure.HandleAzureSdkForGoBug2824(*existing.ID)) + return tf.ImportAsExistsError("azurerm_site_recovery_protection_container", azure.HandleAzureSdkForGoBug2824(*existing.ID)) } } diff --git a/azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_protection_policy_vm_test.go b/azurerm/internal/services/recoveryservices/tests/data_source_backup_policy_vm_test.go similarity index 51% rename from azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_protection_policy_vm_test.go rename to azurerm/internal/services/recoveryservices/tests/data_source_backup_policy_vm_test.go index 03af8b3759efe..34c33c7f01dd5 100644 --- a/azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_protection_policy_vm_test.go +++ b/azurerm/internal/services/recoveryservices/tests/data_source_backup_policy_vm_test.go @@ -8,17 +8,17 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) -func TestAccDataSourceAzureRMRecoveryServicesProtectionPolicyVm_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "data.azurerm_recovery_services_protection_policy_vm", "test") +func TestAccDataSourceAzureRMBackupPolicyVm_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_backup_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceRecoveryServicesProtectionPolicyVm_basic(data), + Config: testAccDataSourceBackupPolicyVm_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectionPolicyVmExists(data.ResourceName), + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), resource.TestCheckResourceAttrSet(data.ResourceName, "name"), resource.TestCheckResourceAttrSet(data.ResourceName, "recovery_vault_name"), resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), @@ -29,14 +29,14 @@ func TestAccDataSourceAzureRMRecoveryServicesProtectionPolicyVm_basic(t *testing }) } -func testAccDataSourceRecoveryServicesProtectionPolicyVm_basic(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data) - return fmt.Sprintf(` +func testAccDataSourceBackupPolicyVm_basic(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectionPolicyVM_basicDaily(data) + return fmt.Sprintf(` %s -data "azurerm_recovery_services_protection_policy_vm" "test" { - name = "${azurerm_recovery_services_protection_policy_vm.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" +data "azurerm_backup_policy_vm" "test" { + name = "${azurerm_backup_policy_vm.test.name}" + recovery_vault_name = "${azurerm_backup_vault.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } `, template) diff --git a/azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_vault_test.go b/azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_vault_test.go index 0a6bae126319c..aaf98ec215ca5 100644 --- a/azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_vault_test.go +++ b/azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_vault_test.go @@ -32,7 +32,7 @@ func TestAccDataSourceAzureRMRecoveryServicesVault_basic(t *testing.T) { func testAccDataSourceRecoveryServicesVault_basic(data acceptance.TestData) string { template := testAccAzureRMRecoveryServicesVault_basic(data) - return fmt.Sprintf(` + return fmt.Sprintf(` %s data "azurerm_recovery_services_vault" "test" { diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_container_storage_account_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_container_storage_account_test.go index 3ca2d9accefcd..9cb29db4d132b 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_container_storage_account_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_container_storage_account_test.go @@ -33,6 +33,10 @@ func TestAccAzureRMBackupProtectionContainerStorageAccount_basic(t *testing.T) { func testAccAzureRMBackupProtectionContainerStorageAccount_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-backup-%d" location = "%s" @@ -40,8 +44,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_recovery_services_vault" "testvlt" { name = "acctest-vault-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" soft_delete_enabled = false @@ -49,17 +53,17 @@ resource "azurerm_recovery_services_vault" "testvlt" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_backup_container_storage_account" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.testvlt.name}" - storage_account_id = "${azurerm_storage_account.test.id}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.testvlt.name + storage_account_id = azurerm_storage_account.test.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString) } diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_file_share_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_file_share_test.go index 2b3938836af7c..30d44d3288d36 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_file_share_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_file_share_test.go @@ -133,7 +133,11 @@ func testCheckAzureRMBackupProtectionPolicyFileShareExists(resourceName string) } func testAccAzureRMBackupProtectionPolicyFileShare_base(data acceptance.TestData) string { - return fmt.Sprintf(` + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-backup-%d" location = "%s" @@ -157,8 +161,8 @@ func testAccAzureRMBackupProtectionPolicyFileShare_basicDaily(data acceptance.Te resource "azurerm_backup_policy_file_share" "test" { name = "acctest-PFS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name backup { frequency = "Daily" @@ -179,8 +183,8 @@ func testAccAzureRMBackupProtectionPolicyFileShare_updateDaily(data acceptance.T resource "azurerm_backup_policy_file_share" "test" { name = "acctest-PFS-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name backup { frequency = "Daily" @@ -200,9 +204,9 @@ func testAccAzureRMBackupProtectionPolicyFileShare_requiresImport(data acceptanc %s resource "azurerm_backup_policy_file_share" "import" { - name = "${azurerm_backup_policy_file_share.test.name}" - resource_group_name = "${azurerm_backup_policy_file_share.test.resource_group_name}" - recovery_vault_name = "${azurerm_backup_policy_file_share.test.recovery_vault_name}" + name = azurerm_backup_policy_file_share.test.name + resource_group_name = azurerm_backup_policy_file_share.test.resource_group_name + recovery_vault_name = azurerm_backup_policy_file_share.test.recovery_vault_name backup { frequency = "Daily" diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_vm_test.go index 4852d07b9de70..754fbe78d7395 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_vm_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_vm_test.go @@ -351,7 +351,11 @@ func testCheckAzureRMBackupProtectionPolicyVmExists(resourceName string) resourc } func testAccAzureRMBackupProtectionPolicyVM_template(data acceptance.TestData) string { - return fmt.Sprintf(` + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-backup-%d" location = "%s" @@ -375,8 +379,8 @@ func testAccAzureRMBackupProtectionPolicyVM_basicDaily(data acceptance.TestData) resource "azurerm_backup_policy_vm" "test" { name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name backup { frequency = "Daily" @@ -396,9 +400,9 @@ func testAccAzureRMBackupProtectionPolicyVM_requiresImport(data acceptance.TestD %s resource "azurerm_backup_policy_vm" "import" { - name = "${azurerm_backup_policy_vm.test.name}" - resource_group_name = "${azurerm_backup_policy_vm.test.resource_group_name}" - recovery_vault_name = "${azurerm_backup_policy_vm.test.recovery_vault_name}" + name = azurerm_backup_policy_vm.test.name + resource_group_name = azurerm_backup_policy_vm.test.resource_group_name + recovery_vault_name = azurerm_backup_policy_vm.test.recovery_vault_name backup { frequency = "Daily" @@ -419,8 +423,8 @@ func testAccAzureRMBackupProtectionPolicyVM_basicWeekly(data acceptance.TestData resource "azurerm_backup_policy_vm" "test" { name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name backup { frequency = "Weekly" @@ -443,8 +447,8 @@ func testAccAzureRMBackupProtectionPolicyVM_completeDaily(data acceptance.TestDa resource "azurerm_backup_policy_vm" "test" { name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name backup { frequency = "Daily" @@ -483,8 +487,8 @@ func testAccAzureRMBackupProtectionPolicyVM_completeWeekly(data acceptance.TestD resource "azurerm_backup_policy_vm" "test" { name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name backup { frequency = "Weekly" @@ -520,8 +524,8 @@ func testAccAzureRMBackupProtectionPolicyVM_completeWeeklyPartial(data acceptanc resource "azurerm_backup_policy_vm" "test" { name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name backup { frequency = "Weekly" diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_file_share_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_file_share_test.go index 4b5a6cf67cac2..383bc268728d7 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_file_share_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_file_share_test.go @@ -30,7 +30,7 @@ func TestAccAzureRMBackupProtectedFileShare_basic(t *testing.T) { ), }, data.ImportStep(), - { //vault cannot be deleted unless we unregister all backups + { // vault cannot be deleted unless we unregister all backups Config: testAccAzureRMBackupProtectedFileShare_base(data), Check: resource.ComposeTestCheckFunc(), }, @@ -59,7 +59,7 @@ func TestAccAzureRMBackupProtectedFileShare_requiresImport(t *testing.T) { ), }, data.RequiresImportErrorStep(testAccAzureRMBackupProtectedFileShare_requiresImport), - { //vault cannot be deleted unless we unregister all backups + { // vault cannot be deleted unless we unregister all backups Config: testAccAzureRMBackupProtectedFileShare_base(data), Check: resource.ComposeTestCheckFunc(), }, @@ -186,7 +186,11 @@ func testCheckAzureRMBackupProtectedFileShareExists(resourceName string) resourc } func testAccAzureRMBackupProtectedFileShare_base(data acceptance.TestData) string { - return fmt.Sprintf(` + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-backup-%[1]d" location = "%[2]s" @@ -204,9 +208,9 @@ resource "azurerm_storage_share" "test" { name = "acctest-ss-%[1]d" storage_account_name = "${azurerm_storage_account.test.name}" metadata = {} - + lifecycle { - ignore_changes = [metadata] // Ignore changes Azure Backup makes to the metadata + ignore_changes = [metadata] // Ignore changes Azure Backup makes to the metadata } } @@ -242,17 +246,17 @@ func testAccAzureRMBackupProtectedFileShare_basic(data acceptance.TestData) stri %s resource "azurerm_backup_container_storage_account" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - storage_account_id = "${azurerm_storage_account.test.id}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + storage_account_id = azurerm_storage_account.test.id } resource "azurerm_backup_protected_file_share" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - source_storage_account_id = "${azurerm_backup_container_storage_account.test.storage_account_id}" - source_file_share_name = "${azurerm_storage_share.test.name}" - backup_policy_id = "${azurerm_backup_policy_file_share.test1.id}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + source_storage_account_id = azurerm_backup_container_storage_account.test.storage_account_id + source_file_share_name = azurerm_storage_share.test.name + backup_policy_id = azurerm_backup_policy_file_share.test1.id } `, template) } @@ -264,8 +268,8 @@ func testAccAzureRMBackupProtectedFileShare_updatePolicy(data acceptance.TestDat resource "azurerm_backup_policy_file_share" "test2" { name = "acctest-%d-Secondary" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name backup { frequency = "Daily" @@ -278,17 +282,17 @@ resource "azurerm_backup_policy_file_share" "test2" { } resource "azurerm_backup_container_storage_account" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - storage_account_id = "${azurerm_storage_account.test.id}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + storage_account_id = azurerm_storage_account.test.id } resource "azurerm_backup_protected_file_share" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - source_storage_account_id = "${azurerm_backup_container_storage_account.test.storage_account_id}" - source_file_share_name = "${azurerm_storage_share.test.name}" - backup_policy_id = "${azurerm_backup_policy_file_share.test2.id}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + source_storage_account_id = azurerm_backup_container_storage_account.test.storage_account_id + source_file_share_name = azurerm_storage_share.test.name + backup_policy_id = azurerm_backup_policy_file_share.test2.id } `, template, data.RandomInteger) } @@ -299,11 +303,11 @@ func testAccAzureRMBackupProtectedFileShare_requiresImport(data acceptance.TestD %s resource "azurerm_backup_protected_file_share" "test_import" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - source_storage_account_id = "${azurerm_storage_account.test.id}" - source_file_share_name = "${azurerm_storage_share.test.name}" - backup_policy_id = "${azurerm_backup_policy_file_share.test1.id}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + source_storage_account_id = azurerm_storage_account.test.id + source_file_share_name = azurerm_storage_share.test.name + backup_policy_id = azurerm_backup_policy_file_share.test1.id } `, template) } diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_vm_test.go index aee64ce3ad091..00fe5d1c8d2be 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_vm_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_vm_test.go @@ -29,7 +29,7 @@ func TestAccAzureRMBackupProtectedVm_basic(t *testing.T) { ), }, data.ImportStep(), - { //vault cannot be deleted unless we unregister all backups + { // vault cannot be deleted unless we unregister all backups Config: testAccAzureRMBackupProtectedVm_base(data), Check: resource.ComposeTestCheckFunc(), }, @@ -58,7 +58,7 @@ func TestAccAzureRMBackupProtectedVm_requiresImport(t *testing.T) { ), }, data.RequiresImportErrorStep(testAccAzureRMBackupProtectedVm_requiresImport), - { //vault cannot be deleted unless we unregister all backups + { // vault cannot be deleted unless we unregister all backups Config: testAccAzureRMBackupProtectedVm_base(data), Check: resource.ComposeTestCheckFunc(), }, @@ -82,7 +82,7 @@ func TestAccAzureRMBackupProtectedVm_separateResourceGroups(t *testing.T) { ), }, data.ImportStep(), - { //vault cannot be deleted unless we unregister all backups + { // vault cannot be deleted unless we unregister all backups Config: testAccAzureRMBackupProtectedVm_additionalVault(data), Check: resource.ComposeTestCheckFunc(), }, @@ -196,7 +196,7 @@ func testCheckAzureRMBackupProtectedVmExists(resourceName string) resource.TestC vaultName := rs.Primary.Attributes["recovery_vault_name"] vmId := rs.Primary.Attributes["source_vm_id"] - //get VM name from id + // get VM name from id parsedVmId, err := azure.ParseAzureResourceID(vmId) if err != nil { return fmt.Errorf("[ERROR] Unable to parse source_vm_id '%s': %+v", vmId, err) @@ -223,7 +223,11 @@ func testCheckAzureRMBackupProtectedVmExists(resourceName string) resource.TestC } func testAccAzureRMBackupProtectedVm_base(data acceptance.TestData) string { - return fmt.Sprintf(` + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-backup-%d" location = "%s" @@ -359,10 +363,10 @@ func testAccAzureRMBackupProtectedVm_basic(data acceptance.TestData) string { %s resource "azurerm_backup_protected_vm" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - source_vm_id = "${azurerm_virtual_machine.test.id}" - backup_policy_id = "${azurerm_backup_policy_vm.test.id}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + source_vm_id = azurerm_virtual_machine.test.id + backup_policy_id = azurerm_backup_policy_vm.test.id } `, template) } @@ -370,6 +374,10 @@ resource "azurerm_backup_protected_vm" "test" { // For update backup policy id test func testAccAzureRMBackupProtectedVm_basePolicyTest(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-backup-%d-1" location = "%s" @@ -377,51 +385,51 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "vnet" - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location address_space = ["10.0.0.0/16"] - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctest_subnet" - virtual_network_name = "${azurerm_virtual_network.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = azurerm_virtual_network.test.name + resource_group_name = azurerm_resource_group.test.name address_prefix = "10.0.10.0/24" } resource "azurerm_network_interface" "test" { name = "acctest_nic" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "acctestipconfig" - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" + public_ip_address_id = azurerm_public_ip.test.id } } resource "azurerm_public_ip" "test" { name = "acctest-ip" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Dynamic" domain_name_label = "acctestip%d" } resource "azurerm_storage_account" "test" { name = "acctest%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_managed_disk" "test" { name = "acctest-datadisk" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name storage_account_type = "Standard_LRS" create_option = "Empty" disk_size_gb = "1023" @@ -437,8 +445,8 @@ func testAccAzureRMBackupProtectedVm_withVault(data acceptance.TestData) string resource "azurerm_recovery_services_vault" "test" { name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" soft_delete_enabled = false @@ -454,8 +462,8 @@ func testAccAzureRMBackupProtectedVm_withFirstPolicy(data acceptance.TestData) s resource "azurerm_backup_policy_vm" "test" { name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name backup { frequency = "Daily" @@ -477,8 +485,8 @@ func testAccAzureRMBackupProtectedVm_withSecondPolicy(data acceptance.TestData) resource "azurerm_backup_policy_vm" "test_change_backup" { name = "acctest2-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name backup { frequency = "Daily" @@ -500,10 +508,10 @@ func testAccAzureRMBackupProtectedVm_withVM(data acceptance.TestData) string { resource "azurerm_virtual_machine" "test" { name = "acctestvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name vm_size = "Standard_A0" - network_interface_ids = ["${azurerm_network_interface.test.id}"] + network_interface_ids = [azurerm_network_interface.test.id] delete_os_disk_on_termination = true storage_image_reference { @@ -522,9 +530,9 @@ resource "azurerm_virtual_machine" "test" { storage_data_disk { name = "acctest-datadisk" - managed_disk_id = "${azurerm_managed_disk.test.id}" + managed_disk_id = azurerm_managed_disk.test.id managed_disk_type = "Standard_LRS" - disk_size_gb = "${azurerm_managed_disk.test.disk_size_gb}" + disk_size_gb = azurerm_managed_disk.test.disk_size_gb create_option = "Attach" lun = 0 } @@ -541,7 +549,7 @@ resource "azurerm_virtual_machine" "test" { boot_diagnostics { enabled = true - storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}" + storage_uri = azurerm_storage_account.test.primary_blob_endpoint } } `, template, data.RandomInteger) @@ -554,10 +562,10 @@ func testAccAzureRMBackupProtectedVm_linkFirstBackupPolicy(data acceptance.TestD %s resource "azurerm_backup_protected_vm" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - source_vm_id = "${azurerm_virtual_machine.test.id}" - backup_policy_id = "${azurerm_backup_policy_vm.test.id}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + source_vm_id = azurerm_virtual_machine.test.id + backup_policy_id = azurerm_backup_policy_vm.test.id } `, template) } @@ -569,10 +577,10 @@ func testAccAzureRMBackupProtectedVm_linkSecondBackupPolicy(data acceptance.Test %s resource "azurerm_backup_protected_vm" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - source_vm_id = "${azurerm_virtual_machine.test.id}" - backup_policy_id = "${azurerm_backup_policy_vm.test_change_backup.id}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + source_vm_id = azurerm_virtual_machine.test.id + backup_policy_id = azurerm_backup_policy_vm.test_change_backup.id } `, template) } @@ -583,10 +591,10 @@ func testAccAzureRMBackupProtectedVm_requiresImport(data acceptance.TestData) st %s resource "azurerm_backup_protected_vm" "import" { - resource_group_name = "${azurerm_backup_protected_vm.test.resource_group_name}" - recovery_vault_name = "${azurerm_backup_protected_vm.test.recovery_vault_name}" - source_vm_id = "${azurerm_backup_protected_vm.test.source_vm_id}" - backup_policy_id = "${azurerm_backup_protected_vm.test.backup_policy_id}" + resource_group_name = azurerm_backup_protected_vm.test.resource_group_name + recovery_vault_name = azurerm_backup_protected_vm.test.recovery_vault_name + source_vm_id = azurerm_backup_protected_vm.test.source_vm_id + backup_policy_id = azurerm_backup_protected_vm.test.backup_policy_id } `, template) } @@ -603,8 +611,8 @@ resource "azurerm_resource_group" "test2" { resource "azurerm_recovery_services_vault" "test2" { name = "acctest2-%d" - location = "${azurerm_resource_group.test2.location}" - resource_group_name = "${azurerm_resource_group.test2.name}" + location = azurerm_resource_group.test2.location + resource_group_name = azurerm_resource_group.test2.name sku = "Standard" soft_delete_enabled = false @@ -612,8 +620,8 @@ resource "azurerm_recovery_services_vault" "test2" { resource "azurerm_backup_policy_vm" "test2" { name = "acctest2-%d" - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test2.name}" + resource_group_name = azurerm_resource_group.test2.name + recovery_vault_name = azurerm_recovery_services_vault.test2.name backup { frequency = "Daily" @@ -633,10 +641,10 @@ func testAccAzureRMBackupProtectedVm_separateResourceGroups(data acceptance.Test %s resource "azurerm_backup_protected_vm" "test" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test2.name}" - backup_policy_id = "${azurerm_backup_policy_vm.test2.id}" - source_vm_id = "${azurerm_virtual_machine.test.id}" + resource_group_name = azurerm_resource_group.test2.name + recovery_vault_name = azurerm_recovery_services_vault.test2.name + backup_policy_id = azurerm_backup_policy_vm.test2.id + source_vm_id = azurerm_virtual_machine.test.id } `, template) } diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_fabric_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_fabric_test.go deleted file mode 100644 index c832d65df33a7..0000000000000 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_fabric_test.go +++ /dev/null @@ -1,113 +0,0 @@ -package tests - -import ( - "fmt" - "net/http" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" -) - -func TestAccAzureRMRecoveryFabric_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_fabric", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryFabricDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryFabric_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryFabricExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMRecoveryFabric_basic(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-recovery-%d" - location = "%s" -} - -resource "azurerm_recovery_services_vault" "test" { - name = "acctest-vault-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Standard" - - soft_delete_enabled = false -} - -resource "azurerm_recovery_services_fabric" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "acctest-fabric-%d" - location = "${azurerm_resource_group.test.location}" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} - -func testCheckAzureRMRecoveryFabricExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // Ensure we have enough information in state to look up in API - state, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - resourceGroupName := state.Primary.Attributes["resource_group_name"] - vaultName := state.Primary.Attributes["recovery_vault_name"] - fabricName := state.Primary.Attributes["name"] - - // Ensure fabric exists in API - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.FabricClient(resourceGroupName, vaultName) - - resp, err := client.Get(ctx, fabricName) - if err != nil { - return fmt.Errorf("Bad: Get on fabricClient: %+v", err) - } - - if resp.Response.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: fabric: %q does not exist", fabricName) - } - - return nil - } -} - -func testCheckAzureRMRecoveryFabricDestroy(s *terraform.State) error { - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_recovery_services_fabric" { - continue - } - - resourceGroupName := rs.Primary.Attributes["resource_group_name"] - vaultName := rs.Primary.Attributes["recovery_vault_name"] - resourceGroup := rs.Primary.Attributes["name"] - - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.FabricClient(resourceGroupName, vaultName) - - resp, err := client.Get(ctx, resourceGroup) - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("Recovery Services Fabric still exists:\n%#v", resp.Properties) - } - } - - return nil -} diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_network_mapping_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_network_mapping_test.go deleted file mode 100644 index fb9148d2e0091..0000000000000 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_network_mapping_test.go +++ /dev/null @@ -1,161 +0,0 @@ -package tests - -import ( - "fmt" - "net/http" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" -) - -func TestAccAzureRMRecoveryNetworkMapping_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_network_mapping", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryNetworkMappingDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryNetworkMapping_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryNetworkMappingExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMRecoveryNetworkMapping_basic(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-recovery-%d-1" - location = "%s" -} - -resource "azurerm_recovery_services_vault" "test" { - name = "acctest-vault-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Standard" - - soft_delete_enabled = false -} - -resource "azurerm_recovery_services_fabric" "test1" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "acctest-fabric1-%d" - location = "${azurerm_resource_group.test.location}" -} - -resource "azurerm_recovery_services_fabric" "test2" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "acctest-fabric2-%d" - location = "%s" - depends_on = ["azurerm_recovery_services_fabric.test1"] -} - -resource "azurerm_virtual_network" "test1" { - name = "network1-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - address_space = ["192.168.1.0/24"] - location = "${azurerm_recovery_services_fabric.test1.location}" -} - -resource "azurerm_virtual_network" "test2" { - name = "network2-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - address_space = ["192.168.2.0/24"] - location = "${azurerm_recovery_services_fabric.test2.location}" -} - -resource "azurerm_recovery_network_mapping" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "mapping-%d" - source_recovery_fabric_name = "${azurerm_recovery_services_fabric.test1.name}" - target_recovery_fabric_name = "${azurerm_recovery_services_fabric.test2.name}" - source_network_id = "${azurerm_virtual_network.test1.id}" - target_network_id = "${azurerm_virtual_network.test2.id}" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testCheckAzureRMRecoveryNetworkMappingExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - // Ensure we have enough information in state to look up in API - state, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - resourceGroupName := state.Primary.Attributes["resource_group_name"] - vaultName := state.Primary.Attributes["recovery_vault_name"] - fabricName := state.Primary.Attributes["source_recovery_fabric_name"] - networkId := state.Primary.Attributes["source_network_id"] - mappingName := state.Primary.Attributes["name"] - - id, err := azure.ParseAzureResourceID(networkId) - if err != nil { - return err - } - networkName := id.Path["virtualNetworks"] - - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.NetworkMappingClient(resourceGroupName, vaultName) - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // TODO Fix Bad: networkMapping error - resp, err := client.Get(ctx, fabricName, networkName, mappingName) - if err != nil { - if resp.Response.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: networkMapping: %q (network %q) does not exist", mappingName, networkName) - } - - return fmt.Errorf("Bad: Get on networkMappingClient: %+v", err) - } - - return nil - } -} - -func testCheckAzureRMRecoveryNetworkMappingDestroy(s *terraform.State) error { - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_recovery_network_mapping" { - continue - } - - resourceGroupName := rs.Primary.Attributes["resource_group_name"] - vaultName := rs.Primary.Attributes["recovery_vault_name"] - fabricName := rs.Primary.Attributes["source_recovery_fabric_name"] - networkId := rs.Primary.Attributes["source_network_id"] - mappingName := rs.Primary.Attributes["name"] - - id, err := azure.ParseAzureResourceID(networkId) - if err != nil { - return err - } - networkName := id.Path["virtualNetworks"] - - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.NetworkMappingClient(resourceGroupName, vaultName) - - resp, err := client.Get(ctx, fabricName, networkName, mappingName) - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("Network Mapping still exists:\n%#v", resp.Properties) - } - } - - return nil -} diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protected_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protected_vm_test.go deleted file mode 100644 index 6fcb6c1e6d365..0000000000000 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protected_vm_test.go +++ /dev/null @@ -1,642 +0,0 @@ -package tests - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func TestAccAzureRMRecoveryServicesProtectedVm_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protected_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectedVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectedVm_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectedVmExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), - ), - }, - data.ImportStep(), - { //vault cannot be deleted unless we unregister all backups - Config: testAccAzureRMRecoveryServicesProtectedVm_base(data), - Check: resource.ComposeTestCheckFunc(), - }, - }, - }) -} - -func TestAccAzureRMRecoveryServicesProtectedVm_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protected_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectedVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectedVm_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectedVmExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), - ), - }, - data.RequiresImportErrorStep(testAccAzureRMRecoveryServicesProtectedVm_requiresImport), - { //vault cannot be deleted unless we unregister all backups - Config: testAccAzureRMRecoveryServicesProtectedVm_base(data), - Check: resource.ComposeTestCheckFunc(), - }, - }, - }) -} - -func TestAccAzureRMRecoveryServicesProtectedVm_separateResourceGroups(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protected_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectedVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectedVm_separateResourceGroups(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectedVmExists(data.ResourceName), - resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), - ), - }, - data.ImportStep(), - { //vault cannot be deleted unless we unregister all backups - Config: testAccAzureRMRecoveryServicesProtectedVm_additionalVault(data), - Check: resource.ComposeTestCheckFunc(), - }, - }, - }) -} - -func TestAccAzureRMRecoveryServicesProtectedVm_updateBackupPolicyId(t *testing.T) { - virtualMachine := "azurerm_virtual_machine.test" - fBackupPolicyResourceName := "azurerm_recovery_services_protection_policy_vm.test" - sBackupPolicyResourceName := "azurerm_recovery_services_protection_policy_vm.test_change_backup" - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protected_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectedVmDestroy, - Steps: []resource.TestStep{ - { // Create resources and link first backup policy id - ResourceName: fBackupPolicyResourceName, - Config: testAccAzureRMRecoveryServicesProtectedVm_linkFirstBackupPolicy(data), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair(data.ResourceName, "backup_policy_id", fBackupPolicyResourceName, "id"), - ), - }, - { // Modify backup policy id to the second one - // Set Destroy false to prevent error from cleaning up dangling resource - ResourceName: sBackupPolicyResourceName, - Config: testAccAzureRMRecoveryServicesProtectedVm_linkSecondBackupPolicy(data), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair(data.ResourceName, "backup_policy_id", sBackupPolicyResourceName, "id"), - ), - }, - { // Remove backup policy link - // Backup policy link will need to be removed first so the VM's backup policy subsequently reverts to Default - // Azure API is quite sensitive, adding the step to control resource cleanup order - ResourceName: fBackupPolicyResourceName, - Config: testAccAzureRMRecoveryServicesProtectedVm_withVM(data), - Check: resource.ComposeTestCheckFunc(), - }, - { // Then VM can be removed - ResourceName: virtualMachine, - Config: testAccAzureRMRecoveryServicesProtectedVm_withSecondPolicy(data), - Check: resource.ComposeTestCheckFunc(), - }, - { // Remove backup policies and vault - ResourceName: data.ResourceName, - Config: testAccAzureRMRecoveryServicesProtectedVm_basePolicyTest(data), - Check: resource.ComposeTestCheckFunc(), - }, - }, - }) -} - -func testCheckAzureRMRecoveryServicesProtectedVmDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.ProtectedItemsClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_recovery_services_protected_vm" { - continue - } - - resourceGroup := rs.Primary.Attributes["resource_group_name"] - vaultName := rs.Primary.Attributes["recovery_vault_name"] - vmId := rs.Primary.Attributes["source_vm_id"] - - parsedVmId, err := azure.ParseAzureResourceID(vmId) - if err != nil { - return fmt.Errorf("[ERROR] Unable to parse source_vm_id '%s': %+v", vmId, err) - } - vmName, hasName := parsedVmId.Path["virtualMachines"] - if !hasName { - return fmt.Errorf("[ERROR] parsed source_vm_id '%s' doesn't contain 'virtualMachines'", vmId) - } - - protectedItemName := fmt.Sprintf("VM;iaasvmcontainerv2;%s;%s", parsedVmId.ResourceGroup, vmName) - containerName := fmt.Sprintf("iaasvmcontainer;iaasvmcontainerv2;%s;%s", parsedVmId.ResourceGroup, vmName) - - resp, err := client.Get(ctx, vaultName, resourceGroup, "Azure", containerName, protectedItemName, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return nil - } - - return err - } - - return fmt.Errorf("Recovery Services Protected VM still exists:\n%#v", resp) - } - - return nil -} - -func testCheckAzureRMRecoveryServicesProtectedVmExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.ProtectedItemsClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // Ensure we have enough information in state to look up in API - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %q", resourceName) - } - - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for Recovery Services Protected VM: %q", resourceName) - } - - vaultName := rs.Primary.Attributes["recovery_vault_name"] - vmId := rs.Primary.Attributes["source_vm_id"] - - //get VM name from id - parsedVmId, err := azure.ParseAzureResourceID(vmId) - if err != nil { - return fmt.Errorf("[ERROR] Unable to parse source_vm_id '%s': %+v", vmId, err) - } - vmName, hasName := parsedVmId.Path["virtualMachines"] - if !hasName { - return fmt.Errorf("[ERROR] parsed source_vm_id '%s' doesn't contain 'virtualMachines'", vmId) - } - - protectedItemName := fmt.Sprintf("VM;iaasvmcontainerv2;%s;%s", parsedVmId.ResourceGroup, vmName) - containerName := fmt.Sprintf("iaasvmcontainer;iaasvmcontainerv2;%s;%s", parsedVmId.ResourceGroup, vmName) - - resp, err := client.Get(ctx, vaultName, resourceGroup, "Azure", containerName, protectedItemName, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Recovery Services Protected VM %q (resource group: %q) was not found: %+v", protectedItemName, resourceGroup, err) - } - - return fmt.Errorf("Bad: Get on recoveryServicesVaultsClient: %+v", err) - } - - return nil - } -} - -func testAccAzureRMRecoveryServicesProtectedVm_base(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-recovery-%d" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "vnet" - location = "${azurerm_resource_group.test.location}" - address_space = ["10.0.0.0/16"] - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "acctest_subnet" - virtual_network_name = "${azurerm_virtual_network.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - address_prefix = "10.0.10.0/24" -} - -resource "azurerm_network_interface" "test" { - name = "acctest_nic" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "acctestipconfig" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" - } -} - -resource "azurerm_public_ip" "test" { - name = "acctest-ip" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - allocation_method = "Dynamic" - domain_name_label = "acctestip%d" -} - -resource "azurerm_storage_account" "test" { - name = "acctest%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - account_tier = "Standard" - account_replication_type = "LRS" -} - -resource "azurerm_managed_disk" "test" { - name = "acctest-datadisk" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_type = "Standard_LRS" - create_option = "Empty" - disk_size_gb = "1023" -} - -resource "azurerm_virtual_machine" "test" { - name = "acctestvm" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - vm_size = "Standard_A0" - network_interface_ids = ["${azurerm_network_interface.test.id}"] - - storage_image_reference { - publisher = "Canonical" - offer = "UbuntuServer" - sku = "16.04-LTS" - version = "latest" - } - - storage_os_disk { - name = "acctest-osdisk" - managed_disk_type = "Standard_LRS" - caching = "ReadWrite" - create_option = "FromImage" - } - - storage_data_disk { - name = "acctest-datadisk" - managed_disk_id = "${azurerm_managed_disk.test.id}" - managed_disk_type = "Standard_LRS" - disk_size_gb = "${azurerm_managed_disk.test.disk_size_gb}" - create_option = "Attach" - lun = 0 - } - - os_profile { - computer_name = "acctest" - admin_username = "vmadmin" - admin_password = "Password123!@#" - } - - os_profile_linux_config { - disable_password_authentication = false - } - - boot_diagnostics { - enabled = true - storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}" - } -} - -resource "azurerm_recovery_services_vault" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Standard" - - soft_delete_enabled = false -} - -resource "azurerm_recovery_services_protection_policy_vm" "test" { - name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - - backup { - frequency = "Daily" - time = "23:00" - } - - retention_daily { - count = 10 - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMRecoveryServicesProtectedVm_basic(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectedVm_base(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protected_vm" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - source_vm_id = "${azurerm_virtual_machine.test.id}" - backup_policy_id = "${azurerm_recovery_services_protection_policy_vm.test.id}" -} -`, template) -} - -// For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_basePolicyTest(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-recovery-%d-1" - location = "%s" -} - -resource "azurerm_virtual_network" "test" { - name = "vnet" - location = "${azurerm_resource_group.test.location}" - address_space = ["10.0.0.0/16"] - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_subnet" "test" { - name = "acctest_subnet" - virtual_network_name = "${azurerm_virtual_network.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - address_prefix = "10.0.10.0/24" -} - -resource "azurerm_network_interface" "test" { - name = "acctest_nic" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "acctestipconfig" - subnet_id = "${azurerm_subnet.test.id}" - private_ip_address_allocation = "Dynamic" - public_ip_address_id = "${azurerm_public_ip.test.id}" - } -} - -resource "azurerm_public_ip" "test" { - name = "acctest-ip" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - allocation_method = "Dynamic" - domain_name_label = "acctestip%d" -} - -resource "azurerm_storage_account" "test" { - name = "acctest%s" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - account_tier = "Standard" - account_replication_type = "LRS" -} - -resource "azurerm_managed_disk" "test" { - name = "acctest-datadisk" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_type = "Standard_LRS" - create_option = "Empty" - disk_size_gb = "1023" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString) -} - -// For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_withVault(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectedVm_basePolicyTest(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_vault" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Standard" - - soft_delete_enabled = false -} -`, template, data.RandomInteger) -} - -// For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_withFirstPolicy(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectedVm_withVault(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protection_policy_vm" "test" { - name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - - backup { - frequency = "Daily" - time = "23:00" - } - - retention_daily { - count = 10 - } -} -`, template, data.RandomInteger) -} - -// For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_withSecondPolicy(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectedVm_withFirstPolicy(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protection_policy_vm" "test_change_backup" { - name = "acctest2-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - - backup { - frequency = "Daily" - time = "23:00" - } - - retention_daily { - count = 15 - } -} -`, template, data.RandomInteger) -} - -// For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_withVM(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectedVm_withSecondPolicy(data) - return fmt.Sprintf(` -%s - -resource "azurerm_virtual_machine" "test" { - name = "acctestvm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - vm_size = "Standard_A0" - network_interface_ids = ["${azurerm_network_interface.test.id}"] - delete_os_disk_on_termination = true - - storage_image_reference { - publisher = "Canonical" - offer = "UbuntuServer" - sku = "16.04-LTS" - version = "latest" - } - - storage_os_disk { - name = "acctest-osdisk" - managed_disk_type = "Standard_LRS" - caching = "ReadWrite" - create_option = "FromImage" - } - - storage_data_disk { - name = "acctest-datadisk" - managed_disk_id = "${azurerm_managed_disk.test.id}" - managed_disk_type = "Standard_LRS" - disk_size_gb = "${azurerm_managed_disk.test.disk_size_gb}" - create_option = "Attach" - lun = 0 - } - - os_profile { - computer_name = "acctest" - admin_username = "vmadmin" - admin_password = "Password123!@#" - } - - os_profile_linux_config { - disable_password_authentication = false - } - - boot_diagnostics { - enabled = true - storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}" - } -} -`, template, data.RandomInteger) -} - -// For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_linkFirstBackupPolicy(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectedVm_withVM(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protected_vm" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - source_vm_id = "${azurerm_virtual_machine.test.id}" - backup_policy_id = "${azurerm_recovery_services_protection_policy_vm.test.id}" -} -`, template) -} - -// For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_linkSecondBackupPolicy(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectedVm_withVM(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protected_vm" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - source_vm_id = "${azurerm_virtual_machine.test.id}" - backup_policy_id = "${azurerm_recovery_services_protection_policy_vm.test_change_backup.id}" -} -`, template) -} - -func testAccAzureRMRecoveryServicesProtectedVm_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectedVm_basic(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protected_vm" "import" { - resource_group_name = "${azurerm_recovery_services_protected_vm.test.resource_group_name}" - recovery_vault_name = "${azurerm_recovery_services_protected_vm.test.recovery_vault_name}" - source_vm_id = "${azurerm_recovery_services_protected_vm.test.source_vm_id}" - backup_policy_id = "${azurerm_recovery_services_protected_vm.test.backup_policy_id}" -} -`, template) -} - -func testAccAzureRMRecoveryServicesProtectedVm_additionalVault(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectedVm_base(data) - return fmt.Sprintf(` -%s - -resource "azurerm_resource_group" "test2" { - name = "acctestRG-recovery-%d-2" - location = "%s" -} - -resource "azurerm_recovery_services_vault" "test2" { - name = "acctest2-%d" - location = "${azurerm_resource_group.test2.location}" - resource_group_name = "${azurerm_resource_group.test2.name}" - sku = "Standard" - - soft_delete_enabled = false -} - -resource "azurerm_recovery_services_protection_policy_vm" "test2" { - name = "acctest2-%d" - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test2.name}" - - backup { - frequency = "Daily" - time = "23:00" - } - - retention_daily { - count = 10 - } -} -`, template, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} - -func testAccAzureRMRecoveryServicesProtectedVm_separateResourceGroups(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectedVm_additionalVault(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protected_vm" "test" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test2.name}" - backup_policy_id = "${azurerm_recovery_services_protection_policy_vm.test2.id}" - source_vm_id = "${azurerm_virtual_machine.test.id}" -} -`, template) -} diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_container_mapping_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_container_mapping_test.go deleted file mode 100644 index 9bd3f3eabebe8..0000000000000 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_container_mapping_test.go +++ /dev/null @@ -1,158 +0,0 @@ -package tests - -import ( - "fmt" - "net/http" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" -) - -func TestAccAzureRMRecoveryProtectionContainerMapping_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_container_mapping", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryProtectionContainerMappingDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryProtectionContainerMapping_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryProtectionContainerMappingExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMRecoveryProtectionContainerMapping_basic(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test1" { - name = "acctestRG-recovery-%d-1" - location = "%s" -} - -resource "azurerm_recovery_services_vault" "test" { - name = "acctest-vault-%d" - location = "${azurerm_resource_group.test1.location}" - resource_group_name = "${azurerm_resource_group.test1.name}" - sku = "Standard" - - soft_delete_enabled = false -} - -resource "azurerm_recovery_services_fabric" "test1" { - resource_group_name = "${azurerm_resource_group.test1.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "acctest-fabric1-%d" - location = "${azurerm_resource_group.test1.location}" -} - -resource "azurerm_recovery_services_fabric" "test2" { - resource_group_name = "${azurerm_resource_group.test1.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "acctest-fabric2-%d" - location = "%s" - depends_on = ["azurerm_recovery_services_fabric.test1"] -} - -resource "azurerm_recovery_services_protection_container" "test1" { - resource_group_name = "${azurerm_resource_group.test1.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_recovery_services_fabric.test1.name}" - name = "acctest-protection-cont1-%d" -} - -resource "azurerm_recovery_services_protection_container" "test2" { - resource_group_name = "${azurerm_resource_group.test1.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_recovery_services_fabric.test2.name}" - name = "acctest-protection-cont2-%d" -} - -resource "azurerm_recovery_services_replication_policy" "test" { - resource_group_name = "${azurerm_resource_group.test1.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "acctest-policy-%d" - recovery_point_retention_in_minutes = "${24 * 60}" - application_consistent_snapshot_frequency_in_minutes = "${4 * 60}" -} - -resource "azurerm_recovery_services_protection_container_mapping" "test" { - resource_group_name = "${azurerm_resource_group.test1.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_recovery_services_fabric.test1.name}" - recovery_source_protection_container_name = "${azurerm_recovery_services_protection_container.test1.name}" - recovery_target_protection_container_id = "${azurerm_recovery_services_protection_container.test2.id}" - recovery_replication_policy_id = "${azurerm_recovery_services_replication_policy.test.id}" - name = "mapping-%d" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testCheckAzureRMRecoveryProtectionContainerMappingExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // Ensure we have enough information in state to look up in API - state, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - resourceGroupName := state.Primary.Attributes["resource_group_name"] - vaultName := state.Primary.Attributes["recovery_vault_name"] - fabricName := state.Primary.Attributes["recovery_fabric_name"] - protectionContainerName := state.Primary.Attributes["recovery_source_protection_container_name"] - mappingName := state.Primary.Attributes["name"] - - // Ensure mapping exists in API - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.ContainerMappingClient(resourceGroupName, vaultName) - - resp, err := client.Get(ctx, fabricName, protectionContainerName, mappingName) - if err != nil { - return fmt.Errorf("Bad: Get on fabricClient: %+v", err) - } - - if resp.Response.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: fabric: %q does not exist", fabricName) - } - - return nil - } -} - -func testCheckAzureRMRecoveryProtectionContainerMappingDestroy(s *terraform.State) error { - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_recovery_services_protection_container_mapping" { - continue - } - - resourceGroupName := rs.Primary.Attributes["resource_group_name"] - vaultName := rs.Primary.Attributes["recovery_vault_name"] - fabricName := rs.Primary.Attributes["recovery_fabric_name"] - protectionContainerName := rs.Primary.Attributes["recovery_source_protection_container_name"] - mappingName := rs.Primary.Attributes["name"] - - // Ensure mapping exists in API - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.ContainerMappingClient(resourceGroupName, vaultName) - - resp, err := client.Get(ctx, fabricName, protectionContainerName, mappingName) - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("Container Mapping still exists:\n%#v", resp.Properties) - } - } - - return nil -} diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_container_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_container_test.go deleted file mode 100644 index 28144fd3ae13d..0000000000000 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_container_test.go +++ /dev/null @@ -1,121 +0,0 @@ -package tests - -import ( - "fmt" - "net/http" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" -) - -func TestAccAzureRMRecoveryProtectionContainer_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_container", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryProtectionContainerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryProtectionContainer_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryProtectionContainerExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMRecoveryProtectionContainer_basic(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-recovery-%d" - location = "%s" -} - -resource "azurerm_recovery_services_vault" "test" { - name = "acctest-vault-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Standard" - - soft_delete_enabled = false -} - -resource "azurerm_recovery_services_fabric" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "acctest-fabric-%d" - location = "${azurerm_resource_group.test.location}" -} - -resource "azurerm_recovery_services_protection_container" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_recovery_services_fabric.test.name}" - name = "acctest-protection-cont-%d" -} - -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testCheckAzureRMRecoveryProtectionContainerExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - state, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - resourceGroupName := state.Primary.Attributes["resource_group_name"] - vaultName := state.Primary.Attributes["recovery_vault_name"] - fabricName := state.Primary.Attributes["recovery_fabric_name"] - protectionContainerName := state.Primary.Attributes["name"] - - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.ProtectionContainerClient(resourceGroupName, vaultName) - - resp, err := client.Get(ctx, fabricName, protectionContainerName) - if err != nil { - return fmt.Errorf("Bad: Get on RecoveryServices.ProtectionContainerClient: %+v", err) - } - - if resp.Response.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: Protection Container: %q does not exist", fabricName) - } - - return nil - } -} - -func testCheckAzureRMRecoveryProtectionContainerDestroy(s *terraform.State) error { - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_recovery_services_protection_container" { - continue - } - - resourceGroupName := rs.Primary.Attributes["resource_group_name"] - vaultName := rs.Primary.Attributes["recovery_vault_name"] - fabricName := rs.Primary.Attributes["recovery_fabric_name"] - protectionContainerName := rs.Primary.Attributes["name"] - - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.ProtectionContainerClient(resourceGroupName, vaultName) - - resp, err := client.Get(ctx, fabricName, protectionContainerName) - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("Protection Container Client still exists:\n%#v", resp.Properties) - } - } - - return nil -} diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_policy_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_policy_vm_test.go deleted file mode 100644 index 06811f24f7233..0000000000000 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_policy_vm_test.go +++ /dev/null @@ -1,555 +0,0 @@ -package tests - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func TestAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data.ResourceName, data.RandomInteger), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMRecoveryServicesProtectionPolicyVm_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data.ResourceName, data.RandomInteger), - }, - data.RequiresImportErrorStep(testAccAzureRMRecoveryServicesProtectionPolicyVm_requiresImport), - }, - }) -} - -func TestAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data.ResourceName, data.RandomInteger), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(data.ResourceName, data.RandomInteger), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data.ResourceName, data.RandomInteger), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateDaily(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data.ResourceName, data.RandomInteger), - }, - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(data.ResourceName, data.RandomInteger), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateWeekly(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data.ResourceName, data.RandomInteger), - }, - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data.ResourceName, data.RandomInteger), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateDailyToWeekly(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data.ResourceName, data.RandomInteger), - }, - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data.ResourceName, data.RandomInteger), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateWeeklyToDaily(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data.ResourceName, data.RandomInteger), - }, - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data.ResourceName, data.RandomInteger), - }, - data.ImportStep(), - }, - }) -} - -func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateWeeklyToPartial(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data.ResourceName, data.RandomInteger), - }, - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeeklyPartial(data), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeeklyPartial(data.ResourceName, data.RandomInteger), - }, - data.ImportStep(), - }, - }) -} - -func testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.ProtectionPoliciesClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_recovery_services_protection_policy_vm" { - continue - } - - resourceGroup := rs.Primary.Attributes["resource_group_name"] - vaultName := rs.Primary.Attributes["recovery_vault_name"] - policyName := rs.Primary.Attributes["name"] - - resp, err := client.Get(ctx, vaultName, resourceGroup, policyName) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return nil - } - - return err - } - - return fmt.Errorf("Recovery Services Vault Policy still exists:\n%#v", resp) - } - - return nil -} - -func testCheckAzureRMRecoveryServicesProtectionPolicyVmExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.ProtectionPoliciesClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // Ensure we have enough information in state to look up in API - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %q", resourceName) - } - - vaultName := rs.Primary.Attributes["recovery_vault_name"] - policyName := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for Recovery Services Vault %q Policy: %q", vaultName, policyName) - } - - resp, err := client.Get(ctx, vaultName, resourceGroup, policyName) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Recovery Services Vault Policy %q (resource group: %q) was not found: %+v", policyName, resourceGroup, err) - } - - return fmt.Errorf("Bad: Get on recoveryServicesVaultsClient: %+v", err) - } - - return nil - } -} - -func testAccAzureRMRecoveryServicesProtectionPolicyVm_base(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%[1]d" - location = "%[2]s" -} - -resource "azurerm_recovery_services_vault" "test" { - name = "acctest-%[1]d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Standard" - - soft_delete_enabled = false -} -`, data.RandomInteger, data.Locations.Primary) -} - -func testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectionPolicyVm_base(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protection_policy_vm" "test" { - name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - - backup { - frequency = "Daily" - time = "23:00" - } - - retention_daily { - count = 10 - } -} -`, template, data.RandomInteger) -} - -func testAccAzureRMRecoveryServicesProtectionPolicyVm_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protection_policy_vm" "import" { - name = "${azurerm_recovery_services_protection_policy_vm.test.name}" - resource_group_name = "${azurerm_recovery_services_protection_policy_vm.test.resource_group_name}" - recovery_vault_name = "${azurerm_recovery_services_protection_policy_vm.test.recovery_vault_name}" - - backup { - frequency = "Daily" - time = "23:00" - } - - retention_daily { - count = 10 - } -} -`, template) -} - -func checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(resourceName string, ri int) resource.TestCheckFunc { - return resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectionPolicyVmExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "resource_group_name", fmt.Sprintf("acctestRG-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "recovery_vault_name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "backup.0.frequency", "Daily"), - resource.TestCheckResourceAttr(resourceName, "backup.0.time", "23:00"), - resource.TestCheckResourceAttr(resourceName, "retention_daily.0.count", "10"), - ) -} - -func testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectionPolicyVm_base(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protection_policy_vm" "test" { - name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - - backup { - frequency = "Weekly" - time = "23:00" - weekdays = ["Sunday", "Wednesday"] - } - - retention_weekly { - count = 42 - weekdays = ["Sunday", "Wednesday"] - } -} -`, template, data.RandomInteger) -} - -func checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(resourceName string, ri int) resource.TestCheckFunc { - return resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectionPolicyVmExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "resource_group_name", fmt.Sprintf("acctestRG-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "recovery_vault_name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "backup.0.frequency", "Weekly"), - resource.TestCheckResourceAttr(resourceName, "backup.0.time", "23:00"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.count", "42"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.weekdays.#", "2"), - ) -} - -func testAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectionPolicyVm_base(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protection_policy_vm" "test" { - name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - - backup { - frequency = "Daily" - time = "23:00" - } - - retention_daily { - count = 10 - } - - retention_weekly { - count = 42 - weekdays = ["Sunday", "Wednesday"] - } - - retention_monthly { - count = 7 - weekdays = ["Sunday", "Wednesday"] - weeks = ["First", "Last"] - } - - retention_yearly { - count = 77 - weekdays = ["Sunday", "Wednesday"] - weeks = ["First", "Last"] - months = ["January", "July"] - } -} -`, template, data.RandomInteger) -} - -func checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(resourceName string, ri int) resource.TestCheckFunc { - return resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectionPolicyVmExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "resource_group_name", fmt.Sprintf("acctestRG-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "recovery_vault_name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "backup.0.frequency", "Daily"), - resource.TestCheckResourceAttr(resourceName, "backup.0.time", "23:00"), - resource.TestCheckResourceAttr(resourceName, "retention_daily.0.count", "10"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.count", "42"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.weekdays.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.count", "7"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.weekdays.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.weeks.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.count", "77"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.weekdays.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.weeks.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.months.#", "2"), - ) -} - -func testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectionPolicyVm_base(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protection_policy_vm" "test" { - name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - - backup { - frequency = "Weekly" - time = "23:00" - weekdays = ["Sunday", "Wednesday", "Friday", "Saturday"] - } - - retention_weekly { - count = 42 - weekdays = ["Sunday", "Wednesday", "Friday", "Saturday"] - } - - retention_monthly { - count = 7 - weekdays = ["Sunday", "Wednesday", "Friday", "Saturday"] - weeks = ["First", "Last"] - } - - retention_yearly { - count = 77 - weekdays = ["Sunday", "Wednesday", "Friday", "Saturday"] - weeks = ["First", "Last"] - months = ["January", "July"] - } -} -`, template, data.RandomInteger) -} - -func checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(resourceName string, ri int) resource.TestCheckFunc { - return resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectionPolicyVmExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "resource_group_name", fmt.Sprintf("acctestRG-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "recovery_vault_name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "backup.0.frequency", "Weekly"), - resource.TestCheckResourceAttr(resourceName, "backup.0.time", "23:00"), - resource.TestCheckResourceAttr(resourceName, "backup.0.weekdays.#", "4"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.count", "42"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.weekdays.#", "4"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.count", "7"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.weekdays.#", "4"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.weeks.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.count", "77"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.weekdays.#", "4"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.weeks.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.months.#", "2"), - ) -} - -func testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeeklyPartial(data acceptance.TestData) string { - template := testAccAzureRMRecoveryServicesProtectionPolicyVm_base(data) - return fmt.Sprintf(` -%s - -resource "azurerm_recovery_services_protection_policy_vm" "test" { - name = "acctest-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - - backup { - frequency = "Weekly" - time = "23:00" - weekdays = ["Sunday", "Wednesday", "Friday", "Saturday"] - } - - retention_weekly { - count = 42 - weekdays = ["Sunday", "Wednesday", "Friday"] - } - - retention_monthly { - count = 7 - weekdays = ["Sunday", "Wednesday"] - weeks = ["First", "Last"] - } - - retention_yearly { - count = 77 - weekdays = ["Sunday"] - weeks = ["Last"] - months = ["January"] - } -} -`, template, data.RandomInteger) -} - -func checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeeklyPartial(resourceName string, ri int) resource.TestCheckFunc { - return resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectionPolicyVmExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "resource_group_name", fmt.Sprintf("acctestRG-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "recovery_vault_name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "backup.0.frequency", "Weekly"), - resource.TestCheckResourceAttr(resourceName, "backup.0.time", "23:00"), - resource.TestCheckResourceAttr(resourceName, "backup.0.weekdays.#", "4"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.count", "42"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.weekdays.#", "3"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.count", "7"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.weekdays.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.weeks.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.count", "77"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.weekdays.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.weeks.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.months.#", "1"), - ) -} diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_replicated_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_replicated_vm_test.go deleted file mode 100644 index ed035ebfd46ee..0000000000000 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_replicated_vm_test.go +++ /dev/null @@ -1,269 +0,0 @@ -package tests - -import ( - "fmt" - "net/http" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" -) - -func TestAccAzureRMRecoveryReplicatedVm_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_replicated_vm", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryReplicatedVmDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryReplicatedVm_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryReplicatedVmExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMRecoveryReplicatedVm_basic(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-recovery-%d-1" - location = "%s" -} - -resource "azurerm_resource_group" "test2" { - name = "acctestRG-recovery-%d-2" - location = "%s" -} - -resource "azurerm_recovery_services_vault" "test" { - name = "acctest-vault-%d" - location = "${azurerm_resource_group.test2.location}" - resource_group_name = "${azurerm_resource_group.test2.name}" - sku = "Standard" - - soft_delete_enabled = false -} - -resource "azurerm_recovery_services_fabric" "test1" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "acctest-fabric1-%d" - location = "${azurerm_resource_group.test.location}" -} - -resource "azurerm_recovery_services_fabric" "test2" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "acctest-fabric2-%d" - location = "${azurerm_resource_group.test2.location}" - depends_on = ["azurerm_recovery_services_fabric.test1"] -} - -resource "azurerm_recovery_services_protection_container" "test1" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_recovery_services_fabric.test1.name}" - name = "acctest-protection-cont1-%d" -} - -resource "azurerm_recovery_services_protection_container" "test2" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_recovery_services_fabric.test2.name}" - name = "acctest-protection-cont2-%d" -} - -resource "azurerm_recovery_services_replication_policy" "test" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "acctest-policy-%d" - recovery_point_retention_in_minutes = "${24 * 60}" - application_consistent_snapshot_frequency_in_minutes = "${4 * 60}" -} - -resource "azurerm_recovery_services_protection_container_mapping" "test" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_recovery_services_fabric.test1.name}" - recovery_source_protection_container_name = "${azurerm_recovery_services_protection_container.test1.name}" - recovery_target_protection_container_id = "${azurerm_recovery_services_protection_container.test2.id}" - recovery_replication_policy_id = "${azurerm_recovery_services_replication_policy.test.id}" - name = "mapping-%d" -} - -resource "azurerm_virtual_network" "test1" { - name = "net-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - address_space = ["192.168.1.0/24"] - location = "${azurerm_recovery_services_fabric.test1.location}" -} -resource "azurerm_subnet" "test1" { - name = "snet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test1.name}" - address_prefix = "192.168.1.0/24" -} - - -resource "azurerm_virtual_network" "test2" { - name = "net-%d" - resource_group_name = "${azurerm_resource_group.test2.name}" - address_space = ["192.168.2.0/24"] - location = "${azurerm_recovery_services_fabric.test2.location}" -} - -resource "azurerm_recovery_network_mapping" "test" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "mapping-%d" - source_recovery_fabric_name = "${azurerm_recovery_services_fabric.test1.name}" - target_recovery_fabric_name = "${azurerm_recovery_services_fabric.test2.name}" - source_network_id = "${azurerm_virtual_network.test1.id}" - target_network_id = "${azurerm_virtual_network.test2.id}" -} - -resource "azurerm_network_interface" "test" { - name = "vm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - ip_configuration { - name = "vm-%d" - subnet_id = "${azurerm_subnet.test1.id}" - private_ip_address_allocation = "Dynamic" - } -} - -resource "azurerm_virtual_machine" "test" { - name = "vm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - vm_size = "Standard_B1s" - - storage_image_reference { - publisher = "OpenLogic" - offer = "CentOS" - sku = "7.5" - version = "latest" - } - - storage_os_disk { - name = "disk-%d" - os_type = "Linux" - caching = "ReadWrite" - create_option = "FromImage" - managed_disk_type = "Premium_LRS" - } - - os_profile { - admin_username = "testadmin" - admin_password = "Password1234!" - computer_name = "vm-%d" - } - - os_profile_linux_config { - disable_password_authentication = false - - } - network_interface_ids = ["${azurerm_network_interface.test.id}"] -} - -resource "azurerm_storage_account" "test" { - name = "acct%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - account_tier = "Standard" - account_replication_type = "LRS" -} - -resource "azurerm_recovery_replicated_vm" "test" { - name = "repl-%d" - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - source_vm_id = "${azurerm_virtual_machine.test.id}" - source_recovery_fabric_name = "${azurerm_recovery_services_fabric.test1.name}" - recovery_replication_policy_id = "${azurerm_recovery_services_replication_policy.test.id}" - source_recovery_protection_container_name = "${azurerm_recovery_services_protection_container.test1.name}" - - target_resource_group_id = "${azurerm_resource_group.test2.id}" - target_recovery_fabric_id = "${azurerm_recovery_services_fabric.test2.id}" - target_recovery_protection_container_id = "${azurerm_recovery_services_protection_container.test2.id}" - - managed_disk { - disk_id = "${azurerm_virtual_machine.test.storage_os_disk.0.managed_disk_id}" - staging_storage_account_id = "${azurerm_storage_account.test.id}" - target_resource_group_id = "${azurerm_resource_group.test2.id}" - target_disk_type = "Premium_LRS" - target_replica_disk_type = "Premium_LRS" - } - depends_on = ["azurerm_recovery_services_protection_container_mapping.test", "azurerm_recovery_network_mapping.test"] -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) -} - -func testCheckAzureRMRecoveryReplicatedVmExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - state, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - resourceGroupName := state.Primary.Attributes["resource_group_name"] - vaultName := state.Primary.Attributes["recovery_vault_name"] - fabricName := state.Primary.Attributes["source_recovery_fabric_name"] - protectionContainerName := state.Primary.Attributes["source_recovery_protection_container_name"] - replicationName := state.Primary.Attributes["name"] - - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.ReplicationMigrationItemsClient(resourceGroupName, vaultName) - - resp, err := client.Get(ctx, fabricName, protectionContainerName, replicationName) - if err != nil { - return fmt.Errorf("Bad: Get on RecoveryServices.ReplicationMigrationItemsClient: %+v", err) - } - - if resp.Response.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: Recovery Services Replicated VM: %q does not exist", fabricName) - } - - return nil - } -} - -func testCheckAzureRMRecoveryReplicatedVmDestroy(s *terraform.State) error { - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_recovery_replicated_vm" { - continue - } - - resourceGroupName := rs.Primary.Attributes["resource_group_name"] - vaultName := rs.Primary.Attributes["recovery_vault_name"] - fabricName := rs.Primary.Attributes["source_recovery_fabric_name"] - protectionContainerName := rs.Primary.Attributes["source_recovery_protection_container_name"] - replicationName := rs.Primary.Attributes["name"] - - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.ReplicationMigrationItemsClient(resourceGroupName, vaultName) - - resp, err := client.Get(ctx, fabricName, protectionContainerName, replicationName) - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("Recovery Services Replicated VM still exists:\n%#v", resp.Properties) - } - } - - return nil -} diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_replication_policy_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_replication_policy_test.go deleted file mode 100644 index a414f13e7aa17..0000000000000 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_replication_policy_test.go +++ /dev/null @@ -1,113 +0,0 @@ -package tests - -import ( - "fmt" - "net/http" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" -) - -func TestAccAzureRMRecoveryReplicationPolicy_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_recovery_services_replication_policy", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRecoveryReplicationPolicyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRecoveryReplicationPolicy_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryReplicationPolicyExists(data.ResourceName), - ), - }, - data.ImportStep(), - }, - }) -} - -func testAccAzureRMRecoveryReplicationPolicy_basic(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-recovery-%d" - location = "%s" -} - -resource "azurerm_recovery_services_vault" "test" { - name = "acctest-vault-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "Standard" - - soft_delete_enabled = false -} - -resource "azurerm_recovery_services_replication_policy" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - name = "acctest-policy-%d" - recovery_point_retention_in_minutes = "${24 * 60}" - application_consistent_snapshot_frequency_in_minutes = "${4 * 60}" -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) -} - -func testCheckAzureRMRecoveryReplicationPolicyExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // Ensure we have enough information in state to look up in API - state, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - resourceGroupName := state.Primary.Attributes["resource_group_name"] - vaultName := state.Primary.Attributes["recovery_vault_name"] - policyName := state.Primary.Attributes["name"] - - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.ReplicationPoliciesClient(resourceGroupName, vaultName) - - resp, err := client.Get(ctx, policyName) - if err != nil { - return fmt.Errorf("Bad: Get on RecoveryServices.ReplicationPoliciesClient: %+v", err) - } - - if resp.Response.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: Replication Policies: %q does not exist", policyName) - } - - return nil - } -} - -func testCheckAzureRMRecoveryReplicationPolicyDestroy(s *terraform.State) error { - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_recovery_services_replication_policy" { - continue - } - - resourceGroup := rs.Primary.Attributes["resource_group_name"] - vaultName := rs.Primary.Attributes["recovery_vault_name"] - policyName := rs.Primary.Attributes["name"] - - client := acceptance.AzureProvider.Meta().(*clients.Client).RecoveryServices.ReplicationPoliciesClient(resourceGroup, vaultName) - - resp, err := client.Get(ctx, policyName) - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("Replication Policy still exists:\n%#v", resp.Properties) - } - } - - return nil -} diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_vault_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_vault_test.go index 4cfce8bca1b63..00e17957a59d5 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_vault_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_vault_test.go @@ -171,6 +171,10 @@ func testCheckAzureRMRecoveryServicesVaultExists(resourceName string) resource.T func testAccAzureRMRecoveryServicesVault_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-recovery-%d" location = "%s" @@ -178,8 +182,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_recovery_services_vault" "test" { name = "acctest-Vault-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" soft_delete_enabled = false @@ -189,6 +193,10 @@ resource "azurerm_recovery_services_vault" "test" { func testAccAzureRMRecoveryServicesVault_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-recovery-%d" location = "%s" @@ -196,8 +204,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_recovery_services_vault" "test" { name = "acctest-Vault-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" soft_delete_enabled = false @@ -211,10 +219,10 @@ func testAccAzureRMRecoveryServicesVault_requiresImport(data acceptance.TestData %s resource "azurerm_recovery_services_vault" "import" { - name = "${azurerm_recovery_services_vault.test.name}" - location = "${azurerm_recovery_services_vault.test.location}" - resource_group_name = "${azurerm_recovery_services_vault.test.resource_group_name}" - sku = "${azurerm_recovery_services_vault.test.sku}" + name = azurerm_recovery_services_vault.test.name + location = azurerm_recovery_services_vault.test.location + resource_group_name = azurerm_recovery_services_vault.test.resource_group_name + sku = azurerm_recovery_services_vault.test.sku } `, template) } diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_fabric_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_fabric_test.go index d6605307aa26f..fcb195318dd8a 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_fabric_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_fabric_test.go @@ -32,6 +32,10 @@ func TestAccAzureRMSiteRecoveryFabric_basic(t *testing.T) { func testAccAzureRMSiteRecoveryFabric_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-recovery-%d" location = "%s" @@ -39,18 +43,18 @@ resource "azurerm_resource_group" "test" { resource "azurerm_recovery_services_vault" "test" { name = "acctest-vault-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" soft_delete_enabled = false } resource "azurerm_site_recovery_fabric" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "acctest-fabric-%d" - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_network_mapping_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_network_mapping_test.go index b446e27a8f588..f4d7217121d12 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_network_mapping_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_network_mapping_test.go @@ -33,6 +33,10 @@ func TestAccAzureRMSiteRecoveryNetworkMapping_basic(t *testing.T) { func testAccAzureRMSiteRecoveryNetworkMapping_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-recovery-%d-1" location = "%s" @@ -40,50 +44,50 @@ resource "azurerm_resource_group" "test" { resource "azurerm_recovery_services_vault" "test" { name = "acctest-vault-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" soft_delete_enabled = false } resource "azurerm_site_recovery_fabric" "test1" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "acctest-fabric1-%d" - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location } resource "azurerm_site_recovery_fabric" "test2" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "acctest-fabric2-%d" location = "%s" - depends_on = ["azurerm_site_recovery_fabric.test1"] + depends_on = [azurerm_site_recovery_fabric.test1] } resource "azurerm_virtual_network" "test1" { name = "network1-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name address_space = ["192.168.1.0/24"] - location = "${azurerm_site_recovery_fabric.test1.location}" + location = azurerm_site_recovery_fabric.test1.location } resource "azurerm_virtual_network" "test2" { name = "network2-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name address_space = ["192.168.2.0/24"] - location = "${azurerm_site_recovery_fabric.test2.location}" + location = azurerm_site_recovery_fabric.test2.location } resource "azurerm_site_recovery_network_mapping" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "mapping-%d" - source_recovery_fabric_name = "${azurerm_site_recovery_fabric.test1.name}" - target_recovery_fabric_name = "${azurerm_site_recovery_fabric.test2.name}" - source_network_id = "${azurerm_virtual_network.test1.id}" - target_network_id = "${azurerm_virtual_network.test2.id}" + source_recovery_fabric_name = azurerm_site_recovery_fabric.test1.name + target_recovery_fabric_name = azurerm_site_recovery_fabric.test2.name + source_network_id = azurerm_virtual_network.test1.id + target_network_id = azurerm_virtual_network.test2.id } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_mapping_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_mapping_test.go index 235ead8384f42..ffcbd8315ad0d 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_mapping_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_mapping_test.go @@ -32,6 +32,10 @@ func TestAccAzureRMSiteRecoveryProtectionContainerMapping_basic(t *testing.T) { func testAccAzureRMSiteRecoveryProtectionContainerMapping_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test1" { name = "acctestRG-recovery-%d-1" location = "%s" @@ -39,57 +43,57 @@ resource "azurerm_resource_group" "test1" { resource "azurerm_recovery_services_vault" "test" { name = "acctest-vault-%d" - location = "${azurerm_resource_group.test1.location}" - resource_group_name = "${azurerm_resource_group.test1.name}" + location = azurerm_resource_group.test1.location + resource_group_name = azurerm_resource_group.test1.name sku = "Standard" soft_delete_enabled = false } resource "azurerm_site_recovery_fabric" "test1" { - resource_group_name = "${azurerm_resource_group.test1.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test1.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "acctest-fabric1-%d" - location = "${azurerm_resource_group.test1.location}" + location = azurerm_resource_group.test1.location } resource "azurerm_site_recovery_fabric" "test2" { - resource_group_name = "${azurerm_resource_group.test1.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test1.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "acctest-fabric2-%d" location = "%s" - depends_on = ["azurerm_site_recovery_fabric.test1"] + depends_on = [azurerm_site_recovery_fabric.test1] } resource "azurerm_site_recovery_protection_container" "test1" { - resource_group_name = "${azurerm_resource_group.test1.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_site_recovery_fabric.test1.name}" + resource_group_name = azurerm_resource_group.test1.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + recovery_fabric_name = azurerm_site_recovery_fabric.test1.name name = "acctest-protection-cont1-%d" } resource "azurerm_site_recovery_protection_container" "test2" { - resource_group_name = "${azurerm_resource_group.test1.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_site_recovery_fabric.test2.name}" + resource_group_name = azurerm_resource_group.test1.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + recovery_fabric_name = azurerm_site_recovery_fabric.test2.name name = "acctest-protection-cont2-%d" } resource "azurerm_site_recovery_replication_policy" "test" { - resource_group_name = "${azurerm_resource_group.test1.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test1.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "acctest-policy-%d" - recovery_point_retention_in_minutes = "${24 * 60}" - application_consistent_snapshot_frequency_in_minutes = "${4 * 60}" + recovery_point_retention_in_minutes = 24 * 60 + application_consistent_snapshot_frequency_in_minutes = 4 * 60 } resource "azurerm_site_recovery_protection_container_mapping" "test" { - resource_group_name = "${azurerm_resource_group.test1.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_site_recovery_fabric.test1.name}" - recovery_source_protection_container_name = "${azurerm_site_recovery_protection_container.test1.name}" - recovery_target_protection_container_id = "${azurerm_site_recovery_protection_container.test2.id}" - recovery_replication_policy_id = "${azurerm_site_recovery_replication_policy.test.id}" + resource_group_name = azurerm_resource_group.test1.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + recovery_fabric_name = azurerm_site_recovery_fabric.test1.name + recovery_source_protection_container_name = azurerm_site_recovery_protection_container.test1.name + recovery_target_protection_container_id = azurerm_site_recovery_protection_container.test2.id + recovery_replication_policy_id = azurerm_site_recovery_replication_policy.test.id name = "mapping-%d" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_test.go index ba734b9971ad3..5d98f7a0f1a30 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_test.go @@ -32,6 +32,10 @@ func TestAccAzureRMSiteRecoveryProtectionContainer_basic(t *testing.T) { func testAccAzureRMSiteRecoveryProtectionContainer_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-recovery-%d" location = "%s" @@ -39,27 +43,26 @@ resource "azurerm_resource_group" "test" { resource "azurerm_recovery_services_vault" "test" { name = "acctest-vault-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" soft_delete_enabled = false } resource "azurerm_site_recovery_fabric" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "acctest-fabric-%d" - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location } resource "azurerm_site_recovery_protection_container" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_site_recovery_fabric.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + recovery_fabric_name = azurerm_site_recovery_fabric.test.name name = "acctest-protection-cont-%d" } - `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replicated_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replicated_vm_test.go index eff437a638795..96b952e8474da 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replicated_vm_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replicated_vm_test.go @@ -32,6 +32,10 @@ func TestAccAzureRMSiteRecoveryReplicatedVm_basic(t *testing.T) { func testAccAzureRMSiteRecoveryReplicatedVm_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-recovery-%d-1" location = "%s" @@ -44,107 +48,107 @@ resource "azurerm_resource_group" "test2" { resource "azurerm_recovery_services_vault" "test" { name = "acctest-vault-%d" - location = "${azurerm_resource_group.test2.location}" - resource_group_name = "${azurerm_resource_group.test2.name}" + location = azurerm_resource_group.test2.location + resource_group_name = azurerm_resource_group.test2.name sku = "Standard" soft_delete_enabled = false } resource "azurerm_site_recovery_fabric" "test1" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test2.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "acctest-fabric1-%d" - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location } resource "azurerm_site_recovery_fabric" "test2" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test2.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "acctest-fabric2-%d" - location = "${azurerm_resource_group.test2.location}" - depends_on = ["azurerm_site_recovery_fabric.test1"] + location = azurerm_resource_group.test2.location + depends_on = [azurerm_site_recovery_fabric.test1] } resource "azurerm_site_recovery_protection_container" "test1" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_site_recovery_fabric.test1.name}" + resource_group_name = azurerm_resource_group.test2.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + recovery_fabric_name = azurerm_site_recovery_fabric.test1.name name = "acctest-protection-cont1-%d" } resource "azurerm_site_recovery_protection_container" "test2" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_site_recovery_fabric.test2.name}" + resource_group_name = azurerm_resource_group.test2.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + recovery_fabric_name = azurerm_site_recovery_fabric.test2.name name = "acctest-protection-cont2-%d" } resource "azurerm_site_recovery_replication_policy" "test" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test2.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "acctest-policy-%d" - recovery_point_retention_in_minutes = "${24 * 60}" - application_consistent_snapshot_frequency_in_minutes = "${4 * 60}" + recovery_point_retention_in_minutes = 24 * 60 + application_consistent_snapshot_frequency_in_minutes = 4 * 60 } resource "azurerm_site_recovery_protection_container_mapping" "test" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - recovery_fabric_name = "${azurerm_site_recovery_fabric.test1.name}" - recovery_source_protection_container_name = "${azurerm_site_recovery_protection_container.test1.name}" - recovery_target_protection_container_id = "${azurerm_site_recovery_protection_container.test2.id}" - recovery_replication_policy_id = "${azurerm_site_recovery_replication_policy.test.id}" + resource_group_name = azurerm_resource_group.test2.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + recovery_fabric_name = azurerm_site_recovery_fabric.test1.name + recovery_source_protection_container_name = azurerm_site_recovery_protection_container.test1.name + recovery_target_protection_container_id = azurerm_site_recovery_protection_container.test2.id + recovery_replication_policy_id = azurerm_site_recovery_replication_policy.test.id name = "mapping-%d" } resource "azurerm_virtual_network" "test1" { name = "net-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name address_space = ["192.168.1.0/24"] - location = "${azurerm_site_recovery_fabric.test1.location}" + location = azurerm_site_recovery_fabric.test1.location } + resource "azurerm_subnet" "test1" { name = "snet-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test1.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test1.name address_prefix = "192.168.1.0/24" } - resource "azurerm_virtual_network" "test2" { name = "net-%d" - resource_group_name = "${azurerm_resource_group.test2.name}" + resource_group_name = azurerm_resource_group.test2.name address_space = ["192.168.2.0/24"] - location = "${azurerm_site_recovery_fabric.test2.location}" + location = azurerm_site_recovery_fabric.test2.location } resource "azurerm_site_recovery_network_mapping" "test" { - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test2.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "mapping-%d" - source_recovery_fabric_name = "${azurerm_site_recovery_fabric.test1.name}" - target_recovery_fabric_name = "${azurerm_site_recovery_fabric.test2.name}" - source_network_id = "${azurerm_virtual_network.test1.id}" - target_network_id = "${azurerm_virtual_network.test2.id}" + source_recovery_fabric_name = azurerm_site_recovery_fabric.test1.name + target_recovery_fabric_name = azurerm_site_recovery_fabric.test2.name + source_network_id = azurerm_virtual_network.test1.id + target_network_id = azurerm_virtual_network.test2.id } resource "azurerm_network_interface" "test" { name = "vm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name ip_configuration { name = "vm-%d" - subnet_id = "${azurerm_subnet.test1.id}" + subnet_id = azurerm_subnet.test1.id private_ip_address_allocation = "Dynamic" } } resource "azurerm_virtual_machine" "test" { name = "vm-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name vm_size = "Standard_B1s" @@ -171,40 +175,42 @@ resource "azurerm_virtual_machine" "test" { os_profile_linux_config { disable_password_authentication = false - } - network_interface_ids = ["${azurerm_network_interface.test.id}"] + network_interface_ids = [azurerm_network_interface.test.id] } resource "azurerm_storage_account" "test" { name = "acct%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_site_recovery_replicated_vm" "test" { name = "repl-%d" - resource_group_name = "${azurerm_resource_group.test2.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" - source_vm_id = "${azurerm_virtual_machine.test.id}" - source_recovery_fabric_name = "${azurerm_site_recovery_fabric.test1.name}" - recovery_replication_policy_id = "${azurerm_site_recovery_replication_policy.test.id}" - source_recovery_protection_container_name = "${azurerm_site_recovery_protection_container.test1.name}" + resource_group_name = azurerm_resource_group.test2.name + recovery_vault_name = azurerm_recovery_services_vault.test.name + source_vm_id = azurerm_virtual_machine.test.id + source_recovery_fabric_name = azurerm_site_recovery_fabric.test1.name + recovery_replication_policy_id = azurerm_site_recovery_replication_policy.test.id + source_recovery_protection_container_name = azurerm_site_recovery_protection_container.test1.name - target_resource_group_id = "${azurerm_resource_group.test2.id}" - target_recovery_fabric_id = "${azurerm_site_recovery_fabric.test2.id}" - target_recovery_protection_container_id = "${azurerm_site_recovery_protection_container.test2.id}" + target_resource_group_id = azurerm_resource_group.test2.id + target_recovery_fabric_id = azurerm_site_recovery_fabric.test2.id + target_recovery_protection_container_id = azurerm_site_recovery_protection_container.test2.id managed_disk { - disk_id = "${azurerm_virtual_machine.test.storage_os_disk.0.managed_disk_id}" - staging_storage_account_id = "${azurerm_storage_account.test.id}" - target_resource_group_id = "${azurerm_resource_group.test2.id}" + disk_id = azurerm_virtual_machine.test.storage_os_disk[0].managed_disk_id + staging_storage_account_id = azurerm_storage_account.test.id + target_resource_group_id = azurerm_resource_group.test2.id target_disk_type = "Premium_LRS" target_replica_disk_type = "Premium_LRS" } - depends_on = ["azurerm_site_recovery_protection_container_mapping.test", "azurerm_site_recovery_network_mapping.test"] + depends_on = [ + azurerm_site_recovery_protection_container_mapping.test, + azurerm_site_recovery_network_mapping.test, + ] } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replication_policy_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replication_policy_test.go index 212466a8e52a4..eb624ad3f3566 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replication_policy_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replication_policy_test.go @@ -32,6 +32,10 @@ func TestAccAzureRMSiteRecoveryReplicationPolicy_basic(t *testing.T) { func testAccAzureRMSiteRecoveryReplicationPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-recovery-%d" location = "%s" @@ -39,19 +43,19 @@ resource "azurerm_resource_group" "test" { resource "azurerm_recovery_services_vault" "test" { name = "acctest-vault-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku = "Standard" soft_delete_enabled = false } resource "azurerm_site_recovery_replication_policy" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = azurerm_resource_group.test.name + recovery_vault_name = azurerm_recovery_services_vault.test.name name = "acctest-policy-%d" - recovery_point_retention_in_minutes = "${24 * 60}" - application_consistent_snapshot_frequency_in_minutes = "${4 * 60}" + recovery_point_retention_in_minutes = 24 * 60 + application_consistent_snapshot_frequency_in_minutes = 4 * 60 } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/redis/data_source_redis_cache.go b/azurerm/internal/services/redis/data_source_redis_cache.go index 13acf329f525a..1125b61068bb7 100644 --- a/azurerm/internal/services/redis/data_source_redis_cache.go +++ b/azurerm/internal/services/redis/data_source_redis_cache.go @@ -196,6 +196,18 @@ func dataSourceArmRedisCache() *schema.Resource { Sensitive: true, }, + "primary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + "tags": tags.SchemaDataSource(), }, } @@ -233,7 +245,8 @@ func dataSourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error d.Set("sku_name", sku.Name) } - if props := resp.Properties; props != nil { + props := resp.Properties + if props != nil { d.Set("ssl_port", props.SslPort) d.Set("hostname", props.HostName) d.Set("minimum_tls_version", string(props.MinimumTLSVersion)) @@ -275,5 +288,10 @@ func dataSourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error d.Set("primary_access_key", keys.PrimaryKey) d.Set("secondary_access_key", keys.SecondaryKey) + if props != nil { + d.Set("primary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keys.PrimaryKey, *props.EnableNonSslPort)) + d.Set("secondary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keys.SecondaryKey, *props.EnableNonSslPort)) + } + return tags.FlattenAndSet(d, resp.Tags) } diff --git a/azurerm/internal/services/redis/registration.go b/azurerm/internal/services/redis/registration.go index 1876b64539187..e3207845f05d8 100644 --- a/azurerm/internal/services/redis/registration.go +++ b/azurerm/internal/services/redis/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Redis" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Redis", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/redis/resource_arm_redis_cache.go b/azurerm/internal/services/redis/resource_arm_redis_cache.go index 6c98387f405e1..1ef1a3f1c2f99 100644 --- a/azurerm/internal/services/redis/resource_arm_redis_cache.go +++ b/azurerm/internal/services/redis/resource_arm_redis_cache.go @@ -19,7 +19,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" @@ -219,7 +218,7 @@ func resourceArmRedisCache() *schema.Resource { Type: schema.TypeString, Required: true, DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validate.DayOfTheWeek(true), + ValidateFunc: validation.IsDayOfTheWeek(true), }, "start_hour_utc": { Type: schema.TypeInt, @@ -257,6 +256,18 @@ func resourceArmRedisCache() *schema.Resource { Sensitive: true, }, + "primary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_connection_string": { + Type: schema.TypeString, + Computed: true, + Sensitive: true, + }, + "tags": tags.Schema(), }, } @@ -540,7 +551,8 @@ func resourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error { d.Set("sku_name", sku.Name) } - if props := resp.Properties; props != nil { + props := resp.Properties + if props != nil { d.Set("ssl_port", props.SslPort) d.Set("hostname", props.HostName) d.Set("minimum_tls_version", string(props.MinimumTLSVersion)) @@ -564,6 +576,11 @@ func resourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error { d.Set("primary_access_key", keysResp.PrimaryKey) d.Set("secondary_access_key", keysResp.SecondaryKey) + if props != nil { + d.Set("primary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keysResp.PrimaryKey, *props.EnableNonSslPort)) + d.Set("secondary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keysResp.SecondaryKey, *props.EnableNonSslPort)) + } + return tags.FlattenAndSet(d, resp.Tags) } @@ -910,3 +927,7 @@ func validateRedisBackupFrequency(v interface{}, _ string) (warnings []string, e return warnings, errors } + +func getRedisConnectionString(redisHostName string, sslPort int32, accessKey string, enableSslPort bool) string { + return fmt.Sprintf("%s:%d,password=%s,ssl=%t,abortConnect=False", redisHostName, sslPort, accessKey, enableSslPort) +} diff --git a/azurerm/internal/services/redis/tests/data_source_redis_cache_test.go b/azurerm/internal/services/redis/tests/data_source_redis_cache_test.go index cd494389d2b26..b2d763652a323 100644 --- a/azurerm/internal/services/redis/tests/data_source_redis_cache_test.go +++ b/azurerm/internal/services/redis/tests/data_source_redis_cache_test.go @@ -27,6 +27,8 @@ func TestAccDataSourceAzureRMRedisCache_standard(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", resourceGroupName), resource.TestCheckResourceAttr(data.ResourceName, "ssl_port", "6380"), resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), ), }, }, @@ -39,8 +41,8 @@ func testAccDataSourceAzureRMRedisCache_standardWithDataSource(data acceptance.T %s data "azurerm_redis_cache" "test" { - name = "${azurerm_redis_cache.test.name}" - resource_group_name = "${azurerm_redis_cache.test.resource_group_name}" + name = azurerm_redis_cache.test.name + resource_group_name = azurerm_redis_cache.test.resource_group_name } `, config) } diff --git a/azurerm/internal/services/redis/tests/resource_arm_redis_cache_test.go b/azurerm/internal/services/redis/tests/resource_arm_redis_cache_test.go index e25b822be436d..f9b62fe5633b8 100644 --- a/azurerm/internal/services/redis/tests/resource_arm_redis_cache_test.go +++ b/azurerm/internal/services/redis/tests/resource_arm_redis_cache_test.go @@ -25,6 +25,8 @@ func TestAccAzureRMRedisCache_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMRedisCacheExists(data.ResourceName), resource.TestCheckResourceAttrSet(data.ResourceName, "minimum_tls_version"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), ), }, data.ImportStep(), @@ -478,6 +480,10 @@ func testCheckAzureRMRedisCacheDestroy(s *terraform.State) error { func testAccAzureRMRedisCache_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -485,15 +491,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "C" sku_name = "Basic" enable_non_ssl_port = false minimum_tls_version = "1.2" - redis_configuration {} + redis_configuration { + } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } @@ -504,21 +511,26 @@ func testAccAzureRMRedisCache_requiresImport(data acceptance.TestData) string { %s resource "azurerm_redis_cache" "import" { - name = "${azurerm_redis_cache.test.name}" - location = "${azurerm_redis_cache.test.location}" - resource_group_name = "${azurerm_redis_cache.test.resource_group_name}" - capacity = "${azurerm_redis_cache.test.capacity}" - family = "${azurerm_redis_cache.test.family}" - sku_name = "${azurerm_redis_cache.test.sku_name}" - enable_non_ssl_port = "${azurerm_redis_cache.test.enable_non_ssl_port}" + name = azurerm_redis_cache.test.name + location = azurerm_redis_cache.test.location + resource_group_name = azurerm_redis_cache.test.resource_group_name + capacity = azurerm_redis_cache.test.capacity + family = azurerm_redis_cache.test.family + sku_name = azurerm_redis_cache.test.sku_name + enable_non_ssl_port = azurerm_redis_cache.test.enable_non_ssl_port - redis_configuration {} + redis_configuration { + } } `, template) } func testAccAzureRMRedisCache_standard(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -526,13 +538,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "C" sku_name = "Standard" enable_non_ssl_port = false - redis_configuration {} + redis_configuration { + } tags = { environment = "production" @@ -543,6 +556,10 @@ resource "azurerm_redis_cache" "test" { func testAccAzureRMRedisCache_premium(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -550,8 +567,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "P" sku_name = "Premium" @@ -569,6 +586,10 @@ resource "azurerm_redis_cache" "test" { func testAccAzureRMRedisCache_premiumSharded(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -576,8 +597,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "P" sku_name = "Premium" @@ -596,6 +617,10 @@ resource "azurerm_redis_cache" "test" { func testAccAzureRMRedisCache_premiumShardedScaled(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -603,8 +628,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 2 family = "P" sku_name = "Premium" @@ -623,6 +648,10 @@ resource "azurerm_redis_cache" "test" { func testAccAzureRMRedisCacheNonStandardCasing(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -630,19 +659,24 @@ resource "azurerm_resource_group" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "c" sku_name = "basic" enable_non_ssl_port = false - redis_configuration {} + redis_configuration { + } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccAzureRMRedisCacheBackupDisabled(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -650,8 +684,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 3 family = "P" sku_name = "Premium" @@ -666,6 +700,10 @@ resource "azurerm_redis_cache" "test" { func testAccAzureRMRedisCacheBackupEnabled(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -673,8 +711,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "GRS" @@ -685,8 +723,8 @@ resource "azurerm_storage_account" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 3 family = "P" sku_name = "Premium" @@ -704,6 +742,10 @@ resource "azurerm_redis_cache" "test" { func testAccAzureRMRedisCacheAOFBackupDisabled(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -711,8 +753,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 3 family = "P" sku_name = "Premium" @@ -727,6 +769,10 @@ resource "azurerm_redis_cache" "test" { func testAccAzureRMRedisCacheAOFBackupEnabled(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -734,8 +780,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "GRS" @@ -746,8 +792,8 @@ resource "azurerm_storage_account" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "P" sku_name = "Premium" @@ -764,6 +810,10 @@ resource "azurerm_redis_cache" "test" { func testAccAzureRMRedisCachePatchSchedule(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -771,8 +821,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "P" sku_name = "Premium" @@ -794,6 +844,10 @@ resource "azurerm_redis_cache" "test" { func testAccAzureRMRedisCacheSubscribeAllEvents(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -801,8 +855,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "GRS" @@ -813,8 +867,8 @@ resource "azurerm_storage_account" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 3 family = "P" sku_name = "Premium" @@ -829,6 +883,10 @@ resource "azurerm_redis_cache" "test" { func testAccAzureRMRedisCache_internalSubnet(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -837,33 +895,38 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestnw-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "P" sku_name = "Premium" enable_non_ssl_port = false - subnet_id = "${azurerm_subnet.test.id}" - redis_configuration {} + subnet_id = azurerm_subnet.test.id + redis_configuration { + } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testAccAzureRMRedisCache_internalSubnetStaticIP(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -872,34 +935,39 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestnw-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "P" sku_name = "Premium" enable_non_ssl_port = false - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id private_static_ip_address = "10.0.1.20" - redis_configuration {} + redis_configuration { + } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testAccAzureRMRedisCache_internalSubnet_withZone(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -908,27 +976,28 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestnw-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "P" sku_name = "Premium" enable_non_ssl_port = false - subnet_id = "${azurerm_subnet.test.id}" - redis_configuration {} + subnet_id = azurerm_subnet.test.id + redis_configuration { + } zones = ["1"] } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) @@ -936,6 +1005,10 @@ resource "azurerm_redis_cache" "test" { func testAccAzureRMRedisCacheWithoutAuth(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -944,26 +1017,26 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestnw-%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "testsubnet" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.1.0/24" } resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "P" sku_name = "Premium" enable_non_ssl_port = false - subnet_id = "${azurerm_subnet.test.id}" + subnet_id = azurerm_subnet.test.id redis_configuration { enable_authentication = false } diff --git a/azurerm/internal/services/redis/tests/resource_arm_redis_firewall_rule_test.go b/azurerm/internal/services/redis/tests/resource_arm_redis_firewall_rule_test.go index d8705fdcaeb05..10e937c566095 100644 --- a/azurerm/internal/services/redis/tests/resource_arm_redis_firewall_rule_test.go +++ b/azurerm/internal/services/redis/tests/resource_arm_redis_firewall_rule_test.go @@ -158,6 +158,10 @@ func testCheckAzureRMRedisFirewallRuleDestroy(s *terraform.State) error { func testAccAzureRMRedisFirewallRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -165,8 +169,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "P" sku_name = "Premium" @@ -181,8 +185,8 @@ resource "azurerm_redis_cache" "test" { resource "azurerm_redis_firewall_rule" "test" { name = "fwrule%d" - redis_cache_name = "${azurerm_redis_cache.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + redis_cache_name = azurerm_redis_cache.test.name + resource_group_name = azurerm_resource_group.test.name start_ip = "1.2.3.4" end_ip = "2.3.4.5" } @@ -196,8 +200,8 @@ func testAccAzureRMRedisFirewallRule_multi(data acceptance.TestData) string { resource "azurerm_redis_firewall_rule" "double" { name = "fwruletwo%d" - redis_cache_name = "${azurerm_redis_cache.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + redis_cache_name = azurerm_redis_cache.test.name + resource_group_name = azurerm_resource_group.test.name start_ip = "4.5.6.7" end_ip = "8.9.0.1" } @@ -210,17 +214,21 @@ func testAccAzureRMRedisFirewallRule_requiresImport(data acceptance.TestData) st %s resource "azurerm_redis_firewall_rule" "import" { - name = "${azurerm_redis_firewall_rule.test.name}" - redis_cache_name = "${azurerm_redis_firewall_rule.test.redis_cache_name}" - resource_group_name = "${azurerm_redis_firewall_rule.test.resource_group_name}" - start_ip = "${azurerm_redis_firewall_rule.test.start_ip}" - end_ip = "${azurerm_redis_firewall_rule.test.end_ip}" + name = azurerm_redis_firewall_rule.test.name + redis_cache_name = azurerm_redis_firewall_rule.test.redis_cache_name + resource_group_name = azurerm_redis_firewall_rule.test.resource_group_name + start_ip = azurerm_redis_firewall_rule.test.start_ip + end_ip = azurerm_redis_firewall_rule.test.end_ip } `, template) } func testAccAzureRMRedisFirewallRule_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -228,8 +236,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_redis_cache" "test" { name = "acctestRedis-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name capacity = 1 family = "P" sku_name = "Premium" @@ -244,8 +252,8 @@ resource "azurerm_redis_cache" "test" { resource "azurerm_redis_firewall_rule" "test" { name = "fwrule%d" - redis_cache_name = "${azurerm_redis_cache.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" + redis_cache_name = azurerm_redis_cache.test.name + resource_group_name = azurerm_resource_group.test.name start_ip = "2.3.4.5" end_ip = "6.7.8.9" } diff --git a/azurerm/internal/services/relay/registration.go b/azurerm/internal/services/relay/registration.go index d5692c8dca53c..1e7c334402e03 100644 --- a/azurerm/internal/services/relay/registration.go +++ b/azurerm/internal/services/relay/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Relay" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Messaging", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{} diff --git a/azurerm/internal/services/relay/tests/resource_arm_relay_hybrid_connection_test.go b/azurerm/internal/services/relay/tests/resource_arm_relay_hybrid_connection_test.go index 1d92278a021a9..5496e5d7cc4ae 100644 --- a/azurerm/internal/services/relay/tests/resource_arm_relay_hybrid_connection_test.go +++ b/azurerm/internal/services/relay/tests/resource_arm_relay_hybrid_connection_test.go @@ -106,6 +106,10 @@ func TestAccAzureRMRelayHybridConnection_requiresImport(t *testing.T) { func testAccAzureRMRelayHybridConnection_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -113,22 +117,26 @@ resource "azurerm_resource_group" "test" { resource "azurerm_relay_namespace" "test" { name = "acctestrn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "Standard" } resource "azurerm_relay_hybrid_connection" "test" { name = "acctestrnhc-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - relay_namespace_name = "${azurerm_relay_namespace.test.name}" + resource_group_name = azurerm_resource_group.test.name + relay_namespace_name = azurerm_relay_namespace.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testAccAzureRMRelayHybridConnection_full(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -136,16 +144,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_relay_namespace" "test" { name = "acctestrn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "Standard" } resource "azurerm_relay_hybrid_connection" "test" { name = "acctestrnhc-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - relay_namespace_name = "${azurerm_relay_namespace.test.name}" + resource_group_name = azurerm_resource_group.test.name + relay_namespace_name = azurerm_relay_namespace.test.name user_metadata = "metadatatest" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) @@ -153,6 +161,10 @@ resource "azurerm_relay_hybrid_connection" "test" { func testAccAzureRMRelayHybridConnection_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -160,16 +172,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_relay_namespace" "test" { name = "acctestrn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "Standard" } resource "azurerm_relay_hybrid_connection" "test" { name = "acctestrnhc-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - relay_namespace_name = "${azurerm_relay_namespace.test.name}" + resource_group_name = azurerm_resource_group.test.name + relay_namespace_name = azurerm_relay_namespace.test.name requires_client_authorization = false user_metadata = "metadataupdated" } diff --git a/azurerm/internal/services/relay/tests/resource_arm_relay_namespace_test.go b/azurerm/internal/services/relay/tests/resource_arm_relay_namespace_test.go index d85f6632df184..98fcdd4d74371 100644 --- a/azurerm/internal/services/relay/tests/resource_arm_relay_namespace_test.go +++ b/azurerm/internal/services/relay/tests/resource_arm_relay_namespace_test.go @@ -146,6 +146,10 @@ func testCheckAzureRMRelayNamespaceDestroy(s *terraform.State) error { func testAccAzureRMRelayNamespace_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -153,8 +157,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_relay_namespace" "test" { name = "acctestrn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "Standard" } @@ -167,9 +171,9 @@ func testAccAzureRMRelayNamespace_requiresImport(data acceptance.TestData) strin %s resource "azurerm_relay_namespace" "import" { - name = "${azurerm_relay_namespace.test.name}" - location = "${azurerm_relay_namespace.test.location}" - resource_group_name = "${azurerm_relay_namespace.test.resource_group_name}" + name = azurerm_relay_namespace.test.name + location = azurerm_relay_namespace.test.location + resource_group_name = azurerm_relay_namespace.test.resource_group_name sku_name = "Standard" } @@ -178,6 +182,10 @@ resource "azurerm_relay_namespace" "import" { func testAccAzureRMRelayNamespace_complete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -185,8 +193,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_relay_namespace" "test" { name = "acctestrn-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name sku_name = "Standard" diff --git a/azurerm/internal/services/resource/group_validator_test.go b/azurerm/internal/services/resource/group_validator_test.go index d242856c08064..d8fef9e6cfd87 100644 --- a/azurerm/internal/services/resource/group_validator_test.go +++ b/azurerm/internal/services/resource/group_validator_test.go @@ -73,7 +73,7 @@ func TestValidateResourceGroupIDOrEmpty(t *testing.T) { ID: "nonsense", Errors: 1, }, - //as this function just calls TestAzureResourceGroupId lets not be as comprehensive + // as this function just calls TestAzureResourceGroupId lets not be as comprehensive { ID: "/providers/provider.name/", Errors: 0, diff --git a/azurerm/internal/services/resource/registration.go b/azurerm/internal/services/resource/registration.go index 156f7b6514a80..1162842afd00f 100644 --- a/azurerm/internal/services/resource/registration.go +++ b/azurerm/internal/services/resource/registration.go @@ -11,6 +11,15 @@ func (r Registration) Name() string { return "Resources" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Base", + "Management", + "Template", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/resource/resource_arm_resource_group.go b/azurerm/internal/services/resource/resource_arm_resource_group.go index cc80dd516055f..b9fa453d74e93 100644 --- a/azurerm/internal/services/resource/resource_arm_resource_group.go +++ b/azurerm/internal/services/resource/resource_arm_resource_group.go @@ -98,9 +98,7 @@ func resourceArmResourceGroupRead(d *schema.ResourceData, meta interface{}) erro return err } - name := id.Name - - resp, err := client.Get(ctx, name) + resp, err := client.Get(ctx, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { log.Printf("[INFO] Error reading resource group %q - removing from state", d.Id()) @@ -128,15 +126,13 @@ func resourceArmResourceGroupDelete(d *schema.ResourceData, meta interface{}) er return err } - name := id.Name - - deleteFuture, err := client.Delete(ctx, name) + deleteFuture, err := client.Delete(ctx, id.Name) if err != nil { if response.WasNotFound(deleteFuture.Response()) { return nil } - return fmt.Errorf("Error deleting Resource Group %q: %+v", name, err) + return fmt.Errorf("Error deleting Resource Group %q: %+v", id.Name, err) } err = deleteFuture.WaitForCompletionRef(ctx, client.Client) @@ -145,7 +141,7 @@ func resourceArmResourceGroupDelete(d *schema.ResourceData, meta interface{}) er return nil } - return fmt.Errorf("Error deleting Resource Group %q: %+v", name, err) + return fmt.Errorf("Error deleting Resource Group %q: %+v", id.Name, err) } return nil diff --git a/azurerm/internal/services/resource/tests/data_source_resource_group_test.go b/azurerm/internal/services/resource/tests/data_source_resource_group_test.go index 850a17354db8c..34079f7713b60 100644 --- a/azurerm/internal/services/resource/tests/data_source_resource_group_test.go +++ b/azurerm/internal/services/resource/tests/data_source_resource_group_test.go @@ -31,6 +31,10 @@ func TestAccDataSourceAzureRMResourceGroup_basic(t *testing.T) { func testAccDataSourceAzureRMResourceGroupBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRg-%d" location = "%s" @@ -41,7 +45,7 @@ resource "azurerm_resource_group" "test" { } data "azurerm_resource_group" "test" { - name = "${azurerm_resource_group.test.name}" + name = azurerm_resource_group.test.name } `, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/resource/tests/data_source_resources_test.go b/azurerm/internal/services/resource/tests/data_source_resources_test.go index 46515e17e182d..2fb126f3b7748 100644 --- a/azurerm/internal/services/resource/tests/data_source_resources_test.go +++ b/azurerm/internal/services/resource/tests/data_source_resources_test.go @@ -94,7 +94,7 @@ func testAccDataSourceAzureRMResources_ByName(data acceptance.TestData) string { %s data "azurerm_resources" "test" { - name = "${azurerm_storage_account.test.name}" + name = azurerm_storage_account.test.name } `, r) } @@ -105,7 +105,7 @@ func testAccDataSourceAzureRMResources_ByResourceGroup(data acceptance.TestData) %s data "azurerm_resources" "test" { - resource_group_name = "${azurerm_storage_account.test.resource_group_name}" + resource_group_name = azurerm_storage_account.test.resource_group_name } `, r) } @@ -116,7 +116,7 @@ func testAccDataSourceAzureRMResources_ByResourceType(data acceptance.TestData) %s data "azurerm_resources" "test" { - resource_group_name = "${azurerm_storage_account.test.resource_group_name}" + resource_group_name = azurerm_storage_account.test.resource_group_name type = "Microsoft.Storage/storageAccounts" } `, r) @@ -128,8 +128,8 @@ func testAccDataSourceAzureRMResources_FilteredByTags(data acceptance.TestData) %s data "azurerm_resources" "test" { - name = "${azurerm_storage_account.test.name}" - resource_group_name = "${azurerm_storage_account.test.resource_group_name}" + name = azurerm_storage_account.test.name + resource_group_name = azurerm_storage_account.test.resource_group_name required_tags = { environment = "production" @@ -140,6 +140,10 @@ data "azurerm_resources" "test" { func testAccDataSourceAzureRMResources_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -147,9 +151,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsads%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" diff --git a/azurerm/internal/services/resource/tests/resource_arm_management_lock_test.go b/azurerm/internal/services/resource/tests/resource_arm_management_lock_test.go index 74dcec3b8420c..f5f447bce3394 100644 --- a/azurerm/internal/services/resource/tests/resource_arm_management_lock_test.go +++ b/azurerm/internal/services/resource/tests/resource_arm_management_lock_test.go @@ -254,6 +254,10 @@ func testCheckAzureRMManagementLockDestroy(s *terraform.State) error { func testAccAzureRMManagementLock_resourceGroupReadOnlyBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -261,7 +265,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_management_lock" "test" { name = "acctestlock-%d" - scope = "${azurerm_resource_group.test.id}" + scope = azurerm_resource_group.test.id lock_level = "ReadOnly" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -273,15 +277,19 @@ func testAccAzureRMManagementLock_requiresImport(data acceptance.TestData) strin %s resource "azurerm_management_lock" "import" { - name = "${azurerm_management_lock.test.name}" - scope = "${azurerm_management_lock.test.scope}" - lock_level = "${azurerm_management_lock.test.lock_level}" + name = azurerm_management_lock.test.name + scope = azurerm_management_lock.test.scope + lock_level = azurerm_management_lock.test.lock_level } `, template) } func testAccAzureRMManagementLock_resourceGroupReadOnlyComplete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -289,7 +297,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_management_lock" "test" { name = "acctestlock-%d" - scope = "${azurerm_resource_group.test.id}" + scope = azurerm_resource_group.test.id lock_level = "ReadOnly" notes = "Hello, World!" } @@ -298,6 +306,10 @@ resource "azurerm_management_lock" "test" { func testAccAzureRMManagementLock_resourceGroupCanNotDeleteBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -305,7 +317,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_management_lock" "test" { name = "acctestlock-%d" - scope = "${azurerm_resource_group.test.id}" + scope = azurerm_resource_group.test.id lock_level = "CanNotDelete" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) @@ -313,6 +325,10 @@ resource "azurerm_management_lock" "test" { func testAccAzureRMManagementLock_resourceGroupCanNotDeleteComplete(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -320,7 +336,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_management_lock" "test" { name = "acctestlock-%d" - scope = "${azurerm_resource_group.test.id}" + scope = azurerm_resource_group.test.id lock_level = "CanNotDelete" notes = "Hello, World!" } @@ -329,6 +345,10 @@ resource "azurerm_management_lock" "test" { func testAccAzureRMManagementLock_publicIPReadOnlyBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -336,15 +356,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" idle_timeout_in_minutes = 30 } resource "azurerm_management_lock" "test" { name = "acctestlock-%d" - scope = "${azurerm_public_ip.test.id}" + scope = azurerm_public_ip.test.id lock_level = "ReadOnly" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) @@ -352,6 +372,10 @@ resource "azurerm_management_lock" "test" { func testAccAzureRMManagementLock_publicIPCanNotDeleteBasic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -359,15 +383,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_public_ip" "test" { name = "acctestpublicip-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name allocation_method = "Static" idle_timeout_in_minutes = 30 } resource "azurerm_management_lock" "test" { name = "acctestlock-%d" - scope = "${azurerm_public_ip.test.id}" + scope = azurerm_public_ip.test.id lock_level = "CanNotDelete" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) @@ -375,11 +399,16 @@ resource "azurerm_management_lock" "test" { func testAccAzureRMManagementLock_subscriptionReadOnlyBasic(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_subscription" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_subscription" "current" { +} resource "azurerm_management_lock" "test" { name = "acctestlock-%d" - scope = "${data.azurerm_subscription.current.id}" + scope = data.azurerm_subscription.current.id lock_level = "ReadOnly" } `, data.RandomInteger) @@ -387,11 +416,16 @@ resource "azurerm_management_lock" "test" { func testAccAzureRMManagementLock_subscriptionCanNotDeleteBasic(data acceptance.TestData) string { return fmt.Sprintf(` -data "azurerm_subscription" "current" {} +provider "azurerm" { + features {} +} + +data "azurerm_subscription" "current" { +} resource "azurerm_management_lock" "test" { name = "acctestlock-%d" - scope = "${data.azurerm_subscription.current.id}" + scope = data.azurerm_subscription.current.id lock_level = "CanNotDelete" } `, data.RandomInteger) diff --git a/azurerm/internal/services/resource/tests/resource_arm_resource_group_test.go b/azurerm/internal/services/resource/tests/resource_arm_resource_group_test.go index 74a892bd24673..ad03a2fcd2569 100644 --- a/azurerm/internal/services/resource/tests/resource_arm_resource_group_test.go +++ b/azurerm/internal/services/resource/tests/resource_arm_resource_group_test.go @@ -186,6 +186,10 @@ func testCheckAzureRMResourceGroupDestroy(s *terraform.State) error { func testAccAzureRMResourceGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -199,14 +203,18 @@ func testAccAzureRMResourceGroup_requiresImport(data acceptance.TestData) string %s resource "azurerm_resource_group" "import" { - name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location } `, template) } func testAccAzureRMResourceGroup_withTags(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -221,6 +229,10 @@ resource "azurerm_resource_group" "test" { func testAccAzureRMResourceGroup_withTagsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" diff --git a/azurerm/internal/services/resource/tests/resource_arm_template_deployment_test.go b/azurerm/internal/services/resource/tests/resource_arm_template_deployment_test.go index 7c46116dd6a3d..eeeb769b6b72e 100644 --- a/azurerm/internal/services/resource/tests/resource_arm_template_deployment_test.go +++ b/azurerm/internal/services/resource/tests/resource_arm_template_deployment_test.go @@ -288,6 +288,10 @@ func testCheckAzureRMTemplateDeploymentDestroy(s *terraform.State) error { func testAccAzureRMTemplateDeployment_basicSingle(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -295,7 +299,7 @@ resource "azurerm_resource_group" "test" { resource "azurerm_template_deployment" "test" { name = "acctesttemplate-%d" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name template_body = < 15 { - errors = append(errors, fmt.Errorf("a maximum of 15 tags can be applied to storage account ARM resource")) + if len(tagsMap) > 50 { + errors = append(errors, fmt.Errorf("a maximum of 50 tags can be applied to storage account ARM resource")) } for k, v := range tagsMap { @@ -591,7 +571,6 @@ func validateAzureRMStorageAccountTags(v interface{}, _ string) (warnings []stri func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Storage.AccountsClient - advancedThreatProtectionClient := meta.(*clients.Client).SecurityCenter.AdvancedThreatProtectionClient ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -617,15 +596,12 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e accountKind := d.Get("account_kind").(string) location := azure.NormalizeLocation(d.Get("location").(string)) t := d.Get("tags").(map[string]interface{}) - enableBlobEncryption := d.Get("enable_blob_encryption").(bool) - enableFileEncryption := d.Get("enable_file_encryption").(bool) enableHTTPSTrafficOnly := d.Get("enable_https_traffic_only").(bool) isHnsEnabled := d.Get("is_hns_enabled").(bool) accountTier := d.Get("account_tier").(string) replicationType := d.Get("account_replication_type").(string) storageType := fmt.Sprintf("%s_%s", accountTier, replicationType) - storageAccountEncryptionSource := d.Get("account_encryption_source").(string) parameters := storage.AccountCreateParameters{ Location: &location, @@ -635,16 +611,6 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e Tags: tags.Expand(t), Kind: storage.Kind(accountKind), AccountPropertiesCreateParameters: &storage.AccountPropertiesCreateParameters{ - Encryption: &storage.Encryption{ - Services: &storage.EncryptionServices{ - Blob: &storage.EncryptionService{ - Enabled: utils.Bool(enableBlobEncryption), - }, - File: &storage.EncryptionService{ - Enabled: utils.Bool(enableFileEncryption), - }}, - KeySource: storage.KeySource(storageAccountEncryptionSource), - }, EnableHTTPSTrafficOnly: &enableHTTPSTrafficOnly, NetworkRuleSet: expandStorageAccountNetworkRules(d), IsHnsEnabled: &isHnsEnabled, @@ -711,22 +677,6 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e log.Printf("[INFO] storage account %q ID: %q", storageAccountName, *account.ID) d.SetId(*account.ID) - // TODO: deprecate & split this out into it's own resource in 2.0 - // as this is not available in all regions, and presumably off by default - // lets only try to set this value when true - // TODO in 2.0 switch to guarding this with d.GetOkExists() ? - if v := d.Get("enable_advanced_threat_protection").(bool); v { - advancedThreatProtectionSetting := security.AdvancedThreatProtectionSetting{ - AdvancedThreatProtectionProperties: &security.AdvancedThreatProtectionProperties{ - IsEnabled: utils.Bool(v), - }, - } - - if _, err = advancedThreatProtectionClient.Create(ctx, d.Id(), advancedThreatProtectionSetting); err != nil { - return fmt.Errorf("Error updating Azure Storage Account enable_advanced_threat_protection %q: %+v", storageAccountName, err) - } - } - if val, ok := d.GetOk("blob_properties"); ok { // FileStorage does not support blob settings if accountKind != string(storage.FileStorage) { @@ -767,6 +717,20 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e } } + if val, ok := d.GetOk("static_website"); ok { + // static website only supported on Storage V2 + if accountKind != string(storage.StorageV2) { + return fmt.Errorf("`static_website` is only supported for Storage V2.") + } + blobAccountClient := meta.(*clients.Client).Storage.BlobAccountsClient + + staticWebsiteProps := expandStaticWebsiteProperties(val.([]interface{})) + + if _, err = blobAccountClient.SetServiceProperties(ctx, storageAccountName, staticWebsiteProps); err != nil { + return fmt.Errorf("Error updating Azure Storage Account `static_website` %q: %+v", storageAccountName, err) + } + } + return resourceArmStorageAccountRead(d, meta) } @@ -775,7 +739,6 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e // available requires a call to Update per parameter... func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Storage.AccountsClient - advancedThreatProtectionClient := meta.(*clients.Client).SecurityCenter.AdvancedThreatProtectionClient ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -786,8 +749,8 @@ func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) e storageAccountName := id.Path["storageAccounts"] resourceGroupName := id.ResourceGroup - locks.ByName(storageAccountName, iothub.IothubResourceName) - defer locks.UnlockByName(storageAccountName, iothub.IothubResourceName) + locks.ByName(storageAccountName, storageAccountResourceName) + defer locks.UnlockByName(storageAccountName, storageAccountResourceName) accountTier := d.Get("account_tier").(string) replicationType := d.Get("account_replication_type").(string) @@ -848,40 +811,6 @@ func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) e d.SetPartial("tags") } - if d.HasChange("enable_blob_encryption") || d.HasChange("enable_file_encryption") { - encryptionSource := d.Get("account_encryption_source").(string) - - opts := storage.AccountUpdateParameters{ - AccountPropertiesUpdateParameters: &storage.AccountPropertiesUpdateParameters{ - Encryption: &storage.Encryption{ - Services: &storage.EncryptionServices{}, - KeySource: storage.KeySource(encryptionSource), - }, - }, - } - - if d.HasChange("enable_blob_encryption") { - enableEncryption := d.Get("enable_blob_encryption").(bool) - opts.Encryption.Services.Blob = &storage.EncryptionService{ - Enabled: utils.Bool(enableEncryption), - } - - d.SetPartial("enable_blob_encryption") - } - - if d.HasChange("enable_file_encryption") { - enableEncryption := d.Get("enable_file_encryption").(bool) - opts.Encryption.Services.File = &storage.EncryptionService{ - Enabled: utils.Bool(enableEncryption), - } - d.SetPartial("enable_file_encryption") - } - - if _, err := client.Update(ctx, resourceGroupName, storageAccountName, opts); err != nil { - return fmt.Errorf("Error updating Azure Storage Account Encryption %q: %+v", storageAccountName, err) - } - } - if d.HasChange("custom_domain") { opts := storage.AccountUpdateParameters{ AccountPropertiesUpdateParameters: &storage.AccountPropertiesUpdateParameters{ @@ -934,20 +863,6 @@ func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) e d.SetPartial("network_rules") } - if d.HasChange("enable_advanced_threat_protection") { - opts := security.AdvancedThreatProtectionSetting{ - AdvancedThreatProtectionProperties: &security.AdvancedThreatProtectionProperties{ - IsEnabled: utils.Bool(d.Get("enable_advanced_threat_protection").(bool)), - }, - } - - if _, err := advancedThreatProtectionClient.Create(ctx, d.Id(), opts); err != nil { - return fmt.Errorf("Error updating Azure Storage Account enable_advanced_threat_protection %q: %+v", storageAccountName, err) - } - - d.SetPartial("enable_advanced_threat_protection") - } - if d.HasChange("blob_properties") { // FileStorage does not support blob settings if accountKind != string(storage.FileStorage) { @@ -991,13 +906,28 @@ func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) e d.SetPartial("queue_properties") } + if d.HasChange("static_website") { + // static website only supported on Storage V2 + if accountKind != string(storage.StorageV2) { + return fmt.Errorf("`static_website` is only supported for Storage V2.") + } + blobAccountClient := meta.(*clients.Client).Storage.BlobAccountsClient + + staticWebsiteProps := expandStaticWebsiteProperties(d.Get("static_website").([]interface{})) + + if _, err = blobAccountClient.SetServiceProperties(ctx, storageAccountName, staticWebsiteProps); err != nil { + return fmt.Errorf("Error updating Azure Storage Account `static_website` %q: %+v", storageAccountName, err) + } + + d.SetPartial("static_website") + } + d.Partial(false) return resourceArmStorageAccountRead(d, meta) } func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Storage.AccountsClient - advancedThreatProtectionClient := meta.(*clients.Client).SecurityCenter.AdvancedThreatProtectionClient endpointSuffix := meta.(*clients.Client).Account.Environment.StorageEndpointSuffix ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() @@ -1051,7 +981,6 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err d.Set("account_kind", resp.Kind) if sku := resp.Sku; sku != nil { - d.Set("account_type", sku.Name) d.Set("account_tier", sku.Tier) d.Set("account_replication_type", strings.Split(fmt.Sprintf("%v", sku.Name), "_")[1]) } @@ -1067,18 +996,6 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err } } - if encryption := props.Encryption; encryption != nil { - if services := encryption.Services; services != nil { - if blob := services.Blob; blob != nil { - d.Set("enable_blob_encryption", blob.Enabled) - } - if file := services.File; file != nil { - d.Set("enable_file_encryption", file.Enabled) - } - } - d.Set("account_encryption_source", string(encryption.KeySource)) - } - // Computed d.Set("primary_location", props.PrimaryLocation) d.Set("secondary_location", props.SecondaryLocation) @@ -1138,23 +1055,6 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err return err } - // TODO in 2.0 switch to guarding this with d.GetOkExists() - atp, err := advancedThreatProtectionClient.Get(ctx, d.Id()) - if err != nil { - msg := err.Error() - if !strings.Contains(msg, "The resource namespace 'Microsoft.Security' is invalid.") { - if !strings.Contains(msg, "No registered resource provider found for location '") { - if !strings.Contains(msg, "' and API version '2017-08-01-preview' for type ") { - return fmt.Errorf("Error reading the advanced threat protection settings of AzureRM Storage Account %q: %+v", name, err) - } - } - } - } else { - if atpp := atp.AdvancedThreatProtectionProperties; atpp != nil { - d.Set("enable_advanced_threat_protection", atpp.IsEnabled) - } - } - storageClient := meta.(*clients.Client).Storage account, err := storageClient.FindAccount(ctx, name) if err != nil { @@ -1205,6 +1105,26 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err } } + var staticWebsite []interface{} + + // static website only supported on Storage V2 + if resp.Kind == storage.StorageV2 { + blobAccountClient := storageClient.BlobAccountsClient + + staticWebsiteProps, err := blobAccountClient.GetServiceProperties(ctx, name) + if err != nil { + if staticWebsiteProps.Response.Response != nil && !utils.ResponseWasNotFound(staticWebsiteProps.Response) { + return fmt.Errorf("Error reading static website for AzureRM Storage Account %q: %+v", name, err) + } + } + + staticWebsite = flattenStaticWebsiteProperties(staticWebsiteProps) + } + + if err := d.Set("static_website", staticWebsite); err != nil { + return fmt.Errorf("Error setting `static_website `for AzureRM Storage Account %q: %+v", name, err) + } + return tags.FlattenAndSet(d, resp.Tags) } @@ -1560,6 +1480,31 @@ func expandQueuePropertiesCors(input []interface{}) *queues.Cors { return cors } +func expandStaticWebsiteProperties(input []interface{}) accounts.StorageServiceProperties { + properties := accounts.StorageServiceProperties{ + StaticWebsite: &accounts.StaticWebsite{ + Enabled: false, + }, + } + if len(input) == 0 { + return properties + } + + attr := input[0].(map[string]interface{}) + + properties.StaticWebsite.Enabled = true + + if v, ok := attr["index_document"]; ok { + properties.StaticWebsite.IndexDocument = v.(string) + } + + if v, ok := attr["error_404_document"]; ok { + properties.StaticWebsite.ErrorDocument404Path = v.(string) + } + + return properties +} + func flattenStorageAccountNetworkRules(input *storage.NetworkRuleSet) []interface{} { if input == nil { return []interface{}{} @@ -1802,6 +1747,24 @@ func flattenCorsProperty(input string) []interface{} { return results } +func flattenStaticWebsiteProperties(input accounts.GetServicePropertiesResult) []interface{} { + if storageServiceProps := input.StorageServiceProperties; storageServiceProps != nil { + if staticWebsite := storageServiceProps.StaticWebsite; staticWebsite != nil { + if !staticWebsite.Enabled { + return []interface{}{} + } + + return []interface{}{ + map[string]interface{}{ + "index_document": staticWebsite.IndexDocument, + "error_404_document": staticWebsite.ErrorDocument404Path, + }, + } + } + } + return []interface{}{} +} + func flattenStorageAccountBypass(input storage.Bypass) []interface{} { bypassValues := strings.Split(string(input), ", ") bypass := make([]interface{}, len(bypassValues)) @@ -1823,22 +1786,6 @@ func ValidateArmStorageAccountName(v interface{}, _ string) (warnings []string, return warnings, errors } -func ValidateArmStorageAccountType(v interface{}, _ string) (warnings []string, errors []error) { - validAccountTypes := []string{"standard_lrs", "standard_zrs", - "standard_grs", "standard_ragrs", "premium_lrs"} - - input := strings.ToLower(v.(string)) - - for _, valid := range validAccountTypes { - if valid == input { - return - } - } - - errors = append(errors, fmt.Errorf("Invalid storage account type %q", input)) - return warnings, errors -} - func expandAzureRmStorageAccountIdentity(d *schema.ResourceData) *storage.Identity { identities := d.Get("identity").([]interface{}) identity := identities[0].(map[string]interface{}) diff --git a/azurerm/internal/services/storage/resource_arm_storage_account_customer_managed_key.go b/azurerm/internal/services/storage/resource_arm_storage_account_customer_managed_key.go new file mode 100644 index 0000000000000..824df8e3de6ba --- /dev/null +++ b/azurerm/internal/services/storage/resource_arm_storage_account_customer_managed_key.go @@ -0,0 +1,282 @@ +package storage + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" + keyVaultParse "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault/parse" + keyVaultValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault/validate" + storageParse "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/parsers" + storageValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmStorageAccountCustomerManagedKey() *schema.Resource { + return &schema.Resource{ + Create: resourceArmStorageAccountCustomerManagedKeyCreateUpdate, + Read: resourceArmStorageAccountCustomerManagedKeyRead, + Update: resourceArmStorageAccountCustomerManagedKeyCreateUpdate, + Delete: resourceArmStorageAccountCustomerManagedKeyDelete, + + // TODO: this needs a custom ID validating importer + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "storage_account_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: storageValidate.StorageAccountID, + }, + + "key_vault_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: keyVaultValidate.KeyVaultID, + }, + + "key_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "key_version": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + } +} + +func resourceArmStorageAccountCustomerManagedKeyCreateUpdate(d *schema.ResourceData, meta interface{}) error { + storageClient := meta.(*clients.Client).Storage.AccountsClient + vaultsClient := meta.(*clients.Client).KeyVault.VaultsClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + storageAccountIdRaw := d.Get("storage_account_id").(string) + storageAccountId, err := storageParse.ParseAccountID(storageAccountIdRaw) + if err != nil { + return err + } + + locks.ByName(storageAccountId.Name, storageAccountResourceName) + defer locks.UnlockByName(storageAccountId.Name, storageAccountResourceName) + + storageAccount, err := storageClient.GetProperties(ctx, storageAccountId.ResourceGroup, storageAccountId.Name, "") + if err != nil { + return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): %+v", storageAccountId.Name, storageAccountId.ResourceGroup, err) + } + if storageAccount.AccountProperties == nil { + return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): `properties` was nil", storageAccountId.Name, storageAccountId.ResourceGroup) + } + + // since we're mutating the storage account here, we can use that as the ID + resourceId := storageAccountIdRaw + + if d.IsNewResource() { + // whilst this looks superflurious given encryption is enabled by default, due to the way + // the Azure API works this technically can be nil + if storageAccount.AccountProperties.Encryption != nil { + if storageAccount.AccountProperties.Encryption.KeySource == storage.MicrosoftKeyvault { + return tf.ImportAsExistsError("azurerm_storage_account_customer_managed_key", resourceId) + } + } + } + + keyVaultIdRaw := d.Get("key_vault_id").(string) + keyVaultId, err := keyVaultParse.KeyVaultID(keyVaultIdRaw) + if err != nil { + return err + } + + keyVault, err := vaultsClient.Get(ctx, keyVaultId.ResourceGroup, keyVaultId.Name) + if err != nil { + return fmt.Errorf("Error retrieving Key Vault %q (Resource Group %q): %+v", keyVaultId.Name, keyVaultId.ResourceGroup, err) + } + + softDeleteEnabled := false + purgeProtectionEnabled := false + if props := keyVault.Properties; props != nil { + if esd := props.EnableSoftDelete; esd != nil { + softDeleteEnabled = *esd + } + if epp := props.EnablePurgeProtection; epp != nil { + purgeProtectionEnabled = *epp + } + } + if !softDeleteEnabled || !purgeProtectionEnabled { + return fmt.Errorf("Key Vault %q (Resource Group %q) must be configured for both Purge Protection and Soft Delete", keyVaultId.Name, keyVaultId.ResourceGroup) + } + + keyVaultBaseURL, err := azure.GetKeyVaultBaseUrlFromID(ctx, vaultsClient, keyVaultIdRaw) + if err != nil { + return fmt.Errorf("Error looking up Key Vault URI from Key Vault %q (Resource Group %q): %+v", keyVaultId.Name, keyVaultId.ResourceGroup, err) + } + + keyName := d.Get("key_name").(string) + keyVersion := d.Get("key_version").(string) + props := storage.AccountUpdateParameters{ + AccountPropertiesUpdateParameters: &storage.AccountPropertiesUpdateParameters{ + Encryption: &storage.Encryption{ + Services: &storage.EncryptionServices{ + Blob: &storage.EncryptionService{ + Enabled: utils.Bool(true), + }, + File: &storage.EncryptionService{ + Enabled: utils.Bool(true), + }, + }, + KeySource: storage.MicrosoftKeyvault, + KeyVaultProperties: &storage.KeyVaultProperties{ + KeyName: utils.String(keyName), + KeyVersion: utils.String(keyVersion), + KeyVaultURI: utils.String(keyVaultBaseURL), + }, + }, + }, + } + + if _, err = storageClient.Update(ctx, storageAccountId.ResourceGroup, storageAccountId.Name, props); err != nil { + return fmt.Errorf("Error updating Customer Managed Key for Storage Account %q (Resource Group %q): %+v", storageAccountId.Name, storageAccountId.ResourceGroup, err) + } + + d.SetId(resourceId) + return resourceArmStorageAccountCustomerManagedKeyRead(d, meta) +} + +func resourceArmStorageAccountCustomerManagedKeyRead(d *schema.ResourceData, meta interface{}) error { + storageClient := meta.(*clients.Client).Storage.AccountsClient + vaultsClient := meta.(*clients.Client).KeyVault.VaultsClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + storageAccountId, err := storageParse.ParseAccountID(d.Id()) + if err != nil { + return err + } + + storageAccount, err := storageClient.GetProperties(ctx, storageAccountId.ResourceGroup, storageAccountId.Name, "") + if err != nil { + if utils.ResponseWasNotFound(storageAccount.Response) { + log.Printf("[DEBUG] Storage Account %q could not be found in Resource Group %q - removing from state!", storageAccountId.Name, storageAccountId.ResourceGroup) + d.SetId("") + return nil + } + + return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): %+v", storageAccountId.Name, storageAccountId.ResourceGroup, err) + } + if storageAccount.AccountProperties == nil { + return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): `properties` was nil", storageAccountId.Name, storageAccountId.ResourceGroup) + } + if storageAccount.AccountProperties.Encryption == nil || storageAccount.AccountProperties.Encryption.KeySource != storage.MicrosoftKeyvault { + log.Printf("[DEBUG] Customer Managed Key was not defined for Storage Account %q (Resource Group %q) - removing from state!", storageAccountId.Name, storageAccountId.ResourceGroup) + d.SetId("") + return nil + } + + encryption := *storageAccount.AccountProperties.Encryption + + keyName := "" + keyVaultUri := "" + keyVersion := "" + if props := encryption.KeyVaultProperties; props != nil { + if props.KeyName != nil { + keyName = *props.KeyName + } + if props.KeyVaultURI != nil { + keyVaultUri = *props.KeyVaultURI + } + if props.KeyVersion != nil { + keyVersion = *props.KeyVersion + } + } + + if keyVaultUri == "" { + return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): `properties.encryption.keyVaultProperties.keyVaultUri` was nil", storageAccountId.Name, storageAccountId.ResourceGroup) + } + + keyVaultId, err := azure.GetKeyVaultIDFromBaseUrl(ctx, vaultsClient, keyVaultUri) + if err != nil { + return fmt.Errorf("Error retrieving Key Vault ID from the Base URI %q: %+v", keyVaultUri, err) + } + + // now we have the key vault uri we can look up the ID + + d.Set("storage_account_id", d.Id()) + d.Set("key_vault_id", keyVaultId) + d.Set("key_name", keyName) + d.Set("key_version", keyVersion) + + return nil +} + +func resourceArmStorageAccountCustomerManagedKeyDelete(d *schema.ResourceData, meta interface{}) error { + storageClient := meta.(*clients.Client).Storage.AccountsClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + storageAccountId, err := storageParse.ParseAccountID(d.Id()) + if err != nil { + return err + } + + locks.ByName(storageAccountId.Name, storageAccountResourceName) + defer locks.UnlockByName(storageAccountId.Name, storageAccountResourceName) + + // confirm it still exists prior to trying to update it, else we'll get an error + storageAccount, err := storageClient.GetProperties(ctx, storageAccountId.ResourceGroup, storageAccountId.Name, "") + if err != nil { + if utils.ResponseWasNotFound(storageAccount.Response) { + return nil + } + + return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): %+v", storageAccountId.Name, storageAccountId.ResourceGroup, err) + } + + // Since this isn't a real object, just modifying an existing object + // "Delete" doesn't really make sense it should really be a "Revert to Default" + // So instead of the Delete func actually deleting the Storage Account I am + // making it reset the Storage Account to it's default state + props := storage.AccountUpdateParameters{ + AccountPropertiesUpdateParameters: &storage.AccountPropertiesUpdateParameters{ + Encryption: &storage.Encryption{ + Services: &storage.EncryptionServices{ + Blob: &storage.EncryptionService{ + Enabled: utils.Bool(true), + }, + File: &storage.EncryptionService{ + Enabled: utils.Bool(true), + }, + }, + KeySource: storage.MicrosoftStorage, + }, + }, + } + + if _, err = storageClient.Update(ctx, storageAccountId.ResourceGroup, storageAccountId.Name, props); err != nil { + return fmt.Errorf("Error removing Customer Managed Key for Storage Account %q (Resource Group %q): %+v", storageAccountId.Name, storageAccountId.ResourceGroup, err) + } + + return nil +} diff --git a/azurerm/internal/services/storage/resource_arm_storage_account_network_rules.go b/azurerm/internal/services/storage/resource_arm_storage_account_network_rules.go index a85b4e115b252..2d8f676f3c881 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account_network_rules.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account_network_rules.go @@ -17,8 +17,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -var storageAccountResourceName = "azurerm_storage_account" - func resourceArmStorageAccountNetworkRules() *schema.Resource { return &schema.Resource{ Create: resourceArmStorageAccountNetworkRulesCreateUpdate, @@ -115,11 +113,15 @@ func resourceArmStorageAccountNetworkRulesCreateUpdate(d *schema.ResourceData, m return fmt.Errorf("Storage Account %q (Resource Group %q) was not found", storageAccountName, resourceGroup) } - return fmt.Errorf("Error loading Storage Account %q (Resource Group %q): %+v", storageAccountName, resourceGroup, err) + return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): %+v", storageAccountName, resourceGroup, err) } - if features.ShouldResourcesBeImported() { - if checkForNonDefaultStorageAccountNetworkRule(storageAccount.NetworkRuleSet) { + if features.ShouldResourcesBeImported() && d.IsNewResource() { + if storageAccount.AccountProperties == nil { + return fmt.Errorf("Error retrieving Storage Account %q (Resource Group %q): `properties` was nil", storageAccountName, resourceGroup) + } + + if checkForNonDefaultStorageAccountNetworkRule(storageAccount.AccountProperties.NetworkRuleSet) { return tf.ImportAsExistsError("azurerm_storage_account_network_rule", *storageAccount.ID) } } @@ -247,8 +249,8 @@ func checkForNonDefaultStorageAccountNetworkRule(rule *storage.NetworkRuleSet) b return false } - if rule.IPRules != nil || len(*rule.IPRules) != 0 || - rule.VirtualNetworkRules != nil || len(*rule.VirtualNetworkRules) == 0 || + if (rule.IPRules != nil && len(*rule.IPRules) != 0) || + (rule.VirtualNetworkRules != nil && len(*rule.VirtualNetworkRules) != 0) || rule.Bypass != "AzureServices" || rule.DefaultAction != "Allow" { return true } diff --git a/azurerm/internal/services/storage/resource_arm_storage_blob.go b/azurerm/internal/services/storage/resource_arm_storage_blob.go index bcf7801da9dbd..d9d469f5774b7 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_blob.go +++ b/azurerm/internal/services/storage/resource_arm_storage_blob.go @@ -8,8 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" @@ -61,15 +59,14 @@ func resourceArmStorageBlob() *schema.Resource { }, "type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - DiffSuppressFunc: suppress.CaseDifference, // TODO: remove in 2.0 + Type: schema.TypeString, + Required: true, + ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ "Append", "Block", "Page", - }, true), + }, false), }, "size": { @@ -133,18 +130,6 @@ func resourceArmStorageBlob() *schema.Resource { }, "metadata": MetaDataComputedSchema(), - - // Deprecated fields - "attempts": { - Type: schema.TypeInt, - Optional: true, - Default: 1, - ForceNew: true, - Deprecated: "Retries are now handled by the Azure SDK as such this field is no longer necessary and will be removed in v2.0 of the Azure Provider", - ValidateFunc: validation.IntAtLeast(1), - }, - - "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), }, } } @@ -314,7 +299,6 @@ func resourceArmStorageBlobRead(d *schema.ResourceData, meta interface{}) error d.Set("name", id.BlobName) d.Set("storage_container_name", id.ContainerName) d.Set("storage_account_name", id.AccountName) - d.Set("resource_group_name", account.ResourceGroup) d.Set("access_tier", string(props.AccessTier)) d.Set("content_type", props.ContentType) diff --git a/azurerm/internal/services/storage/resource_arm_storage_container.go b/azurerm/internal/services/storage/resource_arm_storage_container.go index 0971adb3adaaf..2efbdf8154696 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_container.go +++ b/azurerm/internal/services/storage/resource_arm_storage_container.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" @@ -75,17 +74,6 @@ func resourceArmStorageContainer() *schema.Resource { Type: schema.TypeBool, Computed: true, }, - - "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), - - "properties": { - Type: schema.TypeMap, - Computed: true, - Deprecated: "This field will be removed in version 2.0 of the Azure Provider", - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, }, } } @@ -229,7 +217,6 @@ func resourceArmStorageContainerRead(d *schema.ResourceData, meta interface{}) e d.Set("name", id.ContainerName) d.Set("storage_account_name", id.AccountName) - d.Set("resource_group_name", account.ResourceGroup) d.Set("container_access_type", flattenStorageContainerAccessLevel(props.AccessLevel)) @@ -237,10 +224,6 @@ func resourceArmStorageContainerRead(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error setting `metadata`: %+v", err) } - if err := d.Set("properties", flattenStorageContainerProperties(props)); err != nil { - return fmt.Errorf("Error setting `properties`: %+v", err) - } - d.Set("has_immutability_policy", props.HasImmutabilityPolicy) d.Set("has_legal_hold", props.HasLegalHold) @@ -277,21 +260,6 @@ func resourceArmStorageContainerDelete(d *schema.ResourceData, meta interface{}) return nil } -func flattenStorageContainerProperties(input containers.ContainerProperties) map[string]interface{} { - output := map[string]interface{}{ - "last_modified": input.Header.Get("Last-Modified"), - "lease_duration": "", - "lease_state": string(input.LeaseState), - "lease_status": string(input.LeaseStatus), - } - - if input.LeaseDuration != nil { - output["lease_duration"] = string(*input.LeaseDuration) - } - - return output -} - func expandStorageContainerAccessLevel(input string) containers.AccessLevel { // for historical reasons, "private" above is an empty string in the API // so the enum doesn't 1:1 match. You could argue the SDK should handle this diff --git a/azurerm/internal/services/storage/resource_arm_storage_queue.go b/azurerm/internal/services/storage/resource_arm_storage_queue.go index b512884cd6fbc..ba77e57565bad 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_queue.go +++ b/azurerm/internal/services/storage/resource_arm_storage_queue.go @@ -7,7 +7,6 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -50,8 +49,6 @@ func resourceArmStorageQueue() *schema.Resource { ValidateFunc: ValidateArmStorageAccountName, }, - "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), - "metadata": MetaDataSchema(), }, } @@ -204,7 +201,6 @@ func resourceArmStorageQueueRead(d *schema.ResourceData, meta interface{}) error d.Set("name", id.QueueName) d.Set("storage_account_name", id.AccountName) - d.Set("resource_group_name", account.ResourceGroup) if err := d.Set("metadata", FlattenMetaData(metaData.MetaData)); err != nil { return fmt.Errorf("Error setting `metadata`: %s", err) diff --git a/azurerm/internal/services/storage/resource_arm_storage_share.go b/azurerm/internal/services/storage/resource_arm_storage_share.go index 04eb1ff535859..9c4edd8c7a436 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_share.go +++ b/azurerm/internal/services/storage/resource_arm_storage_share.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -55,8 +54,6 @@ func resourceArmStorageShare() *schema.Resource { ValidateFunc: ValidateArmStorageShareName, }, - "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), - "storage_account_name": { Type: schema.TypeString, Required: true, @@ -230,9 +227,6 @@ func resourceArmStorageShareRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Error flattening `acl`: %+v", err) } - // Deprecated: remove in 2.0 - d.Set("resource_group_name", account.ResourceGroup) - return nil } diff --git a/azurerm/internal/services/storage/resource_arm_storage_table.go b/azurerm/internal/services/storage/resource_arm_storage_table.go index 7d2960cafec03..21d52120c07da 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -63,9 +62,6 @@ func resourceArmStorageTable() *schema.Resource { ValidateFunc: ValidateArmStorageAccountName, }, - // TODO: deprecate this in the docs - "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), - "acl": { Type: schema.TypeSet, Optional: true, @@ -199,7 +195,6 @@ func resourceArmStorageTableRead(d *schema.ResourceData, meta interface{}) error d.Set("name", id.TableName) d.Set("storage_account_name", id.AccountName) - d.Set("resource_group_name", account.ResourceGroup) if err := d.Set("acl", flattenStorageTableACLs(acls)); err != nil { return fmt.Errorf("Error flattening `acl`: %+v", err) diff --git a/azurerm/internal/services/storage/resource_arm_storage_table_migration.go b/azurerm/internal/services/storage/resource_arm_storage_table_migration.go index e6cb71ba0da07..d5ad2d88fcca9 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table_migration.go @@ -26,7 +26,7 @@ func ResourceStorageTableStateResourceV0V1() *schema.Resource { ForceNew: true, ValidateFunc: ValidateArmStorageAccountName, }, - "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), + "resource_group_name": azure.SchemaResourceGroupName(), "acl": { Type: schema.TypeSet, Optional: true, diff --git a/azurerm/internal/services/storage/tests/data_source_storage_account_blob_container_sas_test.go b/azurerm/internal/services/storage/tests/data_source_storage_account_blob_container_sas_test.go index 6b719546e072d..31795359647ce 100644 --- a/azurerm/internal/services/storage/tests/data_source_storage_account_blob_container_sas_test.go +++ b/azurerm/internal/services/storage/tests/data_source_storage_account_blob_container_sas_test.go @@ -49,6 +49,10 @@ func TestAccDataSourceArmStorageAccountBlobContainerSas_basic(t *testing.T) { func testAccDataSourceAzureRMStorageAccountBlobContainerSas_basic(data acceptance.TestData, startDate string, endDate string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "rg" { name = "acctestRG-storage-%d" location = "%s" @@ -56,23 +60,22 @@ resource "azurerm_resource_group" "rg" { resource "azurerm_storage_account" "storage" { name = "acctestsads%s" - resource_group_name = "${azurerm_resource_group.rg.name}" + resource_group_name = azurerm_resource_group.rg.name - location = "${azurerm_resource_group.rg.location}" + location = azurerm_resource_group.rg.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "container" { name = "sas-test" - resource_group_name = "${azurerm_resource_group.rg.name}" - storage_account_name = "${azurerm_storage_account.storage.name}" + storage_account_name = azurerm_storage_account.storage.name container_access_type = "private" } data "azurerm_storage_account_blob_container_sas" "test" { - connection_string = "${azurerm_storage_account.storage.primary_connection_string}" - container_name = "${azurerm_storage_container.container.name}" + connection_string = azurerm_storage_account.storage.primary_connection_string + container_name = azurerm_storage_container.container.name https_only = true ip_address = "168.1.5.65" diff --git a/azurerm/internal/services/storage/tests/data_source_storage_account_sas_test.go b/azurerm/internal/services/storage/tests/data_source_storage_account_sas_test.go index 15161389c63aa..7791bf2906f4b 100644 --- a/azurerm/internal/services/storage/tests/data_source_storage_account_sas_test.go +++ b/azurerm/internal/services/storage/tests/data_source_storage_account_sas_test.go @@ -36,6 +36,10 @@ func TestAccDataSourceArmStorageAccountSas_basic(t *testing.T) { func testAccDataSourceAzureRMStorageAccountSas_basic(data acceptance.TestData, startDate string, endDate string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -43,9 +47,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsads%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -55,7 +59,7 @@ resource "azurerm_storage_account" "test" { } data "azurerm_storage_account_sas" "test" { - connection_string = "${azurerm_storage_account.test.primary_connection_string}" + connection_string = azurerm_storage_account.test.primary_connection_string https_only = true resource_types { diff --git a/azurerm/internal/services/storage/tests/data_source_storage_account_test.go b/azurerm/internal/services/storage/tests/data_source_storage_account_test.go index 9456fb8c42e99..3809b0c75f559 100644 --- a/azurerm/internal/services/storage/tests/data_source_storage_account_test.go +++ b/azurerm/internal/services/storage/tests/data_source_storage_account_test.go @@ -62,6 +62,10 @@ func TestAccDataSourceAzureRMStorageAccount_withWriteLock(t *testing.T) { func testAccDataSourceAzureRMStorageAccount_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -69,9 +73,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsads%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -89,7 +93,7 @@ func testAccDataSourceAzureRMStorageAccount_basicWriteLock(data acceptance.TestD resource "azurerm_management_lock" "test" { name = "acctestlock-%d" - scope = "${azurerm_storage_account.test.id}" + scope = azurerm_storage_account.test.id lock_level = "ReadOnly" } `, template, data.RandomInteger) @@ -101,8 +105,8 @@ func testAccDataSourceAzureRMStorageAccount_basicWithDataSource(data acceptance. %s data "azurerm_storage_account" "test" { - name = "${azurerm_storage_account.test.name}" - resource_group_name = "${azurerm_storage_account.test.resource_group_name}" + name = azurerm_storage_account.test.name + resource_group_name = azurerm_storage_account.test.resource_group_name } `, config) } @@ -113,8 +117,8 @@ func testAccDataSourceAzureRMStorageAccount_basicWriteLockWithDataSource(data ac %s data "azurerm_storage_account" "test" { - name = "${azurerm_storage_account.test.name}" - resource_group_name = "${azurerm_storage_account.test.resource_group_name}" + name = azurerm_storage_account.test.name + resource_group_name = azurerm_storage_account.test.resource_group_name } `, config) } diff --git a/azurerm/internal/services/storage/tests/data_source_storage_container_test.go b/azurerm/internal/services/storage/tests/data_source_storage_container_test.go index 351a2ab4e5a34..4c278bb2bc6c9 100644 --- a/azurerm/internal/services/storage/tests/data_source_storage_container_test.go +++ b/azurerm/internal/services/storage/tests/data_source_storage_container_test.go @@ -31,6 +31,10 @@ func TestAccDataSourceArmStorageContainer_basic(t *testing.T) { func testAccDataSourceAzureRMStorageContainer_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "containerdstest-%s" location = "%s" @@ -47,7 +51,6 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "containerdstest-%s" - resource_group_name = "${azurerm_resource_group.test.name}" storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" metadata = { diff --git a/azurerm/internal/services/storage/tests/data_source_storage_management_policy_test.go b/azurerm/internal/services/storage/tests/data_source_storage_management_policy_test.go index 2c1e9ad47d5ac..4b2d756c933e0 100644 --- a/azurerm/internal/services/storage/tests/data_source_storage_management_policy_test.go +++ b/azurerm/internal/services/storage/tests/data_source_storage_management_policy_test.go @@ -9,7 +9,7 @@ import ( ) func TestAccDataSourceAzureRMStorageManagementPolicy_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "data.azurerm_storage_account", "test") + data := acceptance.BuildTestData(t, "data.azurerm_storage_management_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -41,6 +41,10 @@ func TestAccDataSourceAzureRMStorageManagementPolicy_basic(t *testing.T) { func testAccDataSourceAzureRMStorageManagementPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -48,16 +52,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" account_kind = "BlobStorage" } resource "azurerm_storage_management_policy" "test" { - storage_account_id = "${azurerm_storage_account.test.id}" + storage_account_id = azurerm_storage_account.test.id rule { name = "rule1" @@ -80,7 +84,7 @@ resource "azurerm_storage_management_policy" "test" { } data "azurerm_storage_management_policy" "test" { - storage_account_id = "${azurerm_storage_management_policy.test.storage_account_id}" + storage_account_id = azurerm_storage_management_policy.test.storage_account_id } `, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/storage/tests/resource_arm_hpc_cache_test.go b/azurerm/internal/services/storage/tests/resource_arm_hpc_cache_test.go new file mode 100644 index 0000000000000..6374de2c2bd18 --- /dev/null +++ b/azurerm/internal/services/storage/tests/resource_arm_hpc_cache_test.go @@ -0,0 +1,158 @@ +package tests + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" +) + +func TestAccAzureRMHPCCache_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_hpc_cache", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMHPCCacheDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMHPCCache_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMHPCCacheExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMStreamAnalyticsJob_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + + data := acceptance.BuildTestData(t, "azurerm_hpc_cache", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMHPCCacheDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMHPCCache_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMHPCCacheExists(data.ResourceName), + ), + }, + data.RequiresImportErrorStep(testAccAzureRMHPCCahce_requiresImport), + }, + }) +} + +func testCheckAzureRMHPCCacheExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acceptance.AzureProvider.Meta().(*clients.Client).Storage.CachesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := conn.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Bad: Get on storageCacheCachesClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: HPC Cache %q (resource group: %q) does not exist", name, resourceGroup) + } + + return nil + } +} + +func testCheckAzureRMHPCCacheDestroy(s *terraform.State) error { + conn := acceptance.AzureProvider.Meta().(*clients.Client).Storage.CachesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_hpc_cache" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + resp, err := conn.Get(ctx, resourceGroup, name) + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("HPC Cache still exists:\n%#v", resp) + } + } + + return nil +} + +func testAccAzureRMHPCCache_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-storage-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctest-VN-%d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_subnet" "test" { + name = "acctestsub-%d" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_hpc_cache" "test" { + name = "acctest-HPCC-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + cache_size_in_gb = 3072 + subnet_id = azurerm_subnet.test.id + sku_name = "Standard_2G" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMHPCCahce_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMHPCCache_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_hpc_cache" "import" { + name = azurerm_hpc_cache.test.name + resource_group_name = azurerm_hpc_cache.test.resource_group_name + location = azurerm_hpc_cache.test.location + cache_size_in_gb = azurerm_hpc_cache.test.cache_size_in_gb + subnet_id = azurerm_hpc_cache.test.subnet_id + sku_name = azurerm_hpc_cache.test.sku_name +} +`, template) +} diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_account_customer_managed_key_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_account_customer_managed_key_test.go new file mode 100644 index 0000000000000..100125b1354d2 --- /dev/null +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_account_customer_managed_key_test.go @@ -0,0 +1,282 @@ +package tests + +import ( + "fmt" + "net/http" + "testing" + + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccAzureRMStorageAccountCustomerManagedKey_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_storage_account_customer_managed_key", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMStorageAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMStorageAccountCustomerManagedKey_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageAccountCustomerManagedKeyExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + // Delete the encryption settings resource and verify it is gone + Config: testAccAzureRMStorageAccountCustomerManagedKey_template(data), + Check: resource.ComposeTestCheckFunc( + // Then ensure the encryption settings on the storage account + // have been reverted to their default state + testCheckAzureRMStorageAccountExistsWithDefaultSettings("azurerm_storage_account.test"), + ), + }, + }, + }) +} + +func TestAccAzureRMStorageAccountCustomerManagedKey_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_storage_account_customer_managed_key", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMStorageAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMStorageAccountCustomerManagedKey_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageAccountCustomerManagedKeyExists(data.ResourceName), + ), + }, + data.RequiresImportErrorStep(testAccAzureRMStorageAccountCustomerManagedKey_requiresImport), + }, + }) +} + +func TestAccAzureRMStorageAccountCustomerManagedKey_updateKey(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_storage_account_customer_managed_key", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMStorageAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMStorageAccountCustomerManagedKey_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageAccountCustomerManagedKeyExists(data.ResourceName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMStorageAccountCustomerManagedKey_updated(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageAccountCustomerManagedKeyExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMStorageAccountExistsWithDefaultSettings(resourceName 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[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + storageAccount := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + // Ensure resource group exists in API + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + conn := acceptance.AzureProvider.Meta().(*clients.Client).Storage.AccountsClient + + resp, err := conn.GetProperties(ctx, resourceGroup, storageAccount, "") + if err != nil { + return fmt.Errorf("Bad: Get on storageServiceClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: StorageAccount %q (resource group: %q) does not exist", storageAccount, resourceGroup) + } + + if props := resp.AccountProperties; props != nil { + if encryption := props.Encryption; encryption != nil { + if services := encryption.Services; services != nil { + if !*services.Blob.Enabled { + return fmt.Errorf("enable_blob_encryption not set to default: %s", resourceName) + } + if !*services.File.Enabled { + return fmt.Errorf("enable_file_encryption not set to default: %s", resourceName) + } + } + + if encryption.KeySource != storage.MicrosoftStorage { + return fmt.Errorf("%s keySource not set to default(storage.MicrosoftStorage): %s", resourceName, encryption.KeySource) + } + } else { + return fmt.Errorf("storage account encryption properties not found: %s", resourceName) + } + } + + return nil + } +} + +func testCheckAzureRMStorageAccountCustomerManagedKeyExists(resourceName 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[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + if storageAccountId := rs.Primary.Attributes["storage_account_id"]; storageAccountId == "" { + return fmt.Errorf("Unable to read storageAccountId: %s", resourceName) + } + + return nil + } +} + +func testAccAzureRMStorageAccountCustomerManagedKey_basic(data acceptance.TestData) string { + template := testAccAzureRMStorageAccountCustomerManagedKey_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_storage_account_customer_managed_key" "test" { + storage_account_id = azurerm_storage_account.test.id + key_vault_id = azurerm_key_vault.test.id + key_name = azurerm_key_vault_key.first.name + key_version = azurerm_key_vault_key.first.version +} +`, template) +} + +func testAccAzureRMStorageAccountCustomerManagedKey_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStorageAccountCustomerManagedKey_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_storage_account_customer_managed_key" "import" { + storage_account_id = azurerm_storage_account_customer_managed_key.test.storage_account_id + key_vault_id = azurerm_storage_account_customer_managed_key.test.key_vault_id + key_name = azurerm_storage_account_customer_managed_key.test.key_name + key_version = azurerm_storage_account_customer_managed_key.test.key_version +} +`, template) +} + +func testAccAzureRMStorageAccountCustomerManagedKey_updated(data acceptance.TestData) string { + template := testAccAzureRMStorageAccountCustomerManagedKey_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_key_vault_key" "second" { + name = "second" + key_vault_id = azurerm_key_vault.test.id + key_type = "RSA" + key_size = 2048 + key_opts = ["decrypt", "encrypt", "sign", "unwrapKey", "verify", "wrapKey"] + + depends_on = [ + azurerm_key_vault_access_policy.client, + azurerm_key_vault_access_policy.storage, + ] +} + +resource "azurerm_storage_account_customer_managed_key" "test" { + storage_account_id = azurerm_storage_account.test.id + key_vault_id = azurerm_key_vault.test.id + key_name = azurerm_key_vault_key.second.name + key_version = azurerm_key_vault_key.second.version +} +`, template) +} + +func testAccAzureRMStorageAccountCustomerManagedKey_template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" {} + +provider "azurerm" { + features { + key_vault { + purge_soft_delete_on_destroy = false + } + } +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_key_vault" "test" { + name = "acctestkv%s" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id + sku_name = "standard" + soft_delete_enabled = true + purge_protection_enabled = true +} + +resource "azurerm_key_vault_access_policy" "storage" { + key_vault_id = azurerm_key_vault.test.id + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = azurerm_storage_account.test.identity.0.principal_id + + key_permissions = ["get", "create", "list", "restore", "recover", "unwrapkey", "wrapkey", "purge", "encrypt", "decrypt", "sign", "verify"] + secret_permissions = ["get"] +} + +resource "azurerm_key_vault_access_policy" "client" { + key_vault_id = azurerm_key_vault.test.id + tenant_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.object_id + + key_permissions = ["get", "create", "delete", "list", "restore", "recover", "unwrapkey", "wrapkey", "purge", "encrypt", "decrypt", "sign", "verify"] + secret_permissions = ["get"] +} + +resource "azurerm_key_vault_key" "first" { + name = "first" + key_vault_id = azurerm_key_vault.test.id + key_type = "RSA" + key_size = 2048 + key_opts = ["decrypt", "encrypt", "sign", "unwrapKey", "verify", "wrapKey"] + + depends_on = [ + azurerm_key_vault_access_policy.client, + azurerm_key_vault_access_policy.storage, + ] +} + +resource "azurerm_storage_account" "test" { + name = "acctestsa%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "LRS" + + identity { + type = "SystemAssigned" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) +} diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_account_network_rules_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_account_network_rules_test.go index f6201ecbd4c09..887c5740dadc7 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_account_network_rules_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_account_network_rules_test.go @@ -81,6 +81,10 @@ func TestAccAzureRMStorageAccountNetworkRules_empty(t *testing.T) { func testAccAzureRMStorageAccountNetworkRules_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -89,22 +93,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" service_endpoints = ["Microsoft.Storage"] } resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -114,18 +118,22 @@ resource "azurerm_storage_account" "test" { } resource "azurerm_storage_account_network_rules" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + resource_group_name = azurerm_resource_group.test.name + storage_account_name = azurerm_storage_account.test.name default_action = "Deny" ip_rules = ["127.0.0.1"] - virtual_network_subnet_ids = ["${azurerm_subnet.test.id}"] + virtual_network_subnet_ids = [azurerm_subnet.test.id] } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomString) } func testAccAzureRMStorageAccountNetworkRules_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -134,30 +142,30 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" service_endpoints = ["Microsoft.Storage"] } resource "azurerm_subnet" "test2" { name = "acctestsubnet2%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.3.0/24" service_endpoints = ["Microsoft.Storage"] } resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -167,12 +175,12 @@ resource "azurerm_storage_account" "test" { } resource "azurerm_storage_account_network_rules" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + resource_group_name = azurerm_resource_group.test.name + storage_account_name = azurerm_storage_account.test.name default_action = "Allow" ip_rules = ["127.0.0.2", "127.0.0.3"] - virtual_network_subnet_ids = ["${azurerm_subnet.test.id}", "${azurerm_subnet.test2.id}"] + virtual_network_subnet_ids = [azurerm_subnet.test.id, azurerm_subnet.test2.id] bypass = ["Metrics"] } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString) @@ -180,6 +188,10 @@ resource "azurerm_storage_account_network_rules" "test" { func testAccAzureRMStorageAccountNetworkRules_empty(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -187,8 +199,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -198,8 +210,8 @@ resource "azurerm_storage_account" "test" { } resource "azurerm_storage_account_network_rules" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + resource_group_name = azurerm_resource_group.test.name + storage_account_name = azurerm_storage_account.test.name default_action = "Deny" bypass = ["Metrics"] diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go index a6afe6f0c7700..bfde8e8fb24b0 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go @@ -3,7 +3,6 @@ package tests import ( "fmt" "net/http" - "os" "regexp" "testing" @@ -18,24 +17,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestValidateArmStorageAccountType(t *testing.T) { - testCases := []struct { - input string - shouldError bool - }{ - {"standard_lrs", false}, - {"invalid", true}, - } - - for _, test := range testCases { - _, es := storage.ValidateArmStorageAccountType(test.input, "account_type") - - if test.shouldError && len(es) == 0 { - t.Fatalf("Expected validating account_type %q to fail", test.input) - } - } -} - func TestValidateArmStorageAccountName(t *testing.T) { testCases := []struct { input string @@ -114,6 +95,25 @@ func TestAccAzureRMStorageAccount_requiresImport(t *testing.T) { }) } +func TestAccAzureRMStorageAccount_tagCount(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMStorageAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMStorageAccount_tagCount(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageAccountExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + func TestAccAzureRMStorageAccount_writeLock(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") @@ -212,68 +212,6 @@ func TestAccAzureRMStorageAccount_blobConnectionString(t *testing.T) { }) } -func TestAccAzureRMStorageAccount_blobEncryption(t *testing.T) { - _, exists := os.LookupEnv("TF_ACC_STORAGE_ENCRYPTION_DISABLE") - if !exists { - t.Skip("`TF_ACC_STORAGE_ENCRYPTION_DISABLE` isn't specified - skipping since disabling encryption is generally disabled") - } - data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMStorageAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMStorageAccount_blobEncryption(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enable_blob_encryption", "true"), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMStorageAccount_blobEncryptionDisabled(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enable_blob_encryption", "false"), - ), - }, - }, - }) -} - -func TestAccAzureRMStorageAccount_fileEncryption(t *testing.T) { - _, exists := os.LookupEnv("TF_ACC_STORAGE_ENCRYPTION_DISABLE") - if !exists { - t.Skip("`TF_ACC_STORAGE_ENCRYPTION_DISABLE` isn't specified - skipping since disabling encryption is generally disabled") - } - data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMStorageAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMStorageAccount_fileEncryption(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enable_file_encryption", "true"), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMStorageAccount_fileEncryptionDisabled(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enable_file_encryption", "false"), - ), - }, - }, - }) -} - func TestAccAzureRMStorageAccount_enableHttpsTrafficOnly(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") @@ -406,6 +344,7 @@ func TestAccAzureRMStorageAccount_fileStorageWithUpdate(t *testing.T) { }, }) } + func TestAccAzureRMStorageAccount_storageV2WithUpdate(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") @@ -571,7 +510,7 @@ func TestAccAzureRMStorageAccount_networkRulesDeleted(t *testing.T) { }) } -func TestAccAzureRMStorageAccount_enableAdvancedThreatProtection(t *testing.T) { +func TestAccAzureRMStorageAccount_blobProperties(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") resource.ParallelTest(t, resource.TestCase{ @@ -580,18 +519,20 @@ func TestAccAzureRMStorageAccount_enableAdvancedThreatProtection(t *testing.T) { CheckDestroy: testCheckAzureRMStorageAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageAccount_enableAdvancedThreatProtection(data), + Config: testAccAzureRMStorageAccount_blobProperties(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enable_advanced_threat_protection", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "blob_properties.0.cors_rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "blob_properties.0.delete_retention_policy.0.days", "300"), ), }, data.ImportStep(), { - Config: testAccAzureRMStorageAccount_enableAdvancedThreatProtectionDisabled(data), + Config: testAccAzureRMStorageAccount_blobPropertiesUpdated(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "enable_advanced_threat_protection", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "blob_properties.0.cors_rule.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "blob_properties.0.delete_retention_policy.0.days", "7"), ), }, data.ImportStep(), @@ -599,7 +540,7 @@ func TestAccAzureRMStorageAccount_enableAdvancedThreatProtection(t *testing.T) { }) } -func TestAccAzureRMStorageAccount_blobProperties(t *testing.T) { +func TestAccAzureRMStorageAccount_queueProperties(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") resource.ParallelTest(t, resource.TestCase{ @@ -608,20 +549,16 @@ func TestAccAzureRMStorageAccount_blobProperties(t *testing.T) { CheckDestroy: testCheckAzureRMStorageAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageAccount_blobProperties(data), + Config: testAccAzureRMStorageAccount_queueProperties(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "blob_properties.0.cors_rule.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "blob_properties.0.delete_retention_policy.0.days", "300"), ), }, data.ImportStep(), { - Config: testAccAzureRMStorageAccount_blobPropertiesUpdated(data), + Config: testAccAzureRMStorageAccount_queuePropertiesUpdated(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "blob_properties.0.cors_rule.#", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "blob_properties.0.delete_retention_policy.0.days", "7"), ), }, data.ImportStep(), @@ -629,7 +566,7 @@ func TestAccAzureRMStorageAccount_blobProperties(t *testing.T) { }) } -func TestAccAzureRMStorageAccount_queueProperties(t *testing.T) { +func TestAccAzureRMStorageAccount_staticWebsiteProperties(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") resource.ParallelTest(t, resource.TestCase{ @@ -638,14 +575,14 @@ func TestAccAzureRMStorageAccount_queueProperties(t *testing.T) { CheckDestroy: testCheckAzureRMStorageAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageAccount_queueProperties(data), + Config: testAccAzureRMStorageAccount_staticWebsiteProperties(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists(data.ResourceName), ), }, data.ImportStep(), { - Config: testAccAzureRMStorageAccount_queuePropertiesUpdated(data), + Config: testAccAzureRMStorageAccount_staticWebsitePropertiesUpdated(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists(data.ResourceName), ), @@ -733,6 +670,10 @@ func testCheckAzureRMStorageAccountDestroy(s *terraform.State) error { func testAccAzureRMStorageAccount_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -740,9 +681,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -753,36 +694,17 @@ resource "azurerm_storage_account" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMStorageAccount_basic(data) - return fmt.Sprintf(` -%s - -resource "azurerm_storage_account" "import" { - name = "${azurerm_storage_account.test.name}" - resource_group_name = "${azurerm_storage_account.test.resource_group_name}" - location = "${azurerm_storage_account.test.location}" - account_tier = "${azurerm_storage_account.test.account_tier}" - account_replication_type = "${azurerm_storage_account.test.account_replication_type}" -} -`, template) -} +func testAccAzureRMStorageAccount_tagCount(data acceptance.TestData) string { + tags := "" + for i := 0; i < 50; i++ { + tags += fmt.Sprintf("t%d = \"v%d\"\n", i, i) + } -func testAccAzureRMStorageAccount_writeLock(data acceptance.TestData) string { - template := testAccAzureRMStorageAccount_basic(data) return fmt.Sprintf(` -%s - -resource "azurerm_management_lock" "test" { - name = "acctestlock-%d" - scope = "${azurerm_storage_account.test.id}" - lock_level = "ReadOnly" -} -`, template, data.RandomInteger) +provider "azurerm" { + features {} } -func testAccAzureRMStorageAccount_premium(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -790,89 +712,53 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" - account_tier = "Premium" + location = azurerm_resource_group.test.location + account_tier = "Standard" account_replication_type = "LRS" tags = { - environment = "production" + %s } } -`, data.RandomInteger, data.Locations.Primary, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, tags) } -func testAccAzureRMStorageAccount_update(data acceptance.TestData) string { +func testAccAzureRMStorageAccount_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStorageAccount_basic(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-storage-%d" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - - location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" - account_replication_type = "GRS" +%s - tags = { - environment = "staging" - } +resource "azurerm_storage_account" "import" { + name = azurerm_storage_account.test.name + resource_group_name = azurerm_storage_account.test.resource_group_name + location = azurerm_storage_account.test.location + account_tier = azurerm_storage_account.test.account_tier + account_replication_type = azurerm_storage_account.test.account_replication_type } -`, data.RandomInteger, data.Locations.Primary, data.RandomString) +`, template) } -func testAccAzureRMStorageAccount_blobEncryption(data acceptance.TestData) string { +func testAccAzureRMStorageAccount_writeLock(data acceptance.TestData) string { + template := testAccAzureRMStorageAccount_basic(data) return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-storage-%d" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - - location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" - account_replication_type = "LRS" - enable_blob_encryption = true +%s - tags = { - environment = "production" - } +resource "azurerm_management_lock" "test" { + name = "acctestlock-%d" + scope = azurerm_storage_account.test.id + lock_level = "ReadOnly" } -`, data.RandomInteger, data.Locations.Primary, data.RandomString) +`, template, data.RandomInteger) } -func testAccAzureRMStorageAccount_blobEncryptionDisabled(data acceptance.TestData) string { +func testAccAzureRMStorageAccount_premium(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-storage-%d" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - - location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" - account_replication_type = "LRS" - enable_blob_encryption = false - - tags = { - environment = "production" - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomString) +provider "azurerm" { + features {} } -func testAccAzureRMStorageAccount_fileEncryption(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -880,12 +766,11 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" + location = azurerm_resource_group.test.location + account_tier = "Premium" account_replication_type = "LRS" - enable_file_encryption = true tags = { environment = "production" @@ -894,8 +779,12 @@ resource "azurerm_storage_account" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_fileEncryptionDisabled(data acceptance.TestData) string { +func testAccAzureRMStorageAccount_update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -903,15 +792,14 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" - account_replication_type = "LRS" - enable_file_encryption = false + account_replication_type = "GRS" tags = { - environment = "production" + environment = "staging" } } `, data.RandomInteger, data.Locations.Primary, data.RandomString) @@ -919,6 +807,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_enableHttpsTrafficOnly(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -926,9 +818,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" enable_https_traffic_only = true @@ -942,6 +834,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_enableHttpsTrafficOnlyDisabled(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -949,9 +845,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" enable_https_traffic_only = false @@ -965,6 +861,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_isHnsEnabledTrue(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -972,9 +872,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_kind = "StorageV2" account_tier = "Standard" account_replication_type = "LRS" @@ -985,6 +885,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_isHnsEnabledFalse(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -992,9 +896,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_kind = "StorageV2" account_tier = "Standard" account_replication_type = "LRS" @@ -1005,6 +909,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_blobStorage(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1012,9 +920,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_kind = "BlobStorage" account_tier = "Standard" account_replication_type = "LRS" @@ -1028,6 +936,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_blobStorageUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1035,9 +947,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_kind = "BlobStorage" account_tier = "Standard" account_replication_type = "LRS" @@ -1052,6 +964,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_blockBlobStorage(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1059,9 +975,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_kind = "BlockBlobStorage" account_tier = "Premium" account_replication_type = "LRS" @@ -1075,6 +991,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_fileStorage(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1082,9 +1002,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_kind = "FileStorage" account_tier = "Premium" account_replication_type = "LRS" @@ -1099,6 +1019,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_fileStorageUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1106,9 +1030,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_kind = "FileStorage" account_tier = "Premium" account_replication_type = "LRS" @@ -1123,6 +1047,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_storageV2(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1130,9 +1058,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_kind = "StorageV2" account_tier = "Standard" account_replication_type = "LRS" @@ -1146,6 +1074,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_storageV2Update(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1153,9 +1085,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_kind = "StorageV2" account_tier = "Standard" account_replication_type = "LRS" @@ -1170,6 +1102,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_nonStandardCasing(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1177,8 +1113,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "standard" account_replication_type = "lrs" @@ -1191,6 +1127,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_identity(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1198,9 +1138,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -1217,6 +1157,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_networkRules(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1225,29 +1169,29 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" service_endpoints = ["Microsoft.Storage"] } resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" network_rules { default_action = "Deny" ip_rules = ["127.0.0.1"] - virtual_network_subnet_ids = ["${azurerm_subnet.test.id}"] + virtual_network_subnet_ids = [azurerm_subnet.test.id] } tags = { @@ -1259,6 +1203,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_networkRulesUpdate(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1267,22 +1215,22 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" service_endpoints = ["Microsoft.Storage"] } resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -1301,6 +1249,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_networkRulesReverted(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1309,29 +1261,29 @@ resource "azurerm_resource_group" "test" { resource "azurerm_virtual_network" "test" { name = "acctestvirtnet%d" address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name } resource "azurerm_subnet" "test" { name = "acctestsubnet%d" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" service_endpoints = ["Microsoft.Storage"] } resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" network_rules { default_action = "Allow" ip_rules = ["127.0.0.1"] - virtual_network_subnet_ids = ["${azurerm_subnet.test.id}"] + virtual_network_subnet_ids = [azurerm_subnet.test.id] } tags = { @@ -1341,44 +1293,12 @@ resource "azurerm_storage_account" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomString) } -func testAccAzureRMStorageAccount_enableAdvancedThreatProtection(data acceptance.TestData) string { +func testAccAzureRMStorageAccount_blobProperties(data acceptance.TestData) string { return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-storage-%d" - location = "%s" +provider "azurerm" { + features {} } -resource "azurerm_storage_account" "test" { - name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" - account_replication_type = "LRS" - enable_advanced_threat_protection = true -} -`, data.RandomInteger, data.Locations.Primary, data.RandomString) -} - -func testAccAzureRMStorageAccount_enableAdvancedThreatProtectionDisabled(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-storage-%d" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" - account_replication_type = "LRS" - enable_advanced_threat_protection = false -} -`, data.RandomInteger, data.Locations.Primary, data.RandomString) -} - -func testAccAzureRMStorageAccount_blobProperties(data acceptance.TestData) string { - return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestAzureRMSA-%d" location = "%s" @@ -1386,9 +1306,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -1411,6 +1331,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_blobPropertiesUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestAzureRMSA-%d" location = "%s" @@ -1418,9 +1342,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -1450,6 +1374,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_queueProperties(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1457,9 +1385,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -1498,6 +1426,10 @@ resource "azurerm_storage_account" "test" { func testAccAzureRMStorageAccount_queuePropertiesUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -1505,9 +1437,9 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -1551,3 +1483,59 @@ resource "azurerm_storage_account" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomString) } + +func testAccAzureRMStorageAccount_staticWebsiteProperties(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-storage-%d" + location = "%s" +} + +resource "azurerm_storage_account" "test" { + name = "unlikely23exst2acct%s" + resource_group_name = azurerm_resource_group.test.name + + location = azurerm_resource_group.test.location + account_kind = "StorageV2" + account_tier = "Standard" + account_replication_type = "LRS" + + static_website { + index_document = "index.html" + error_404_document = "404.html" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} + +func testAccAzureRMStorageAccount_staticWebsitePropertiesUpdated(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-storage-%d" + location = "%s" +} + +resource "azurerm_storage_account" "test" { + name = "unlikely23exst2acct%s" + resource_group_name = azurerm_resource_group.test.name + + location = azurerm_resource_group.test.location + account_kind = "StorageV2" + account_tier = "Standard" + account_replication_type = "LRS" + + static_website { + index_document = "index-2.html" + error_404_document = "404-2.html" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_blob_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_blob_test.go index ddc5438f401b7..ac1d91a7dee1d 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_blob_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_blob_test.go @@ -54,7 +54,7 @@ func TestAccAzureRMStorageBlob_appendEmpty(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, }, }) @@ -78,7 +78,7 @@ func TestAccAzureRMStorageBlob_appendEmptyMetaData(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, }, }) @@ -102,7 +102,7 @@ func TestAccAzureRMStorageBlob_blockEmpty(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, }, }) @@ -126,7 +126,7 @@ func TestAccAzureRMStorageBlob_blockEmptyAzureADAuth(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, }, }) @@ -150,7 +150,7 @@ func TestAccAzureRMStorageBlob_blockEmptyMetaData(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, }, }) @@ -175,7 +175,7 @@ func TestAccAzureRMStorageBlob_blockEmptyAccessTier(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, { Config: testAccAzureRMStorageBlob_blockEmptyAccessTier(data, blobs.Hot), @@ -213,7 +213,7 @@ func TestAccAzureRMStorageBlob_blockFromInlineContent(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source_content", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "source_content", "type"}, }, }, }) @@ -237,7 +237,7 @@ func TestAccAzureRMStorageBlob_blockFromPublicBlob(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source_uri", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "source_uri", "type"}, }, }, }) @@ -261,7 +261,7 @@ func TestAccAzureRMStorageBlob_blockFromPublicFile(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source_uri", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "source_uri", "type"}, }, }, }) @@ -285,7 +285,7 @@ func TestAccAzureRMStorageBlob_blockFromExistingBlob(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source_uri", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "source_uri", "type"}, }, }, }) @@ -318,7 +318,7 @@ func TestAccAzureRMStorageBlob_blockFromLocalFile(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "source", "type"}, }, }, }) @@ -342,7 +342,7 @@ func TestAccAzureRMStorageBlob_contentType(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, { Config: testAccAzureRMStorageBlob_contentTypeUpdated(data), @@ -354,7 +354,7 @@ func TestAccAzureRMStorageBlob_contentType(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, }, }) @@ -378,7 +378,7 @@ func TestAccAzureRMStorageBlob_contentTypePremium(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, }, }) @@ -402,7 +402,7 @@ func TestAccAzureRMStorageBlob_pageEmpty(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, }, }) @@ -426,7 +426,7 @@ func TestAccAzureRMStorageBlob_pageEmptyPremium(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, }, }) @@ -450,7 +450,7 @@ func TestAccAzureRMStorageBlob_pageEmptyMetaData(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, }, }) @@ -474,7 +474,7 @@ func TestAccAzureRMStorageBlob_pageFromExistingBlob(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source_uri", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "source_uri", "type"}, }, }, }) @@ -507,7 +507,7 @@ func TestAccAzureRMStorageBlob_pageFromLocalFile(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "source", "type"}, }, }, }) @@ -554,7 +554,7 @@ func TestAccAzureRMStorageBlob_update(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, { Config: testAccAzureRMStorageBlob_updateUpdated(data), @@ -566,7 +566,7 @@ func TestAccAzureRMStorageBlob_update(t *testing.T) { ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, + ImportStateVerifyIgnore: []string{"parallelism", "size", "type"}, }, }, }) @@ -763,10 +763,9 @@ func testAccAzureRMStorageBlob_appendEmpty(data acceptance.TestData) string { resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "append" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Append" } `, template) } @@ -778,10 +777,9 @@ func testAccAzureRMStorageBlob_appendEmptyMetaData(data acceptance.TestData) str resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "append" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Append" metadata = { hello = "world" @@ -797,10 +795,9 @@ func testAccAzureRMStorageBlob_blockEmpty(data acceptance.TestData) string { resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "block" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Block" } `, template) } @@ -823,10 +820,9 @@ func testAccAzureRMStorageBlob_blockEmptyMetaData(data acceptance.TestData) stri resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "block" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Block" metadata = { hello = "world" @@ -842,10 +838,9 @@ func testAccAzureRMStorageBlob_blockEmptyAccessTier(data acceptance.TestData, ac resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "block" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Block" access_tier = "%s" } `, template, string(accessTier)) @@ -858,10 +853,9 @@ func testAccAzureRMStorageBlob_blockFromInlineContent(data acceptance.TestData) resource "azurerm_storage_blob" "test" { name = "rick.morty" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "block" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Block" source_content = "Wubba Lubba Dub Dub" } `, template) @@ -874,29 +868,26 @@ func testAccAzureRMStorageBlob_blockFromPublicBlob(data acceptance.TestData) str resource "azurerm_storage_blob" "source" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "block" - source_uri = "http://releases.ubuntu.com/18.04.3/ubuntu-18.04.3-desktop-amd64.iso" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Block" + source_uri = "http://old-releases.ubuntu.com/releases/bionic/ubuntu-18.04-desktop-amd64.iso" content_type = "application/x-iso9660-image" } resource "azurerm_storage_container" "second" { name = "second" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } resource "azurerm_storage_blob" "test" { name = "copied.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.second.name}" - type = "block" - source_uri = "${azurerm_storage_blob.source.id}" - content_type = "${azurerm_storage_blob.source.content_type}" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.second.name + type = "Block" + source_uri = azurerm_storage_blob.source.id + content_type = azurerm_storage_blob.source.content_type } `, template) } @@ -908,11 +899,10 @@ func testAccAzureRMStorageBlob_blockFromPublicFile(data acceptance.TestData) str resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "block" - source_uri = "http://releases.ubuntu.com/18.04.3/ubuntu-18.04.3-desktop-amd64.iso" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Block" + source_uri = "http://old-releases.ubuntu.com/releases/bionic/ubuntu-18.04-desktop-amd64.iso" content_type = "application/x-iso9660-image" } `, template) @@ -925,22 +915,20 @@ func testAccAzureRMStorageBlob_blockFromExistingBlob(data acceptance.TestData) s resource "azurerm_storage_blob" "source" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "block" - source_uri = "http://releases.ubuntu.com/18.04.3/ubuntu-18.04.3-desktop-amd64.iso" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Block" + source_uri = "http://old-releases.ubuntu.com/releases/bionic/ubuntu-18.04-desktop-amd64.iso" content_type = "application/x-iso9660-image" } resource "azurerm_storage_blob" "test" { name = "copied.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "block" - source_uri = "${azurerm_storage_blob.source.id}" - content_type = "${azurerm_storage_blob.source.content_type}" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Block" + source_uri = azurerm_storage_blob.source.id + content_type = azurerm_storage_blob.source.content_type } `, template) } @@ -952,10 +940,9 @@ func testAccAzureRMStorageBlob_blockFromLocalBlob(data acceptance.TestData, file resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "block" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Block" source = "%s" } `, template, fileName) @@ -968,10 +955,9 @@ func testAccAzureRMStorageBlob_contentType(data acceptance.TestData) string { resource "azurerm_storage_blob" "test" { name = "example.ext" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "page" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Page" size = 5120 content_type = "image/png" } @@ -985,10 +971,9 @@ func testAccAzureRMStorageBlob_contentTypePremium(data acceptance.TestData) stri resource "azurerm_storage_blob" "test" { name = "example.ext" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "page" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Page" size = 5120 content_type = "image/png" } @@ -1002,10 +987,9 @@ func testAccAzureRMStorageBlob_contentTypeUpdated(data acceptance.TestData) stri resource "azurerm_storage_blob" "test" { name = "example.ext" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "page" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Page" size = 5120 content_type = "image/gif" } @@ -1019,10 +1003,9 @@ func testAccAzureRMStorageBlob_pageEmpty(data acceptance.TestData) string { resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "page" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Page" size = 5120 } `, template) @@ -1035,10 +1018,9 @@ func testAccAzureRMStorageBlob_pageEmptyPremium(data acceptance.TestData) string resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "page" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Page" size = 5120 } `, template) @@ -1051,10 +1033,9 @@ func testAccAzureRMStorageBlob_pageEmptyMetaData(data acceptance.TestData) strin resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "page" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Page" size = 5120 metadata = { @@ -1071,22 +1052,20 @@ func testAccAzureRMStorageBlob_pageFromExistingBlob(data acceptance.TestData) st resource "azurerm_storage_blob" "source" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "page" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Page" size = 5120 content_type = "application/x-iso9660-image" } resource "azurerm_storage_blob" "test" { name = "copied.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "page" - source_uri = "${azurerm_storage_blob.source.id}" - content_type = "${azurerm_storage_blob.source.content_type}" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Page" + source_uri = azurerm_storage_blob.source.id + content_type = azurerm_storage_blob.source.content_type } `, template) } @@ -1098,10 +1077,9 @@ func testAccAzureRMStorageBlob_pageFromLocalBlob(data acceptance.TestData, fileN resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "page" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Page" source = "%s" } `, template, fileName) @@ -1145,12 +1123,11 @@ func testAccAzureRMStorageBlob_requiresImport(data acceptance.TestData) string { %s resource "azurerm_storage_blob" "import" { - name = "${azurerm_storage_blob.test.name}" - resource_group_name = "${azurerm_storage_blob.test.resource_group_name}" - storage_account_name = "${azurerm_storage_blob.test.storage_account_name}" - storage_container_name = "${azurerm_storage_blob.test.storage_container_name}" - type = "${azurerm_storage_blob.test.type}" - size = "${azurerm_storage_blob.test.size}" + name = azurerm_storage_blob.test.name + storage_account_name = azurerm_storage_blob.test.storage_account_name + storage_container_name = azurerm_storage_blob.test.storage_container_name + type = azurerm_storage_blob.test.type + size = azurerm_storage_blob.test.size } `, template) } @@ -1162,10 +1139,9 @@ func testAccAzureRMStorageBlob_update(data acceptance.TestData) string { resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "block" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Block" size = 5120 content_type = "vnd/panda+pops" metadata = { @@ -1182,10 +1158,9 @@ func testAccAzureRMStorageBlob_updateUpdated(data acceptance.TestData) string { resource "azurerm_storage_blob" "test" { name = "example.vhd" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" - storage_container_name = "${azurerm_storage_container.test.name}" - type = "block" + storage_account_name = azurerm_storage_account.test.name + storage_container_name = azurerm_storage_container.test.name + type = "Block" size = 5120 content_type = "vnd/mountain-mover-3000" metadata = { @@ -1198,6 +1173,10 @@ resource "azurerm_storage_blob" "test" { func testAccAzureRMStorageBlob_template(data acceptance.TestData, accessLevel string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1205,16 +1184,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestacc%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "test" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "%s" } `, data.RandomInteger, data.Locations.Primary, data.RandomString, accessLevel) @@ -1222,6 +1200,10 @@ resource "azurerm_storage_container" "test" { func testAccAzureRMStorageBlob_templateBlockBlobStorage(data acceptance.TestData, accessLevel string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1229,8 +1211,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestacc%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_kind = "StorageV2" account_tier = "Standard" account_replication_type = "LRS" @@ -1238,8 +1220,7 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_container" "test" { name = "test" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "%s" } `, data.RandomInteger, data.Locations.Primary, data.RandomString, accessLevel) @@ -1247,6 +1228,10 @@ resource "azurerm_storage_container" "test" { func testAccAzureRMStorageBlob_templatePremium(data acceptance.TestData, accessLevel string) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -1254,16 +1239,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestacc%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Premium" account_replication_type = "LRS" } resource "azurerm_storage_container" "test" { name = "test" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "%s" } `, data.RandomInteger, data.Locations.Primary, data.RandomString, accessLevel) diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_container_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_container_test.go index 45753cc73f351..fa0f16071db17 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_container_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_container_test.go @@ -311,8 +311,7 @@ func testAccAzureRMStorageContainer_basic(data acceptance.TestData) string { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } `, template) @@ -335,10 +334,9 @@ func testAccAzureRMStorageContainer_requiresImport(data acceptance.TestData) str %s resource "azurerm_storage_container" "import" { - name = "${azurerm_storage_container.test.name}" - resource_group_name = "${azurerm_storage_container.test.resource_group_name}" - storage_account_name = "${azurerm_storage_container.test.storage_account_name}" - container_access_type = "${azurerm_storage_container.test.container_access_type}" + name = azurerm_storage_container.test.name + storage_account_name = azurerm_storage_container.test.storage_account_name + container_access_type = azurerm_storage_container.test.container_access_type } `, template) } @@ -350,8 +348,7 @@ func testAccAzureRMStorageContainer_update(data acceptance.TestData, accessType resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "%s" } `, template, accessType) @@ -364,8 +361,7 @@ func testAccAzureRMStorageContainer_metaData(data acceptance.TestData) string { resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" metadata = { @@ -382,8 +378,7 @@ func testAccAzureRMStorageContainer_metaDataUpdated(data acceptance.TestData) st resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" metadata = { @@ -401,12 +396,10 @@ func testAccAzureRMStorageContainer_metaDataEmpty(data acceptance.TestData) stri resource "azurerm_storage_container" "test" { name = "vhds" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" - metadata = { - } + metadata = {} } `, template) } @@ -418,8 +411,7 @@ func testAccAzureRMStorageContainer_root(data acceptance.TestData) string { resource "azurerm_storage_container" "test" { name = "$root" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } `, template) @@ -432,8 +424,7 @@ func testAccAzureRMStorageContainer_web(data acceptance.TestData) string { resource "azurerm_storage_container" "test" { name = "$web" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name container_access_type = "private" } `, template) @@ -441,6 +432,10 @@ resource "azurerm_storage_container" "test" { func testAccAzureRMStorageContainer_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -448,8 +443,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestacc%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_data_lake_gen2_filesystem_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_data_lake_gen2_filesystem_test.go index 44d993cc0c86f..71b3f75152c3b 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_data_lake_gen2_filesystem_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_data_lake_gen2_filesystem_test.go @@ -155,7 +155,7 @@ func testAccAzureRMStorageDataLakeGen2FileSystem_requiresImport(data acceptance. resource "azurerm_storage_data_lake_gen2_filesystem" "import" { name = azurerm_storage_data_lake_gen2_filesystem.test.name - storage_account_id = azurerm_storage_data_lake_gen2_filesystem.storage_account_id + storage_account_id = azurerm_storage_data_lake_gen2_filesystem.test.storage_account_id } `, template) } @@ -178,6 +178,10 @@ resource "azurerm_storage_data_lake_gen2_filesystem" "test" { func testAccAzureRMStorageDataLakeGen2FileSystem_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -185,8 +189,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestacc%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_kind = "BlobStorage" account_tier = "Standard" account_replication_type = "LRS" diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_management_policy_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_management_policy_test.go index 73315c739f722..072e7cd597bfb 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_management_policy_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_management_policy_test.go @@ -258,6 +258,10 @@ func testCheckAzureRMStorageAccountManagementPolicyExistsInternal(storageAccount func testAccAzureRMStorageManagementPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -265,16 +269,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" account_kind = "BlobStorage" } resource "azurerm_storage_management_policy" "test" { - storage_account_id = "${azurerm_storage_account.test.id}" + storage_account_id = azurerm_storage_account.test.id rule { name = "rule1" @@ -300,6 +304,10 @@ resource "azurerm_storage_management_policy" "test" { func testAccAzureRMStorageManagementPolicy_multipleRule(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -307,16 +315,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" account_kind = "BlobStorage" } resource "azurerm_storage_management_policy" "test" { - storage_account_id = "${azurerm_storage_account.test.id}" + storage_account_id = azurerm_storage_account.test.id rule { name = "rule1" @@ -360,6 +368,10 @@ resource "azurerm_storage_management_policy" "test" { func testAccAzureRMStorageManagementPolicy_multipleRuleUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" location = "%s" @@ -367,16 +379,16 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.test.name}" + resource_group_name = azurerm_resource_group.test.name - location = "${azurerm_resource_group.test.location}" + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" account_kind = "BlobStorage" } resource "azurerm_storage_management_policy" "test" { - storage_account_id = "${azurerm_storage_account.test.id}" + storage_account_id = azurerm_storage_account.test.id rule { name = "rule1" diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_queue_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_queue_test.go index c72d4adf9e518..349c500329b6f 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_queue_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_queue_test.go @@ -225,7 +225,7 @@ func testAccAzureRMStorageQueue_basic(data acceptance.TestData) string { resource "azurerm_storage_queue" "test" { name = "mysamplequeue-%d" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name } `, template, data.RandomInteger) } @@ -247,8 +247,8 @@ func testAccAzureRMStorageQueue_requiresImport(data acceptance.TestData) string %s resource "azurerm_storage_queue" "import" { - name = "${azurerm_storage_queue.test.name}" - storage_account_name = "${azurerm_storage_queue.test.storage_account_name}" + name = azurerm_storage_queue.test.name + storage_account_name = azurerm_storage_queue.test.storage_account_name } `, template) } @@ -260,7 +260,7 @@ func testAccAzureRMStorageQueue_metaData(data acceptance.TestData) string { resource "azurerm_storage_queue" "test" { name = "mysamplequeue-%d" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name metadata = { hello = "world" @@ -276,7 +276,7 @@ func testAccAzureRMStorageQueue_metaDataUpdated(data acceptance.TestData) string resource "azurerm_storage_queue" "test" { name = "mysamplequeue-%d" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name metadata = { hello = "world" @@ -288,6 +288,10 @@ resource "azurerm_storage_queue" "test" { func testAccAzureRMStorageQueue_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -295,8 +299,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestacc%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -304,6 +308,5 @@ resource "azurerm_storage_account" "test" { environment = "staging" } } - `, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_share_directory_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_share_directory_test.go index 24c9c87314775..6792afb73b814 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_share_directory_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_share_directory_test.go @@ -227,8 +227,8 @@ func testAccAzureRMStorageShareDirectory_basic(data acceptance.TestData) string resource "azurerm_storage_share_directory" "test" { name = "dir" - share_name = "${azurerm_storage_share.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + share_name = azurerm_storage_share.test.name + storage_account_name = azurerm_storage_account.test.name } `, template) } @@ -240,8 +240,8 @@ func testAccAzureRMStorageShareDirectory_uppercase(data acceptance.TestData) str resource "azurerm_storage_share_directory" "test" { name = "UpperCaseCharacterS" - share_name = "${azurerm_storage_share.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + share_name = azurerm_storage_share.test.name + storage_account_name = azurerm_storage_account.test.name } `, template) } @@ -252,9 +252,9 @@ func testAccAzureRMStorageShareDirectory_requiresImport(data acceptance.TestData %s resource "azurerm_storage_share_directory" "import" { - name = "${azurerm_storage_share_directory.test.name}" - share_name = "${azurerm_storage_share_directory.test.share_name}" - storage_account_name = "${azurerm_storage_share_directory.test.storage_account_name}" + name = azurerm_storage_share_directory.test.name + share_name = azurerm_storage_share_directory.test.share_name + storage_account_name = azurerm_storage_share_directory.test.storage_account_name } `, template) } @@ -266,8 +266,8 @@ func testAccAzureRMStorageShareDirectory_complete(data acceptance.TestData) stri resource "azurerm_storage_share_directory" "test" { name = "dir" - share_name = "${azurerm_storage_share.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + share_name = azurerm_storage_share.test.name + storage_account_name = azurerm_storage_account.test.name metadata = { hello = "world" @@ -283,8 +283,8 @@ func testAccAzureRMStorageShareDirectory_updated(data acceptance.TestData) strin resource "azurerm_storage_share_directory" "test" { name = "dir" - share_name = "${azurerm_storage_share.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + share_name = azurerm_storage_share.test.name + storage_account_name = azurerm_storage_account.test.name metadata = { hello = "world" @@ -301,20 +301,24 @@ func testAccAzureRMStorageShareDirectory_nested(data acceptance.TestData) string resource "azurerm_storage_share_directory" "parent" { name = "parent" - share_name = "${azurerm_storage_share.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + share_name = azurerm_storage_share.test.name + storage_account_name = azurerm_storage_account.test.name } resource "azurerm_storage_share_directory" "child" { name = "${azurerm_storage_share_directory.parent.name}/child" - share_name = "${azurerm_storage_share.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + share_name = azurerm_storage_share.test.name + storage_account_name = azurerm_storage_account.test.name } `, template) } func testAccAzureRMStorageShareDirectory_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -322,15 +326,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_share" "test" { name = "fileshare" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name quota = 50 } `, data.RandomInteger, data.Locations.Primary, data.RandomString) diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_share_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_share_test.go index 211babe020461..ac83398c00b49 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_share_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_share_test.go @@ -266,8 +266,7 @@ func testAccAzureRMStorageShare_basic(data acceptance.TestData) string { resource "azurerm_storage_share" "test" { name = "testshare%s" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name } `, template, data.RandomString) } @@ -279,8 +278,7 @@ func testAccAzureRMStorageShare_metaData(data acceptance.TestData) string { resource "azurerm_storage_share" "test" { name = "testshare%s" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name metadata = { hello = "world" @@ -296,8 +294,7 @@ func testAccAzureRMStorageShare_metaDataUpdated(data acceptance.TestData) string resource "azurerm_storage_share" "test" { name = "testshare%s" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name metadata = { hello = "world" @@ -314,8 +311,7 @@ func testAccAzureRMStorageShare_acl(data acceptance.TestData) string { resource "azurerm_storage_share" "test" { name = "testshare%s" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name acl { id = "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI" @@ -337,8 +333,7 @@ func testAccAzureRMStorageShare_aclUpdated(data acceptance.TestData) string { resource "azurerm_storage_share" "test" { name = "testshare%s" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name acl { id = "AAAANDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI" @@ -367,9 +362,8 @@ func testAccAzureRMStorageShare_requiresImport(data acceptance.TestData) string %s resource "azurerm_storage_share" "import" { - name = "${azurerm_storage_share.test.name}" - resource_group_name = "${azurerm_storage_share.test.resource_group_name}" - storage_account_name = "${azurerm_storage_share.test.storage_account_name}" + name = azurerm_storage_share.test.name + storage_account_name = azurerm_storage_share.test.storage_account_name } `, template) } @@ -381,8 +375,7 @@ func testAccAzureRMStorageShare_updateQuota(data acceptance.TestData) string { resource "azurerm_storage_share" "test" { name = "testshare%s" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name quota = 5 } `, template, data.RandomString) @@ -390,6 +383,10 @@ resource "azurerm_storage_share" "test" { func testAccAzureRMStorageShare_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -397,8 +394,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestacc%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_table_entity_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_table_entity_test.go index df29e6263cc51..7916e19d2bfb8 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_table_entity_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_table_entity_test.go @@ -183,8 +183,8 @@ func testAccAzureRMTableEntity_basic(data acceptance.TestData) string { %s resource "azurerm_storage_table_entity" "test" { - storage_account_name = "${azurerm_storage_account.test.name}" - table_name = "${azurerm_storage_table.test.name}" + storage_account_name = azurerm_storage_account.test.name + table_name = azurerm_storage_table.test.name partition_key = "test_partition%d" row_key = "test_row%d" @@ -200,9 +200,9 @@ func testAccAzureRMTableEntity_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s -resource "azurerm_storage_table_entity" "test" { - storage_account_name = "${azurerm_storage_account.test.name}" - table_name = "${azurerm_storage_table.test.name}" +resource "azurerm_storage_table_entity" "import" { + storage_account_name = azurerm_storage_account.test.name + table_name = azurerm_storage_table.test.name partition_key = "test_partition%d" row_key = "test_row%d" @@ -219,8 +219,8 @@ func testAccAzureRMTableEntity_updated(data acceptance.TestData) string { %s resource "azurerm_storage_table_entity" "test" { - storage_account_name = "${azurerm_storage_account.test.name}" - table_name = "${azurerm_storage_table.test.name}" + storage_account_name = azurerm_storage_account.test.name + table_name = azurerm_storage_table.test.name partition_key = "test_partition%d" row_key = "test_row%d" @@ -234,6 +234,10 @@ resource "azurerm_storage_table_entity" "test" { func testAccAzureRMTableEntity_template(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -241,16 +245,15 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_storage_table" "test" { name = "acctestst%d" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_table_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_table_test.go index d07f2387d5b8b..85b7676121f1a 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_table_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_table_test.go @@ -258,6 +258,10 @@ func TestValidateArmStorageTableName(t *testing.T) { func testAccAzureRMStorageTable_basic(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -265,8 +269,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestacc%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -277,8 +281,7 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_table" "test" { name = "acctestst%d" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name } `, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } @@ -289,15 +292,18 @@ func testAccAzureRMStorageTable_requiresImport(data acceptance.TestData) string %s resource "azurerm_storage_table" "import" { - name = "${azurerm_storage_table.test.name}" - resource_group_name = "${azurerm_storage_table.test.resource_group_name}" - storage_account_name = "${azurerm_storage_table.test.storage_account_name}" + name = azurerm_storage_table.test.name + storage_account_name = azurerm_storage_table.test.storage_account_name } `, template) } func testAccAzureRMStorageTable_acl(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -305,8 +311,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestacc%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -317,8 +323,7 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_table" "test" { name = "acctestst%d" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name acl { id = "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI" @@ -334,6 +339,10 @@ resource "azurerm_storage_table" "test" { func testAccAzureRMStorageTable_aclUpdated(data acceptance.TestData) string { return fmt.Sprintf(` +provider "azurerm" { + features {} +} + resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" @@ -341,8 +350,8 @@ resource "azurerm_resource_group" "test" { resource "azurerm_storage_account" "test" { name = "acctestacc%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" @@ -353,8 +362,7 @@ resource "azurerm_storage_account" "test" { resource "azurerm_storage_table" "test" { name = "acctestst%d" - resource_group_name = "${azurerm_resource_group.test.name}" - storage_account_name = "${azurerm_storage_account.test.name}" + storage_account_name = azurerm_storage_account.test.name acl { id = "AAAANDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI" diff --git a/azurerm/internal/services/storage/validate/storage_account.go b/azurerm/internal/services/storage/validate/storage_account.go new file mode 100644 index 0000000000000..3fe3b6d2710b9 --- /dev/null +++ b/azurerm/internal/services/storage/validate/storage_account.go @@ -0,0 +1,22 @@ +package validate + +import ( + "fmt" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/parsers" +) + +func StorageAccountID(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) + return + } + + if _, err := parsers.ParseAccountID(v); err != nil { + errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err)) + return + } + + return warnings, errors +} diff --git a/azurerm/internal/services/streamanalytics/registration.go b/azurerm/internal/services/streamanalytics/registration.go index 2764a2feb81c4..5523f6b27f662 100644 --- a/azurerm/internal/services/streamanalytics/registration.go +++ b/azurerm/internal/services/streamanalytics/registration.go @@ -11,6 +11,13 @@ func (r Registration) Name() string { return "Stream Analytics" } +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Stream Analytics", + } +} + // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job.go index ac43aa2d11efd..c824560677aa5 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job.go @@ -57,7 +57,7 @@ func resourceArmStreamAnalyticsJob() *schema.Resource { "1.1", // TODO: support for 1.2 when this is fixed: // https://github.com/Azure/azure-rest-api-specs/issues/5604 - //"1.2", + // "1.2", }, false), }, diff --git a/azurerm/internal/services/streamanalytics/tests/data_source_stream_analytics_job_test.go b/azurerm/internal/services/streamanalytics/tests/data_source_stream_analytics_job_test.go index 05b69ccefc9f7..591279c3295a0 100644 --- a/azurerm/internal/services/streamanalytics/tests/data_source_stream_analytics_job_test.go +++ b/azurerm/internal/services/streamanalytics/tests/data_source_stream_analytics_job_test.go @@ -32,8 +32,8 @@ func testAccDataSourceAzureRMStreamAnalyticsJob_basic(data acceptance.TestData) %s data "azurerm_stream_analytics_job" "test" { - name = "${azurerm_stream_analytics_job.test.name}" - resource_group_name = "${azurerm_stream_analytics_job.test.resource_group_name}" + name = azurerm_stream_analytics_job.test.name + resource_group_name = azurerm_stream_analytics_job.test.resource_group_name } `, config) } diff --git a/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_function_javascript_udf_test.go b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_function_javascript_udf_test.go index 3868327c495b4..bdb18a41bcced 100644 --- a/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_function_javascript_udf_test.go +++ b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_function_javascript_udf_test.go @@ -140,8 +140,8 @@ func testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(data acceptance.Te resource "azurerm_stream_analytics_function_javascript_udf" "test" { name = "acctestinput-%d" - stream_analytics_job_name = "${azurerm_stream_analytics_job.test.name}" - resource_group_name = "${azurerm_stream_analytics_job.test.resource_group_name}" + stream_analytics_job_name = azurerm_stream_analytics_job.test.name + resource_group_name = azurerm_stream_analytics_job.test.resource_group_name script = <