Use data.external to execute a CLI script:
credentials=$(aws --profile dev iam list-service-specific-credentials \
--user-name jenkins --service-name codecommit.amazonaws.com --query 'ServiceSpecificCredentials[0]')
if [[ $credentials == "null" ]]; then
credentials=$(aws --profile dev iam create-service-specific-credential --user-name jenkins \
--service-name codecommit.amazonaws.com --query ServiceSpecificCredential)
fi
echo "$credentials"
Then the terraform:
data "external" "jenkins" {
count = "${local.is_pcs_dev}"
program = ["${path.root}/jenkins.sh"]
}
resource "aws_ssm_parameter" "jenkins_cc_id" {
name = "${local.jenkins}/codecommit_https_user"
value = "${lookup(data.external.jenkins.result, "ServiceUserName", "")}"
}
resource "aws_ssm_parameter" "jenkins_cc_p" {
name = "${local.jenkins}/codecommit_https_pass"
value = "${lookup(data.external.jenkins.result, "ServicePassword", "")}"
}