Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

can't get the correct terraform state file when importing the existed resources #297

Open
bretagne-peiqi opened this issue Aug 17, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@bretagne-peiqi
Copy link

What happened?

importing existed resources with yaml file filled required fields and annotations: crossplane.io/external-name: xxx

expected to import the resource, but following the logs: the provider can't get the good result during oberservation, which means, it failed to get the right tfstate file and thought the resources does't existed and try to create one.

 cat terraform.tfstate
{
  "version": 4,
  "terraform_version": "1.1.5",
  "serial": 1,
  "lineage": "4a5f1ef0-9c2e-41fa-a0c6-3b3a92cc8666",
  "outputs": {},
  "resources": []
}

some logs:

DEBUG   provider-jet-alicloud   refresh ended   {"workspace": "/tmp/4a5f1ef0-9c2e-41fa-a0c6-3b3a92cc8666", "out": "{\"@level\":\"info\",\"@message\":\"Terraform 1.1.5\",\"@module\":\"terraform.ui\",\"@timestamp\":\"2022-08-17T05:36:22.570388Z\",\"terraform\":\"1.1.5\",\"type\":\"version\",\"ui\":\"1.0\"}\n{\"@level\":\"info\",\"@message\":\"Plan: 0 to add, 0 to change, 0 to destroy.\",\"@module\":\"terraform.ui\",\"@timestamp\":\"2022-08-17T05:36:25.251256Z\",\"changes\":{\"add\":0,\"change\":0,\"remove\":0,\"operation\":\"plan\"},\"type\":\"change_summary\"}\n{\"@level\":\"info\",\"@message\":\"Apply complete! Resources: 0 added, 0 changed, 0 destroyed.\",\"@module\":\"terraform.ui\",\"@timestamp\":\"2022-08-17T05:36:25.255911Z\",\"changes\":{\"add\":0,\"change\":0,\"remove\":0,\"operation\":\"apply\"},\"type\":\"change_summary\"}\n{\"@level\":\"info\",\"@message\":\"Outputs: 0\",\"@module\":\"terraform.ui\",\"@timestamp\":\"2022-08-17T05:36:25.255961Z\",\"outputs\":{},\"type\":\"outputs\"}\n"}
1.6607145853248382e+09  DEBUG   provider-jet-alicloud   Successfully requested creation of external resource    {"controller": "managed/managedk8s.alicloud.jet.crossplane.io/v1alpha1, kind=managedkubernetes", "request": "/k8s-infra-test", "uid": "4a5f1ef0-9c2e-41fa-a0c6-3b3a92cc8666", "version": "3686057787", "external-name": "k8s-infra-test", "external-name": "k8s-infra-test"}


How can we reproduce it?

my config file:

apiVersion: managedk8s.alicloud.jet.crossplane.io/v1alpha1
kind: ManagedKubernetes
metadata:
  name: k8s-infra-test
  annotations:
    external-name: k8s-infra-test
spec:
  forProvider:
    workerVswitchIds:
      - vsw-ufxxxxxxxxxxxxx
    securityGroupId: sg-uf63gxxxxxxxxxxxx
  providerConfigRef:
    name: default-mk8s
  deletionPolicy: Delete

@bretagne-peiqi bretagne-peiqi added the bug Something isn't working label Aug 17, 2022
@bretagne-peiqi
Copy link
Author

I am wondering the cmd := w.executor.CommandContext(ctx, "terraform", "apply", "-refresh-only", "-auto-approve", "-input=false", "-lock=false", "-json") whether can get the good tfstate file ?, because it generated the file with resources [], and provider thought the resource doesn't exist

@huangyanhong
Copy link

I had the same problem,who can support ?

@huangyanhong
Copy link

add terraform import resource can resolve this problem

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants