Skip to content

Commit

Permalink
OPS-6304 Add basic configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
snovikov committed Oct 30, 2024
1 parent bf595c5 commit 480679a
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test: _pull-tf
echo "------------------------------------------------------------"; \
echo "# Terraform init"; \
echo "------------------------------------------------------------"; \
if docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \
if docker run $$(tty -s && echo "-it" || echo) --rm --network host -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \
init \
-lock=false \
-upgrade \
Expand Down
124 changes: 111 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# terraform-module-template
Template for Terraform modules

<!-- Uncomment and replace with your module name
[![lint](https://github.com/flaconi/<MODULENAME>/workflows/lint/badge.svg)](https://github.com/flaconi/<MODULENAME>/actions?query=workflow%3Alint)
[![test](https://github.com/flaconi/<MODULENAME>/workflows/test/badge.svg)](https://github.com/flaconi/<MODULENAME>/actions?query=workflow%3Atest)
[![Tag](https://img.shields.io/github/tag/flaconi/<MODULENAME>.svg)](https://github.com/flaconi/<MODULENAME>/releases)
-->
# terraform-aws-bedrock

Module to create Amazon Bedrock custom model

[![lint](https://github.com/flaconi/terraform-aws-bedrock/workflows/lint/badge.svg)](https://github.com/flaconi/terraform-aws-bedrock/actions?query=workflow%3Alint)
[![test](https://github.com/flaconi/terraform-aws-bedrock/workflows/test/badge.svg)](https://github.com/flaconi/terraform-aws-bedrock/actions?query=workflow%3Atest)
[![Tag](https://img.shields.io/github/tag/flaconi/terraform-aws-bedrock.svg)](https://github.com/flaconi/terraform-aws-bedrock/releases)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

For requirements regarding module structure: [style-guide-terraform.md](https://github.com/Flaconi/devops-docs/blob/master/doc/conventions/style-guide-terraform.md)
Expand All @@ -18,7 +17,9 @@ For requirements regarding module structure: [style-guide-terraform.md](https://
<!-- TFDOCS_PROVIDER_START -->
## Providers

No providers.
| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 5.73 |

<!-- TFDOCS_PROVIDER_END -->

Expand All @@ -28,29 +29,126 @@ No providers.
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.3 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 5.73 |

<!-- TFDOCS_REQUIREMENTS_END -->

<!-- TFDOCS_INPUTS_START -->
## Required Inputs

No required inputs.
The following input variables are required:

### <a name="input_name"></a> [name](#input\_name)

Description: Name for the custom model.

Type: `string`

### <a name="input_job_name"></a> [job\_name](#input\_job\_name)

Description: A name for the customization job.

Type: `string`

### <a name="input_model_role_arn"></a> [model\_role\_arn](#input\_model\_role\_arn)

Description: The Amazon Resource Name (ARN) of an IAM role that Bedrock can assume to perform tasks on your behalf.

Type: `string`

### <a name="input_output_data_s3_uri"></a> [output\_data\_s3\_uri](#input\_output\_data\_s3\_uri)

Description: The S3 URI where the output data is stored.

Type: `string`

### <a name="input_training_data_s3_uri"></a> [training\_data\_s3\_uri](#input\_training\_data\_s3\_uri)

Description: The S3 URI where the training data is stored.

Type: `string`

## Optional Inputs

No optional inputs.
The following input variables are optional (have default values):

### <a name="input_foundation_model_id"></a> [foundation\_model\_id](#input\_foundation\_model\_id)

Description: Model identifier.

Type: `string`

Default: `"amazon.titan-text-express-v1"`

### <a name="input_model_kms_key_id"></a> [model\_kms\_key\_id](#input\_model\_kms\_key\_id)

Description: The custom model is encrypted at rest using this key. Specify the key ARN.

Type: `string`

Default: `null`

### <a name="input_model_customization_type"></a> [model\_customization\_type](#input\_model\_customization\_type)

Description: The customization type. Valid values: `FINE_TUNING`, `CONTINUED_PRE_TRAINING`.

Type: `string`

Default: `null`

### <a name="input_model_hyperparameters"></a> [model\_hyperparameters](#input\_model\_hyperparameters)

Description: Parameters related to tuning the model.

Type: `map(string)`

Default: `{}`

### <a name="input_validation_data_s3_uri"></a> [validation\_data\_s3\_uri](#input\_validation\_data\_s3\_uri)

Description: The S3 URI where the validation data is stored.

Type: `string`

Default: `null`

### <a name="input_vpc_config"></a> [vpc\_config](#input\_vpc\_config)

Description: Configuration parameters for the private Virtual Private Cloud (VPC) that contains the resources you are using for this job.

Type:

```hcl
object({
security_group_ids = list(string)
subnet_ids = list(string)
})
```

Default: `null`

### <a name="input_tags"></a> [tags](#input\_tags)

Description: A map of tags to assign to the customization job and custom model.

Type: `map(string)`

Default: `{}`

<!-- TFDOCS_INPUTS_END -->

<!-- TFDOCS_OUTPUTS_START -->
## Outputs

No outputs.
| Name | Description |
|------|-------------|
| <a name="output_custom_model_arn"></a> [custom\_model\_arn](#output\_custom\_model\_arn) | The ARN of the output model. |
| <a name="output_job_arn"></a> [job\_arn](#output\_job\_arn) | The ARN of the customization job. |

<!-- TFDOCS_OUTPUTS_END -->

## License

**[MIT License](LICENSE)**

Copyright (c) 2023 **[Flaconi GmbH](https://github.com/flaconi)**
Copyright (c) 2024 **[Flaconi GmbH](https://github.com/flaconi)**
3 changes: 3 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "aws_bedrock_foundation_model" "this" {
model_id = var.foundation_model_id
}
36 changes: 36 additions & 0 deletions examples/titan/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Example

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 5.73 |

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_model"></a> [model](#module\_model) | ../../ | n/a |

## Resources

No resources.

## Inputs

No inputs.

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_custom_model_arn"></a> [custom\_model\_arn](#output\_custom\_model\_arn) | The ARN of the output model. |
| <a name="output_job_arn"></a> [job\_arn](#output\_job\_arn) | The ARN of the customization job. |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
28 changes: 28 additions & 0 deletions examples/titan/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module "model" {
source = "../../"

name = "titan"
job_name = "titan-job-1"
foundation_model_id = "amazon.titan-text-express-v1"
model_role_arn = "arn:aws:iam::123456789101:role/TitanModelRole"

model_hyperparameters = {
"epochCount" = "1"
"batchSize" = "1"
"learningRate" = "0.005"
"learningRateWarmupSteps" = "0"
}

output_data_s3_uri = "s3://titan-output-data/data/"
training_data_s3_uri = "s3://titan-training-data/data/train.jsonl"
}

output "custom_model_arn" {
description = "The ARN of the output model."
value = module.model.custom_model_arn
}

output "job_arn" {
description = "The ARN of the customization job."
value = module.model.job_arn
}
9 changes: 9 additions & 0 deletions examples/titan/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.3"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.73"
}
}
}
37 changes: 37 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
resource "aws_bedrock_custom_model" "this" {
custom_model_name = var.name
job_name = var.job_name

base_model_identifier = data.aws_bedrock_foundation_model.this.model_arn
custom_model_kms_key_id = var.model_kms_key_id
customization_type = var.model_customization_type
hyperparameters = var.model_hyperparameters
role_arn = var.model_role_arn

output_data_config {
s3_uri = var.output_data_s3_uri
}

training_data_config {
s3_uri = var.training_data_s3_uri
}

dynamic "validation_data_config" {
for_each = var.training_data_s3_uri != null ? ["this"] : []
content {
validator {
s3_uri = var.validation_data_s3_uri
}
}
}

dynamic "vpc_config" {
for_each = var.vpc_config != null ? ["this"] : []
content {
security_group_ids = var.vpc_config["security_group_ids"]
subnet_ids = var.vpc_config["subnet_ids"]
}
}

tags = var.tags
}
9 changes: 9 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "custom_model_arn" {
description = "The ARN of the output model."
value = aws_bedrock_custom_model.this.custom_model_arn
}

output "job_arn" {
description = "The ARN of the customization job."
value = aws_bedrock_custom_model.this.job_arn
}
69 changes: 69 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
variable "name" {
description = "Name for the custom model."
type = string
}

variable "job_name" {
description = "A name for the customization job."
type = string
}

variable "foundation_model_id" {
description = "Model identifier."
type = string
default = "amazon.titan-text-express-v1"
}

variable "model_kms_key_id" {
description = "The custom model is encrypted at rest using this key. Specify the key ARN."
type = string
default = null
}

variable "model_customization_type" {
description = "The customization type. Valid values: `FINE_TUNING`, `CONTINUED_PRE_TRAINING`."
type = string
default = null
}

variable "model_hyperparameters" {
description = "Parameters related to tuning the model."
type = map(string)
default = {}
}

variable "model_role_arn" {
description = "The Amazon Resource Name (ARN) of an IAM role that Bedrock can assume to perform tasks on your behalf."
type = string
}

variable "output_data_s3_uri" {
description = "The S3 URI where the output data is stored."
type = string
}

variable "training_data_s3_uri" {
description = "The S3 URI where the training data is stored."
type = string
}

variable "validation_data_s3_uri" {
description = "The S3 URI where the validation data is stored."
type = string
default = null
}

variable "vpc_config" {
description = "Configuration parameters for the private Virtual Private Cloud (VPC) that contains the resources you are using for this job."
type = object({
security_group_ids = list(string)
subnet_ids = list(string)
})
default = null
}

variable "tags" {
description = "A map of tags to assign to the customization job and custom model."
type = map(string)
default = {}
}
6 changes: 6 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
terraform {
required_version = "~> 1.3"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.73"
}
}
}

0 comments on commit 480679a

Please sign in to comment.