-
Notifications
You must be signed in to change notification settings - Fork 61
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
Support for importing terraform resources #193
Comments
Have you tried using the declarative |
You can point to the existing state if you like in the configuration block |
Hello @ytsarev :) I came across your answer by accident while searching for how to solve an issue we encountered during our Crossplane migration. The problem is that we want to continue using terraform for several infrastructure components and don't want to deploy them using Crossplane/Gitops. An example is the AWS IPAM service. If we create the service using terraform, we will need the pool or scope IDs later when creating a VPC using Crossplane. The question is how can Crossplane access the terraform state (to get IDs from there)? Will Crossplane also populate the existing state outputs into a Sorry for a damb question, we're still making our first steps with Crossplane |
@NikitaCloudRuntime if all you need is the data associated with the resources, and you don't need to manipulate the state of the resources, you have a couple of options to do that without
It really depends on how often you need to use the data and in how many places. Hope this helps |
@NikitaCloudRuntime, no worries at all, it is actually pretty advanced question :) There are a couple of examples around that you can use in addition to great suggestions from @bobh66
Cheers. |
Hi @ytsarev That might be a topic for a separate thread but... what if we wanted to revert the direction of information flow? I mean, examples you provided demonstrate how we could get attributes of resources created with terraform into crossplane. But what if we wanted to access attributes of resources created by crossplane inside some other tool. We are in the process of migration so there will be most likely a transition phase when we would need to use two IaC systems. In such a case let's say we create a VPC with Crossplane and then we want to create inside a security group with Terraform. To do so we would need to load somehow the vpcid into tf. Naturally while having this as close to declarative approach as possible. One way I could think of was to write all interesting information about resources created by Crossplane into ConfigMap and then read the map similarly to the way we would read remote tf state files... but I cannot find a clear way to simply extract any resource attribute into ConfigMap (or Secret). |
@hellofresh-tkaplonski The first thing that comes to mind is to use some form of |
@ytsarev Thank you for prompt answer. Getting resources with kubectl would be an option but it seems to be dangerously close to imperative programming. Isn't there a way to somehow export attributes to ConfigMap so that we could kinda "emulate" terraform's outputs and read those dedicated values with Terraform data source (https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/config_map)? Something like AWS ACK offers: https://aws-controllers-k8s.github.io/community/docs/user-docs/field-export/ ? |
@hellofresh-tkaplonski you can do this today using a Composition with provider-kubernetes - create a provider-terraform You could also use |
What problem are you facing?
We're currently using upbound-provider-gcp to provision GKE clusters, but we're considering moving to provider-terraform for a variety of reasons (ability to use google-beta features, ability to use our in-house TF module registry rather than duplicating everything as crossplane compositions).
Migrating to provider-terraform is a little painful, because it tries to create things which already exist (because they're not in the TF state), and get's ALREADY_EXISTS errors back from GCP. When we migrated our DNS resources to upbound-provider-terraform, we did a maintenance window, and deleted the upbound-provider-gcp resources so that everything got recreated. That's not really an option for GKE clusters.
How could Official Terraform Provider help solve your problem?
It would be extremely useful if there was a mechanism to make provider-terraform import resources into its state (using the terraform import command).
My idea for how to do this is to have an annotation like
terraform.upbound.io/needs-import: true
which could be manually added to Workspace resources. Upon seeing that annotation, the provider can run terraform import before running plan/apply, and then remove in annotation if successful. I'm open to alternative suggestions though.Assuming adding this feature wouldn't take too long, I think we'd be happy to contribute it.
The text was updated successfully, but these errors were encountered: