title: How to use Terraform to define cloundwatch event rules to trigger StepFunction statemachine
body: <p>I have defined the creation of a StepFunction state machine in Terraform, now I want to set a timer to trigger the state machine everyday, I think probably using cloudwatch event rules is a good choice, I know how to set event rule to trigger a Lambda:</p>
  <pre><code>resource &quot;aws_cloudwatch_event_rule&quot; &quot;lambda_event_rule&quot; {
    name                = xxx
    schedule_expression = xxx
    description         = xxx
  }
  
  resource &quot;aws_cloudwatch_event_target&quot; &quot;lambda_event_target&quot; {
    target_id = xxx
    rule      = aws_cloudwatch_event_rule.lambda_event_rule.name
    arn       = xxx
  }
  
  #I must setup the right permissions using 'aws_lambda_permission' 
  #see: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target
  
  resource &quot;aws_lambda_permission&quot; &quot;lambda_event_permission&quot; {
    statement_id  = xxx
    action        = &quot;lambda:InvokeFunction&quot;
    function_name = xxx
    principal     = &quot;events.amazonaws.com&quot;
    source_arn    = aws_cloudwatch_event_rule.lambda_event_rule.name
  }
  </code></pre>
  <p>but how can I setup the permission part for triggerring a state machine? I couldn't find any examples about it, am I missing anything? Is it because we don't need a permission config for state machine? Can someone help please?</p>
  <p>Below is what I got to use cloudwatch event rules to trigger state machine so far:</p>
  <pre><code>resource &quot;aws_cloudwatch_event_rule&quot; &quot;step_function_event_rule&quot; {
    name                = xxx
    schedule_expression = xxx
    description         = xxx
  }
  
  resource &quot;aws_cloudwatch_event_target&quot; &quot;step_function_event_target&quot; {
    target_id = xxx
    rule      = aws_cloudwatch_event_rule.step_function_event_rule.name
    arn       = xxx
  }
  
  
  ?????What else should I add here?
  
  </code></pre>
  <p>PS: I found someone else was asking about a similar question <a href="https://discuss.hashicorp.com/t/aws-step-function-state-machine-execution-via-cloudwatch/2632" rel="nofollow noreferrer">here</a>, but no answers yet.</p>