From dcc4346ca4e1f7ba99e88460a231c91128d4a6fb Mon Sep 17 00:00:00 2001 From: Oscar Cobles Date: Fri, 20 Sep 2024 18:23:25 +0200 Subject: [PATCH] fix generate examples Signed-off-by: Oscar Cobles --- scripts/generate_examples.sh | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/scripts/generate_examples.sh b/scripts/generate_examples.sh index e44c6e03..aaac32d1 100755 --- a/scripts/generate_examples.sh +++ b/scripts/generate_examples.sh @@ -224,8 +224,34 @@ delete_nonexistent_pulumi_examples() { echo "NOT FOUND $pulumi_example_dir" fi if [[ "$found" == false && -f "$pulumi_example_dir/.autogenerated" ]]; then - echo -e "\n\033[0;33m Warning:\033[0m deleting autogenerated example that no longer exist in Terraform: $pulumi_example_dir" >&2 - rm -rf "$pulumi_example_dir" + + # Check if there are subdirectories with examples that need to be preserved + subdirs_to_keep=() + for tf_example_dir in "${ALL_TF_EXAMPLES[@]}"; do + if [[ "$tf_example_dir" == "$pulumi_example_dir/"* ]]; then + subdirs_to_keep+=("$tf_example_dir") + fi + done + + if [ ${#subdirs_to_keep[@]} -eq 0 ]; then + echo -e "\n\033[0;33m Warning:\033[0m deleting autogenerated example that no longer exist in Terraform: $pulumi_example_dir" >&2 + rm -rf "$pulumi_example_dir" + else + echo -e "\n\033[0;33m Warning:\033[0m partially deleting autogenerated example that no longer exist in Terraform: $pulumi_example_dir" >&2 + # Remove only the files and subdirectories that are not in the list of subdirs_to_keep + for item in "$pulumi_example_dir"/*; do + keep=false + for keep_dir in "${subdirs_to_keep[@]}"; do + if [[ "$item" == "$keep_dir" ]]; then + keep=true + break + fi + done + if [[ "$keep" == false ]]; then + rm -rf "$item" + fi + done + fi else new_pulumi_examples+=("$pulumi_example") fi @@ -357,6 +383,7 @@ generate_examples_and_docs merge_example_files "equinix_network_device" merge_example_files "equinix_fabric_connection" +merge_example_files "equinix_fabric_cloud_router" merge_example_files "equinix_fabric_routing_protocol" merge_example_files "equinix_metal_device" merge_example_files "equinix_metal_project"