Skip to content

Commit

Permalink
Merge pull request #1751 from quixoticmonk/d-improve-awscc_qbusiness_…
Browse files Browse the repository at this point in the history
…data_source

docs: added example for awscc_qbusiness_data_source
  • Loading branch information
marcosentino committed Jul 26, 2024
2 parents ff1e278 + 42a0029 commit 4e46607
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 2 deletions.
125 changes: 123 additions & 2 deletions docs/resources/qbusiness_data_source.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_qbusiness_data_source Resource - terraform-provider-awscc"
subcategory: ""
description: |-
Expand All @@ -10,7 +9,129 @@ description: |-

Definition of AWS::QBusiness::DataSource Resource Type


## Example Usage

### QBusiness data source of type S3 with the IAM role specifications for S3 access.

```terraform
resource "awscc_qbusiness_data_source" "exaple" {
application_id = awscc_qbusiness_application.example.application_id
display_name = "example_q_data_source"
index_id = awscc_qbusiness_index.example.index_id
role_arn = awscc_iam_role.ds.arn
configuration = jsonencode(
{
type = "S3"
version = "1.0.0"
syncMode = "FORCED_FULL_CRAWL"
connectionConfiguration = {
repositoryEndpointMetadata = {
BucketName = var.bucket_name
}
}
additionalProperties = {
inclusionPrefixes = ["docs/"]
}
repositoryConfigurations = {
document = {
fieldMappings = [
{
dataSourceFieldName = "s3_document_id"
indexFieldType = "STRING"
indexFieldName = "s3_document_id"
}
]
}
}
}
)
tags = [{
key = "Modified By"
value = "AWSCC"
}]
}
resource "awscc_iam_role" "example" {
role_name = "QBusiness-DataSource-Role"
description = "QBusiness Data source role"
assume_role_policy_document = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "AllowsAmazonQToAssumeRoleForServicePrincipal"
Effect = "Allow"
Principal = {
Service = "qbusiness.amazonaws.com"
}
Action = [
"sts:AssumeRole"
]
Condition = {
StringEquals = {
"aws:SourceAccount" = data.aws_caller_identity.current.account_id
}
}
}
]
})
tags = [{
key = "Modified By"
value = "AWSCC"
}]
}
resource "awscc_iam_role_policy" "example" {
policy_name = "sample_iam_role_policy"
role_name = awscc_iam_role.ds.id
policy_document = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = "s3:GetObject"
Resource = "arn:aws:s3:::${var.bucket_name}/*"
},
{
Effect = "Allow"
Action = "s3:ListBucket"
Resource = "arn:aws:s3:::${var.bucket_name}"
},
{
Effect = "Allow"
Action = [
"qbusiness:BatchPutDocument",
"qbusiness:BatchDeleteDocument"
]
Resource = "arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.example.id}/index/${awscc_qbusiness_index.example.id}"
},
{
Effect = "Allow"
Action = ["qbusiness:PutGroup",
"qbusiness:CreateUser",
"qbusiness:DeleteGroup",
"qbusiness:UpdateUser",
"qbusiness:ListGroups"]
Resource = [
"arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.example.id}",
"arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.example.id}/index/${awscc_qbusiness_index.example.id}",
"arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.example.id}/index/${awscc_qbusiness_index.example.id}/data-source/*"
]
}
]
})
}
variable "bucket_name" {
type = string
description = "Name of the bucket to be used as the data source input"
}
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
resource "awscc_qbusiness_data_source" "exaple" {
application_id = awscc_qbusiness_application.example.application_id
display_name = "example_q_data_source"
index_id = awscc_qbusiness_index.example.index_id
role_arn = awscc_iam_role.ds.arn
configuration = jsonencode(
{
type = "S3"
version = "1.0.0"
syncMode = "FORCED_FULL_CRAWL"
connectionConfiguration = {
repositoryEndpointMetadata = {
BucketName = var.bucket_name
}
}
additionalProperties = {
inclusionPrefixes = ["docs/"]
}
repositoryConfigurations = {
document = {
fieldMappings = [
{
dataSourceFieldName = "s3_document_id"
indexFieldType = "STRING"
indexFieldName = "s3_document_id"
}
]
}
}
}
)
tags = [{
key = "Modified By"
value = "AWSCC"
}]
}

resource "awscc_iam_role" "example" {
role_name = "QBusiness-DataSource-Role"
description = "QBusiness Data source role"
assume_role_policy_document = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "AllowsAmazonQToAssumeRoleForServicePrincipal"
Effect = "Allow"
Principal = {
Service = "qbusiness.amazonaws.com"
}
Action = [
"sts:AssumeRole"
]
Condition = {
StringEquals = {
"aws:SourceAccount" = data.aws_caller_identity.current.account_id
}
}
}
]
})

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

resource "awscc_iam_role_policy" "example" {
policy_name = "sample_iam_role_policy"
role_name = awscc_iam_role.ds.id

policy_document = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = "s3:GetObject"
Resource = "arn:aws:s3:::${var.bucket_name}/*"
},
{
Effect = "Allow"
Action = "s3:ListBucket"
Resource = "arn:aws:s3:::${var.bucket_name}"
},
{
Effect = "Allow"
Action = [
"qbusiness:BatchPutDocument",
"qbusiness:BatchDeleteDocument"
]
Resource = "arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.example.id}/index/${awscc_qbusiness_index.example.id}"
},
{
Effect = "Allow"
Action = ["qbusiness:PutGroup",
"qbusiness:CreateUser",
"qbusiness:DeleteGroup",
"qbusiness:UpdateUser",
"qbusiness:ListGroups"]
Resource = [
"arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.example.id}",
"arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.example.id}/index/${awscc_qbusiness_index.example.id}",
"arn:aws:qbusiness:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:application/${awscc_qbusiness_application.example.id}/index/${awscc_qbusiness_index.example.id}/data-source/*"
]
}
]
})
}

variable "bucket_name" {
type = string
description = "Name of the bucket to be used as the data source input"
}

data "aws_caller_identity" "current" {}

data "aws_region" "current" {}
27 changes: 27 additions & 0 deletions templates/resources/qbusiness_data_source.md.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}"
subcategory: ""
description: |-
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
---

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

{{ .Description | trimspace }}

## Example Usage

### QBusiness data source of type S3 with the IAM role specifications for S3 access.

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

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

## Import

Import is supported using the following syntax:

{{ codefile "shell" .ImportFile }}

{{- end }}

0 comments on commit 4e46607

Please sign in to comment.