Hey guys,
I am trying to create small POC of testing SFN workflow on Localstack through Terraform
(I am aware of https://github.com/whummer/localstack-demo using serverless, but I'd like to get this to work with terraform )
Terraform template : 
```
provider "aws" {
  access_key                  = "mock_access_key"
  region                      = "us-east-1"
  s3_force_path_style         = true
  secret_key                  = "mock_secret_key"
  skip_credentials_validation = true
  skip_metadata_api_check     = true
  skip_requesting_account_id  = true

  endpoints {
    apigateway     = "http://localhost:4567"
    cloudformation = "http://localhost:4581"
    cloudwatch     = "http://localhost:4582"
    dynamodb       = "http://localhost:4569"
    es             = "http://localhost:4578"
    firehose       = "http://localhost:4573"
    iam            = "http://localhost:4593"
    kinesis        = "http://localhost:4568"
    lambda         = "http://localhost:4574"
    route53        = "http://localhost:4580"
    redshift       = "http://localhost:4577"
    s3             = "http://localhost:4572"
    secretsmanager = "http://localhost:4584"
    ses            = "http://localhost:4579"
    sns            = "http://localhost:4575"
    sqs            = "http://localhost:4576"
    ssm            = "http://localhost:4583"
    stepfunctions  = "http://localhost:4585"
    sts            = "http://localhost:4592"
  }
}

data "aws_iam_policy_document" "lambda_assume_policy" {
  statement {
    sid    = ""
    effect = "Allow"

    principals {
      identifiers = ["lambda.amazonaws.com"]
      type        = "Service"
    }

    actions = ["sts:AssumeRole"]
  }
}

data "aws_iam_policy_document" "sfn_assume_policy" {
  statement {
    sid    = ""
    effect = "Allow"

    principals {
      identifiers = ["states.eu-west-1.amazonaws.com"]
      type        = "Service"
    }

    actions = ["sts:AssumeRole"]
  }
}

resource "aws_iam_role" "iam_for_lambda_add" {
  name               = "iam_for_lambda_add"
  assume_role_policy = "${data.aws_iam_policy_document.lambda_assume_policy.json}"
}

resource "aws_iam_role" "iam_for_lambda_subtract" {
  name               = "iam_for_lambda_subtract"
  assume_role_policy = "${data.aws_iam_policy_document.lambda_assume_policy.json}"
}

resource "aws_iam_role" "iam_for_sfn" {
  name               = "iam_for_sfn"
  assume_role_policy = "${data.aws_iam_policy_document.sfn_assume_policy.json}"
}

resource "aws_iam_role_policy_attachment" "lambda-invocation" {
  role       = "${aws_iam_role.iam_for_sfn.name}"
  policy_arn = "arn:aws:iam::aws:policy/AWSLambdaFullAccess"
}

resource "aws_lambda_function" "add_lambda" {
  filename      = "${path.cwd}/../dist/local-stack-take-one.zip"
  function_name = "add"
  role          = "${aws_iam_role.iam_for_lambda_add.arn}"
  handler       = "index.add"

  runtime = "nodejs8.10"
}

resource "aws_lambda_function" "subtract_lambda" {
  filename      = "${path.cwd}/../dist/local-stack-take-one.zip"
  function_name = "subtract"
  role          = "${aws_iam_role.iam_for_lambda_subtract.arn}"
  handler       = "index.subtract"

  runtime = "nodejs8.10"
}

resource "aws_sfn_state_machine" "sfn_state_machine" {
  name     = "my-state-machine"
  role_arn = "${aws_iam_role.iam_for_sfn.arn}"

  definition = <<EOF
{
  "Comment": "A Hello World example of the Amazon States Language using an AWS Lambda Function",
  "StartAt": "AddNumbers",
  "States": {
    "AddNumbers": {
      "Type": "Task",
      "Resource": "${aws_lambda_function.add_lambda.arn}",
      "Next":"SubtractNumbers"
    },
    "SubtractNumbers": {
      "Type": "Task",
      "Resource": "${aws_lambda_function.subtract_lambda.arn}",
      "End": true
    }
  }
}
EOF
}
```
errors:
``` 
 terraform apply --auto-approve
data.aws_iam_policy_document.lambda_assume_policy: Refreshing state...
data.aws_iam_policy_document.sfn_assume_policy: Refreshing state...
aws_iam_role.iam_for_lambda_subtract: Refreshing state... (ID: iam_for_lambda_subtract)
aws_iam_role.iam_for_lambda_add: Refreshing state... (ID: iam_for_lambda_add)
aws_iam_role.iam_for_sfn: Refreshing state... (ID: iam_for_sfn)

Error: Error refreshing state: 3 error(s) occurred:

* aws_iam_role.iam_for_lambda_add: 1 error(s) occurred:

* aws_iam_role.iam_for_lambda_add: aws_iam_role.iam_for_lambda_add: Error reading IAM Role iam_for_lambda_add: SerializationError: failed to unmarshal error message
        status code: 404, request id: 
caused by: UnmarshalError: failed to unmarshal error message
        00000000  3c 3f 78 6d 6c 20 76 65  72 73 69 6f 6e 3d 22 31  |<?xml version="1|
00000010  2e 30 22 20 65 6e 63 6f  64 69 6e 67 3d 22 55 54  |.0" encoding="UT|
00000020  46 2d 38 22 3f 3e 0a 20  20 3c 52 65 73 70 6f 6e  |F-8"?>.  <Respon|
00000030  73 65 3e 0a 20 20 20 20  3c 45 72 72 6f 72 73 3e  |se>.    <Errors>|
00000040  0a 20 20 20 20 20 20 3c  45 72 72 6f 72 3e 0a 20  |.      <Error>. |
00000050  20 20 20 20 20 20 20 3c  43 6f 64 65 3e 4e 6f 53  |       <Code>NoS|
00000060  75 63 68 45 6e 74 69 74  79 3c 2f 43 6f 64 65 3e  |uchEntity</Code>|
00000070  0a 20 20 20 20 20 20 20  20 3c 4d 65 73 73 61 67  |.        <Messag|
00000080  65 3e 52 6f 6c 65 20 69  61 6d 5f 66 6f 72 5f 6c  |e>Role iam_for_l|
00000090  61 6d 62 64 61 5f 61 64  64 20 6e 6f 74 20 66 6f  |ambda_add not fo|
000000a0  75 6e 64 3c 2f 4d 65 73  73 61 67 65 3e 0a 20 20  |und</Message>.  |
000000b0  20 20 20 20 20 20 0a 20  20 20 20 20 20 3c 2f 45  |      .      </E|
000000c0  72 72 6f 72 3e 0a 20 20  20 20 3c 2f 45 72 72 6f  |rror>.    </Erro|
000000d0  72 73 3e 0a 20 20 3c 52  65 71 75 65 73 74 49 44  |rs>.  <RequestID|
000000e0  3e 37 61 36 32 63 34 39  66 2d 33 34 37 65 2d 34  |>7a62c49f-347e-4|
000000f0  66 63 34 2d 39 33 33 31  2d 36 65 38 65 45 58 41  |fc4-9331-6e8eEXA|
00000100  4d 50 4c 45 3c 2f 52 65  71 75 65 73 74 49 44 3e  |MPLE</RequestID>|
00000110  0a 3c 2f 52 65 73 70 6f  6e 73 65 3e              |.</Response>|

caused by: unknown error response tag, {{ Response} []}
* aws_iam_role.iam_for_lambda_subtract: 1 error(s) occurred:

* aws_iam_role.iam_for_lambda_subtract: aws_iam_role.iam_for_lambda_subtract: Error reading IAM Role iam_for_lambda_subtract: SerializationError: failed to unmarshal error message
        status code: 404, request id: 
caused by: UnmarshalError: failed to unmarshal error message
        00000000  3c 3f 78 6d 6c 20 76 65  72 73 69 6f 6e 3d 22 31  |<?xml version="1|
00000010  2e 30 22 20 65 6e 63 6f  64 69 6e 67 3d 22 55 54  |.0" encoding="UT|
00000020  46 2d 38 22 3f 3e 0a 20  20 3c 52 65 73 70 6f 6e  |F-8"?>.  <Respon|
00000030  73 65 3e 0a 20 20 20 20  3c 45 72 72 6f 72 73 3e  |se>.    <Errors>|
00000040  0a 20 20 20 20 20 20 3c  45 72 72 6f 72 3e 0a 20  |.      <Error>. |
00000050  20 20 20 20 20 20 20 3c  43 6f 64 65 3e 4e 6f 53  |       <Code>NoS|
00000060  75 63 68 45 6e 74 69 74  79 3c 2f 43 6f 64 65 3e  |uchEntity</Code>|
00000070  0a 20 20 20 20 20 20 20  20 3c 4d 65 73 73 61 67  |.        <Messag|
00000080  65 3e 52 6f 6c 65 20 69  61 6d 5f 66 6f 72 5f 6c  |e>Role iam_for_l|
00000090  61 6d 62 64 61 5f 73 75  62 74 72 61 63 74 20 6e  |ambda_subtract n|
000000a0  6f 74 20 66 6f 75 6e 64  3c 2f 4d 65 73 73 61 67  |ot found</Messag|
000000b0  65 3e 0a 20 20 20 20 20  20 20 20 0a 20 20 20 20  |e>.        .    |
000000c0  20 20 3c 2f 45 72 72 6f  72 3e 0a 20 20 20 20 3c  |  </Error>.    <|
000000d0  2f 45 72 72 6f 72 73 3e  0a 20 20 3c 52 65 71 75  |/Errors>.  <Requ|
000000e0  65 73 74 49 44 3e 37 61  36 32 63 34 39 66 2d 33  |estID>7a62c49f-3|
000000f0  34 37 65 2d 34 66 63 34  2d 39 33 33 31 2d 36 65  |47e-4fc4-9331-6e|
00000100  38 65 45 58 41 4d 50 4c  45 3c 2f 52 65 71 75 65  |8eEXAMPLE</Reque|
00000110  73 74 49 44 3e 0a 3c 2f  52 65 73 70 6f 6e 73 65  |stID>.</Response|
00000120  3e                                                |>|

caused by: unknown error response tag, {{ Response} []}
* aws_iam_role.iam_for_sfn: 1 error(s) occurred:

* aws_iam_role.iam_for_sfn: aws_iam_role.iam_for_sfn: Error reading IAM Role iam_for_sfn: SerializationError: failed to unmarshal error message
        status code: 404, request id: 
caused by: UnmarshalError: failed to unmarshal error message
        00000000  3c 3f 78 6d 6c 20 76 65  72 73 69 6f 6e 3d 22 31  |<?xml version="1|
00000010  2e 30 22 20 65 6e 63 6f  64 69 6e 67 3d 22 55 54  |.0" encoding="UT|
00000020  46 2d 38 22 3f 3e 0a 20  20 3c 52 65 73 70 6f 6e  |F-8"?>.  <Respon|
00000030  73 65 3e 0a 20 20 20 20  3c 45 72 72 6f 72 73 3e  |se>.    <Errors>|
00000040  0a 20 20 20 20 20 20 3c  45 72 72 6f 72 3e 0a 20  |.      <Error>. |
00000050  20 20 20 20 20 20 20 3c  43 6f 64 65 3e 4e 6f 53  |       <Code>NoS|
00000060  75 63 68 45 6e 74 69 74  79 3c 2f 43 6f 64 65 3e  |uchEntity</Code>|
00000070  0a 20 20 20 20 20 20 20  20 3c 4d 65 73 73 61 67  |.        <Messag|
00000080  65 3e 52 6f 6c 65 20 69  61 6d 5f 66 6f 72 5f 73  |e>Role iam_for_s|
00000090  66 6e 20 6e 6f 74 20 66  6f 75 6e 64 3c 2f 4d 65  |fn not found</Me|
000000a0  73 73 61 67 65 3e 0a 20  20 20 20 20 20 20 20 0a  |ssage>.        .|
000000b0  20 20 20 20 20 20 3c 2f  45 72 72 6f 72 3e 0a 20  |      </Error>. |
000000c0  20 20 20 3c 2f 45 72 72  6f 72 73 3e 0a 20 20 3c  |   </Errors>.  <|
000000d0  52 65 71 75 65 73 74 49  44 3e 37 61 36 32 63 34  |RequestID>7a62c4|
000000e0  39 66 2d 33 34 37 65 2d  34 66 63 34 2d 39 33 33  |9f-347e-4fc4-933|
000000f0  31 2d 36 65 38 65 45 58  41 4d 50 4c 45 3c 2f 52  |1-6e8eEXAMPLE</R|
00000100  65 71 75 65 73 74 49 44  3e 0a 3c 2f 52 65 73 70  |equestID>.</Resp|
00000110  6f 6e 73 65 3e                                    |onse>|

caused by: unknown error response tag, {{ Response} []}
```
<!-- Love localstack? Please consider supporting our collective:
👉  https://opencollective.com/localstack/donate -->
import re
from localstack.constants import TEST_AWS_ACCOUNT_ID
from localstack.utils.common import to_str
from localstack.services.generic_proxy import ProxyListener
class ProxyListenerIAM(ProxyListener):
    def return_response(self, method, path, data, headers, response):
        
        if response.content:
            content = to_str(response.content)
            pattern = r'<Arn>\s*arn:aws:iam::([0-9]+):([^<]+)</Arn>'
            replacement = r'<Arn>arn:aws:iam::%s:\2</Arn>' % TEST_AWS_ACCOUNT_ID
            response._content = re.sub(pattern, replacement, content)
            response.headers['content-length'] = len(response._content)
UPDATE_IAM = ProxyListenerIAM()