-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add aiven_azure_privatelink_connection_approval test
- Loading branch information
Showing
5 changed files
with
170 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
internal/service/vpc/resource_azure_privatelink_connection_approve_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |