Skip to content

Commit

Permalink
fix generate examples
Browse files Browse the repository at this point in the history
Signed-off-by: Oscar Cobles <[email protected]>
  • Loading branch information
Oscar Cobles committed Sep 20, 2024
1 parent 021e6af commit dcc4346
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions scripts/generate_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit dcc4346

Please sign in to comment.