如何使用Terraform创建Azure Redis缓存的私有端点?

huangapple go评论93阅读模式
英文:

How to create a private endpoint for azure redis cache using terraform?

问题

我已经使用Azure Redis Cache中的Terraform创建了私有端点。

以下是我Terraform代码的相关部分:

  1. terraform {
  2. required_providers {
  3. azurerm = {
  4. source = "hashicorp/azurerm"
  5. version = ">=3.0.0"
  6. }
  7. }
  8. }
  9. provider "azurerm" {
  10. features {}
  11. }
  12. locals {
  13. redis_name = "my-private-endpoint"
  14. resource_group = "my-resource-group"
  15. location = "eastus"
  16. }
  17. resource "azurerm_private_endpoint" "example" {
  18. name = local.redis_name
  19. location = local.location
  20. resource_group_name = local.resource_group
  21. subnet_id = data.azurerm_subnet.example.id
  22. private_service_connection {
  23. name = "akhil-obeliskredis-cache-testing-connection-private"
  24. private_connection_resource_id = data.azurerm_redis_cache.example.id
  25. subresource_names = ["redisCache"]
  26. is_manual_connection = false
  27. }
  28. private_dns_zone_group {
  29. name = "default"
  30. private_dns_zone_ids = [azurerm_private_dns_zone.example.id]
  31. }
  32. }
  33. resource "azurerm_private_dns_zone" "example" {
  34. name = "privatelinktest.redis.cache.windows.net"
  35. resource_group_name = "cvad-int-us-k8s-rg-a"
  36. }
  37. data "azurerm_subnet" "example" {
  38. name = "aks-subnet"
  39. virtual_network_name = "cvad-int-us-vnet-a"
  40. resource_group_name = "cvad-int-us-k8s-rg-a"
  41. }
  42. data "azurerm_redis_cache" "example" {
  43. name = "akhil-obeliskredis-cache-testing"
  44. resource_group_name = "my-resource-group"
  45. }

私有端点创建后,当我在网络上运行netcat时遇到了问题:

  1. nc: getaddrinfo for host "akhil-obeliskredis-cache-testing.redis.cache.windows.net" port 6380: Name or service not known

我看到一个区别。在Terraform创建时,fqdn没有创建,而当我从Azure门户手动创建时,fqdn被创建并且可以正常工作,没有任何错误。

使用Terraform创建:

如何使用Terraform创建Azure Redis缓存的私有端点?

从Azure门户手动创建后:

如何使用Terraform创建Azure Redis缓存的私有端点?

请在我尝试使用Terraform创建Azure Redis Cache的私有端点时可能遗漏了什么方面给我提供指导。

提前致谢!

英文:

I have created the private endpoint using terraform in azure redis cache.

Here's the relevant part of my Terraform code:

  1. terraform {
  2. required_providers {
  3. azurerm = {
  4. source = "hashicorp/azurerm"
  5. version = ">=3.0.0"
  6. }
  7. }
  8. }
  9. provider "azurerm" {
  10. features {}
  11. }
  12. locals {
  13. redis_name = "my-private-endpoint"
  14. resource_group = "my-resource-group"
  15. location = "eastus"
  16. }
  17. resource "azurerm_private_endpoint" "example" {
  18. name = local.redis_name
  19. location = local.location
  20. resource_group_name = local.resource_group
  21. subnet_id = data.azurerm_subnet.example.id
  22. private_service_connection {
  23. name = "akhil-obeliskredis-cache-testing-connection-private"
  24. private_connection_resource_id = data.azurerm_redis_cache.example.id
  25. subresource_names = ["redisCache"]
  26. is_manual_connection = false
  27. }
  28. private_dns_zone_group {
  29. name = "default"
  30. private_dns_zone_ids = [azurerm_private_dns_zone.example.id]
  31. }
  32. }
  33. resource "azurerm_private_dns_zone" "example" {
  34. name = "privatelinktest.redis.cache.windows.net"
  35. resource_group_name = "cvad-int-us-k8s-rg-a"
  36. }
  37. data "azurerm_subnet" "example" {
  38. name = "aks-subnet"
  39. virtual_network_name = "cvad-int-us-vnet-a"
  40. resource_group_name = "cvad-int-us-k8s-rg-a"
  41. }
  42. data "azurerm_redis_cache" "example" {
  43. name = "akhil-obeliskredis-cache-testing"
  44. resource_group_name = "my-resource-group"
  45. }

Once private endpoint is created I am facing the issue when I did netcat on the network:

  1. nc: getaddrinfo for host "akhil-obeliskredis-cache-testing.redis.cache.windows.net" port 6380: Name or service not known

I see one difference. In terraform creation fqdn is not creating and when I created manually from azure portal fqdn is creating and it is working with out any error

Using Terraform
如何使用Terraform创建Azure Redis缓存的私有端点?

Manually Creating from azure portal - After that when I p
如何使用Terraform创建Azure Redis缓存的私有端点?

