-
Notifications
You must be signed in to change notification settings - Fork 203
INTMDB-382: Improve the importing of default alert configurations for a project #993
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fffac4d
Added alert_configurations data_source
evertsd 5b0c016
Added documentation on how to use data_source_alert_configuration out…
evertsd 9dd402d
Removed duplicate function declaration
evertsd 308d3a7
Resolving lint errors around looping
evertsd 68d42c5
Added example for importing atlas-alert-configurations en masse
evertsd 189b6c3
Got tests passing, added documentation for alert_configuration data_s…
evertsd 3aa7d6d
Fixed alert_configurations test
evertsd 9c3c11a
Updated readme to include instructions for creating the data source
evertsd c7c9aa4
Fixed spacing and added a link to the full example on the data source…
evertsd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.sh | ||
alert-configurations.tf | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## Using the data source | ||
Example exists in `alert-configurations-data.tf`. To use this example exactly: | ||
evertsd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Copy directory to local disk | ||
- Add a `terraform.tfvars` | ||
- Add your `project_id` | ||
- Run `terraform apply` | ||
|
||
### Create alert resources and import them into state file | ||
``` | ||
terraform output -raw alert_imports > import-alerts.sh | ||
terraform output -raw alert_resources > alert-configurations.tf | ||
chmod +x ./import-alerts.sh | ||
./import-alerts.sh | ||
terraform apply | ||
``` | ||
|
||
## Contingency Plans | ||
If unhappy with the resource file or imports, here are some things that can be done: | ||
|
||
### Remove targeted resources from the appropriate files and remove the alet_configuration from state | ||
- Manually remove the resource (ex: `mongodbatlas_alert_configuration.CLUSTER_MONGOS_IS_MISSING_2`) from the `tf` file, and then remove it from state, ex: | ||
``` | ||
terraform state rm mongodbatlas_alert_configuration.CLUSTER_MONGOS_IS_MISSING_2 | ||
``` | ||
|
||
### Remove all alert_configurations from state | ||
- Delete the `tf` file that was used for import, and then: | ||
``` | ||
terraform state list | grep ^mongodbatlas_alert_configuration. | awk '{print "terraform state rm " $1}' > state-rm-alerts.sh | ||
chmod +x state-rm-alerts.sh | ||
./state-rm-alerts.sh | ||
``` |
29 changes: 29 additions & 0 deletions
29
examples/atlas-alert-configurations/alert-configurations-data.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
data "mongodbatlas_alert_configurations" "import" { | ||
project_id = var.project_id | ||
|
||
output_type = ["resource_hcl", "resource_import"] | ||
} | ||
|
||
locals { | ||
alerts = data.mongodbatlas_alert_configurations.import.results | ||
|
||
alert_resources = compact([ | ||
for i, alert in local.alerts : | ||
alert.output == null ? null : | ||
length(alert.output) < 1 == null ? null : alert.output[0].value | ||
]) | ||
|
||
alert_imports = compact([ | ||
for i, alert in local.alerts : | ||
alert.output == null ? null : | ||
length(alert.output) < 2 == null ? null : alert.output[1].value | ||
]) | ||
} | ||
|
||
output "alert_resources" { | ||
value = join("\n", local.alert_resources) | ||
} | ||
|
||
output "alert_imports" { | ||
value = join("", local.alert_imports) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
provider "mongodbatlas" { | ||
public_key = var.public_key | ||
private_key = var.private_key | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
variable "public_key" { | ||
description = "Public API key to authenticate to Atlas" | ||
} | ||
variable "private_key" { | ||
description = "Private API key to authenticate to Atlas" | ||
} | ||
variable "project_id" { | ||
description = "Atlas project name" | ||
default = "" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
terraform { | ||
required_providers { | ||
mongodbatlas = { | ||
source = "mongodb/mongodbatlas" | ||
} | ||
} | ||
required_version = ">= 0.13" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.