Skip to content

Commit

Permalink
ksynth on ec2 instance (#61)
Browse files Browse the repository at this point in the history
* ksynth on ec2 instance

* Implemented suggestions from review
  • Loading branch information
jdziurzynski authored Dec 6, 2024
1 parent e1f3e91 commit 867d757
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
37 changes: 37 additions & 0 deletions synthetics_AWS/terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Synthetics agent deployment on AWS ec2 instance

The module creates ec2 instance with provided configuration and deploys `ksynth` agent.

## Requirements

| Name | Version |
|--------------|---------|
| terraform | ~> 1.0 |
| aws provider | ~> 4.0 |
| AWS CLI | ~> 4.0 |


## Inputs

| Name | Description | Type | Default | Required |
|------------------------|--------------------------------------------------|--------------|---------|----------|
| vpc_security_group_ids | List of security groups IDs | list(string) | | true |
| plan_id | Kentik plan ID | string | | true |
| region | Specifies AWS provider region | string | | false |
| key_name | Key name of the Key Pair to use for the instance | string | | false |
| iam_instance_profile | IAM role ID | string | | false |
| subnet_id | Subnet ID | string | | false |


## Usage

```bash
terraform init
terraform apply \
-var='vpc_security_group_ids=["<vpc-security-group-id>"]' \
-var='plan_id=<plan-id>' \
-var='region=<region-name>' \
-var='key_name=<key-name>' \
-var='iam_instance_profile=<iam-instance-profile>' \
-var='subnet_id=<subnet-id>'
```
40 changes: 40 additions & 0 deletions synthetics_AWS/terraform/ec2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
data "aws_ami" "ubuntu" {
most_recent = true

filter {
name = "name"
# Make sure that given ami is not deprecated.
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = ["099720109477"]
}

resource "aws_instance" "instance" {
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"

iam_instance_profile = var.iam_instance_profile
key_name = var.key_name
vpc_security_group_ids = var.vpc_security_group_ids
subnet_id = var.subnet_id

user_data = <<EOF
#!/bin/bash
curl -s https://packagecloud.io/install/repositories/kentik/ksynth/script.deb.sh | sudo bash
apt-get install ksynth
echo "KENTIK_COMPANY=${var.plan_id}" >> /etc/default/ksynth
systemctl start ksynth
# Restart agent after setting variables
systemctl stop ksynth && systemctl start ksynth
EOF

tags = {
Name = "ksynth_agent"
}
}
12 changes: 12 additions & 0 deletions synthetics_AWS/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_version = "~> 1.0"
required_providers {
aws = {
version = "~> 4.0"
}
}
}

provider "aws" {
region = var.region
}
35 changes: 35 additions & 0 deletions synthetics_AWS/terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
variable "key_name" {
description = "Key name of the Key Pair to use for the instance"
type = string
default = ""
}

variable "iam_instance_profile" {
description = "IAM role ID"
type = string
default = ""
}

variable "subnet_id" {
description = "Subnet ID"
type = string
default = ""
}

variable "vpc_security_group_ids" {
description = "List of security groups IDs"
type = list(string)
default = [""]
}

variable "plan_id" {
description = "Kentik plan ID"
type = string
default = ""
}

variable "region" {
description = "Specifies AWS provider region"
type = string
default = ""
}

0 comments on commit 867d757

Please sign in to comment.