Use terraform to generate HTTPS Git credentials for AWS CodeCommit

0 votes

I am using terraform to create IAM User. How to use terraform to generate HTTPS Git credentials for AWS CodeCommit?

My code :

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"
}
Apr 16, 2019 in Jenkins by anonymous
571 views

1 answer to this question.

0 votes

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", "")}"
}
answered Apr 16, 2019 by Jaimy

Related Questions In Jenkins

0 votes
2 answers

Is possible for Jenkins to auto start and stop slave nodes?

Try Jenkins Plugin called as Slave SetupPlugin. This ...READ MORE

answered Aug 6, 2018 in Jenkins by Nilesh
• 6,970 points
2,053 views
+1 vote
5 answers

Unable to login to Jenkins even if I enter valid credentials.

Disable security by editing these two classes ...READ MORE

answered Apr 26, 2019 in Jenkins by Vedant
11,755 views
+1 vote
1 answer

Unable to access Jenkins. I newly installed Jenkins but for some reason I cannot access it.

Try changing the port, Change JENKINS_AJP_PORT="xyz" to JENKINS_AJP_PORT="abc" If changing the ...READ MORE

answered Jul 4, 2018 in Jenkins by Sophie may
• 9,940 points
921 views
+2 votes
6 answers

Jenkins unable to run jobs (pending - waiting for next executor)

Increase the number of executors. I had ...READ MORE

answered Apr 24, 2019 in Jenkins by Maya
12,103 views
+1 vote
3 answers
0 votes
1 answer

Jenkins failed to set git

Change to the jenkins user and run the command ...READ MORE

answered Jul 19, 2018 in Jenkins by Kalgi
• 2,620 points
1,855 views
0 votes
1 answer

How to construct Maven installation in Jenkins for each Slave node?

I’m assuming that Java and Maven are ...READ MORE

answered Aug 1, 2018 in Jenkins by Sophie may
• 9,940 points
1,557 views
+4 votes
7 answers

How to set the pipeline name and description for a Jenkinsfile?

You can rename pipeline jobs in jenkins ...READ MORE

answered Oct 11, 2018 in Jenkins by Hannah
• 18,060 points
15,482 views
0 votes
2 answers