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

Cloud SQL - Error importing database instance #4626

Closed
olegkorol opened this issue Oct 7, 2019 · 5 comments
Closed

Cloud SQL - Error importing database instance #4626

olegkorol opened this issue Oct 7, 2019 · 5 comments
Assignees
Labels

Comments

@olegkorol
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
  • If an issue is assigned to the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to "hashibot", a community member has claimed the issue already.

Terraform Version

Terraform v0.12.9

Affected Resource(s)

  • provider.google v2.16.0
  • provider.google-beta v2.16.0

Terraform Configuration Files

provider "google" {
  region      = "${var.region}"
  credentials = "${file("${var.credentials_file_path}")}"
}

resource "google_sql_database_instance" "sql-instance" {
  project          = "${var.gcp_project}"
  provider         = "google"
  name             = "instance-id"
  region           = "${var.region}"
  database_version = "MYSQL_5_7"
  settings = {
    tier = "db-n1-standard-1"
  }
}

Then I am running:

terraform import google_sql_database_instance.sql-instance instance-id

Debug Output

N/A

Panic Output

The import command mentioned above returns:

Error: project: required field is not set

(Note that the project field is set... and it is actually not a required field, AFAIK)

Expected Behavior

It should import the specified resource.

Actual Behavior

Errors and fails to execute command.

Steps to Reproduce

  1. Use the config provided above.
  2. Run the import command provided above.

Important Factoids

N/A

References

N/A

@ghost ghost added the bug label Oct 7, 2019
@rileykarson rileykarson self-assigned this Oct 7, 2019
@rileykarson
Copy link
Collaborator

project is a required field, although not necessarily on the resource. It needs to come from somewhere- whether it's the resource, provider, or an environment variable.

Many users will specify their project in config (or an env var) so we allow convenience import ids by just the name of the resource. Unfortunately, when running terraform import, Terraform doesn't actually look at the config of the resource so the project can't be pulled from there.

If you use the terraform import google_sql_database_instance.my-instance {{project}}/{{name}} form to specify the project instead of the terraform import google_sql_database_instance.my-instance /{{name}} form which would pull it from the environment/provider, this should work.

@olegkorol
Copy link
Author

Thanks for the quick feedback, @rileykarson.

I can confirm that the import works using the proposed syntax (of which I wasn't aware, TBH):
terraform import google_sql_database_instance.my-instance {{project}}/{{name}}

At this point I am having a new issue though: while trying to import a google_sql_database with this same syntax, it just fails.

Let's say I have this config:

resource "google_sql_database_instance" "some-database-instance" {
  project          = "${var.gcp_project}"
  provider        = "google"
  name             = "some-name"
  region           = "europe-west3"
  database_version = "MYSQL_5_7"
  settings {
    tier = "db-n1-standard-1"
  }
}

resource "google_sql_database" "some-database" {
  project  = "${var.gcp_project}"
  name     = "some_name"
  instance = "${google_sql_database_instance.name}" 
}

... and I run this command:
terraform import google_sql_database.some-database {{project}}/{{some_name}}

This is the output:

google_sql_database.some-database: Importing from ID "{{project}}/{{some_name}}"...

Error: project: required field is not set

Am I missing something here?
It is a little bit confusing.

@Chupaka
Copy link
Contributor

Chupaka commented Oct 8, 2019

@olegkorol please check the documentation for the list of available import formats: https://www.terraform.io/docs/providers/google/r/sql_database.html#import

@olegkorol
Copy link
Author

Ok, got it. Thanks a lot @Chupaka.

@ghost
Copy link

ghost commented Nov 7, 2019

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!

@ghost ghost locked and limited conversation to collaborators Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants