Closed th3cod3r closed 2 months ago
Hi, could you please provide more extensive log or test case? I have almost no idea, what happened there or what you are trying to achieve.
Hi below is my terraform file
terraform { required_providers { mysql = { source = "petoju/mysql" version = "3.0.54" } sql = { source = "paultyng/sql" version = "0.5.0" } } }
provider "mysql" { endpoint = "192.168.19.25:3306" username = "root" password = "password" }
resource "mysql_database" "db" { name = "db" }
resource "mysql_user" "abc" { user = "abc" # Adjusted username to match grant definition host = "192.168.19.25" plaintext_password = "your_password" # Replace with your desired password }
resource "mysql_grant" "test" { user = mysql_user.abc.user # Reference the created user host = "192.168.19.25" database = "db" privileges = ["SELECT", "INSERT", "UPDATE", "DELETE", "CREATE"] depends_on = [mysql_user.abc] # Grant privileges depend on user creation }
provider "sql" { alias = "mysql" url = "mysql://root:password@tcp(192.168.19.25:3306)/db" # Update with database name after username and password (e.g., mysql://user:password@host:port/database_name)
}
data "sql_query" "test" {
provider = sql.mysql
query = <<EOF
CREATE TABLE test
(
id
int(10) NOT NULL AUTO_INCREMENT,
name
varchar(128) NOT NULL,
shortname
varchar(32) DEFAULT NULL,
type
varchar(30) DEFAULT 'other',
description
varchar(200) DEFAULT 'RADIUS Client',
PRIMARY KEY (id
),
KEY name
(name
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
EOF
depends_on = [mysql_database.db, mysql_grant.test] # Ensure user has privileges before creating table }
I want to create some tables that's why i am using another provider (petoju) as the table creation feature is not available in your provider. The terraform runs the complete file and due to this dependency was create of user when i used another provider. Error was shown above.
If possible please add the feature else help out with the following dependencies.
Ah yes, so the issue is that the other provider need DB to be created as a part of its initialization stage. Terraform currently doesn't support anything like that.
I don't plan implementing anything like that in this provider as I believe terraform is not the best tool to run migrations. There are other providers (like atlas https://registry.terraform.io/providers/ariga/atlas/latest/docs ) that do this for terraform and should work well even with this provider.
Just a query here, the ariga/atlas is for the migration. It can perform the table creation with migration of database? If so that can happen can you please confirm what about the previous server db.
I have not used it, but I believe it can do that well. Plus it can do things like changing indexes without removing table and adding it back (that is what a straightforward implementation of terraform provider would do).
Dňa pi 19. 4. 2024, 7:55 th3cod3r @.***> napísal(a):
Just a query here, the ariga/atlas is for the migration. It can perform the table creation with migration of database? If so that can happen can you please confirm what about the previous server db.
— Reply to this email directly, view it on GitHub https://github.com/petoju/terraform-provider-mysql/issues/135#issuecomment-2065813832, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXINWBDEWHN5YMZK6IK3E3Y6CWWZAVCNFSM6AAAAABGM7W5LOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRVHAYTGOBTGI . You are receiving this because you commented.Message ID: @.***>
Thanks for the reply. I will lookout into that. closing the issue for now.
can someone include the code of table creation in the provider. Because when i use different provider to create the table it was not compatible with the petoju provider (it mixed up all the code and throws error). Error: failed getting version: Error 1133 (28000): Can't find any matching row in the user table │ │ with mysql_user.test, │ on main.tf line 21, in resource "mysql_user" "test": │ 21: resource "mysql_user" "test" {
also use depends_on meta option but it not worked.