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

feat: s3 data forwarding #636

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

imranismail
Copy link

@imranismail imranismail commented Mar 22, 2024

Support use-case to deploy S3 data forwarding destination and rules

resource "aws_s3_bucket" "this" {
  bucket = "${terraform.workspace}-sumologic"
}

resource "aws_s3_bucket_public_access_block" "this" {
  bucket                  = aws_s3_bucket.this.id
  block_public_acls       = true
  block_public_policy     = true
  ignore_public_acls      = true
  restrict_public_buckets = true
}

data "aws_iam_policy_document" "trust" {
  statement {
    actions = ["sts:AssumeRole"]
    effect  = "Allow"

    principals {
      type        = "AWS"
      identifiers = ["arn:aws:iam::926226587429:root"]
    }

    condition {
      test     = "StringEquals"
      variable = "sts:ExternalId"
      values   = ["au:0000000000595DED"]
    }
  }
}

resource "aws_iam_role" "this" {
  name               = "${terraform.workspace}-sumologic-s3-writer"
  assume_role_policy = data.aws_iam_policy_document.trust.json
}

data "aws_iam_policy_document" "role" {
  statement {
    actions   = ["s3:PutObject"]
    resources = ["${aws_s3_bucket.this.arn}/*"]
  }
}

resource "aws_iam_role_policy" "this" {
  name   = "sumologic-s3-writer"
  role   = aws_iam_role.this.id
  policy = data.aws_iam_policy_document.role.json
}

data "sumologic_partitions" "this" {}

resource "sumologic_s3_data_forwarding_destination" "this" {
  depends_on          = [aws_iam_role_policy.this]
  name                = "${terraform.workspace}-sumologic"
  bucket_name         = aws_s3_bucket.this.bucket
  authentication_mode = "RoleBased"
  role_arn            = aws_iam_role.this.arn
  encrypted           = true
}


locals {
  partitions = {
    for partition in data.sumologic_partitions.this.partitions : partition.name => partition
    if startswith(partition.name, "${terraform.workspace}_eks_") && partition.analytics_tier != "infrequent"
  }
}


resource "sumologic_s3_data_forwarding_rule" "this" {
  for_each       = local.partitions
  index_id       = each.value.id
  destination_id = sumologic_s3_data_forwarding_destination.this.id
  file_format    = "{index}/{day}/{hour}_{minute}_{second}"
}

@sumovishal
Copy link
Collaborator

@vsinghal13 can you take a look?

@vsinghal13
Copy link
Collaborator

@sumovishal this is not owned by Data Collection team.

@vsinghal13
Copy link
Collaborator

@ksbagr seems to be last person who made some changes to partitions. can you review this?

@imranismail
Copy link
Author

Hi folks, any chance to get this in?

@imranismail
Copy link
Author

Hey folks, any chance to get this in or do we have to maintain a fork of this from now on?

@sumovishal
Copy link
Collaborator

@AyanGhatak can you take a look?

func (s *Client) ListPartitions() ([]Partition, error) {
var listPartitionResp ListPartitionResp

data, _, err := s.Get("v1/partitions")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of fetching default no of partitions, it might be better to fetch max limit allowed 1000 to reduce number of api calls https://api.sumologic.com/docs/#operation/listPartitions

d.SetId(createdDfd.IndexID)
}

return resourceSumologicS3DataForwardingRuleUpdate(d, meta)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be RuleRead not update


type S3DataForwardingDestination struct {
ID string `json:"id,omitempty"`
Name string `json:"destinationName,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please rename this to DestinationName for clarity

State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here to rename this to destination_name to have similar naming convention with api

d.SetId(createdDfd.ID)
}

return resourceSumologicS3DataForwardingDestinationUpdate(d, meta)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Read not Update

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be changed, right @sumovishal

@ssharma-sumologic
Copy link
Collaborator

Tests are missing

@sumovishal
Copy link
Collaborator

@ssharma-sumologic please review again. If the PR looks good, can you open it against the provider repo? We can't run acceptance tests here.


func resourceSumologicS3DataForwardingRuleDelete(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Client)
return c.DeleteS3DataForwardingRule(d.Id())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change this to d.index_id

return fmt.Errorf("S3DataForwardingRule for id %s not found", id)
}

d.SetId(dfr.IndexID)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The id of a data forwarding rule isn't equal to the indexId. Please set the id of the rule here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there's some confusion around Id and indexId. IndexId is the id of the partition/view , while the id is a unique identifier of the rule. Please see the docs https://api.sumologic.com/docs/#operation/createDataForwardingRule for more reference

@namangoya
Copy link
Collaborator

@imranismail - We will be releasing the changes here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants