Skip to content

Commit

Permalink
add aiven_azure_privatelink_connection_approval test
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Nov 7, 2022
1 parent 00430bc commit 433a429
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/resources/azure_privatelink_connection_approval.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ resource "azurerm_private_endpoint" "endpoint" {
resource "aiven_azure_privatelink_connection_approval" "approval" {
project = var.aiven_project_id
service_name = aiven_pg.default
service_name = aiven_pg.default.service_name
endpoint_ip_address = azurerm_private_endpoint.endpoint.private_service_connection[0].private_ip_address
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ resource "azurerm_private_endpoint" "endpoint" {

resource "aiven_azure_privatelink_connection_approval" "approval" {
project = var.aiven_project_id
service_name = aiven_pg.default
service_name = aiven_pg.default.service_name
endpoint_ip_address = azurerm_private_endpoint.endpoint.private_service_connection[0].private_ip_address
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ go 1.18

require (
github.com/aiven/aiven-go-client v1.7.1-0.20221026113217-a95eea5bc930
github.com/aiven/aiven-go-client/tools/exp v0.0.0-20221026123647-c6884e17f117
github.com/aiven/aiven-go-client/tools/exp v0.0.0-20221102122203-4f39deb34b6a
github.com/docker/go-units v0.5.0
github.com/gruntwork-io/terratest v0.40.22
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.22.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/stretchr/testify v1.8.0
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7l
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/aiven/aiven-go-client v1.7.1-0.20221026113217-a95eea5bc930 h1:nBCuvgrc/KSYj4RPukBOYWMluGj+76O8xvhrvhSCK5Q=
github.com/aiven/aiven-go-client v1.7.1-0.20221026113217-a95eea5bc930/go.mod h1:TkcTcz6bA/SmGoLiDrsLZTdhEwVECN9DI0zT8FacbEs=
github.com/aiven/aiven-go-client/tools/exp v0.0.0-20221026123647-c6884e17f117 h1:0gvxOcVWDD1aiPHcJLL0pstZ01UM3Kk0VXOHzY+Hzfw=
github.com/aiven/aiven-go-client/tools/exp v0.0.0-20221026123647-c6884e17f117/go.mod h1:PEjz1ETUA7nlqD9gpbLWDyAEwkYbAU1JvhhKXtUQjwM=
github.com/aiven/aiven-go-client/tools/exp v0.0.0-20221102122203-4f39deb34b6a h1:cG+TKgxX2azRUkOGgE+H0+gBEeKDgS1B3Ntr6baWZto=
github.com/aiven/aiven-go-client/tools/exp v0.0.0-20221102122203-4f39deb34b6a/go.mod h1:PEjz1ETUA7nlqD9gpbLWDyAEwkYbAU1JvhhKXtUQjwM=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4tdgBZjnU=
Expand Down Expand Up @@ -245,8 +245,8 @@ github.com/hashicorp/terraform-plugin-go v0.14.0 h1:ttnSlS8bz3ZPYbMb84DpcPhY4F5D
github.com/hashicorp/terraform-plugin-go v0.14.0/go.mod h1:2nNCBeRLaenyQEi78xrGrs9hMbulveqG/zDMQSvVJTE=
github.com/hashicorp/terraform-plugin-log v0.7.0 h1:SDxJUyT8TwN4l5b5/VkiTIaQgY6R+Y2BQ0sRZftGKQs=
github.com/hashicorp/terraform-plugin-log v0.7.0/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0 h1:FtCLTiTcykdsURXPt/ku7fYXm3y19nbzbZcUxHx9RbI=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.0/go.mod h1:80wf5oad1tW+oLnbXS4UTYmDCrl7BuN1Q+IA91X1a4Y=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.22.0 h1:MzfNfrheTt24xbEbA4npUSbX3GYu4xjXS7czcpJFyQY=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.22.0/go.mod h1:q1XKSxXg9nDmhV0IvNZNZxe3gcTAHzMqrjs8wX1acng=
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c h1:D8aRO6+mTqHfLsK/BC3j5OAoogv1WLRWzY1AaTo3rBg=
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI=
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package vpc_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/kelseyhightower/envconfig"

acc "github.com/aiven/terraform-provider-aiven/internal/acctest"
)

// azurePLCASecrets AzurePrivateLinkConnectionApproval secrets
type azurePLCASecrets struct {
Project string `envconfig:"AIVEN_PROJECT_NAME" required:"true"`
ClientID string `envconfig:"AZURE_CLIENT_ID" required:"true"`
ClientSecret string `envconfig:"AZURE_CLIENT_SECRET" required:"true"`
TenantID string `envconfig:"AZURE_TENANT_ID" required:"true"`
SubscriptionID string `envconfig:"AZURE_SUBSCRIPTION_ID" required:"true"`
}

func TestAccAivenAzurePrivateLinkConnectionApproval_basic(t *testing.T) {
var s azurePLCASecrets
err := envconfig.Process("", &s)
if err != nil {
t.Skipf("Not all values has been provided: %s", err)
}

prefix := "test-tf-acc-" + acctest.RandString(7)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
ProviderFactories: acc.TestAccProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
"azurerm": {
Source: "hashicorp/azurerm",
VersionConstraint: "=3.30.0",
},
},
Steps: []resource.TestStep{
{
Config: testAccAzurePrivateLinkConnectionApprovalResource(prefix, &s),
Check: resource.ComposeTestCheckFunc(
// Aiven resources
resource.TestCheckResourceAttr("aiven_project_vpc.project_vpc", "state", "ACTIVE"),
resource.TestCheckResourceAttr("aiven_pg.pg", "state", "RUNNING"),
resource.TestCheckResourceAttr("aiven_azure_privatelink.private_link", "state", "active"),
resource.TestCheckResourceAttr("aiven_azure_privatelink_connection_approval.approval", "state", "active"),
resource.TestCheckResourceAttrSet("aiven_azure_privatelink_connection_approval.approval", "endpoint_ip_address"),
resource.TestCheckResourceAttrSet("aiven_azure_privatelink_connection_approval.approval", "privatelink_connection_id"),

// Azure resources
resource.TestCheckResourceAttrSet("azurerm_resource_group.resource_group", "id"),
resource.TestCheckResourceAttrSet("azurerm_virtual_network.virtual_network", "id"),
resource.TestCheckResourceAttrSet("azurerm_subnet.subnet", "id"),
resource.TestCheckResourceAttrSet("azurerm_private_endpoint.private_endpoint", "id"),
),
},
},
})
}

func testAccAzurePrivateLinkConnectionApprovalResource(prefix string, s *azurePLCASecrets) string {
return fmt.Sprintf(`
data "aiven_project" "project" {
project = %[2]q
}
provider "azurerm" {
features {}
client_id = %[3]q
client_secret = %[4]q
tenant_id = %[5]q
subscription_id = %[6]q
}
resource "aiven_project_vpc" "project_vpc" {
project = data.aiven_project.project.project
cloud_name = "azure-germany-north"
network_cidr = "192.168.1.0/24"
timeouts {
create = "15m"
}
}
resource "aiven_static_ip" "static_ips" {
count = 2
project = aiven_project_vpc.project_vpc.project
cloud_name = aiven_project_vpc.project_vpc.cloud_name
}
resource "aiven_pg" "pg" {
service_name = "%[1]s-pg"
project = data.aiven_project.project.project
project_vpc_id = aiven_project_vpc.project_vpc.id
cloud_name = aiven_project_vpc.project_vpc.cloud_name
plan = "startup-4"
static_ips = [for sip in aiven_static_ip.static_ips : sip.static_ip_address_id]
pg_user_config {
static_ips = true
privatelink_access {
pg = true
pgbouncer = true
}
}
}
resource "aiven_azure_privatelink" "private_link" {
project = data.aiven_project.project.project
service_name = aiven_pg.pg.service_name
user_subscription_ids = [
%[6]q,
]
}
resource "azurerm_resource_group" "resource_group" {
location = "germanynorth"
name = "%[1]s-private-link"
}
resource "azurerm_virtual_network" "virtual_network" {
name = "%[1]s-virtual-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.resource_group.location
resource_group_name = azurerm_resource_group.resource_group.name
}
resource "azurerm_subnet" "subnet" {
name = "%[1]s-subnet"
resource_group_name = azurerm_resource_group.resource_group.name
virtual_network_name = azurerm_virtual_network.virtual_network.name
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_private_endpoint" "private_endpoint" {
name = "%[1]s-private-endpoint"
location = azurerm_resource_group.resource_group.location
resource_group_name = azurerm_resource_group.resource_group.name
subnet_id = azurerm_subnet.subnet.id
private_service_connection {
name = aiven_pg.pg.service_name
request_message = aiven_pg.pg.service_name
private_connection_resource_id = aiven_azure_privatelink.private_link.azure_service_id
is_manual_connection = true
}
depends_on = [
aiven_azure_privatelink.private_link,
]
}
resource "aiven_azure_privatelink_connection_approval" "approval" {
project = data.aiven_project.project.project
service_name = aiven_pg.pg.service_name
endpoint_ip_address = azurerm_private_endpoint.private_endpoint.private_service_connection[0].private_ip_address
}`, prefix, s.Project, s.ClientID, s.ClientSecret, s.TenantID, s.SubscriptionID)
}

0 comments on commit 433a429

Please sign in to comment.