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 17, 2019 in Jenkins by anonymous
2,531 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 17, 2019 by Jaimy

Related Questions In Jenkins

+1 vote
1 answer
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
• 7,060 points
6,842 views
+1 vote
6 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
48,242 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
• 10,620 points
8,302 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
41,299 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,680 points
5,562 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 2, 2018 in Jenkins by Sophie may
• 10,620 points
5,185 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,520 points
36,364 views
0 votes
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP