Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: s3 / sqs resources with workload identity #10

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions examples/s3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# AWS S3

This example configures an S3 bucket resource definition, with two different access policies:

* `basic-admin` (full access)
* `basic-read-only` (read-only access)

Those resources can be used in your score file like:

```yaml
resources:
...
s3:
type: s3
class: basic-admin
```

The workload service account will automatically be assigned the necessary AWS IAM Role with the selected IAM Policy.

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| terraform | >= 1.3.0 |
| humanitec | ~> 0 |

## Providers

| Name | Version |
|------|---------|
| humanitec | ~> 0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| iam\_policy\_s3\_admin | ../../humanitec-resource-defs/iam-policy/s3 | n/a |
| iam\_policy\_s3\_read\_only | ../../humanitec-resource-defs/iam-policy/s3 | n/a |
| iam\_role\_service\_account | ../../humanitec-resource-defs/iam-role/service-account | n/a |
| k8s\_service\_account | ../../humanitec-resource-defs/k8s/service-account | n/a |
| s3\_basic | ../../humanitec-resource-defs/s3/basic | n/a |
| s3\_basic\_admin | ../../humanitec-resource-defs/s3/passthrough | n/a |
| s3\_basic\_read\_only | ../../humanitec-resource-defs/s3/passthrough | n/a |
| workload | ../../humanitec-resource-defs/workload/service-account | n/a |

## Resources

| Name | Type |
|------|------|
| [humanitec_application.example](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/application) | resource |
| [humanitec_resource_definition_criteria.iam_policy_s3_admin](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.iam_policy_s3_read_only](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.iam_role_service_account](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.k8s_service_account](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.s3_basic](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.s3_basic_admin](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.s3_basic_read_only](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.workload](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| access\_key | AWS Access Key | `string` | n/a | yes |
| cluster\_name | Name of the EKS cluster | `string` | n/a | yes |
| region | AWS Region | `string` | n/a | yes |
| secret\_key | AWS Secret Key | `string` | n/a | yes |
| name | Name of the example application | `string` | `"s3-test"` | no |
| resource\_packs\_aws\_rev | AWS Resource Pack git branch | `string` | `"refs/heads/main"` | no |
| resource\_packs\_aws\_url | AWS Resource Pack git url | `string` | `"https://github.com/humanitec-architecture/resource-packs-aws.git"` | no |
<!-- END_TF_DOCS -->
173 changes: 173 additions & 0 deletions examples/s3/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
locals {
res_def_prefix = "${var.name}-"
}

resource "humanitec_application" "example" {
id = var.name
name = var.name
}

# S3 bucket

locals {
# Classes used to build the resource definition graph
s3_basic_class = "basic"
s3_admin_policy_class = "s3-basic-admin"
s3_read_only_policy_class = "s3-basic-read-only"

# Classes that developers can select from
s3_basic_admin_class = "basic-admin"
s3_basic_read_only_class = "basic-read-only"
}

# Define s3 bucket basic "flavour" as base

module "s3_basic" {
source = "../../humanitec-resource-defs/s3/basic"

resource_packs_aws_url = var.resource_packs_aws_url
resource_packs_aws_rev = var.resource_packs_aws_rev

access_key = var.access_key
secret_key = var.secret_key
region = var.region

prefix = local.res_def_prefix
}

resource "humanitec_resource_definition_criteria" "s3_basic" {
resource_definition_id = module.s3_basic.id
app_id = humanitec_application.example.id
class = local.s3_basic_class
}

# Add different access policy to s3 basic bucket

# Admin

## Policy
module "iam_policy_s3_admin" {
source = "../../humanitec-resource-defs/iam-policy/s3"

resource_packs_aws_url = var.resource_packs_aws_url
resource_packs_aws_rev = var.resource_packs_aws_rev

access_key = var.access_key
secret_key = var.secret_key
region = var.region

policy = "admin"

prefix = local.res_def_prefix

s3_resource_class = local.s3_basic_class
}

resource "humanitec_resource_definition_criteria" "iam_policy_s3_admin" {
resource_definition_id = module.iam_policy_s3_admin.id
app_id = humanitec_application.example.id
class = local.s3_admin_policy_class
}

## Exposed passthrough resource definition
module "s3_basic_admin" {
source = "../../humanitec-resource-defs/s3/passthrough"

prefix = local.res_def_prefix

s3_resource_class = local.s3_basic_class
policy_resource_class = local.s3_admin_policy_class
}

resource "humanitec_resource_definition_criteria" "s3_basic_admin" {
resource_definition_id = module.s3_basic_admin.id
app_id = humanitec_application.example.id
class = local.s3_basic_admin_class
}


# Read-only

## Policy
module "iam_policy_s3_read_only" {
source = "../../humanitec-resource-defs/iam-policy/s3"

resource_packs_aws_url = var.resource_packs_aws_url
resource_packs_aws_rev = var.resource_packs_aws_rev

access_key = var.access_key
secret_key = var.secret_key
region = var.region

policy = "read-only"

prefix = local.res_def_prefix

s3_resource_class = local.s3_basic_class
}

resource "humanitec_resource_definition_criteria" "iam_policy_s3_read_only" {
resource_definition_id = module.iam_policy_s3_read_only.id
app_id = humanitec_application.example.id
class = local.s3_read_only_policy_class
}

## Exposed passthrough resource definition
module "s3_basic_read_only" {
source = "../../humanitec-resource-defs/s3/passthrough"

prefix = local.res_def_prefix

s3_resource_class = local.s3_basic_class
policy_resource_class = local.s3_read_only_policy_class
}

resource "humanitec_resource_definition_criteria" "s3_basic_read_only" {
resource_definition_id = module.s3_basic_read_only.id
app_id = humanitec_application.example.id
class = local.s3_basic_read_only_class
}


# Required resources for workload identity

module "k8s_service_account" {
source = "../../humanitec-resource-defs/k8s/service-account"

prefix = local.res_def_prefix
}

resource "humanitec_resource_definition_criteria" "k8s_service_account" {
resource_definition_id = module.k8s_service_account.id
app_id = humanitec_application.example.id
}

module "iam_role_service_account" {
source = "../../humanitec-resource-defs/iam-role/service-account"

resource_packs_aws_url = var.resource_packs_aws_url
resource_packs_aws_rev = var.resource_packs_aws_rev

access_key = var.access_key
secret_key = var.secret_key
region = var.region

cluster_name = var.cluster_name
prefix = local.res_def_prefix
}

resource "humanitec_resource_definition_criteria" "iam_role_service_account" {
resource_definition_id = module.iam_role_service_account.id
app_id = humanitec_application.example.id
}

module "workload" {
source = "../../humanitec-resource-defs/workload/service-account"

prefix = local.res_def_prefix
}

resource "humanitec_resource_definition_criteria" "workload" {
resource_definition_id = module.workload.id
app_id = humanitec_application.example.id
}
13 changes: 13 additions & 0 deletions examples/s3/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
humanitec = {
source = "humanitec/humanitec"
version = "~> 0"
}
}

required_version = ">= 1.3.0"
}


provider "humanitec" {}
21 changes: 21 additions & 0 deletions examples/s3/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# AWS Access Key
access_key = ""

# Name of the EKS cluster
cluster_name = ""

# Name of the example application
name = "s3-test"

# AWS Region
region = ""

# AWS Resource Pack git branch
resource_packs_aws_rev = "refs/heads/main"

# AWS Resource Pack git url
resource_packs_aws_url = "https://github.com/humanitec-architecture/resource-packs-aws.git"

# AWS Secret Key
secret_key = ""
37 changes: 37 additions & 0 deletions examples/s3/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
variable "access_key" {
description = "AWS Access Key"
type = string
}

variable "secret_key" {
description = "AWS Secret Key"
type = string
}

variable "region" {
description = "AWS Region"
type = string
}

variable "cluster_name" {
description = "Name of the EKS cluster"
type = string
}

variable "resource_packs_aws_url" {
description = "AWS Resource Pack git url"
type = string
default = "https://github.com/humanitec-architecture/resource-packs-aws.git"
}

variable "resource_packs_aws_rev" {
description = "AWS Resource Pack git branch"
type = string
default = "refs/heads/main"
}

variable "name" {
description = "Name of the example application"
type = string
default = "s3-test"
}
49 changes: 35 additions & 14 deletions examples/sqs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# AWS SQS

This example configures an SQS queue resource definition, with two different access policies:

* `basic-publisher` (allowed to send messages)
* `basic-consumer` (allowed to receive messages)

Those resources can be used in your score file like:

```yaml
resources:
...
sqs:
type: sqs
class: basic-publisher
```

The workload service account will automatically be assigned the necessary AWS IAM Role with the selected IAM Policy.

<!-- BEGIN_TF_DOCS -->
## Requirements

Expand All @@ -16,36 +35,38 @@

| Name | Source | Version |
|------|--------|---------|
| iam\_policy\_s3\_admin | ../../humanitec-resource-defs/iam-policy/s3-admin | n/a |
| iam\_policy\_sqs\_admin | ../../humanitec-resource-defs/iam-policy/sqs-admin | n/a |
| iam\_policy\_sqs\_consumer | ../../humanitec-resource-defs/iam-policy/sqs | n/a |
| iam\_policy\_sqs\_publisher | ../../humanitec-resource-defs/iam-policy/sqs | n/a |
| iam\_role\_service\_account | ../../humanitec-resource-defs/iam-role/service-account | n/a |
| k8s\_service\_account | ../../humanitec-resource-defs/k8s/service-account | n/a |
| s3\_basic | ../../humanitec-resource-defs/s3/basic | n/a |
| sqs\_basic | ../../humanitec-resource-defs/sqs/basic | n/a |
| sqs\_basic\_consumer | ../../humanitec-resource-defs/sqs/passthrough | n/a |
| sqs\_basic\_publisher | ../../humanitec-resource-defs/sqs/passthrough | n/a |
| workload | ../../humanitec-resource-defs/workload/service-account | n/a |

## Resources

| Name | Type |
|------|------|
| [humanitec_application.example](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/application) | resource |
| [humanitec_resource_definition_criteria.iam_policy_s3_admin](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.iam_policy_sqs_admin](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.iam_policy_sqs_consumer](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.iam_policy_sqs_publisher](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.iam_role_service_account](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.k8s_service_account](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.s3_basic](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.sqs_basic](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.sqs_basic_consumer](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.sqs_basic_publisher](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
| [humanitec_resource_definition_criteria.workload](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| access\_key | n/a | `string` | n/a | yes |
| oidc\_provider | n/a | `string` | n/a | yes |
| oidc\_provider\_arn | n/a | `string` | n/a | yes |
| secret\_key | n/a | `string` | n/a | yes |
| name | n/a | `string` | `"item-list"` | no |
| region | n/a | `string` | `"eu-central-1"` | no |
| resource\_packs\_aws\_rev | n/a | `string` | `"refs/heads/main"` | no |
<!-- END_TF_DOCS -->
| access\_key | AWS Access Key | `string` | n/a | yes |
| cluster\_name | Name of the EKS cluster | `string` | n/a | yes |
| region | AWS Region | `string` | n/a | yes |
| secret\_key | AWS Secret Key | `string` | n/a | yes |
| name | Name of the example application | `string` | `"sqs-test"` | no |
| resource\_packs\_aws\_rev | AWS Resource Pack git branch | `string` | `"refs/heads/main"` | no |
| resource\_packs\_aws\_url | AWS Resource Pack git url | `string` | `"https://github.com/humanitec-architecture/resource-packs-aws.git"` | no |
<!-- END_TF_DOCS -->
Loading
Loading