Unable to import Oracle Public Cloud resource

93 views
Skip to first unread message

Scott M. Parrill

unread,
Jun 16, 2017, 6:35:56 PM6/16/17
to terrafo...@googlegroups.com

I’m new to Terraform and evaluating it as a tool to help us manage our compute resource in the Oracle Public Cloud.  I’m trying to import the current state of an opc_compute_instance and getting the following result:

 

> terraform import opc_compute_instance.instance INSTANCE/<id>

opc_compute_instance.instance: Importing from ID "INSTANCE/<id>"...

opc_compute_instance.instance: Import complete!

  Imported opc_compute_instance (ID: <id>)

opc_compute_instance.instance: Refreshing state... (ID: <id>)

Error importing: 1 error(s) occurred:

 

* opc_compute_instance.instance (import id: INSTANCE/<id>): 1 error(s) occurred:

 

* import opc_compute_instance.instance result: <id>: import opc_compute_instance.instance (id: <id>): Terraform detected a resource with this ID doesn't exist. Please verify the ID is correct. You cannot import non-existent resources using Terraform import.

 

My .tf file looks like:

provider "opc" {

  identity_domain = "xxxx"

  endpoint        = "https://xxxx.oraclecloud.com/"

  user            = "xxxx"

  password        = "xxxx"

}

 

resource "opc_compute_instance" "instance" {

  name       = "INSTANCE"

  shape      = "oc2m"

  image_list = "/oracle/public/OL_6.6_10GB_x11"

}

 

Am I missing a step somewhere?  The ‘terraform plan’ command does not object to the .tf file:

 

> terraform plan

Refreshing Terraform state in-memory prior to plan...

The refreshed state will be used to calculate this plan, but will not be

persisted to local or remote state storage.

 

The Terraform execution plan has been generated and is shown below.

Resources are shown in alphabetical order for quick scanning. Green resources

will be created (or destroyed and then created if an existing resource

exists), yellow resources are being changed in-place, and red resources

will be destroyed. Cyan entries are data sources to be read.

 

Note: You didn't specify an "-out" parameter to save this plan, so when

"apply" is called, Terraform can't guarantee this is what will execute.

 

+ opc_compute_instance.instance

    attributes:               "<computed>"

    availability_domain:      "<computed>"

    domain:                   "<computed>"

    entry:                    "<computed>"

    fingerprint:              "<computed>"

    hostname:                 "<computed>"

    image_format:             "<computed>"

    image_list:               "/oracle/public/OL_6.6_10GB_x11"

    ip_address:               "<computed>"

    label:                    "<computed>"

    name:                     "INSTANCE"

    networking_info.#:        "<computed>"

    placement_requirements.#: "<computed>"

    platform:                 "<computed>"

    priority:                 "<computed>"

    quota_reservation:        "<computed>"

    relationships.#:          "<computed>"

    resolvers.#:              "<computed>"

    reverse_dns:              "true"

    shape:                    "oc2m"

    site:                     "<computed>"

    start_time:               "<computed>"

    state:                    "<computed>"

    vcable:                   "<computed>"

    virtio:                   "<computed>"

    vnc_address:              "<computed>"

 

 

Plan: 1 to add, 0 to change, 0 to destroy.

 

Thanks,

Scott

 

 

---------------------------------------

Scott Parrill

Systems Administrator

IT/Telecom and System Support Services

University of Wyoming

spar...@uwyo.edu

307-766-4829

 

Jake Champlin

unread,
Jun 26, 2017, 9:11:52 AM6/26/17
to terrafo...@googlegroups.com
Hi Scott, 

First, I'd like to apologize for the delayed response here! 

Second, Terraform can only import infrastructure that is already created, but not included in your Terraform statefile. It appears that Terraform cannot find the OPC instance based on the name/id that was provided. This can either be due to the instance not existing, incorrect user credentials/permissions, or an incorrect Site being used during the OPC authentication. 

The most common reason is a misconfiguration of the OPC site. This is configured via the `endpoint` parameter in the provider initialization. This can also be set via the OPC_ENDPOINT environment variable, so be sure the site in the endpoint matches the site where the instance you wish to import exists in.

If I create an instance either manually or via Terraform, I can import the instance as shown below. However, if I create an instance in a different site than I have configured in Terraform, the import will fail as you've experienced: 

```
$ terraform import opc_compute_instance.foo acc-test-instance-6315887379811366436/8c463fb0-14a3-4bc3-8d5b-41a19986d461
opc_compute_instance.foo: Importing from ID "acc-test-instance-6315887379811366436/8c463fb0-14a3-4bc3-8d5b-41a19986d461"...
opc_compute_instance.foo: Import complete!
  Imported opc_compute_instance (ID: 8c463fb0-14a3-4bc3-8d5b-41a19986d461)
opc_compute_instance.foo: Refreshing state... (ID: 8c463fb0-14a3-4bc3-8d5b-41a19986d461)
```

Happy to assist you with this further as well. Currently I don't see a bug in the OPC provider, but there definitely could be one here! 

Thanks again, and sorry for the delayed response. 


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CO2PR05MB6332727D53E508AF26CC68EBFC10%40CO2PR05MB633.namprd05.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.

Raj Gupta

unread,
Sep 20, 2017, 2:39:39 PM9/20/17
to Terraform
Hi Jack-

Hope you are doing good.

 

I also need some suggestion on terraform. Please do the needful.

 

- Suppose I am having directory- terraform and I placed my terraform exe(Binary) file there and more then one terraform- configuration.tf and Test.tf- My question is how can call individual .tf file from same directory or can we create separate .tf file for individual work and one common place for terraform.exe?

 

- Suppose I am having one .tf file and I applied the same, after one day i just add some more resource in same file, then how I can run those changes only insted of applying all the changes again?

 

- Just example- If i have create one cloud instance/server and added 1 boo-table and 1 persistent disk, and later wanted to add one more persistent disk then changed the same .tf file and used terraform inti command and then checked the plan but its show 1 object to be destroyed and when run its create new persistent storage but destroyed the instance and recreate and add new storage? but i just wanted to execute only newly added storage resource and add the same to instance without destroying the instance.

 

Please guide me on above doubt.


Thanks

Raj Gupta

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages