Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database_uri: add URI parameters as attributes #387

Merged

Conversation

kobajagi
Copy link
Contributor

@kobajagi kobajagi commented Sep 16, 2024

Description

Adds URI parameters as individual attributes to make it easier to use.

New attributes are: schema, host, port, username, password & db_name.
Attributes can be nil as not all database services support all the attributes.

Closes #279 and #382

Checklist

(For exoscale contributors)

  • Changelog updated (under Unreleased block)
  • Acceptance tests OK
  • For a new resource, datasource or new attributes: acceptance test added/updated

Testing

$ TF_ACC=1 go test ./... -run TestDatabase/DataSourceURI 
?       github.com/exoscale/terraform-provider-exoscale [no test files]
?       github.com/exoscale/terraform-provider-exoscale/pkg/config      [no test files]
?       github.com/exoscale/terraform-provider-exoscale/pkg/general     [no test files]
ok      github.com/exoscale/terraform-provider-exoscale/exoscale        0.011s [no tests to run]
ok      github.com/exoscale/terraform-provider-exoscale/pkg/filter      0.003s [no tests to run]
?       github.com/exoscale/terraform-provider-exoscale/pkg/provider    [no test files]
?       github.com/exoscale/terraform-provider-exoscale/pkg/provider/config     [no test files]
ok      github.com/exoscale/terraform-provider-exoscale/pkg/list        0.019s [no tests to run]
ok      github.com/exoscale/terraform-provider-exoscale/pkg/resources/anti_affinity_group       0.011s [no tests to run]
ok      github.com/exoscale/terraform-provider-exoscale/pkg/resources/block_storage     0.010s [no tests to run]
?       github.com/exoscale/terraform-provider-exoscale/pkg/resources/zones     [no test files]
?       github.com/exoscale/terraform-provider-exoscale/pkg/testutils   [no test files]
?       github.com/exoscale/terraform-provider-exoscale/pkg/validators  [no test files]
?       github.com/exoscale/terraform-provider-exoscale/pkg/version     [no test files]
?       github.com/exoscale/terraform-provider-exoscale/pkg/utils       [no test files]
?       github.com/exoscale/terraform-provider-exoscale/version [no test files]
ok      github.com/exoscale/terraform-provider-exoscale/pkg/resources/database  53.592s
ok      github.com/exoscale/terraform-provider-exoscale/pkg/resources/iam       0.013s [no tests to run]
ok      github.com/exoscale/terraform-provider-exoscale/pkg/resources/instance  0.013s [no tests to run]
ok      github.com/exoscale/terraform-provider-exoscale/pkg/resources/instance_pool     0.011s [no tests to run]
ok      github.com/exoscale/terraform-provider-exoscale/pkg/resources/nlb_service       0.011s [no tests to run]

Kafka

$ terraform state show data.exoscale_database_uri.my_database
# data.exoscale_database_uri.my_database:
data "exoscale_database_uri" "my_database" {
    host = "mydb-exoscale-9f21ec06-ab34-44e1-a8de-1714e4120c91.d.aivencloud.com"
    id   = "mydb"
    name = "mydb"
    port = 21701
    type = "kafka"
    uri  = (sensitive value)
    zone = "ch-gva-2"
}

MySQL

$ terraform state show data.exoscale_database_uri.my_database
# data.exoscale_database_uri.my_database:
data "exoscale_database_uri" "my_database" {
    db_name  = "defaultdb"
    host     = "mydb-exoscale-9f21ec06-ab34-44e1-a8de-1714e4120c91.d.aivencloud.com"
    id       = "mydb"
    name     = "mydb"
    password = (sensitive value)
    port     = 21699
    schema   = "mysql"
    type     = "mysql"
    uri      = (sensitive value)
    username = "avnadmin"
    zone     = "ch-gva-2"
}

Pg

$ terraform state show data.exoscale_database_uri.my_database
# data.exoscale_database_uri.my_database:
data "exoscale_database_uri" "my_database" {
    db_name  = "defaultdb"
    host     = "mydb-exoscale-9f21ec06-ab34-44e1-a8de-1714e4120c91.d.aivencloud.com"
    id       = "mydb"
    name     = "mydb"
    password = (sensitive value)
    port     = 21699
    schema   = "postgres"
    type     = "pg"
    uri      = (sensitive value)
    username = "avnadmin"
    zone     = "ch-gva-2"
}

Redis

$ terraform state show data.exoscale_database_uri.my_database
# data.exoscale_database_uri.my_database:
data "exoscale_database_uri" "my_database" {
    host     = "mydb-exoscale-9f21ec06-ab34-44e1-a8de-1714e4120c91.d.aivencloud.com"
    id       = "mydb"
    name     = "mydb"
    password = (sensitive value)
    port     = 21700
    schema   = "rediss"
    type     = "redis"
    uri      = (sensitive value)
    username = "default"
    zone     = "ch-gva-2"
}

OpenSearch

$ terraform state show data.exoscale_database_uri.my_database
# data.exoscale_database_uri.my_database:
data "exoscale_database_uri" "my_database" {
    host     = "mydb-exoscale-9f21ec06-ab34-44e1-a8de-1714e4120c91.d.aivencloud.com"
    id       = "mydb"
    name     = "mydb"
    password = (sensitive value)
    port     = 21699
    schema   = "https"
    type     = "opensearch"
    uri      = (sensitive value)
    username = "avnadmin"
    zone     = "ch-gva-2"
}

Grafana

$ terraform state show data.exoscale_database_uri.my_database
# data.exoscale_database_uri.my_database:
data "exoscale_database_uri" "my_database" {
    host     = "mydb-exoscale-9f21ec06-ab34-44e1-a8de-1714e4120c91.d.aivencloud.com"
    id       = "mydb"
    name     = "mydb"
    password = (sensitive value)
    port     = 443
    schema   = "https"
    type     = "grafana"
    uri      = (sensitive value)
    username = "avnadmin"
    zone     = "ch-gva-2"
}

@kobajagi kobajagi marked this pull request as ready for review September 17, 2024 08:03
Copy link
Member

@PhilippeChepy PhilippeChepy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
(modulo acceptance tests)

- migrates resource to egoscale v3;
- adds URI parameters as a separate fields.
- refactor kafka to set common params after db type loop;
- add params for remaining databases.
@kobajagi kobajagi force-pushed the predrag/sc-102819/gh-issue-terraform-provider-exoscale-feature branch from 586fb20 to a056f3e Compare September 24, 2024 11:05
@kobajagi kobajagi merged commit 376a17c into master Sep 25, 2024
3 checks passed
@kobajagi kobajagi deleted the predrag/sc-102819/gh-issue-terraform-provider-exoscale-feature branch September 25, 2024 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add outputs to the datasource exoscale_database
3 participants