title: Terraform AWS Cloudwatch Rule with Event Pattern not working
body: <p>I have been facing problem to trigger lambda from cloudwatch rule with event pattern created from terraform.</p>
  <p>Below is my terraform code:</p>
  <pre><code>resource &quot;aws_cloudwatch_event_rule&quot; &quot;event_rule_pattern&quot; {   
      name = &quot;test-event-rule&quot;   
      description = &quot;${var.description}&quot;   
      role_arn            = &quot;${var.execution_role}&quot;   
      event_pattern = &lt;&lt;PATTERN
       {
        &quot;source&quot;: [
          &quot;aws.ecs&quot;
        ],
        &quot;detail-type&quot;: [
          &quot;ECS Task State Change&quot;
        ],
        &quot;detail&quot;: {
          &quot;lastStatus&quot;: [
            &quot;STOPPED&quot;
          ],
          &quot;taskDefinitionArn&quot;: [
            &quot;${data.aws_ssm_parameter.task_arn.value}&quot;
          ]
        }
      }
    PATTERN
      tags = &quot;app&quot;
  }
      
      
  resource &quot;aws_cloudwatch_event_target&quot; &quot;event_target_pattern&quot; {   
      rule = &quot;${element(aws_cloudwatch_event_rule.event_rule_pattern.*.name, 0)}&quot;   
      arn       = &quot;${data.aws_ssm_parameter.special_alert_arn.value}&quot; 
  }
  </code></pre>
  <p>Above cloudwatch rule is to trigger lambda on completion of ECS task. So far it is able to trigger cloudwatch event at completion of ECS task, but failed to invoke lambda.</p>
  <p><a href="https://i.stack.imgur.com/0d5TC.png" rel="nofollow noreferrer">Failure Image</a></p>
  <p>After failure I was checking from aws ui console and just re-saved cloudwatch rule from aws ui console and it started working.</p>
  <p>So not sure but looks like terraform is not able to configured cloudwatch rule target properly or I have done something wrong on my side.</p>
  <p>Can some terraform/aws expert please help on this?</p>