Skip to content

Commit b8b9aed

Browse files
authored
Merge pull request #9 from StackGuardian/aws-oidc-complete-onboarding
onboarding-example-oidc
2 parents 95d281a + 67b79b7 commit b8b9aed

File tree

25 files changed

+555
-146
lines changed

25 files changed

+555
-146
lines changed

aws_oidc/main.tf

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,5 @@ resource "aws_iam_role" "oidc_role" {
3333
resource "aws_iam_policy_attachment" "sg_role_policy" {
3434
name = "${var.role_name}-policy"
3535
policy_arn = var.aws_policy
36-
roles = [aws_iam_role.sg-test-role.name]
37-
}
38-
39-
output "oidc_provider_arn" {
40-
value = aws_iam_openid_connect_provider.oidc_provider.arn
41-
}
42-
43-
output "oidc_role_arn" {
44-
value = aws_iam_role.oidc_role.arn
36+
roles = [aws_iam_role.oidc_role.name]
4537
}

aws_oidc/provider.tf

Lines changed: 0 additions & 12 deletions
This file was deleted.

aws_oidc/variables.tf

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
variable "region" {
22
type = string
33
description = "the region for deploying the resources"
4-
default = "eu-central-1"
54
}
65

76
variable "url" {
87
type = string
98
description = "URL of the identity provider"
10-
default = "https://api.app.stackguardian.io"
119
}
1210

1311
variable "client_id" {
1412
type = string
15-
description = "List of client IDs (audiences) that identify the application registered with the OpenID Connect provider"
16-
default = "https://api.app.stackguardian.io"
13+
description = "List of client IDs (audiences) that identify the application registered with the OpenID Connect provider"
1714
}
1815

1916
variable "role_name" {
2017
type = string
2118
description = "name of the aws role thats getting created"
22-
default = "test-clara-001"
2319
}
2420

2521
variable "org_name" {
2622
type = string
2723
description = "the name of the StackGuardian Organization"
28-
default = "wicked-hop"
2924
}
3025

3126
variable "account_number" {
3227
type = number
3328
description = "the value of the account number"
34-
default = 790543352839
3529
}
3630

31+
variable "aws_policy" {
32+
type = string
33+
description = "arn of aws policy"
34+
}

main.tf

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# ################################
2+
# # Stackguardian Workflow Group
3+
# ################################
4+
module "stackguardian_workflow_group" {
5+
source = "../terraform-stackguardian-modules/stackguardian_workflow_group"
6+
api_key = var.api_key
7+
org_name = var.org_name
8+
workflow_group_name = var.workflow_group_name
9+
}
10+
11+
# ################################
12+
# # Stackguardian aws oidc
13+
# ################################
14+
module "aws_oidc" {
15+
source = "../terraform-stackguardian-modules/aws_oidc"
16+
account_number = var.account_number
17+
client_id = var.client_id
18+
region = var.region
19+
aws_policy = var.aws_policy
20+
role_name = var.role_name
21+
url = var.url
22+
org_name = var.org_name
23+
}
24+
25+
# ################################
26+
# # Stackguardian cloud connector
27+
# ################################
28+
module "stackguardian_connector_cloud" {
29+
source = "../terraform-stackguardian-modules/stackguardian_connector_cloud"
30+
cloud_connector_name = var.cloud_connector_name
31+
connector_type = var.connector_type
32+
api_key = var.api_key
33+
org_name = var.org_name
34+
35+
role_arn = module.aws_oidc.oidc_role_arn
36+
37+
aws_access_key_id = var.aws_access_key_id
38+
aws_secret_access_key = var.aws_secret_access_key
39+
aws_default_region = var.aws_default_region
40+
41+
armTenantId = var.armTenantId
42+
armSubscriptionId = var.armSubscriptionId
43+
armClientId = var.client_id
44+
armClientSecret = var.armClientSecret
45+
}
46+
47+
################################
48+
# Stackguardian vcs
49+
################################
50+
locals {
51+
# Determine which VCS connector to create based on non-empty credentials
52+
selected_connector = merge(
53+
# If GitLab creds are provided, use GitLab connector
54+
length(var.gitlab_creds) > 0 ? {
55+
vcs_gitlab = {
56+
kind = "GITLAB_COM"
57+
config = [{
58+
gitlab_creds = var.gitlab_creds
59+
}]
60+
}
61+
} : {},
62+
63+
# If GitHub creds are provided, use GitHub connector
64+
length(var.github_creds) > 0 ? {
65+
vcs_github = {
66+
kind = "GITHUB_COM"
67+
config = [{
68+
github_creds = var.github_creds
69+
}]
70+
}
71+
} : {},
72+
73+
# If Bitbucket creds are provided, use Bitbucket connector
74+
length(var.bitbucket_creds) > 0 ? {
75+
vcs_bitbucket = {
76+
kind = "BITBUCKET_COM"
77+
config = [{
78+
bitbucket_creds = var.bitbucket_creds
79+
}]
80+
}
81+
} : {}
82+
)
83+
}
84+
85+
module "stackguardian_connector_vcs" {
86+
source = "../terraform-stackguardian-modules/stackguardian_connector_vcs"
87+
stackguardian_connector_vcs_name = var.stackguardian_connector_vcs_name
88+
api_key = var.api_key
89+
org_name = var.org_name
90+
stackguardian_connector_kinds = local.selected_connector
91+
}
92+
93+
################################
94+
# Stackguardian role
95+
################################
96+
module "stackguardian_role" {
97+
source = "../terraform-stackguardian-modules/stackguardian_role"
98+
api_key = var.api_key
99+
org_name = var.org_name
100+
role_name = var.role_name
101+
cloud_connector = var.cloud_connector
102+
stackguardian_connector_vcs = var.stackguardian_connector_vcs
103+
workflow_group = var.workflow_group
104+
template_list = var.template_list
105+
#depends_on = [ module.stackguardian_workflow_group, module.stackguardian_connector_cloud, module.stackguardian_connector_vcs ]
106+
}
107+
108+
# ################################
109+
# # Stackguardian role assignment
110+
# ################################
111+
module "stackguardian_role_assignment" {
112+
source = "../terraform-stackguardian-modules/stackguardian_role_assignment"
113+
api_key = var.api_key
114+
org_name = var.org_name
115+
role_name = var.role_name
116+
user_or_group = var.user_or_group
117+
entity_type = var.entity_type
118+
}

provider.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
terraform {
2+
required_providers {
3+
stackguardian = {
4+
source = "StackGuardian/stackguardian"
5+
version = "1.1.0-rc5"
6+
}
7+
aws = {
8+
source = "hashicorp/aws"
9+
version = "5.84.0"
10+
}
11+
}
12+
}
13+
14+
# StackGuardian provider configuration
15+
provider "stackguardian" {
16+
api_key = var.api_key
17+
org_name = var.org_name
18+
api_uri = "https://api.app.stackguardian.io"
19+
}
20+
21+
# AWS provider configuration
22+
provider "aws" {
23+
region = var.region
24+
}

stackguardian_connector_cloud/main.tf

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
resource "stackguardian_connector" "sg_aws_static_connector" {
22
count = (var.connector_type == "AWS_STATIC") ? 1 : 0
3-
resource_name = var.resource_name
3+
resource_name = var.cloud_connector_name
44
description = "Onboarding example of terraform-provider-stackguardian for AWSConnectorCloud"
55
settings = {
66
kind = var.connector_type,
@@ -10,12 +10,24 @@ resource "stackguardian_connector" "sg_aws_static_connector" {
1010
aws_default_region = var.aws_default_region
1111
}]
1212
}
13-
scope = ["*"]
13+
}
14+
15+
16+
resource "stackguardian_connector" "sg_aws_oidc_connector" {
17+
count = (var.connector_type == "AWS_OIDC") ? 1 : 0
18+
resource_name = var.cloud_connector_name
19+
description = "Onboarding example of terraform-provider-stackguardian for AWSConnectorCloud"
20+
settings = {
21+
kind = var.connector_type,
22+
config = [{
23+
role_arn = var.role_arn
24+
}]
25+
}
1426
}
1527

