Giter VIP home page Giter VIP logo

Comments (8)

damienleger avatar damienleger commented on June 3, 2024 1

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.

themantissa avatar themantissa commented on June 3, 2024 1

@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.

damienleger avatar damienleger commented on June 3, 2024 1

I can confirm that it is now working with release 0.6.0 🙂

from terraform-provider-mongodbatlas.

themantissa avatar themantissa commented on June 3, 2024

@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.

kgriffiths avatar kgriffiths commented on June 3, 2024

@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.

skully avatar skully commented on June 3, 2024

@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.

themantissa avatar themantissa commented on June 3, 2024

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.

themantissa avatar themantissa commented on June 3, 2024

Believe we are far enough out a migration guide is probably no longer needed. Closing

from terraform-provider-mongodbatlas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.