Skip to content

Commit

Permalink
docs: add example for awscc_databrew_project (#2198)
Browse files Browse the repository at this point in the history
* docs: add example for awscc_databrew_project

* docs: remove extra line
  • Loading branch information
BondAnthony authored Feb 25, 2025
1 parent 581c285 commit c0e431c
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 2 deletions.
99 changes: 97 additions & 2 deletions docs/resources/databrew_project.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "awscc_databrew_project Resource - terraform-provider-awscc"
subcategory: ""
description: |-
Expand All @@ -10,7 +9,103 @@ description: |-

Resource schema for AWS::DataBrew::Project.


## Example Usage

### DataBrew Project

Creates an AWS DataBrew project using an S3 source dataset, with necessary IAM roles and permissions to allow Databrew access to S3.

```terraform
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
# Create an S3 bucket for the DataBrew dataset
resource "awscc_s3_bucket" "databrew_input" {
bucket_name = "databrew-input-${data.aws_caller_identity.current.account_id}-${data.aws_region.current.name}"
tags = [{
key = "Modified By"
value = "AWSCC"
}]
}
# Upload a sample CSV file to the bucket
resource "aws_s3_object" "sample_data" {
bucket = awscc_s3_bucket.databrew_input.id
key = "input/sample.csv"
content = "id,name,age\n1,John,30\n2,Jane,25"
}
# Create the DataBrew dataset
resource "awscc_databrew_dataset" "example" {
name = "example-dataset"
input = {
s3_input_definition = {
bucket = awscc_s3_bucket.databrew_input.id
key = aws_s3_object.sample_data.key
}
}
format = "CSV"
format_options = {
csv = {
delimiter = ","
header_row = true
}
}
tags = [{
key = "Modified By"
value = "AWSCC"
}]
}
# Create an IAM role to allow Databrew access to S3 Bucket
resource "awscc_iam_role" "example" {
assume_role_policy_document = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "databrew.amazonaws.com"
}
},
]
})
}
resource "awscc_iam_role_policy" "example" {
role_name = awscc_iam_role.example.role_name
policy_name = "example-policy"
policy_document = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"s3:ListBucket",
"s3:GetObject"
]
Effect = "Allow"
Resource = [
awscc_s3_bucket.databrew_input.arn,
"${awscc_s3_bucket.databrew_input.arn}/*"
]
}
]
})
}
# Create a DataBrew project
resource "awscc_databrew_project" "example" {
dataset_name = awscc_databrew_dataset.example.name
name = "example-project"
recipe_name = "example-recipe"
role_arn = awscc_iam_role.example.arn
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
89 changes: 89 additions & 0 deletions examples/resources/awscc_databrew_project/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}

# Create an S3 bucket for the DataBrew dataset
resource "awscc_s3_bucket" "databrew_input" {
bucket_name = "databrew-input-${data.aws_caller_identity.current.account_id}-${data.aws_region.current.name}"

tags = [{
key = "Modified By"
value = "AWSCC"
}]
}

# Upload a sample CSV file to the bucket
resource "aws_s3_object" "sample_data" {
bucket = awscc_s3_bucket.databrew_input.id
key = "input/sample.csv"
content = "id,name,age\n1,John,30\n2,Jane,25"
}

# Create the DataBrew dataset
resource "awscc_databrew_dataset" "example" {
name = "example-dataset"

input = {
s3_input_definition = {
bucket = awscc_s3_bucket.databrew_input.id
key = aws_s3_object.sample_data.key
}
}

format = "CSV"
format_options = {
csv = {
delimiter = ","
header_row = true
}
}

tags = [{
key = "Modified By"
value = "AWSCC"
}]
}

# Create an IAM role to allow Databrew access to S3 Bucket
resource "awscc_iam_role" "example" {
assume_role_policy_document = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "databrew.amazonaws.com"
}
},
]
})
}

resource "awscc_iam_role_policy" "example" {
role_name = awscc_iam_role.example.role_name
policy_name = "example-policy"
policy_document = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"s3:ListBucket",
"s3:GetObject"
]
Effect = "Allow"
Resource = [
awscc_s3_bucket.databrew_input.arn,
"${awscc_s3_bucket.databrew_input.arn}/*"
]
}
]
})
}

# Create a DataBrew project
resource "awscc_databrew_project" "example" {
dataset_name = awscc_databrew_dataset.example.name
name = "example-project"
recipe_name = "example-recipe"
role_arn = awscc_iam_role.example.arn
}
29 changes: 29 additions & 0 deletions templates/resources/databrew_project.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}"
subcategory: ""
description: |-
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
---

# {{.Name}} ({{.Type}})

{{ .Description | trimspace }}

## Example Usage

### DataBrew Project

Creates an AWS DataBrew project using an S3 source dataset, with necessary IAM roles and permissions to allow Databrew access to S3.

{{ tffile (printf "examples/resources/%s/main.tf" .Name)}}

{{ .SchemaMarkdown | trimspace }}
{{- if .HasImport }}

## Import

Import is supported using the following syntax:

{{ codefile "shell" .ImportFile }}

{{- end }}

0 comments on commit c0e431c

Please sign in to comment.