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      = ["${}"]
  policy_arn = "arn:aws:iam::aws:policy/AWSCodeCommitPowerUser"
Apr 16 in Jenkins by anonymous

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 --query 'ServiceSpecificCredentials[0]')

if [[ $credentials == "null" ]]; then
  credentials=$(aws --profile dev iam create-service-specific-credential --user-name jenkins \
  --service-name --query ServiceSpecificCredential)
echo "$credentials"

Then the terraform:

data "external" "jenkins" {
  count   = "${local.is_pcs_dev}"
  program = ["${path.root}/"]

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 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,880 points
+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 in Jenkins by Vedant
0 votes
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,850 points
+2 votes
6 answers
+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
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,850 points
0 votes
2 answers

Managing SSH keys within Jenkins for Git

Have you tried logging in as the ...READ MORE

answered Aug 8 in Jenkins by Sirajul
• 35,810 points
+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
• 16,210 points
0 votes
2 answers