Is there a roadmap to implement terraform import...?
tetsuya28 opened this issue ยท 11 comments
Hi, admins.
I use terraform-provider-eksctl for new eks cluster.
Also, I'm thinking to import existing eks cluster with terraform import
, Is there any way to import or plan to implement import function for terraform-provider-eksctl?
Error: resource eksctl_cluster doesn't support import
@tetsuya28 Hey! Thanks a lot for trying this provider.
I don't really have a sort of roadmap but I added initial support or terraform import
in b9f3a37.
Would you mind trying it?
Any success here?
@jchoi926 I did implement it and confirmed that it works for me ๐
Can we close this and reopen only after anyone finds it to not work?
@mumoshu The import feature seems very basic according to the output of terraform show.
` terraform show
module.eks.eksctl_cluster.cluster:
resource "eksctl_cluster" "cluster" {
eksctl_bin = "eksctl"
id = "buo1mtmvvhftrxxxxxx"
name = "cluster"
region = "eu-west-1"
version = "1.17"
vpc_id = "vpc-xxxxxxxxx"
}`
Is there no support for importing the spec block (nodegroups, vpc, etc)?
@jchoi926 I'm not sure how that's technically possible. eksctl
doesn't support generating the original cluster.yaml from the eks cluster.
Can't you just bring your original cluster.yaml and put its content into imported eksctl_cluster's spec
?
Or maybe we can enhance the import feature so that you can specify the path to the original cluster.yaml like terraform import eksctl_cluster path/to/cluster.yaml
? That way, the provider could generate the spec
content as well.
@mumoshu Bringing in the existing cluster.yaml unfortunately triggers an update on the cluster. Not a huge deal, just wondering if there was a way to bring in the existing configuration.
@mumoshu I would definitely love to have a way to import the existing cluster spec via terraform import eksctl_cluster path/to/cluster.yaml
.
If this could include the ability to add the existing security_group_ids (since that seems to be "(known after apply)" after importing and I can't seem to set it through security_group_ids), that would be great! ๐
@jchoi926 @DragonStuff Thanks for requests! I hear you, but it's just that I don't know how it's technically possible.
AFAIK, terraform-import's syntax is something like terraform import TYPE.NAME TYPE_SPECIFIC_ARBITRARY_ID_STRING
and we use eksctl cluster name for the ID. Perhaps we can address your use-cases by assuming the ID is the path to your cluster.yaml, and then somehow parsing your cluster.yaml and producing appropriate terraform state here?
terraform-provider-eksctl/pkg/resource/cluster/import.go
Lines 11 to 18 in 7c4587c
Would you mind contributing it, by any chance?
AFAIK, terraform-import's syntax is something like
terraform import TYPE.NAME TYPE_SPECIFIC_ARBITRARY_ID_STRING
and we use eksctl cluster name for the ID. Perhaps we can address your use-cases by assuming the ID is the path to your cluster.yaml, and then somehow parsing your cluster.yaml and producing appropriate terraform state here?terraform-provider-eksctl/pkg/resource/cluster/import.go
Lines 11 to 18 in 7c4587c
An idea, perhaps executing eksctl with the given spec and seeing if anything has changed during import would solve this? If there is no difference, and if spec
is null, it will import the object as per the definition?
A sample import flow would look something like:
- User executes
terraform import eksctl_cluster.eks-cluster["eks-some-cluster"] eks-some-cluster
- User executes
terraform plan
<-- The plan notices thatspec
is empty but the id exists. - --> it then checks via
eksctl upgrade cluster
or similar mechanism if the cluster has changed - --> if it hasn't, it imports from the file
- --> if it has, it does not import
Of course, this point is moot if it does this anyway (if during the apply, it has no change, so it's automatically imported without change). I haven't tested this. ๐
Thanks!
If there is no difference, and if spec is null, it will import the object as per the definition?
Terraform doesn't provide the custom provider to access tf file content and writing tf file from the import process, afaik. So - at least the user must write tf file on their own. Perhaps that makes --> if it hasn't, it imports from the file
part impossible?
terraform import eksctl_cluster.NAME
already imports a few bits of your cluster info today. So if the user can accept running a few cycle of terraform plan
, then terraform apply
, and edit tf file after terraform import
, it should already work. But if there's anything more to do on the terraform state on the import process, we should do that(That's where I'm not sure what to do).
Thoughts?