1628
resource "stackguardian_connector" "sg_azure_static_connector" {
1729
count = (var.connector_type == "AZURE_STATIC") ? 1 : 0
18-
resource_name = var.resource_name
30+
resource_name = var.cloud_connector_name
1931
description = "Onboarding example of terraform-provider-stackguardian for AzureConnectorCloud"
2032
settings = {
2133
kind = var.connector_type,
@@ -26,5 +38,4 @@ resource "stackguardian_connector" "sg_azure_static_connector" {
2638
armClientSecret = var.armClientSecret
2739
}]
2840
}
29-
scope = ["*"]
3041
}

stackguardian_connector_cloud/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
output "resource_name" {
22
description = "Cloud Connector Name created"
3-
value = var.resource_name
3+
value = var.cloud_connector_name
44
}
55
output "connector_type" {
66
description = "Cloud Connector Type created"

stackguardian_connector_cloud/provider.tf

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ terraform {
22
required_providers {
33
stackguardian = {
44
source = "StackGuardian/stackguardian"
5-
version = "1.0.0-rc3"
5+
version = "1.1.0-rc5"
66
}
77
}
88
}
99

1010
provider "stackguardian" {
11-
12-
api_key = var.api_key # Replace this with your API key(test wiothout it)
13-
org_name = var.org_name # Replace this with your organization name
14-
api_uri = "https://testapi.qa.stackguardian.io" # Use testapi instead of production for testing
11+
api_key = var.api_key
12+
org_name = var.org_name
13+
api_uri = "https://api.app.stackguardian.io"
1514
}
Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
variable "connector_type" {
1+
variable "api_key" {
22
type = string
3-
# AWS_STATIC, AWS_RBAC, AWS_OIDC, AZURE_STATIC, AZURE_OIDC, GCP_STATIC
3+
description = "Your organization's API key on the StackGuardian Platform"
44
}
55

6-
variable "resource_name" {
7-
type = string
8-
description = "Name of the Cloud connector"
9-
}
10-
variable "api_key" {
6+
variable "org_name" {
117
type = string
12-
description = "API key to authenticate to StackGuardian"
8+
description = "Your organization name on StackGuardian Platform"
139
}
14-
variable "org_name" {
10+
11+
variable "connector_type" {
1512
type = string
16-
description = "Organisation name in StackGuardian platform"
13+
description = "type of connector. You can select anyone of the following AWS_STATIC, AWS_RBAC, AWS_OIDC, AZURE_STATIC, AZURE_OIDC, GCP_STATIC"
14+
}
15+
16+
variable "cloud_connector_name" {
17+
type = string
18+
description = "Name of the Cloud connector"
1719
}
1820

1921

@@ -23,42 +25,47 @@ variable "org_name" {
2325

2426
variable "aws_access_key_id" {
2527
type = string
26-
description = "AWS ACCESS Key ID"
27-
default = ""
28+
description = "your AWS acoount access key"
2829
}
30+
2931
variable "aws_secret_access_key" {
3032
type = string
31-
description = "AWS ACCESS Key Secret"
32-
default = ""
33+
description = "your AWS account secret access key"
3334
}
35+
3436
variable "aws_default_region" {
3537
type = string
36-
description = "AWS Default Region for Connector"
37-
default = ""
38+
description = "any default region you want to set, for all your deployments"
3839
}
3940

4041
################
4142
# AZURE_STATIC Credentials
4243
################
4344

44-
4545
variable "armTenantId" {
4646
type = string
47-
description = "Azure Tenant ID"
48-
default = ""
47+
description = "your azure account tenant id"
4948
}
49+
5050
variable "armSubscriptionId" {
5151
type = string
52-
description = "Subscription ID"
53-
default = ""
52+
description = "your azure subscription id"
5453
}
54+
5555
variable "armClientId" {
5656
type = string
57-
description = "Client ID for Enterprise App"
58-
default = ""
57+
description = "your azure client id"
5958
}
59+
6060
variable "armClientSecret" {
6161
type = string
62-
description = "Client Secret for Enterprise App"
63-
default = ""
62+
description = "your azure client secret"
63+
}
64+
65+
################
66+
# aws_oidc
67+
################
68+
variable "role_arn" {
69+
type = string
70+
description = "arn of the aws oidc role"
6471
}

0 commit comments

Comments
 (0)