如何为AWS CodeCommit生成HTTPS Git凭证?

时间:2019-01-23 11:01:00

标签: terraform-provider-aws

我使用Terraform创建IAM用户。 如何使用terraform为AWS CodeCommit生成HTTPS Git凭证?

我的代码:

resource "aws_iam_user" "gitlab" {
  name = "user-gitlab"
}

resource "aws_iam_policy_attachment" "gitlab" {
  name       = "iam-gitlab"
  users      = ["${aws_iam_user.gitlab.name}"]
  policy_arn = "arn:aws:iam::aws:policy/AWSCodeCommitPowerUser"
}

此致

2 个答案:

答案 0 :(得分:1)

使用data.external执行CLI脚本:

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"

然后是地形:

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", "")}"
}

答案 1 :(得分:0)

不幸的是,Terraform中似乎不支持此API。我建议您在AWS provider GitHub repo中发布功能请求。