Ft/rework acceptance tests (#675)
* Rework IaaS acceptance tests Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de> * Rework mongodb acceptance tests Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de> * Rework observability acceptance tests Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de> * Rework secretsmanager acceptance tests Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de> * Rework loadbalancer acceptance tests Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de> * Rework ske acceptance tests Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de> * Update documentation Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de> --------- Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
This commit is contained in:
parent
ada9e096fe
commit
f0168cfed9
9 changed files with 325 additions and 446 deletions
|
|
@ -20,31 +20,137 @@ import (
|
|||
|
||||
// Instance resource data
|
||||
var loadBalancerResource = map[string]string{
|
||||
"project_id": testutil.ProjectId,
|
||||
"name": fmt.Sprintf("tf-acc-%s", acctest.RandStringFromCharSet(7, acctest.CharSetAlphaNum)),
|
||||
"target_pool_name": "example-target-pool",
|
||||
"target_port": "5432",
|
||||
"target_port_updated": "5431",
|
||||
"target_display_name": "example-target",
|
||||
"healthy_threshold": "3",
|
||||
"interval": "10s",
|
||||
"interval_jitter": "5s",
|
||||
"timeout": "10s",
|
||||
"unhealthy_threshold": "3",
|
||||
"use_source_ip_address": "true",
|
||||
"listener_display_name": "example-listener",
|
||||
"listener_port": "5432",
|
||||
"listener_protocol": "PROTOCOL_TLS_PASSTHROUGH",
|
||||
"serverNameIndicator": "domain.com",
|
||||
"network_role": "ROLE_LISTENERS_AND_TARGETS",
|
||||
"private_network_only": "true",
|
||||
"credential_display_name": fmt.Sprintf("tf-acc-cred%s", acctest.RandStringFromCharSet(7, acctest.CharSetAlphaNum)),
|
||||
"credential_username": "username",
|
||||
"credential_password": "password",
|
||||
"project_id": testutil.ProjectId,
|
||||
"name": fmt.Sprintf("tf-acc-%s", acctest.RandStringFromCharSet(7, acctest.CharSetAlphaNum)),
|
||||
"target_pool_name": "example-target-pool",
|
||||
"target_port": "5432",
|
||||
"target_port_updated": "5431",
|
||||
"target_display_name": "example-target",
|
||||
"healthy_threshold": "3",
|
||||
"interval": "10s",
|
||||
"interval_jitter": "5s",
|
||||
"timeout": "10s",
|
||||
"unhealthy_threshold": "3",
|
||||
"use_source_ip_address": "true",
|
||||
"listener_display_name": "example-listener",
|
||||
"listener_port": "5432",
|
||||
"listener_protocol": "PROTOCOL_TLS_PASSTHROUGH",
|
||||
"network_role": "ROLE_LISTENERS_AND_TARGETS",
|
||||
"private_network_only": "false",
|
||||
}
|
||||
|
||||
func configResources(targetPort string) string {
|
||||
// Network resource data
|
||||
var networkResource = map[string]string{
|
||||
"project_id": testutil.ProjectId,
|
||||
"name": fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)),
|
||||
"nameserver0": "8.8.8.8",
|
||||
"ipv4_prefix": "192.168.0.0/25",
|
||||
"routed": "true",
|
||||
}
|
||||
|
||||
// Server resource data
|
||||
var serverResource = map[string]string{
|
||||
"project_id": testutil.ProjectId,
|
||||
"availability_zone": "eu01-1",
|
||||
"size": "32",
|
||||
"source_type": "image",
|
||||
"source_id": testutil.IaaSImageId,
|
||||
"name": fmt.Sprintf("tf-acc-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlpha)),
|
||||
"machine_type": "t1.1",
|
||||
"user_data": "#!/bin/bash",
|
||||
"delete_on_termination": "true",
|
||||
}
|
||||
|
||||
// Public ip resource data
|
||||
var publicIpResource = map[string]string{
|
||||
"project_id": testutil.ProjectId,
|
||||
"network_interface_id": "stackit_network_interface.network_interface.network_interface_id",
|
||||
}
|
||||
|
||||
func publicIpResourceConfig() string {
|
||||
return fmt.Sprintf(`
|
||||
resource "stackit_public_ip" "public_ip" {
|
||||
project_id = "%s"
|
||||
network_interface_id = %s
|
||||
lifecycle {
|
||||
ignore_changes = [
|
||||
network_interface_id
|
||||
]
|
||||
}
|
||||
}
|
||||
`,
|
||||
publicIpResource["project_id"],
|
||||
publicIpResource["network_interface_id"],
|
||||
)
|
||||
}
|
||||
|
||||
func networkResourceConfig() string {
|
||||
return fmt.Sprintf(`
|
||||
resource "stackit_network" "network" {
|
||||
project_id = "%s"
|
||||
name = "%s"
|
||||
ipv4_nameservers = ["%s"]
|
||||
ipv4_prefix = "%s"
|
||||
routed = "%s"
|
||||
}
|
||||
`,
|
||||
networkResource["project_id"],
|
||||
networkResource["name"],
|
||||
networkResource["nameserver0"],
|
||||
networkResource["ipv4_prefix"],
|
||||
networkResource["routed"],
|
||||
)
|
||||
}
|
||||
|
||||
func networkInterfaceResourceConfig() string {
|
||||
return `
|
||||
resource "stackit_network_interface" "network_interface" {
|
||||
project_id = stackit_network.network.project_id
|
||||
network_id = stackit_network.network.network_id
|
||||
name = "name"
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
// server config
|
||||
func serverResourceConfig() string {
|
||||
return fmt.Sprintf(`
|
||||
resource "stackit_server" "server" {
|
||||
project_id = "%s"
|
||||
availability_zone = "%s"
|
||||
name = "%s"
|
||||
machine_type = "%s"
|
||||
boot_volume = {
|
||||
size = %s
|
||||
source_type = "%s"
|
||||
source_id = "%s"
|
||||
delete_on_termination = "%s"
|
||||
}
|
||||
network_interfaces = [stackit_network_interface.network_interface.network_interface_id]
|
||||
user_data = "%s"
|
||||
}
|
||||
`,
|
||||
serverResource["project_id"],
|
||||
serverResource["availability_zone"],
|
||||
serverResource["name"],
|
||||
serverResource["machine_type"],
|
||||
serverResource["size"],
|
||||
serverResource["source_type"],
|
||||
serverResource["source_id"],
|
||||
serverResource["delete_on_termination"],
|
||||
serverResource["user_data"],
|
||||
)
|
||||
}
|
||||
|
||||
// loadbalancer config
|
||||
func loadbalancerResourceConfig(targetPort string) string {
|
||||
return fmt.Sprintf(`
|
||||
%s
|
||||
|
||||
%s
|
||||
|
||||
%s
|
||||
|
||||
%s
|
||||
|
||||
%s
|
||||
|
|
@ -59,12 +165,9 @@ func configResources(targetPort string) string {
|
|||
targets = [
|
||||
{
|
||||
display_name = "%s"
|
||||
ip = openstack_compute_instance_v2.example.network.0.fixed_ip_v4
|
||||
ip = stackit_network_interface.network_interface.ipv4
|
||||
}
|
||||
]
|
||||
session_persistence = {
|
||||
use_source_ip_address = %s
|
||||
}
|
||||
active_health_check = {
|
||||
healthy_threshold = %s
|
||||
interval = "%s"
|
||||
|
|
@ -76,47 +179,34 @@ func configResources(targetPort string) string {
|
|||
]
|
||||
listeners = [
|
||||
{
|
||||
display_name = "%s"
|
||||
port = %s
|
||||
protocol = "%s"
|
||||
server_name_indicators = [
|
||||
{
|
||||
name = "%s"
|
||||
}
|
||||
]
|
||||
target_pool = "%s"
|
||||
display_name = "%s"
|
||||
port = %s
|
||||
protocol = "%s"
|
||||
target_pool = "%s"
|
||||
}
|
||||
]
|
||||
networks = [
|
||||
{
|
||||
network_id = openstack_networking_network_v2.example.id
|
||||
network_id = stackit_network.network.network_id
|
||||
role = "%s"
|
||||
}
|
||||
]
|
||||
external_address = stackit_public_ip.public_ip.ip
|
||||
options = {
|
||||
private_network_only = %s
|
||||
}
|
||||
}
|
||||
|
||||
resource "stackit_loadbalancer_observability_credential" "credential" {
|
||||
project_id = "%s"
|
||||
display_name = "%s"
|
||||
username = "%s"
|
||||
password = "%s"
|
||||
}
|
||||
`,
|
||||
supportingInfraResources(loadBalancerResource["name"], OpenStack{
|
||||
userDomainName: testutil.OSUserDomainName,
|
||||
userName: testutil.OSUserName,
|
||||
password: testutil.OSPassword,
|
||||
}),
|
||||
testutil.LoadBalancerProviderConfig(),
|
||||
networkResourceConfig(),
|
||||
networkInterfaceResourceConfig(),
|
||||
publicIpResourceConfig(),
|
||||
serverResourceConfig(),
|
||||
loadBalancerResource["project_id"],
|
||||
loadBalancerResource["name"],
|
||||
loadBalancerResource["target_pool_name"],
|
||||
targetPort,
|
||||
loadBalancerResource["target_display_name"],
|
||||
loadBalancerResource["use_source_ip_address"],
|
||||
loadBalancerResource["healthy_threshold"],
|
||||
loadBalancerResource["interval"],
|
||||
loadBalancerResource["interval_jitter"],
|
||||
|
|
@ -125,105 +215,20 @@ func configResources(targetPort string) string {
|
|||
loadBalancerResource["listener_display_name"],
|
||||
loadBalancerResource["listener_port"],
|
||||
loadBalancerResource["listener_protocol"],
|
||||
loadBalancerResource["serverNameIndicator"],
|
||||
loadBalancerResource["target_pool_name"],
|
||||
loadBalancerResource["network_role"],
|
||||
loadBalancerResource["private_network_only"],
|
||||
loadBalancerResource["project_id"],
|
||||
loadBalancerResource["credential_display_name"],
|
||||
loadBalancerResource["credential_username"],
|
||||
loadBalancerResource["credential_password"],
|
||||
)
|
||||
}
|
||||
|
||||
func supportingInfraResources(name string, os OpenStack) string {
|
||||
return fmt.Sprintf(`
|
||||
provider "openstack" {
|
||||
user_domain_name = "%s"
|
||||
user_name = "%s"
|
||||
password = "%s"
|
||||
region = "RegionOne"
|
||||
auth_url = "https://keystone.api.iaas.eu01.stackit.cloud/v3"
|
||||
}
|
||||
|
||||
# Create a network
|
||||
resource "openstack_networking_network_v2" "example" {
|
||||
name = "%s_network"
|
||||
}
|
||||
|
||||
resource "openstack_networking_subnet_v2" "example" {
|
||||
name = "%s_subnet"
|
||||
cidr = "192.168.0.0/25"
|
||||
dns_nameservers = ["8.8.8.8"]
|
||||
network_id = openstack_networking_network_v2.example.id
|
||||
}
|
||||
|
||||
data "openstack_networking_network_v2" "public" {
|
||||
name = "floating-net"
|
||||
}
|
||||
|
||||
resource "openstack_networking_floatingip_v2" "example_ip" {
|
||||
pool = data.openstack_networking_network_v2.public.name
|
||||
}
|
||||
|
||||
# Create an instance
|
||||
data "openstack_compute_flavor_v2" "example" {
|
||||
name = "g1.1"
|
||||
}
|
||||
|
||||
resource "openstack_compute_instance_v2" "example" {
|
||||
depends_on = [openstack_networking_subnet_v2.example]
|
||||
name = "%s_instance"
|
||||
flavor_id = data.openstack_compute_flavor_v2.example.id
|
||||
admin_pass = "example"
|
||||
security_groups = ["default"]
|
||||
|
||||
block_device {
|
||||
uuid = "4364cdb2-dacd-429b-803e-f0f7cfde1c24" // Ubuntu 22.04
|
||||
volume_size = 32
|
||||
source_type = "image"
|
||||
destination_type = "volume"
|
||||
delete_on_termination = true
|
||||
}
|
||||
|
||||
network {
|
||||
name = openstack_networking_network_v2.example.name
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [security_groups]
|
||||
}
|
||||
}
|
||||
|
||||
resource "openstack_networking_router_v2" "example_router" {
|
||||
name = "%s_router"
|
||||
admin_state_up = "true"
|
||||
external_network_id = data.openstack_networking_network_v2.public.id
|
||||
}
|
||||
|
||||
resource "openstack_networking_router_interface_v2" "example_interface" {
|
||||
router_id = openstack_networking_router_v2.example_router.id
|
||||
subnet_id = openstack_networking_subnet_v2.example.id
|
||||
}
|
||||
|
||||
`,
|
||||
os.userDomainName, os.userName, os.password, name, name, name, name)
|
||||
}
|
||||
|
||||
func TestAccLoadBalancerResource(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
|
||||
ExternalProviders: map[string]resource.ExternalProvider{
|
||||
"openstack": {
|
||||
VersionConstraint: "= 1.52.1",
|
||||
Source: "terraform-provider-openstack/openstack",
|
||||
},
|
||||
},
|
||||
CheckDestroy: testAccCheckLoadBalancerDestroy,
|
||||
CheckDestroy: testAccCheckLoadBalancerDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
// Creation
|
||||
{
|
||||
Config: configResources(loadBalancerResource["target_port"]),
|
||||
Config: loadbalancerResourceConfig(loadBalancerResource["target_port"]),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
// Load balancer instance
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "project_id", loadBalancerResource["project_id"]),
|
||||
|
|
@ -237,25 +242,13 @@ func TestAccLoadBalancerResource(t *testing.T) {
|
|||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "target_pools.0.active_health_check.interval_jitter", loadBalancerResource["interval_jitter"]),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "target_pools.0.active_health_check.timeout", loadBalancerResource["timeout"]),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "target_pools.0.active_health_check.unhealthy_threshold", loadBalancerResource["unhealthy_threshold"]),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "target_pools.0.session_persistence.use_source_ip_address", loadBalancerResource["use_source_ip_address"]),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "listeners.0.display_name", loadBalancerResource["listener_display_name"]),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "listeners.0.port", loadBalancerResource["listener_port"]),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "listeners.0.protocol", loadBalancerResource["listener_protocol"]),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "listeners.0.server_name_indicators.0.name", loadBalancerResource["serverNameIndicator"]),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "listeners.0.target_pool", loadBalancerResource["target_pool_name"]),
|
||||
resource.TestCheckResourceAttrSet("stackit_loadbalancer.loadbalancer", "networks.0.network_id"),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "networks.0.role", loadBalancerResource["network_role"]),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "options.private_network_only", loadBalancerResource["private_network_only"]),
|
||||
|
||||
// Credential
|
||||
resource.TestCheckResourceAttrPair(
|
||||
"stackit_loadbalancer_observability_credential.credential", "project_id",
|
||||
"stackit_loadbalancer.loadbalancer", "project_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrSet("stackit_loadbalancer_observability_credential.credential", "credentials_ref"),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer_observability_credential.credential", "display_name", loadBalancerResource["credential_display_name"]),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer_observability_credential.credential", "username", loadBalancerResource["credential_username"]),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer_observability_credential.credential", "password", loadBalancerResource["credential_password"]),
|
||||
),
|
||||
},
|
||||
// Data source
|
||||
|
|
@ -268,7 +261,7 @@ func TestAccLoadBalancerResource(t *testing.T) {
|
|||
name = stackit_loadbalancer.loadbalancer.name
|
||||
}
|
||||
`,
|
||||
configResources(loadBalancerResource["target_port"]),
|
||||
loadbalancerResourceConfig(loadBalancerResource["target_port"]),
|
||||
),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
// Load balancer instance
|
||||
|
|
@ -292,15 +285,12 @@ func TestAccLoadBalancerResource(t *testing.T) {
|
|||
resource.TestCheckResourceAttr("data.stackit_loadbalancer.loadbalancer", "target_pools.0.active_health_check.interval_jitter", loadBalancerResource["interval_jitter"]),
|
||||
resource.TestCheckResourceAttr("data.stackit_loadbalancer.loadbalancer", "target_pools.0.active_health_check.timeout", loadBalancerResource["timeout"]),
|
||||
resource.TestCheckResourceAttr("data.stackit_loadbalancer.loadbalancer", "target_pools.0.active_health_check.unhealthy_threshold", loadBalancerResource["unhealthy_threshold"]),
|
||||
resource.TestCheckResourceAttr("data.stackit_loadbalancer.loadbalancer", "target_pools.0.session_persistence.use_source_ip_address", loadBalancerResource["use_source_ip_address"]),
|
||||
resource.TestCheckResourceAttr("data.stackit_loadbalancer.loadbalancer", "listeners.0.display_name", loadBalancerResource["listener_display_name"]),
|
||||
resource.TestCheckResourceAttr("data.stackit_loadbalancer.loadbalancer", "listeners.0.port", loadBalancerResource["listener_port"]),
|
||||
resource.TestCheckResourceAttr("data.stackit_loadbalancer.loadbalancer", "listeners.0.protocol", loadBalancerResource["listener_protocol"]),
|
||||
resource.TestCheckResourceAttr("data.stackit_loadbalancer.loadbalancer", "listeners.0.server_name_indicators.0.name", loadBalancerResource["serverNameIndicator"]),
|
||||
resource.TestCheckResourceAttr("data.stackit_loadbalancer.loadbalancer", "listeners.0.target_pool", loadBalancerResource["target_pool_name"]),
|
||||
resource.TestCheckResourceAttrSet("data.stackit_loadbalancer.loadbalancer", "networks.0.network_id"),
|
||||
resource.TestCheckResourceAttr("data.stackit_loadbalancer.loadbalancer", "networks.0.role", loadBalancerResource["network_role"]),
|
||||
resource.TestCheckResourceAttr("data.stackit_loadbalancer.loadbalancer", "options.private_network_only", loadBalancerResource["private_network_only"]),
|
||||
),
|
||||
},
|
||||
// Import
|
||||
|
|
@ -318,29 +308,13 @@ func TestAccLoadBalancerResource(t *testing.T) {
|
|||
|
||||
return fmt.Sprintf("%s,%s", testutil.ProjectId, name), nil
|
||||
},
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
{
|
||||
ResourceName: "stackit_loadbalancer_observability_credential.credential",
|
||||
ImportStateIdFunc: func(s *terraform.State) (string, error) {
|
||||
r, ok := s.RootModule().Resources["stackit_loadbalancer_observability_credential.credential"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find resource stackit_loadbalancer_observability_credential.credential")
|
||||
}
|
||||
credentialsRef, ok := r.Primary.Attributes["credentials_ref"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find attribute credentials_ref")
|
||||
}
|
||||
return fmt.Sprintf("%s,%s", testutil.ProjectId, credentialsRef), nil
|
||||
},
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
ImportStateVerifyIgnore: []string{"password"},
|
||||
ImportStateVerifyIgnore: []string{"options.private_network_only"},
|
||||
},
|
||||
// Update
|
||||
{
|
||||
Config: configResources(loadBalancerResource["target_port_updated"]),
|
||||
Config: loadbalancerResourceConfig(loadBalancerResource["target_port_updated"]),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "project_id", loadBalancerResource["project_id"]),
|
||||
resource.TestCheckResourceAttr("stackit_loadbalancer.loadbalancer", "name", loadBalancerResource["name"]),
|
||||
|
|
@ -352,12 +326,6 @@ func TestAccLoadBalancerResource(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
type OpenStack struct {
|
||||
userDomainName string
|
||||
userName string
|
||||
password string
|
||||
}
|
||||
|
||||
func testAccCheckLoadBalancerDestroy(s *terraform.State) error {
|
||||
ctx := context.Background()
|
||||
var client *loadbalancer.APIClient
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue