Comments (8)
I share what I did for the migration.
Note: in the diff, -
is for old tf provider, +
is for new
First, modify my Makefile
init
target
- official tf provider is on repo, so no need to download it manually: tf will manage the download
- change the tf state, because running a
terraform plan
command with the old tf state makes tf crash
rm -rf .terraform/modules .terraform/terraform.tfstate
mkdir -p .terraform/plugins/linux_amd64/
- [ ! -f .terraform/plugins/linux_amd64/terraform-provider-mongodbatlas_v1.1.0 ] && wget -q \
- https://github.com/akshaykarle/terraform-provider-mongodbatlas/releases/download/v1.1.0/terraform-provider-mongodbatlas_v1.1.0_linux_amd64 \
- -O .terraform/plugins/linux_amd64/terraform-provider-mongodbatlas_v1.1.0
- chmod u+x .terraform/plugins/linux_amd64/terraform-provider-mongodbatlas*
terraform init \
-backend-config="bucket=$(BUCKET)" \
- -backend-config="prefix=mongodbatlas/${PROJECT}.tfstate"
+ -backend-config="prefix=mongodbatlas/${PROJECT}-v2.tfstate"
Then, modify my main.tf.j2
- I only use mongodbatlas_database_user resources (because of old tf provider limitation)
- Some keys to rename, but that's all, not big change
- don't mind the
{{ variable }}
format: I use an Ansible JINJA2 template layer to generate tf code because tf is not able to do loop correctly...
provider "mongodbatlas" {
- username = "{{ vault_username }}"
- api_key = "{{ vault_api_key }}"
- version = "~> 1.1.0"
+ public_key = "{{ vault_public_key }}"
+ private_key = "{{ vault_private_key }}"
+ version = "~> 0.5.1"
}
resource "mongodbatlas_database_user" "{{ db_user.username }}" {
username = "{{ db_user.username }}"
password = "{{ db_user.password }}"
- database = "admin"
- group = "${var.project_id}"
+ project_id = "${var.project_id}"
+ auth_database_name = "admin"
+
roles {
- name = "readWrite"
- database = "{{ db_user.database }}"
+ role_name = "readWrite"
+ database_name = "{{ db_user.database }}"
}
}
After that, just need to import the resources following the doc -> https://www.terraform.io/docs/providers/mongodbatlas/r/database_user.html#import
Unfortunately I cannot run this part entirely because of this issue -> https://github.com/terraform-providers/terraform-provider-mongodbatlas/issues/179
from terraform-provider-mongodbatlas.
@damienleger thank you for sharing your experience and tips. It is very appreciated.
Also we are working on #179 and hope to have a fix in our next release (we releasing approximately once a month).
from terraform-provider-mongodbatlas.
I can confirm that it is now working with release 0.6.0 🙂
from terraform-provider-mongodbatlas.
@gschaffer-cxn a great suggestion. Would be great if anyone in the community could contribute to this. I'll also look internal and see if we have someone who could take this on.
from terraform-provider-mongodbatlas.
@gschaffer-cxn to start off with, you'd want to remove the plugin created by akshaykarle from ~/.terraform.d/plugins
. (I also removed "mongodbatlas": "aee1981e690ac5a5bd75ce778d2ff786e7fc2de60e8554976e9285d02524d042"
from my repo's lock.json, found at PROJECT/.terraform/plugins/darwin_amd64/lock.json
)
Then you would start updating the provider code
(Old)
provider "mongodbatlas" {
username = "${var.mongodb_atlas_username}"
api_key = "${var.mongodb_atlas_api_key}"
}
(New)
provider "mongodbatlas" {
public_key = "${var.mongodb_atlas_public_key}"
private_key = "${var.mongodb_atlas_private_key}"
}
from terraform-provider-mongodbatlas.
@kgriffiths Hi, the problem is that this solution will redeploy the whole db, even if you just wants to make totally different modifications in your infra. We hope there is other solution to migrate than editing the tfstate file.
from terraform-provider-mongodbatlas.
The general path forward, I believe, will be both what @kgriffiths notes, rewriting the configs for the new, updated, resources but also one will need to import the existing infrastructure into state: https://www.terraform.io/docs/import/index.html
Hopefully HashiCorp will, as noted in their doc, add being able to create the resources from import vs the somewhat manual process it requires now.
from terraform-provider-mongodbatlas.
Believe we are far enough out a migration guide is probably no longer needed. Closing
from terraform-provider-mongodbatlas.
Related Issues (20)
- `replication_specs` do not support deep diff HOT 9
- The terraform-provider-mongodbatlas_v1.12.2 plugin crashed! HOT 2
- `mongodbatlas_cloud_backup_snapshot_export_bucket` resource stuck on `Still distroying...` HOT 2
- mongodbatlas_project_ip_access_list Unexpected replacement of CIDR with IP address HOT 11
- Rate limit of 10 invitations per 1 minutes exceeded HOT 2
- Changes to mongodbatlas_project_ip_access_list comments force a replacement HOT 2
- Terraform Bud in updating serverless project HOT 2
- mongodbatlas_search_index does not allow for name changing HOT 3
- 'tags' not working for cluster HOT 2
- 401 Unauthorised when importing Organization, but other resources import successfully HOT 5
- breaking change in data.mongodbatlas_cluster.connection_strings on v1.12 HOT 4
- In the `mongodbatlas_advanced_cluster` ressource, forbidden characters for the values of the tags are allowed by the provider and fail on apply. HOT 3
- Provider not working with Secret Manager HOT 3
- Error: Provider produced inconsistent final plan for mongodbatlas_privatelink_endpoint_service HOT 3
- Provider produced inconsistent result after apply HOT 1
- Provider produced inconsistent result after apply HOT 8
- mongodbatlas_alert_configuration failing to be created on apply due to METRIC_TYPE_UNSUPPORTED for DISK_PARTITION_ alerts 400 error HOT 3
- Unable to add encryption at rest through terraform HOT 7
- [Bug]: backup_compliance_policy resource missing required attribute HOT 3
- [Bug]: Provider produces inconsistent result after importing encryption_at_rest HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-provider-mongodbatlas.