Setup s3 access at ec2 level
This commit is contained in:
parent
875e715ce9
commit
865831f1de
6 changed files with 47 additions and 58 deletions
|
|
@ -19,10 +19,6 @@ resource "aws_secretsmanager_secret_version" "dumpnet" {
|
|||
talosconfig = data.talos_client_configuration.this.talos_config
|
||||
kubeconfig = talos_cluster_kubeconfig.this.kubeconfig_raw
|
||||
}
|
||||
fluentbit = {
|
||||
aws_access_key_id = aws_iam_access_key.fluentbit.id
|
||||
aws_secret_access_key = aws_iam_access_key.fluentbit.secret
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
41
terraform/iam.tf
Normal file
41
terraform/iam.tf
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# IAM role for the EC2 node
|
||||
# Grants the node (and all pods on it) access to AWS services via instance metadata.
|
||||
# Add policies here as new services need AWS access.
|
||||
|
||||
resource "aws_iam_role" "node" {
|
||||
name = "${var.cluster_name}-node"
|
||||
|
||||
assume_role_policy = jsonencode({
|
||||
Version = "2012-10-17"
|
||||
Statement = [{
|
||||
Effect = "Allow"
|
||||
Principal = { Service = "ec2.amazonaws.com" }
|
||||
Action = "sts:AssumeRole"
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
resource "aws_iam_instance_profile" "node" {
|
||||
name = "${var.cluster_name}-node"
|
||||
role = aws_iam_role.node.name
|
||||
}
|
||||
|
||||
# S3 access for fluent-bit log shipping
|
||||
resource "aws_iam_role_policy" "node_s3_logs" {
|
||||
name = "s3-logs-write"
|
||||
role = aws_iam_role.node.id
|
||||
|
||||
policy = jsonencode({
|
||||
Version = "2012-10-17"
|
||||
Statement = [
|
||||
{
|
||||
Effect = "Allow"
|
||||
Action = ["s3:PutObject", "s3:GetObject", "s3:ListBucket"]
|
||||
Resource = [
|
||||
aws_s3_bucket.logs.arn,
|
||||
"${aws_s3_bucket.logs.arn}/*"
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
|
@ -60,31 +60,6 @@ resource "aws_athena_workgroup" "logs" {
|
|||
}
|
||||
}
|
||||
|
||||
# IAM user for fluent-bit to write to S3
|
||||
resource "aws_iam_user" "fluentbit" {
|
||||
name = "${var.cluster_name}-fluentbit"
|
||||
}
|
||||
|
||||
resource "aws_iam_access_key" "fluentbit" {
|
||||
user = aws_iam_user.fluentbit.name
|
||||
}
|
||||
|
||||
resource "aws_iam_user_policy" "fluentbit" {
|
||||
name = "fluentbit-s3-write"
|
||||
user = aws_iam_user.fluentbit.name
|
||||
|
||||
policy = jsonencode({
|
||||
Version = "2012-10-17"
|
||||
Statement = [
|
||||
{
|
||||
Effect = "Allow"
|
||||
Action = ["s3:PutObject"]
|
||||
Resource = "${aws_s3_bucket.logs.arn}/*"
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
output "logs_bucket" {
|
||||
value = aws_s3_bucket.logs.bucket
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,8 +64,9 @@ resource "aws_eip_association" "controlplane" {
|
|||
|
||||
# Launch control plane instance
|
||||
resource "aws_instance" "controlplane" {
|
||||
ami = var.ami_id
|
||||
instance_type = var.instance_type
|
||||
ami = var.ami_id
|
||||
instance_type = var.instance_type
|
||||
iam_instance_profile = aws_iam_instance_profile.node.name
|
||||
|
||||
network_interface {
|
||||
network_interface_id = aws_network_interface.controlplane.id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue