Skip to content

Commit 8b28e36

Browse files
committed
restructuring of modules
1 parent b8b9aed commit 8b28e36

File tree

20 files changed

+247
-302
lines changed

20 files changed

+247
-302
lines changed

aws_oidc/main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Step 1: Create an OpenID Connect provider in AWS IAM
22
resource "aws_iam_openid_connect_provider" "oidc_provider" {
3-
url = var.url # OIDC provider URL
4-
client_id_list = [ var.client_id ] # OIDC client ID or the Audience id
3+
url = "https://api.app.stackguardian.io" # OIDC provider URL
4+
client_id_list = [ "https://api.app.stackguardian.io" ] # OIDC client ID or the Audience id
55
thumbprint_list = []
66
}
77

@@ -19,7 +19,7 @@ resource "aws_iam_role" "oidc_role" {
1919
"Action": "sts:AssumeRoleWithWebIdentity",
2020
"Condition": {
2121
"StringEquals": {
22-
"api.app.stackguardian.io:aud" = var.url
22+
"api.app.stackguardian.io:aud" = "https://api.app.stackguardian.io"
2323
},
2424
"StringLike": {
2525
"api.app.stackguardian.io:sub" = "/orgs/${var.org_name}"

aws_oidc/variables.tf

-10
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ variable "region" {
33
description = "the region for deploying the resources"
44
}
55

6-
variable "url" {
7-
type = string
8-
description = "URL of the identity provider"
9-
}
10-
11-
variable "client_id" {
12-
type = string
13-
description = "List of client IDs (audiences) that identify the application registered with the OpenID Connect provider"
14-
}
15-
166
variable "role_name" {
177
type = string
188
description = "name of the aws role thats getting created"

aws_rbac/main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_iam_role" "sg-test-role" {
2-
name = var.role_name
2+
name = var.aws_role_name
33
description = "StackGuardianIntegrationRole"
44
assume_role_policy = jsonencode({
55
Version = "2012-10-17"
@@ -23,7 +23,7 @@ resource "aws_iam_role" "sg-test-role" {
2323
}
2424

2525
resource "aws_iam_policy_attachment" "sg_role_policy" {
26-
name = "${var.role_name}-policy"
26+
name = "${var.aws_role_name}-policy"
2727
policy_arn = var.aws_policy
2828
roles = [aws_iam_role.sg-test-role.name]
2929
}

main.tf

+42-40
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,36 @@
1+
locals {
2+
cloud_connectors_list = [for con in var.cloud_connectors : con.name]
3+
}
4+
15
# ################################
26
# # Stackguardian Workflow Group
37
# ################################
48
module "stackguardian_workflow_group" {
5-
source = "../terraform-stackguardian-modules/stackguardian_workflow_group"
9+
for_each = toset(var.workflow_groups)
10+
source = "./stackguardian_workflow_group"
611
api_key = var.api_key
712
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
13+
workflow_group_name = each.key
2314
}
2415

2516
# ################################
2617
# # Stackguardian cloud connector
2718
# ################################
2819
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
20+
for_each = { for c in var.cloud_connectors : c.name => c }
21+
source = "./stackguardian_connector_cloud"
22+
cloud_connector_name = each.key
23+
connector_type = each.value.connector_type
24+
role_arn = each.value.role_arn
25+
role_external_id = each.value.aws_role_external_id
3226
api_key = var.api_key
3327
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
4528
}
4629

4730
################################
4831
# Stackguardian vcs
4932
################################
33+
/*
5034
locals {
5135
# Determine which VCS connector to create based on non-empty credentials
5236
selected_connector = merge(
@@ -81,26 +65,28 @@ locals {
8165
} : {}
8266
)
8367
}
68+
*/
69+
8470

85-
module "stackguardian_connector_vcs" {
86-
source = "../terraform-stackguardian-modules/stackguardian_connector_vcs"
87-
stackguardian_connector_vcs_name = var.stackguardian_connector_vcs_name
71+
module "vcs_connector" {
72+
source = "./stackguardian_connector_vcs"
73+
vcs_connectors = var.vcs_connectors
8874
api_key = var.api_key
8975
org_name = var.org_name
90-
stackguardian_connector_kinds = local.selected_connector
9176
}
9277

78+
9379
################################
9480
# Stackguardian role
9581
################################
9682
module "stackguardian_role" {
97-
source = "../terraform-stackguardian-modules/stackguardian_role"
83+
source = "./stackguardian_role"
9884
api_key = var.api_key
9985
org_name = var.org_name
10086
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
87+
cloud_connectors = [for con in var.cloud_connectors : con.name]
88+
vcs_connectors = [for vcs in var.vcs_connectors : vcs.name]
89+
workflow_groups = var.workflow_groups
10490
template_list = var.template_list
10591
#depends_on = [ module.stackguardian_workflow_group, module.stackguardian_connector_cloud, module.stackguardian_connector_vcs ]
10692
}
@@ -109,10 +95,26 @@ module "stackguardian_role" {
10995
# # Stackguardian role assignment
11096
# ################################
11197
module "stackguardian_role_assignment" {
112-
source = "../terraform-stackguardian-modules/stackguardian_role_assignment"
98+
source = "./stackguardian_role_assignment"
11399
api_key = var.api_key
114100
org_name = var.org_name
115101
role_name = var.role_name
116102
user_or_group = var.user_or_group
117103
entity_type = var.entity_type
118-
}
104+
depends_on = [ module.stackguardian_role ]
105+
}
106+
107+
/*
108+
# ################################
109+
# # Create OIDC provider and StackGuardian Role in AWS
110+
# ################################
111+
module "aws_oidc" {
112+
count = var.account_number != null ? 1 : 0
113+
source = "./aws_oidc"
114+
account_number = var.account_number
115+
region = var.region
116+
aws_policy = var.aws_policy
117+
role_name = var.role_name
118+
org_name = var.org_name
119+
}
120+
*/

provider.tf

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ provider "stackguardian" {
1919
}
2020

2121
# AWS provider configuration
22+
/*
2223
provider "aws" {
2324
region = var.region
2425
}
26+
*/

stackguardian_connector_cloud/main.tf

+15-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,25 @@ resource "stackguardian_connector" "sg_aws_static_connector" {
1616
resource "stackguardian_connector" "sg_aws_oidc_connector" {
1717
count = (var.connector_type == "AWS_OIDC") ? 1 : 0
1818
resource_name = var.cloud_connector_name
19-
description = "Onboarding example of terraform-provider-stackguardian for AWSConnectorCloud"
19+
description = "Onboarding an AWS Role with OIDC"
20+
settings = {
21+
kind = var.connector_type,
22+
config = [{
23+
role_arn = var.role_arn
24+
}]
25+
}
26+
}
27+
28+
resource "stackguardian_connector" "sg_aws_rbac_connector" {
29+
count = (var.connector_type == "AWS_RBAC") ? 1 : 0
30+
resource_name = var.cloud_connector_name
31+
description = "Onboarding an AWS Role with RBAC"
2032
settings = {
2133
kind = var.connector_type,
2234
config = [{
2335
role_arn = var.role_arn
36+
external_id = var.role_external_id
37+
duration_seconds = 3600
2438
}]
2539
}
2640
}

stackguardian_connector_cloud/provider.tf

-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,4 @@ terraform {
55
version = "1.1.0-rc5"
66
}
77
}
8-
}
9-
10-
provider "stackguardian" {
11-
api_key = var.api_key
12-
org_name = var.org_name
13-
api_uri = "https://api.app.stackguardian.io"
148
}

stackguardian_connector_cloud/variables.tf

+19-2
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ variable "cloud_connector_name" {
2626
variable "aws_access_key_id" {
2727
type = string
2828
description = "your AWS acoount access key"
29+
default = null
2930
}
3031

3132
variable "aws_secret_access_key" {
3233
type = string
3334
description = "your AWS account secret access key"
35+
default = null
3436
}
3537

3638
variable "aws_default_region" {
3739
type = string
3840
description = "any default region you want to set, for all your deployments"
41+
default = null
3942
}
4043

4144
################
@@ -45,27 +48,41 @@ variable "aws_default_region" {
4548
variable "armTenantId" {
4649
type = string
4750
description = "your azure account tenant id"
51+
default = null
52+
4853
}
4954

5055
variable "armSubscriptionId" {
5156
type = string
5257
description = "your azure subscription id"
58+
default = null
59+
5360
}
5461

5562
variable "armClientId" {
5663
type = string
5764
description = "your azure client id"
65+
default = null
66+
5867
}
5968

6069
variable "armClientSecret" {
6170
type = string
6271
description = "your azure client secret"
72+
default = null
6373
}
6474

6575
################
66-
# aws_oidc
76+
# AWS_OIDC Credentials + AWS_RBAC Credentials
6777
################
6878
variable "role_arn" {
6979
type = string
7080
description = "arn of the aws oidc role"
71-
}
81+
}
82+
83+
###### for AWS_RBAC the externalID is also needed
84+
variable "role_external_id" {
85+
type = string
86+
description = "external id of the aws rbac role"
87+
#default = "<org_name>:<random_string>"
88+
}

stackguardian_connector_vcs/main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
resource "stackguardian_connector" "sg_vcs_connector" {
1313
for_each = {
14-
for key, value in var.stackguardian_connector_kinds :
14+
for key, value in var.vcs_connectors :
1515
key => value if (
1616
# Check if any credentials are provided for gitlab, github or bitbucket
1717
(
@@ -22,8 +22,8 @@ resource "stackguardian_connector" "sg_vcs_connector" {
2222
)
2323
}
2424

25-
resource_name = var.stackguardian_connector_vcs_name
26-
description = "Onboarding example of terraform-provider-stackguardian for ConnectorVcs"
25+
resource_name = each.value.name
26+
description = "Onboarding VCS connector"
2727

2828
settings = {
2929
kind = each.value.kind
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
output "connector_vcs" {
22
description = "Created VCS connector"
3-
value = var.stackguardian_connector_vcs_name
3+
value = [for con in var.vcs_connectors : con.name]
44
}

stackguardian_connector_vcs/provider.tf

-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,4 @@ terraform {
55
version = "1.1.0-rc5"
66
}
77
}
8-
}
9-
10-
provider "stackguardian" {
11-
api_key = var.api_key
12-
org_name = var.org_name
13-
api_uri = "https://api.app.stackguardian.io"
148
}

stackguardian_connector_vcs/variables.tf

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
variable "stackguardian_connector_vcs_name" {
2-
type = string
3-
description = "name of the connector"
4-
}
51
variable "api_key" {
62
type = string
73
description = "API key to authenticate to StackGuardian"
@@ -11,12 +7,13 @@ variable "org_name" {
117
description = "Organisation name in StackGuardian platform"
128
}
139

14-
variable "stackguardian_connector_kinds" {
15-
description = "A map of connector kinds and their respective configurations"
10+
variable "vcs_connectors" {
11+
description = "A map of connectors and their respective configurations"
1612
type = map(any)
1713
default = {
1814
vcs_gitlab = {
1915
kind = "GITLAB_COM"
16+
name = "gitlab-connector"
2017
config = [{
2118
gitlab_creds = {
2219
gitlabCreds = "gitlabuser:gitlab_pat",
@@ -26,6 +23,7 @@ variable "stackguardian_connector_kinds" {
2623
}]
2724
},
2825
vcs_github = {
26+
name = "github-connector"
2927
kind = "GITHUB_COM"
3028
config = [{
3129
github_creds = {
@@ -35,6 +33,7 @@ variable "stackguardian_connector_kinds" {
3533
}]
3634
},
3735
vcs_bitbucket = {
36+
name = "bitbucket-connector"
3837
kind = "BITBUCKET_ORG"
3938
config = [{
4039
bitbucket_creds = {

stackguardian_role/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resource "stackguardian_role" "role" {
33
resource_name = var.role_name
44
description = "Onboarding example of terraform-provider-stackguardian for Role Developer"
55
tags = [
6-
"demo-org"
6+
var.org_name
77
]
88
allowed_permissions = local.team_onboarding_permissions
99

0 commit comments

Comments
 (0)