Please guide me on what might be missing when I try to create a private endpoint for Azure Redis Cache using Terraform.

Thanks in Advance

答案1

得分: 1

以下是翻译好的部分:

  • 私有终结点
  • 私有 DNS 区域
  • DNS 区域组
  • VNet 链接

你的虚拟网络是否已链接到私有 DNS 区域?我在你的代码中没有看到 VNet 链接资源。

"azurerm_private_dns_zone_virtual_network_link" 使得可以在 Azure 虚拟网络内启用 DNS 解析和注册,使用 Azure 私有 DNS。

参考链接:https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone_virtual_network_link

英文:

There are several resources that needs to be configured correctly for this to work:

  • Private Endpoint
  • Private DNS Zone
  • DNS Zone Group
  • VNet Link

Is your Vnet linked to the private DNS zone? I don't see a Vnet link resource in your code.

"azurerm_private_dns_zone_virtual_network_link" enable DNS resolution and registration inside Azure Virtual Networks using Azure Private DNS.

<!-- begin snippet -->

  1. resource &quot;azurerm_private_dns_zone_virtual_network_link&quot; &quot;example&quot; {
  2. name = &quot;test&quot;
  3. resource_group_name = azurerm_resource_group.example.name
  4. private_dns_zone_name = azurerm_private_dns_zone.example.name
  5. virtual_network_id = azurerm_virtual_network.example.id
  6. }

<!-- end snippet -->

Refer: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone_virtual_network_link

答案2

得分: 0

我正在使用以下方法来使用Redis缓存的私有端点:

  1. module "redis_cache" {
  2. source = "../shared/redis"
  3. env_config = local.env_config
  4. config = local.redis_config
  5. }
  6. module "redis_cache_endpoint" {
  7. source = "../shared/network/private_endpoint"
  8. depends_on = [
  9. module.redis_cache,
  10. data.azurerm_subnet.bkend
  11. ]
  12. env_config = local.env_config
  13. config = {
  14. connected_resource = module.redis_cache.redis_config.id
  15. endpoint_name = "${module.redis_cache.redis_config.redis_cache_name}-pep"
  16. service_connection_name = "${module.redis_cache.redis_config.redis_cache_name}-sc"
  17. subnet_id = data.azurerm_subnet.bkend.id
  18. subresource_names = ["redisCache"]
  19. }
  20. }
  21. module "redis_cache_private_network_a_record" {
  22. source = "../shared/private_dns/private_dns_a_record"
  23. depends_on = [
  24. module.redis_cache,
  25. module.redis_cache_endpoint
  26. ]
  27. providers = {
  28. azurerm = azurerm.hubdns
  29. }
  30. env_config = local.env_config
  31. config = {
  32. a_record_name = module.redis_cache.redis_config.redis_cache_name
  33. private_dns_zone_name = "privatelink.redis.cache.windows.net"
  34. private_ip_address = [module.redis_cache_endpoint.config.private_ip_address]
  35. ttl = 3600
  36. }
  37. }

我已经将所有配置都进行了驱动,并且对我来说正常工作。

英文:

I am using the following approach to use Private Endpoint with Redis Cache:

  1. module &quot;redis_cache&quot; {
  2. source = &quot;../shared/redis&quot;
  3. env_config = local.env_config
  4. config = local.redis_config
  5. }
  6. module &quot;redis_cache_endpoint&quot; {
  7. source = &quot;../shared/network/private_endpoint&quot;
  8. depends_on = [
  9. module.redis_cache,
  10. data.azurerm_subnet.bkend
  11. ]
  12. env_config = local.env_config
  13. config = {
  14. connected_resource = module.redis_cache.redis_config.id
  15. endpoint_name = &quot;${module.redis_cache.redis_config.redis_cache_name}-pep&quot;
  16. service_connection_name = &quot;${module.redis_cache.redis_config.redis_cache_name}-sc&quot;
  17. subnet_id = data.azurerm_subnet.bkend.id
  18. subresource_names = [&quot;redisCache&quot;]
  19. }
  20. }
  21. module &quot;redis_cache_private_network_a_record&quot; {
  22. source = &quot;../shared/private_dns/private_dns_a_record&quot;
  23. depends_on = [
  24. module.redis_cache,
  25. module.redis_cache_endpoint
  26. ]
  27. providers = {
  28. azurerm = azurerm.hubdns
  29. }
  30. env_config = local.env_config
  31. config = {
  32. a_record_name = module.redis_cache.redis_config.redis_cache_name
  33. private_dns_zone_name = &quot;privatelink.redis.cache.windows.net&quot;
  34. private_ip_address = [module.redis_cache_endpoint.config.private_ip_address]
  35. ttl = 3600
  36. }
  37. }

I have everything config driven and it is working fine for me.

huangapple
  • 本文由 发表于 2023年6月5日 20:45:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76406553.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定