-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add ability to import google_sql_database
#12
Add ability to import google_sql_database
#12
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the awesome work! I left a few comments if you don't mind going over them.
google/resource_sql_database.go
Outdated
@@ -86,6 +90,13 @@ func resourceSqlDatabaseRead(d *schema.ResourceData, meta interface{}) error { | |||
return err | |||
} | |||
|
|||
// In the import case this won't be set | |||
if _, ok := d.GetOk("instance"); !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding a conditional block here where we set the database name and instance name on refresh, we can just get them from the ID every time. That way, both terraform import
and the refreshes that happen (such as part of terraform plan
) will follow the same code paths.
To make sure we update the state file, then, we should also d.Set
name
and instance
at the end of the function; we can use the variables we make here, or (preferably imo) pull them off the db
object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense however for it to work I've had to add a d.setId
in the Create method as it's currently set as part of the Read.
@@ -48,3 +48,12 @@ In addition to the arguments listed above, the following computed attributes are | |||
exported: | |||
|
|||
* `self_link` - The URI of the created resource. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind subbing "users-db"
for "image-store-bucket"
above in the example? (Github doesn't like comments on unchanged lines)
|
||
## Import | ||
|
||
Database resources can be imported using the `name` of the database instance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this text look more like the router
family of resources' import docs:
SQL databases can be imported using the instance
and name
, e.g.
$ terraform import google_sql_database.users master-instance:users-db
6235f4e
to
6274602
Compare
Thanks for the review @rileykarson. I've added all your suggestions however note that I now conflict as someone has already revised the documentation to make roughly the same change. Do you wish me to rebase?
|
google/resource_sql_database.go
Outdated
database_name := d.Get("name").(string) | ||
instance_name := d.Get("instance").(string) | ||
s := strings.Split(d.Id(), ":") | ||
instance_name := s[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should validate that there are exactly 2 elements in this array, and return an error specifying the format otherwise. That way, users that discover they can import the resource through the Importability page and try just a name
will find that they also need to specify instance
.
Let's use Also, I just noticed something I missed initially - sorry about that! I added a comment for it if you don't mind looking at it as well. |
4e10b77
to
6274602
Compare
I have added the array check and provided a suitable error message.
|
Thanks! Would you mind resolving the merge by taking your changes? |
ae6ab0b
to
4a8b337
Compare
4a8b337
to
2605a17
Compare
Rebase completed @rileykarson |
LGTM, thanks @gh-mlfowler!
|
Add `google_sql_database` and `google_sql_database_instance` to Importability page. @danawillow hashicorp/terraform-provider-google#11 hashicorp/terraform-provider-google#12
Add `google_sql_database` and `google_sql_database_instance` to Importability page. @danawillow hashicorp/terraform-provider-google#11 hashicorp/terraform-provider-google#12
* Add ability to import `google_sql_database` * Update from code review * Ensure split id length and report error otherwise
* Add ability to import `google_sql_database` * Update from code review * Ensure split id length and report error otherwise
Output from magician generating into ga and beta providers
Output from magician generating into ga and beta providers
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Previously raised as hashicorp/terraform#15237