This repository contains the Atlas CLI plugin for Terraform's MongoDB Atlas Provider.
It has the following commands to help with your Terraform configurations:
- clusterToAdvancedCluster: Convert a
mongodbatlas_clusterTerraform configuration tomongodbatlas_advanced_cluster(preview provider 2.0.0).
Install the Atlas CLI if you haven't done it yet.
Install the plugin by running:
atlas plugin install github.com/mongodb-labs/atlas-cli-plugin-terraformIf you have it installed and want to update it to the latest version, run:
atlas plugin update mongodb-labs/atlas-cli-plugin-terraformIf you want to see the list of installed plugins or check if this plugin is installed, run:
atlas plugin listNote: In order to use the Preview for MongoDB Atlas Provider 2.0.0 of mongodbatlas_advanced_cluster, you need to set the environment variable MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER to true.
If you want to convert a Terraform configuration from mongodbatlas_cluster to mongodbatlas_advanced_cluster, use the following command:
atlas terraform clusterToAdvancedCluster --file in.tf --output out.tfyou can also use shorter aliases, e.g.:
atlas tf clu2adv -f in.tf -o out.tfIf you want to include the moved blocks in the output file, use the --includeMoved or the -m flag.
If you want to overwrite the output file if it exists, or even use the same output file as the input file, use the --replaceOutput or the -r flag.
You can use the --watch or the -w flag to keep the plugin running and watching for changes in the input file. You can have input and output files open in an editor and see easily how changes to the input file affect the output file.
You can find here some examples of input files (suffix .in.tf) and the corresponding output files (suffix .out.tf).
dynamic blocks are used to generate multiple nested blocks based on a set of values.
Given the different ways of using dynamic blocks, we recommend reviewing the output and making sure it fits your needs.
You can use dynamic blocks for tags and labels. The plugin assumes that for_each has an expression which is evaluated to a map of strings.
You can also combine the use of dynamic blocks in tags and labels with individual blocks in the same cluster definition, e.g.:
tags {
key = "environment"
value = var.environment
}
dynamic "tags" {
for_each = var.tags
content {
key = tags.key
value = replace(tags.value, "/", "_")
}
}You can use dynamic blocks for regions_config. The plugin assumes that for_each has an expression which is evaluated to a list or set of objects.
Dynamic block and individual blocks for regions_config are not supported at the same time in a replication_specs.
- The plugin doesn't support
regions_configwithoutelectable_nodesas there can be some issues withprioritywhen they only haveanalytics_nodesand/orelectable_nodes. priorityis required inregions_configand must be a numeric literal expression between 7 and 1, e.g.var.priorityis not supported. This is to allow reordering them by descending priority as this is expected inmongodbatlas_advanced_cluster.num_shardsinreplication_specsmust be a numeric literal expression, e.g.var.num_shardsis not supported. This is to allow creating areplication_specselement per shard inmongodbatlas_advanced_cluster.dynamicblocks are currently supported only fortags,labelsandregions_config. Coming soon: support forreplication_specs.
See our CONTRIBUTING.md guide.
MongoDB Atlas CLI is released under the Apache 2.0 license. See LICENSE.md