forked from SumoLogic/sumologic-kubernetes-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update python script and add terraform import script (SumoLogic#35)
* Write terraform resource reference for collector_ids and role_ids * Only get the role names once and before beginning to write to the config file * Fix how roles are written to file * Add roles files output from script to gitignore * Add script that imports resources into terraform * Add docstrings to functions * Add new line * Fix return type for function
- Loading branch information
1 parent
cc70483
commit 8c70cd8
Showing
3 changed files
with
135 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
.vscode | ||
collectors-resources.tf | ||
sources-resources.tf | ||
roles-resources.tf | ||
users-resources.tf | ||
*-role.tf |
This file contains 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
This file contains 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,31 @@ | ||
#!/bin/bash | ||
|
||
# Can only import one resource type for each run of this script | ||
|
||
if [ -z "$1" ] || [ -z "$2" ] ; then | ||
echo "Usage: $0 <file with output from create-tf-config-file.py> <resource type>"; | ||
echo "Resource type options: sumologic_collector, sumologic_http_source, sumologic_role, sumologic_user"; | ||
exit 1; | ||
fi | ||
|
||
filename=$1 # a file containing the output of the create-tf-config-file.py script | ||
resource_type=$2 # name of resource type in terraform, e.g. sumologic_collector | ||
|
||
# delete the first line in the file because it's the Sumo Logic api url | ||
sed '1d' $filename > tmpfile; mv tmpfile $filename | ||
|
||
terraform init --backend=false | ||
|
||
n=1 | ||
while read line; do | ||
|
||
# even numbered lines contain the second argument needed for terraform import | ||
if [ $(($n%2)) == 0 ]; then | ||
second_arg=$line | ||
terraform import "$resource_type.$resource_name" $second_arg | ||
# odd numbered lines contain the name of the resource in terraform | ||
else | ||
resource_name=$line | ||
fi | ||
n=$((n+1)) | ||
done < $filename |