Skip to content
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

Switch to for_each for log forwarding resources #59

Merged
merged 1 commit into from
Feb 15, 2024
Merged

Conversation

zbstof
Copy link
Contributor

@zbstof zbstof commented Feb 14, 2024

In case var.cloudwatch_log_groups changes somewhere in the middle of the list, all resources indexed since that position must be recreated.
This can be remedied by switching to for_each instead of count

Was:

  # module.datadog[0].aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter[0] will be created
  + resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter" {
      + destination_arn = (known after apply)
      + distribution    = "Random"
      + id              = (known after apply)
      + log_group_name  = "/aws/sagemaker/TransformJobs"
      + name            = "/aws/sagemaker/TransformJobs-filter"
      + role_arn        = (known after apply)
    }

  # module.datadog[0].aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter[1] will be created
  + resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter" {
      + destination_arn = (known after apply)
      + distribution    = "Random"
      + id              = (known after apply)
      + log_group_name  = "/aws/sagemaker/Endpoints/slideshare-spam-model"
      + name            = "/aws/sagemaker/Endpoints/slideshare-spam-model-filter"
      + role_arn        = (known after apply)
    }

  # module.datadog[0].aws_lambda_permission.allow_cloudwatch_logs_to_call_dd_lambda_handler[0] will be created
  + resource "aws_lambda_permission" "allow_cloudwatch_logs_to_call_dd_lambda_handler" {
      + action              = "lambda:InvokeFunction"
      + function_name       = (known after apply)
      + id                  = (known after apply)
      + principal           = "logs.us-east-2.amazonaws.com"
      + source_arn          = "arn:aws:logs:us-east-2::log-group:/aws/sagemaker/TransformJobs:*"
      + statement_id        = "_aws_sagemaker_TransformJobs-AllowExecutionFromCloudWatchLogs"
      + statement_id_prefix = (known after apply)
    }

  # module.datadog[0].aws_lambda_permission.allow_cloudwatch_logs_to_call_dd_lambda_handler[1] will be created
  + resource "aws_lambda_permission" "allow_cloudwatch_logs_to_call_dd_lambda_handler" {
      + action              = "lambda:InvokeFunction"
      + function_name       = (known after apply)
      + id                  = (known after apply)
      + principal           = "logs.us-east-2.amazonaws.com"
      + source_arn          = "arn:aws:logs:us-east-2::log-group:/aws/sagemaker/Endpoints/slideshare-spam-model:*"
      + statement_id        = "_aws_sagemaker_Endpoints_slideshare-spam-model-AllowExecutionFromCloudWatchLogs"
      + statement_id_prefix = (known after apply)
    }

Is:

  # module.datadog[0].aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter["/aws/sagemaker/Endpoints/slideshare-spam-model"] will be created
  + resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter" {
      + destination_arn = (known after apply)
      + distribution    = "Random"
      + id              = (known after apply)
      + log_group_name  = "/aws/sagemaker/Endpoints/slideshare-spam-model"
      + name            = "/aws/sagemaker/Endpoints/slideshare-spam-model-filter"
      + role_arn        = (known after apply)
    }

  # module.datadog[0].aws_cloudwatch_log_subscription_filter.test_lambdafunction_logfilter["/aws/sagemaker/TransformJobs"] will be created
  + resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter" {
      + destination_arn = (known after apply)
      + distribution    = "Random"
      + id              = (known after apply)
      + log_group_name  = "/aws/sagemaker/TransformJobs"
      + name            = "/aws/sagemaker/TransformJobs-filter"
      + role_arn        = (known after apply)
    }

  # module.datadog[0].aws_lambda_permission.allow_cloudwatch_logs_to_call_dd_lambda_handler["/aws/sagemaker/Endpoints/slideshare-spam-model"] will be created
  + resource "aws_lambda_permission" "allow_cloudwatch_logs_to_call_dd_lambda_handler" {
      + action              = "lambda:InvokeFunction"
      + function_name       = (known after apply)
      + id                  = (known after apply)
      + principal           = "logs.us-east-2.amazonaws.com"
      + source_arn          = "arn:aws:logs:us-east-2::log-group:/aws/sagemaker/Endpoints/slideshare-spam-model:*"
      + statement_id        = "_aws_sagemaker_Endpoints_slideshare-spam-model-AllowExecutionFromCloudWatchLogs"
      + statement_id_prefix = (known after apply)
    }

  # module.datadog[0].aws_lambda_permission.allow_cloudwatch_logs_to_call_dd_lambda_handler["/aws/sagemaker/TransformJobs"] will be created
  + resource "aws_lambda_permission" "allow_cloudwatch_logs_to_call_dd_lambda_handler" {
      + action              = "lambda:InvokeFunction"
      + function_name       = (known after apply)
      + id                  = (known after apply)
      + principal           = "logs.us-east-2.amazonaws.com"
      + source_arn          = "arn:aws:logs:us-east-2::log-group:/aws/sagemaker/TransformJobs:*"
      + statement_id        = "_aws_sagemaker_TransformJobs-AllowExecutionFromCloudWatchLogs"
      + statement_id_prefix = (known after apply)
    }

In case `var.cloudwatch_log_groups` changes somewhere in the middle of the list, all resources indexed since that position must be recreated. This can be remedied by switching to `for_each` instead of `count`
@zbstof zbstof merged commit af7e1c2 into master Feb 15, 2024
4 checks passed
@zbstof zbstof deleted the zbstof-patch-1 branch February 15, 2024 14:25
Copy link

🎉 This PR is included in version 3.3.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants