Skip to content

Commit

Permalink
fix(apiconvert): never skip basic auth username/password (#1442)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serpentiel authored Nov 14, 2023
1 parent b672c6c commit b54da41
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ nav_order: 1

- Deprecating `project_user`, `account_team` and `account_team_member` resources
- Fix unmarshalling empty userconfig crash
- Never skip basic auth username/password in service integrations user config options when sending them to the API

## [4.9.3] - 2023-10-27

Expand Down
2 changes: 1 addition & 1 deletion internal/schemautil/userconfig/apiconvert/toapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func itemToAPI(
}
}

if omitValue && isRequired {
if omitValue && isRequired || key == "basic_auth_username" || key == "basic_auth_password" {
omitValue = false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestAccAivenServiceIntegrationEndpoint_basic(t *testing.T) {
CheckDestroy: testAccCheckAivenServiceIntegraitonEndpointResourceDestroy,
Steps: []resource.TestStep{
{
Config: testAccServiceIntegrationEndpointResource(rName),
Config: testAccServiceIntegrationEndpointBasicResource(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAivenServiceEndpointIntegrationAttributes("data.aiven_service_integration_endpoint.endpoint"),
resource.TestCheckResourceAttr(resourceName, "project", os.Getenv("AIVEN_PROJECT_NAME")),
Expand All @@ -37,7 +37,50 @@ func TestAccAivenServiceIntegrationEndpoint_basic(t *testing.T) {
})
}

func testAccServiceIntegrationEndpointResource(name string) string {
func TestAccAivenServiceIntegrationEndpoint_username_password(t *testing.T) {
resourceName := "aiven_service_integration_endpoint.bar"
rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
ProtoV6ProviderFactories: acc.TestProtoV6ProviderFactories,
CheckDestroy: testAccCheckAivenServiceIntegraitonEndpointResourceDestroy,
Steps: []resource.TestStep{
{
Config: testAccServiceIntegrationEndpointUsernamePasswordResource(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAivenServiceEndpointIntegrationAttributes(
"data.aiven_service_integration_endpoint.endpoint",
),
resource.TestCheckResourceAttr(resourceName, "project", os.Getenv("AIVEN_PROJECT_NAME")),
resource.TestCheckResourceAttr(
resourceName, "endpoint_name", fmt.Sprintf("test-acc-ie-%s", rName),
),
resource.TestCheckResourceAttr(
resourceName, "endpoint_type", "external_schema_registry",
),
),
},
{
Config: testAccServiceIntegrationEndpointUpdatePasswordResource(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAivenServiceEndpointIntegrationAttributes(
"data.aiven_service_integration_endpoint.endpoint",
),
resource.TestCheckResourceAttr(resourceName, "project", os.Getenv("AIVEN_PROJECT_NAME")),
resource.TestCheckResourceAttr(
resourceName, "endpoint_name", fmt.Sprintf("test-acc-ie-%s", rName),
),
resource.TestCheckResourceAttr(
resourceName, "endpoint_type", "external_schema_registry",
),
),
},
},
})
}

func testAccServiceIntegrationEndpointBasicResource(name string) string {
return fmt.Sprintf(`
data "aiven_project" "foo" {
project = "%s"
Expand Down Expand Up @@ -91,6 +134,102 @@ data "aiven_service_integration_endpoint" "endpoint" {
}`, os.Getenv("AIVEN_PROJECT_NAME"), name, name, name)
}

func testAccServiceIntegrationEndpointUsernamePasswordResource(name string) string {
return fmt.Sprintf(`
data "aiven_project" "foo" {
project = "%[1]s"
}
resource "aiven_pg" "bar-pg" {
project = data.aiven_project.foo.project
cloud_name = "google-europe-west1"
plan = "startup-4"
service_name = "test-acc-sr-pg-%[2]s"
maintenance_window_dow = "monday"
maintenance_window_time = "10:00:00"
pg_user_config {
public_access {
pg = true
prometheus = false
}
pg {
idle_in_transaction_session_timeout = 900
}
}
}
resource "aiven_service_integration_endpoint" "bar" {
project = data.aiven_project.foo.project
endpoint_name = "test-acc-ie-%[2]s"
endpoint_type = "external_schema_registry"
external_schema_registry_user_config {
url = "https://schema-registry.example.com:8081"
authentication = "basic"
basic_auth_username = "username"
basic_auth_password = "password"
}
}
data "aiven_service_integration_endpoint" "endpoint" {
project = aiven_service_integration_endpoint.bar.project
endpoint_name = aiven_service_integration_endpoint.bar.endpoint_name
depends_on = [aiven_service_integration_endpoint.bar]
}`, os.Getenv("AIVEN_PROJECT_NAME"), name)
}

func testAccServiceIntegrationEndpointUpdatePasswordResource(name string) string {
return fmt.Sprintf(`
data "aiven_project" "foo" {
project = "%[1]s"
}
resource "aiven_pg" "bar-pg" {
project = data.aiven_project.foo.project
cloud_name = "google-europe-west1"
plan = "startup-4"
service_name = "test-acc-sr-pg-%[2]s"
maintenance_window_dow = "monday"
maintenance_window_time = "10:00:00"
pg_user_config {
public_access {
pg = true
prometheus = false
}
pg {
idle_in_transaction_session_timeout = 900
}
}
}
resource "aiven_service_integration_endpoint" "bar" {
project = data.aiven_project.foo.project
endpoint_name = "test-acc-ie-%[2]s"
endpoint_type = "external_schema_registry"
external_schema_registry_user_config {
url = "https://schema-registry.example.com:8081"
authentication = "basic"
basic_auth_username = "username"
basic_auth_password = "new-password"
}
}
data "aiven_service_integration_endpoint" "endpoint" {
project = aiven_service_integration_endpoint.bar.project
endpoint_name = aiven_service_integration_endpoint.bar.endpoint_name
depends_on = [aiven_service_integration_endpoint.bar]
}`, os.Getenv("AIVEN_PROJECT_NAME"), name)
}

func testAccCheckAivenServiceIntegraitonEndpointResourceDestroy(s *terraform.State) error {
c := acc.GetTestAivenClient()

Expand Down

0 comments on commit b54da41

Please sign in to comment.