Skip to content

Commit bce6ae5

Browse files
committed
Adding Terraform snippet, making changes Luis requested [netlify-build]
1 parent 5061ad7 commit bce6ae5

File tree

1 file changed

+128
-29
lines changed
  • src/connections/storage/catalog/aws-s3

1 file changed

+128
-29
lines changed

src/connections/storage/catalog/aws-s3/index.md

Lines changed: 128 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ The Segment Tracking API processes data from your sources, and collects the Even
2828

2929
## Create a new destination
3030

31-
Complete either [Create an IAM role in the AWS console](#create-an-iam-role-in-the-aws-console), [Create an IAM role using the AWS CLI](#create-an-iam-role-using-the-aws-cli), or [Configure resources using Terraform](#configure-resources-using-terraform) to set up the AWS S3 Destination with IAM Role Support.
31+
Complete either [Create an IAM role in the AWS console](#create-an-iam-role-in-the-aws-console), [Create an IAM role using the AWS CLI](#create-an-iam-role-using-the-aws-cli), or [Create IAM roles using Terraform](#create-iam-roles-using-terraform) to set up the AWS S3 Destination with IAM Role Support.
3232

33-
All three setup methods provide a base level of permissions to Segment (for example, the correct IAM role to allow Segment to send data to your S3 bucket). If you want stricter permissions or other custom configurations, you can customize these setup instructions manually.
33+
All three setup methods provide a base level of permissions to Segment. If you want stricter permissions or other custom configurations, you can customize these setup instructions manually.
3434

3535
### Create an IAM role in the AWS console
3636

@@ -192,12 +192,106 @@ To create an S3 IAM role, you must first install and configure the AWS CLI on yo
192192
> info ""
193193
> To verify that the IAM role is created, navigate to the AWS console and open the IAM Management Console. On the Permissions tab, verify that there is a `segment-s3-putobject` Permissions policy.
194194

195-
### Configure resources using Terraform
195+
### Create IAM roles using Terraform
196196

197-
You can use the instructions provided in the open source Terraform module to automate some of the required setup steps for this destination. The setup process for AWS S3 uses Terraform v12.0+. The AWS provider must use v4, which is included in our example `main.tf`.
197+
You can run the provided Terraform module from your command line to create the IAM roles required for this destination.
198198

199-
> note "Support for the AWS S3 Terraform module"
200-
> If you’re familiar with Terraform, you can modify the module to meet your organization’s needs, however, Segment guarantees support only for the template as provided.
199+
> warning "Support for the AWS S3 Terraform module"
200+
> If you’re familiar with Terraform, you can modify the module to meet your organization’s needs: however, Segment guarantees support only for the template as provided.
201+
202+
To set up the required IAM roles for this destination, run the following Terraform module from your command line:
203+
204+
```hcl
205+
# Creates the IAM role used by Segment.
206+
# https://www.terraform.io/docs/providers/aws/r/iam_role.html
207+
resource "aws_iam_role" "segment_aws_s3_iam_role" {
208+
name = "SegmentAWSS3Role"
209+
description = "IAM Role used by Segment"
210+
assume_role_policy = data.aws_iam_policy_document.segment_aws_s3_assume_role_policy_document.json
211+
}
212+
213+
# Trust relationship policy attached to the IAM role.
214+
# https://www.terraform.io/docs/providers/aws/d/iam_policy_document.html
215+
data "aws_iam_policy_document" "segment_aws_s3_assume_role_policy_document" {
216+
version = "2012-10-17"
217+
# Allows Segment to assume a role.
218+
statement {
219+
actions = [
220+
"sts:AssumeRole"
221+
]
222+
principals {
223+
type = "AWS"
224+
identifiers = ["arn:aws:iam::595280932656:role/segment-s3-integration-production-access", ]
225+
}
226+
effect = "Allow"
227+
condition {
228+
test = "StringEquals"
229+
variable = "sts:ExternalId"
230+
values = ["<YOUR_WORKSPACE_ID>", ]
231+
}
232+
}
233+
}
234+
235+
# https://www.terraform.io/docs/providers/aws/d/caller_identity.html
236+
data "aws_caller_identity" "current" {}
237+
# https://www.terraform.io/docs/providers/aws/d/region.html
238+
data "aws_region" "current" {}
239+
resource "aws_iam_policy" "segment_aws_s3_policy" {
240+
name = "SegmentAWSS3Policy"
241+
description = "Gives access to resources in your S3 bucket"
242+
policy = data.aws_iam_policy_document.segment_aws_s3_policy_document.json
243+
}
244+
245+
data "aws_iam_policy_document" "segment_aws_s3_policy_document" {
246+
version = "2012-10-17"
247+
# Allows Segment to write to your S3 bucket.
248+
statement {
249+
sid = "PutObjectsInBucket"
250+
actions = [
251+
"s3:PutObject",
252+
"s3:PutObjectAcl",
253+
]
254+
resources = [
255+
"arn:aws:s3:::<YOUR_BUCKET_NAME>/segment-logs/*",
256+
]
257+
effect = "Allow"
258+
}
259+
}
260+
261+
resource "aws_iam_role_policy_attachment" "segment_aws_s3_role_policy_attachment" {
262+
role = aws_iam_role.segment_aws_s3_iam_role.name
263+
policy_arn = aws_iam_policy.segment_aws_s3_policy.arn
264+
}
265+
266+
# Include the following sections if you’re using KMS encryption on your S3 bucket
267+
resource "aws_iam_policy" "segment_aws_s3_kms_policy" {
268+
name = "SegmentAWSS3KMSPolicy"
269+
path = "/"
270+
description = "Gives access to your KMS key"
271+
policy = data.aws_iam_policy_document.segment_aws_s3_kms_policy_document.json
272+
}
273+
274+
data "aws_iam_policy_document" "segment_aws_s3_kms_policy_document" {
275+
version = "2012-10-17"
276+
statement {
277+
sid = "AllowKMS"
278+
actions = [
279+
"kms:GenerateDataKey",
280+
"kms:Decrypt",
281+
]
282+
# ARN of your KMS key.
283+
resources = [
284+
"<YOUR_KEY_ARN>",
285+
]
286+
effect = "Allow"
287+
}
288+
}
289+
290+
resource "aws_iam_role_policy_attachment" "segment_aws_s3_role_kms_policy_attachment" {
291+
role = aws_iam_role.segment_aws_s3_iam_role.name
292+
policy_arn = aws_iam_policy.segment_aws_s3_kms_policy.arn
293+
}
294+
```
201295

202296
### Add the AWS S3 with IAM Role Support Destination
203297

@@ -261,23 +355,43 @@ This procedure uses Segment's Public API to migrate an existing Amazon S3 destin
261355
262356
To migrate to the AWS S3 destination using the Public API:
263357

358+
#### Step 1 - Verify your configuration
359+
264360
1. Open the Segment app, select the Connections tab and then select Catalog.
265361
2. From the Catalog, select the Storage Destinations tab and select the **AWS S3** destination.
266362
3. On the AWS S3 destination page, click the **Configure AWS S3** button.
267363
4. Configure your AWS S3 destination. When asked for the bucket name, enter `<YOUR_BUCKET_NAME>/segment-logs/test`.
268364
5. Enable the destination, and verify data is received at `<YOUR_BUCKET_NAME>/segment-logs/test/segment-logs`. <br/>**Note:** If the folder receives data, continue to the next step. If you don't see log entries, check the trust relationship document and IAM policy attached to your IAM role.
269-
6. Create your new AWS S3 destination using the [`create destination`](https://api.segmentapis.com/docs/connections/destinations/#create-destination) Public API call. The `sourceId`, `metadataId`, and `settings` parameters are required. An example of the parameters is below: <br/>
365+
366+
367+
#### Step 2 - Migrate an existing destination using the Public API
368+
369+
1. Identify the source IDs for your old Amazon S3 destination(s). You can use the Public API to return information about a list of your Amazon S3 destinations or an individual destination. <br/>
370+
To return a list of all of your Amazon S3 destinations, use the [`list destinations`](https://api.segmentapis.com/docs/connections/destinations/#list-destinations) call and filter the results using metadata id `54f418c3db31d978f14aa925` or slug `amazon-s3`: <br/>
371+
```shell
372+
curl -vvv --location --request GET https://api.segmentapis.com/destinations?pagination.count=1 \
373+
--header 'Content-Type: application/json' \
374+
--header 'Authorization: Bearer ...' \
375+
--data-raw '
376+
```
377+
To return the information for an individual Amazon S3 destination, use the [`get destination`](https://api.segmentapis.com/docs/connections/destinations/#get-destination) call, using the destination ID for your individual Amazon S3 destination (**Note:** The destination ID for your Amazon S3 source is visible in the Segment app, on the destination's settings page.) <br/>
378+
```shell
379+
curl -vvv --location --request GET https://api.segmentapis.com/destinations/$DESTINATION_ID \
380+
--header 'Content-Type: application/json' \
381+
--header 'Authorization: Bearer ...' \
382+
--data-raw '
383+
```
384+
2. Create your new AWS S3 destination using the [`create destination`](https://api.segmentapis.com/docs/connections/destinations/#create-destination) Public API call. The `sourceId`, `metadataId`, and `settings` parameters are required. An example of the parameters is below: <br/>
270385
```json
271386
{
272387
"sourceId": "$SOURCE_ID",
273388
"metadataId": "60be92c8dabdd561bf6c9130",
274389
"name": "AWS S3",
275390
"settings": {
276-
"region": "XYZ",
277-
"s3Bucket": "test",
391+
"region": "$BUCKET_REGION",
392+
"s3Bucket": "$YOUR_BUCKET_NAME",
278393
"iamRoleArn": "$IAM_ROLE_ARN"
279394
}
280-
}
281395
```
282396
<br/>**Optional:** You can create a destination that's not enabled automatically upon creation by setting `enabled` to `false` when creating the new AWS S3 destination:
283397
<br/>
@@ -293,23 +407,8 @@ curl -vvv --location --request PATCH https://api.segmentapis.com/destinations/$D
293407
' | jq
294408
```
295409
<br/>
296-
8. Identify the source IDs for your old Amazon S3 destination(s). You can use the Public API to return information about a list of your Amazon S3 destinations or an individual destination. <br/><br/>
297-
To return a list of all of your Amazon S3 destinations, use the [`list destinations`](https://api.segmentapis.com/docs/connections/destinations/#list-destinations) call and filter the results using metadata id `54f418c3db31d978f14aa925` or slug `amazon-s3`: <br/>
298-
```shell
299-
curl -vvv --location --request GET https://api.segmentapis.com/destinations?pagination.count=1 \
300-
--header 'Content-Type: application/json' \
301-
--header 'Authorization: Bearer ...' \
302-
--data-raw '
303-
```
304-
To return the information for an individual Amazon S3 destination, use the [`get destination`](https://api.segmentapis.com/docs/connections/destinations/#get-destination) call, using the destination ID for your individual Amazon S3 destination (**Note:** The destination ID for your Amazon S3 source is visible in the Segment app, on the destination's settings page.) <br/>
305-
```shell
306-
curl -vvv --location --request GET https://api.segmentapis.com/destinations/$DESTINATION_ID \
307-
--header 'Content-Type: application/json' \
308-
--header 'Authorization: Bearer ...' \
309-
--data-raw '
310-
```
311410

312-
9. Disable the Amazon S3 destinations using the following command, replacing `$DESTINATION_ID` with the ID of your Amazon S3 destination you found in the previous step:
411+
3. Disable the Amazon S3 destinations using the following command, replacing `$DESTINATION_ID` with the ID of your Amazon S3 destination you found in a previous step:
313412

314413
```shell
315414
curl -vvv --location --request PATCH https://api.segmentapis.com/destinations/$DESTINATION_ID \
@@ -321,10 +420,10 @@ curl -vvv --location --request PATCH https://api.segmentapis.com/destinations/$D
321420
"enabled": false
322421
}
323422
' | jq
324-
```
423+
```
325424

326425
> error " "
327-
> You must migrate to the new S3 destination before you disable your legacy destination to ensure Segment continues to deliver data to your S3 bucket.
426+
> You must migrate to the new S3 destination before you disable your legacy destination to ensure Segment continues to deliver data to your S3 bucket.
328427
329428
## Test your migrated source
330429
You can validate that you configured your migrated source correctly on the AWS S3 destination page in the Segment app.
@@ -389,4 +488,4 @@ For user-property destinations, Segment sends an [identify](/docs/connections/sp
389488

390489
When you first create an audience, Personas sends an Identify call for every user in that audience. Later audience syncs send updates for users whose membership has changed since the last sync.
391490

392-
{% include content/destination-footer.md %}
491+
{% include content/destination-footer.md %}

0 commit comments

Comments
 (0)