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

docs: add example for awscc_databrew_project #2198

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
100 changes: 98 additions & 2 deletions docs/resources/databrew_project.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "awscc_databrew_project Resource - terraform-provider-awscc"
subcategory: ""
description: |-
Expand All @@ -10,7 +10,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
}
30 changes: 30 additions & 0 deletions templates/resources/databrew_project.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

---
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 }}
Loading