oracle / terraform-provider-oci

Terraform Oracle Cloud Infrastructure provider
https://www.terraform.io/docs/providers/oci/
Mozilla Public License 2.0
757 stars 680 forks source link

terraform-provider-oci_v4.81.0 -generate_state fails to create terraform files and statefile. #1620

Open rifty opened 2 years ago

rifty commented 2 years ago

When using the -generate_state option on the provider plugin neither the terraform configs or the statefile are created. If I leave off -generate_state all terraform resources for the compartment that I have the credentials to see are present in the resulting output.

This works: ./terraform-provider-oci_v4.81.0 -command=export -compartment_name=xxxxxxxx -output_path=v12-iad-devapp -services=core -tf_version=0.12

This fails: ./terraform-provider-oci_v4.81.0 -command=export -compartment_name=xxxxxxxx -output_path=v12-iad-devapp -services=core -tf_version=0.12 -generate_state

Output files are here from the above commands:

tf_481_wout_generate_state.txt

tf_481_w_generate_state.txt

Sample of some of the errors seen with -generate_state enabled

INFO 2022/06/24 16:54:21.232542 [INFO] ===> Importing resource 'oci_core_drg_attachment.export_devapp-oci-to-corp-1-attachment'
INFO 2022/06/24 16:54:21.339788 [ERROR] terraform import command failed for resource 'oci_core_drg_attachment.export_devapp-oci-to-corp-1-attachment' at id 'ocid1.drgattachment.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2022/06/24 16:54:21 [DEBUG] Using modified User-Agent: Terraform/0.12.31 HashiCorp-terraform-exec/0.14.0

Error: No Terraform configuration files

The directory v12-iad-devapp does not contain any Terraform configuration
files (.tf or .tf.json). To specify a different configuration directory, use
the -config="..." command line option.

Any ideas on what I might do to get the statefile generated? Thanks!

kamuridesu commented 1 year ago

Bump

kamuridesu commented 1 year ago

The bug is also present in v4.107.0

kamuridesu commented 1 year ago

Command:

TF_LOG=TRACE OCI_GO_SDK_DEBUG=1 ./.terraform/providers/registry.terraform.io/oracle/oci/4.107.0/linux_amd64/terraform-provider-oci_v4.107.0  -command=export -compartment_name= -output_path=test -generate_state

Output: https://gist.github.com/kamuridesu/d10831c9211d6c98b0dadf3494d468cf

Most of the files have the following:

## This is tmp config to run import for resources

Except for object_storage.tf and availability_domain.tf, which have:

data oci_objectstorage_namespace export_namespace {
  compartment_id =
}

and

data oci_identity_availability_domain export_UPcS-SA-SAOPAULO-1-AD-1 {
  compartment_id =
  ad_number      = "1"
}

respectively. Also, identity.tf, provider.tf, and vars.tf contains valid terraform.

The terraform.tfstate contains only:

{
  "version": 4,
  "terraform_version": "1.3.7",
  "serial": 1,
  "lineage": "c2513081-a746-bd70-ccb2-d3b8c18b2cb4",
  "outputs": {},
  "resources": [],
  "check_results": null
}
kylem0 commented 1 year ago

I have noticed the terraform.tfstate gets generated correctly using Terraform version 0.12.31. https://releases.hashicorp.com/terraform/0.12.31/

ravinitp commented 1 year ago

Thank you for reporting the issue. We observed the affected resources are not provided in the description or it's incorrect. We request you to add it in issue description as mentioned in below format. Example: affected_resources = oci_core_instance , oci_core_instances

If it's not related to any particular resource then mention affected resource as terraform. Example: affected_resources = terraform

As this works through automation, request you to follow exact syntax.

franciscvass commented 1 year ago

hi, I have the same issue. Trying to get the state with:

terraform-provider-oci -compartment_name=fvassComp1 -command=export -output_path=/Users/vefeo/workORCL/oci-tf-discovery -generate_state

The error I got:

INFO 2023/05/01 14:26:42.921234 [ERROR] terraform import command failed for resource 'oci_artifacts_container_configuration.export_container_configuration' at id 'ocid1.compartment.oc1..aaaaaaaawrkzz3hmmifq65xo6zx7impepmtoekwqyhzzc7dctzmxn75gyjnq': exit status 1

Error: Missing required argument

on /Users/vefeo/workORCL/oci-tf-discovery/availability_domain.tf line 3, in data "oci_identity_availability_domain" "export_GqIF-US-ASHBURN-AD-1": 3: data oci_identity_availability_domain export_GqIF-US-ASHBURN-AD-1 {}

The argument "compartment_id" is required, but no definition was found.

Error: Missing required argument

on /Users/vefeo/workORCL/oci-tf-discovery/availability_domain.tf line 5, in data "oci_identity_availability_domain" "export_GqIF-US-ASHBURN-AD-2": 5: data oci_identity_availability_domain export_GqIF-US-ASHBURN-AD-2 {}

The argument "compartment_id" is required, but no definition was found.

Error: Missing required argument

on /Users/vefeo/workORCL/oci-tf-discovery/availability_domain.tf line 7, in data "oci_identity_availability_domain" "export_GqIF-US-ASHBURN-AD-3": 7: data oci_identity_availability_domain export_GqIF-US-ASHBURN-AD-3 {}

The argument "compartment_id" is required, but no definition was found.

Thaks

bestrocker221 commented 1 year ago

Same here. I also tried to use Terraform version v0.12.31 but same problem. Resources are generated when only if "-generate_state" is not present

andreiPtr commented 2 months ago

I'm still having this issue. Same as @bestrocker221 it works without the -generate_state but fails if we add it: exit status 1 2024/08/29 13:41:29 [DEBUG] Using modified User-Agent: Terraform/0.12.31 HashiCorp-terraform-exec/0.20.0

Error: No Terraform configuration files

The directory test-bucket does not contain any Terraform configuration files (.tf or .tf.json). To specify a different configuration directory, use the -config="..." command line option.

Any references to this resource have been replaced with hard coded values in generated configurations Error Message:
Suggestion:

Later edit: Found out that you have to be in the folder you pass at output_path=, so you can use for example $tf-oci -command=export -compartment_name=test-terraform-compartment -services=object_storage -generate_state -output_path=. :facepalm: