Skip to content

Commit 4269d4c

Browse files
committed
update var manes. comply with some precommit rules
1 parent 484b1b3 commit 4269d4c

File tree

7 files changed

+65
-23
lines changed

7 files changed

+65
-23
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ We recommend using GitLab's OIDC issuer to get short-lived credentials needed fo
5757
IMPORTANT: The master branch is used in source just as an example. In your code, do not pin to master because there may be breaking changes between releases. Instead pin to the release tag (e.g. ?ref=tags/x.y.z) of one of our [latest releases](https://github.com/terraform-module/terraform-aws-gitlab-oidc-provider/releases).
5858

5959
```hcl
60-
module "gitlab-oidc" {
60+
module "gitlab_oidc" {
6161
source = "terraform-module/gitlab-oidc-provider/aws"
6262
version = "~> 1"
6363
6464
create_oidc_provider = true
6565
create_oidc_role = true
6666
67-
repositories = ["terraform-module/module-blueprint"]
67+
project_paths = ["project_path:terraform-module/module-blueprint", "project_path:foo/bar"]
6868
oidc_role_attach_policies = ["arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"]
6969
}
7070
```

examples/basic/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,34 @@ $ terraform apply
1515
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
1616

1717
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
18+
## Requirements
1819

20+
| Name | Version |
21+
|------|---------|
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23+
24+
## Providers
25+
26+
No providers.
27+
28+
## Modules
29+
30+
| Name | Source | Version |
31+
|------|--------|---------|
32+
| <a name="module_gitlab_oidc"></a> [gitlab\_oidc](#module\_gitlab\_oidc) | ../.. | n/a |
33+
34+
## Resources
35+
36+
No resources.
37+
38+
## Inputs
39+
40+
No inputs.
41+
42+
## Outputs
43+
44+
| Name | Description |
45+
|------|-------------|
46+
| <a name="output_oidc_provider_arn"></a> [oidc\_provider\_arn](#output\_oidc\_provider\_arn) | OIDC provider ARN |
47+
| <a name="output_oidc_role"></a> [oidc\_role](#output\_oidc\_role) | CICD GiLab role. |
1948
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/basic/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
}
4+
15
################################################################################
26
# Resources
37
################################################################################
@@ -8,7 +12,7 @@ module "gitlab_oidc" {
812
create_oidc_provider = true
913
create_oidc_role = true
1014

11-
repositories = ["terraform-module/terraform-aws-gitlab-oidc-provider"]
15+
project_paths = ["project_path:terraform-module/terraform-aws-gitlab-oidc-provider"]
1216
oidc_role_attach_policies = ["arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"]
1317
}
1418

main.tf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
* # AWS Gitlab OIDC Provider Terraform Module
33
*
44
* ## Purpose
5-
* This module allows you to create a Gitlab OIDC provider for your AWS account, that will help Gitlab Actions to securely authenticate against the AWS API using an IAM role
5+
* This module allows you to create a Gitlab OIDC provider for your AWS account, that will allow Gitlab pipelines to securely authenticate against the AWS API using an IAM role
66
*
77
*/
8+
89
data "tls_certificate" "gitlab" {
910
url = var.gitlab_tls_url
1011
}
@@ -13,7 +14,7 @@ resource "aws_iam_openid_connect_provider" "this" {
1314
count = var.create_oidc_provider ? 1 : 0
1415

1516
client_id_list = var.aud_value
16-
thumbprint_list = ["${data.tls_certificate.gitlab.certificates.0.sha1_fingerprint}"]
17+
thumbprint_list = [data.tls_certificate.gitlab.certificates[0].sha1_fingerprint]
1718
url = var.url
1819
}
1920

@@ -22,7 +23,7 @@ resource "aws_iam_role" "this" {
2223
name = var.role_name
2324
description = var.role_description
2425
max_session_duration = var.max_session_duration
25-
assume_role_policy = join("", data.aws_iam_policy_document.this.*.json)
26+
assume_role_policy = join("", data.aws_iam_policy_document.this[*].json)
2627
tags = var.tags
2728

2829
depends_on = [aws_iam_openid_connect_provider.this]
@@ -32,7 +33,7 @@ resource "aws_iam_role_policy_attachment" "attach" {
3233
count = var.create_oidc_role ? length(var.oidc_role_attach_policies) : 0
3334

3435
policy_arn = var.oidc_role_attach_policies[count.index]
35-
role = join("", aws_iam_role.this.*.name)
36+
role = join("", aws_iam_role.this[*].name)
3637

3738
depends_on = [aws_iam_role.this]
3839
}
@@ -48,8 +49,8 @@ data "aws_iam_policy_document" "this" {
4849

4950
condition {
5051
test = "StringLike"
51-
values = var.projects
52-
variable = "${join("", aws_iam_openid_connect_provider.this.*.url)}:${var.match_field}"
52+
values = var.project_paths
53+
variable = "${join("", aws_iam_openid_connect_provider.this[*].url)}:${var.match_field}"
5354
}
5455

5556
principals {

outputs.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ output "thumbprint" {
1414
}
1515

1616
output "policy_document" {
17-
value = join("", data.aws_iam_policy_document.this.*.json)
17+
description = "joined IAM policy documents"
18+
value = join("", data.aws_iam_policy_document.this[*].json)
1819
}

variables.tf

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ variable "role_description" {
3434
default = "Role assumed by the Gitlab OIDC provider."
3535
}
3636

37-
variable "projects" {
37+
variable "project_paths" {
3838
description = "List of GitLab namesapce/project names authorized to assume the role."
3939
type = list(string)
4040
default = []
@@ -43,9 +43,9 @@ variable "projects" {
4343
# Ensures each element of gitlab_projects list matches the
4444
# namespace/project format used by GitLab.
4545
condition = length([
46-
for proj in var.projects : 1
47-
if length(regexall("[A-Za-z0-9_.-]+?/([A-Za-z0-9_.:/-]+|\\*)$", proj)) > 0
48-
]) == length(var.projects)
46+
for path in var.project_paths : 1
47+
if length(regexall("project_path:[A-Za-z0-9_.-]+?/([A-Za-z0-9_.:/-]+|\\*)$", path)) > 0
48+
]) == length(var.project_paths)
4949
error_message = "Projects must be specified in the namespace/project format."
5050
}
5151
}
@@ -68,18 +68,14 @@ variable "oidc_role_attach_policies" {
6868
}
6969

7070
variable "match_field" {
71-
type = string
72-
default = "sub"
73-
}
74-
75-
variable "gitlab_url" {
76-
type = string
77-
default = "https://gitlab.com"
71+
description = "the token field the OIDC provider filter on"
72+
type = string
73+
default = "sub"
7874
}
7975

8076
variable "gitlab_tls_url" {
81-
type = string
82-
# Avoid using https scheme because the Hashicorp TLS provider has started following redirects starting v4.
77+
type = string
78+
description = "the Hashicorp TLS provider has started following redirects starting v4. so we use tls://"
8379
# See https://github.com/hashicorp/terraform-provider-tls/issues/249
8480
default = "tls://gitlab.com:443"
8581
}

versions.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
terraform {
22
required_version = ">= 1"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.40"
8+
}
9+
tls = {
10+
source = "hashicorp/tls"
11+
version = ">= 3.0"
12+
}
13+
}
314
}

0 commit comments

Comments
 (0)