Skip to content

Commit bca0e59

Browse files
author
ramureddy
committed
add aws creds
1 parent a178e0a commit bca0e59

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

Jenkinsfile

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ pipeline {
66
choice(name: 'action', choices: 'create\ndestroy', description: 'Create/update or destroy the eks cluster.')
77
string(name: 'aws_region', defaultValue : 'us-west-2', description: "AWS region.")
88
string(name: 'env', defaultValue: 'la', description: "lab environment")
9-
string(name: 'rolename', defaultValue: 'aws-jenkins', description: "default aws role for jenkins")
10-
string(name: 'role-account', defaultValue: '843653485881', description: "default aws role account for jenkins")
9+
//string(name: 'rolename', defaultValue: 'aws-jenkins', description: "default aws role for jenkins")
10+
//string(name: 'role-account', defaultValue: '534992115889', description: "default aws role account for jenkins")
1111
string(name: 'cluster', defaultValue: 'twistlock-eks-terraform', description: "eks cluster name")
1212
string(name: 'cidrblock', defaultValue : '10.123.0.0/16', description: "First 2 octets of vpc network; eg 10.0")
1313
string(name: 'cidr_public', defaultValue: '["10.123.1.0/24","10.123.2.0/24"]', description: "cidr block for public subnets")
1414
string(name: 'cidr_private', defaultValue: '["10.123.3.0/24","10.123.4.0/24"]', description: "cidr block for private subnets")
1515
string(name: 'count', defaultValue : '2', description: "Number of vpc subnets/AZs.")
16-
//string(name: 'credential', defaultValue : 'aws-jenkins', description: "Jenkins credential that provides the AWS access key and secret.")
16+
string(name: 'credential', defaultValue : 'jenkins-la', description: "Jenkins credential that provides the AWS access key and secret.")
1717
string(name: 'accessIp', defaultValue: '0.0.0.0/0', description: "cidr block for bastion host restrict to your ip or vpn")
1818
string(name: 'instancetype', defaultValue: 't2.micro', description: "instance type for ec2")
1919
string(name: 'keyname', defaultValue: 'tfs-key', description: "keyname to be used for ssh access to ec2 vm")
@@ -25,7 +25,7 @@ pipeline {
2525
options {
2626
disableConcurrentBuilds()
2727
timeout(time: 1, unit: 'HOURS')
28-
//withAWS(credentials: params.credential, region: params.region)
28+
withAWS(credentials: params.credential, region: params.aws_region)
2929
}
3030

3131
agent { label 'master' }
@@ -67,7 +67,11 @@ pipeline {
6767
}
6868
steps {
6969
script {
70-
withAWS([profile:${params.env}, region:${params.aws_region}, role:${params.rolename}, roleAccount:${params.role-account}]) {
70+
//withAWS([profile:${params.env}, region:${params.aws_region}, role:${params.rolename}, roleAccount:${params.role-account}])
71+
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',
72+
credentialsId: params.credential,
73+
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
74+
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
7175

7276

7377
sh """
@@ -96,8 +100,11 @@ pipeline {
96100
script {
97101
input "Create/update Terraform stack eks-${params.cluster} in aws?"
98102

99-
withAWS([profile:${params.env}, region:${params.aws_region}, role:${params.rolename}, roleAccount:${params.role-account}]) {
100-
103+
//withAWS([profile:${params.env}, region:${params.aws_region}, role:${params.rolename}, roleAccount:${params.role-account}]) {
104+
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',
105+
credentialsId: params.credential,
106+
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
107+
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
101108
sh """
102109
cd terraform-aws-secure-webapplication
103110
terraform apply -input=false -auto-approve ${plan}
@@ -115,8 +122,11 @@ pipeline {
115122
script {
116123
input "Destroy Terraform stack eks-${params.cluster} in aws?"
117124

118-
withAWS([profile:${params.env}, region:${params.aws_region}, role:${params.rolename}, roleAccount:${params.role-account}]) {
119-
125+
// withAWS([profile:${params.env}, region:${params.aws_region}, role:${params.rolename}, roleAccount:${params.role-account}]) {
126+
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',
127+
credentialsId: params.credential,
128+
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
129+
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
120130
sh """
121131
cd terraform-aws-secure-webapplication
122132
terraform destroy -auto-approve

main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#-----------Provider AWS --------------------
22
provider "aws" {
33
region = var.aws_region
4-
//shared_credentials_file = "~/.aws/credentials"
5-
assume_role {
6-
role_arn = "arn:aws:iam::${var.role_acc}:role/aws-jenkins"
7-
}
4+
#shared_credentials_file = "~/.aws/credentials"
5+
#assume_role {
6+
# role_arn = "arn:aws:iam::${var.role_acc}:role/aws-jenkins"
7+
#}
88
profile = var.env
99
version = "~> 2.0"
1010
}

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ variable "env" {
77
description = "specify the environment. eg: test or prod"
88
default = "la"
99
}
10-
10+
/*
1111
variable "role_acc" {
1212
description = "role account"
1313
default = "843653485881"
1414
}
15-
15+
*/
1616
variable "accessIp" {
1717
default = "0.0.0.0/0"
1818
description = "pass the cidr block for bastion host restricting access to your Mypublic ip or vpn ip or allow it from 0.0.0.0/0 if wanted to open for all"

0 commit comments

Comments
 (0)