title: Access a private docker registry with ECS Fargate and Terraform
body: <p>I need my ECS Task definition to contain the credentials of my private Docker registry, using if possible a simple token, or, a user:password.</p>
  <p>Below is my code:</p>
  <pre><code>resource &quot;aws_secretsmanager_secret&quot; &quot;docker_registry_secret&quot; {
    name_prefix = &quot;/my_environment/registry/pwd&quot;
  }
  
  resource &quot;aws_secretsmanager_secret_version&quot; &quot;docker_registry_secret_version&quot; {
    secret_id     = aws_secretsmanager_secret.docker_registry_secret.id
    secret_string = xxxMYTOKENxxx
  }
  
  resource &quot;aws_iam_role_policy&quot; &quot;password_policy_secretsmanager&quot; {
    name = &quot;${var.task_name}-secretsmanager&quot;
    role = aws_iam_role.MY_ECS_ROLE.id
  
    policy = &lt;&lt;-EOF
    {
      &quot;Version&quot;: &quot;2012-10-17&quot;,
      &quot;Statement&quot;: [
        {
          &quot;Action&quot;: [
            &quot;secretsmanager:GetSecretValue&quot;
          ],
          &quot;Effect&quot;: &quot;Allow&quot;,
          &quot;Resource&quot;: [
            &quot;${aws_secretsmanager_secret.docker_registry_secret.arn}&quot;,
          ]
        }
      ]
    }
    EOF
  }
  
  resource &quot;aws_ecs_task_definition&quot; &quot;task_to_be_scheduled&quot; {
    .....
    ....
    requires_compatibilities = [&quot;FARGATE&quot;]
    network_mode             = &quot;awsvpc&quot;
    container_definitions = jsonencode([
      {
        &quot;repositoryCredentials&quot; : {
          &quot;credentialsParameter&quot; : aws_secretsmanager_secret.docker_registry_secret.arn
        },
        ....
        ....
    ])
  }
  </code></pre>
  <p>However, when I launch my task, I have the following error on my ECS: <strong>unable to unmarshal secret value of authorization data from asm</strong></p>
  <p>I'm pretty sure the error is related to secret manager, but not sure where exactly. Any idea what I'm doing wrong?</p>