Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions s3-shield/terraform-aws/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform.git
rev: v1.97.4
hooks:
- id: terraform_fmt
- id: terraform_docs
args: ['--args=--anchor=false', '--args=--hide resources,modules,data-sources']
- id: terraform_tflint
args: ['--args=--chdir=__GIT_WORKING_DIR__']
59 changes: 43 additions & 16 deletions s3-shield/terraform-aws/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
# Deploy on AWS via terraform and cloud-init

[terraform](https://www.terraform.io/) is an automation tool which allows you to manage cloud resources (spin up instances, create security groups, etc.) in cloud environment. The tool is extremely versatile, but we'll focus here on using it to deploy on AWS, using Varnish Enterprise AMIs.

## Requirements

`terraform`, that's it.

## Getting started

We first need to generate the cloud-init, there you need to edit `../cloud-init/s3.conf`, and then generate the `yaml` file that `terraform` will use:

``` bash
../cloud-init/generate_yaml.sh
1. Edit the ``../cloud-init/s3.conf`` to match your AWS environment
2. Generate the yaml configuration, later required by Terraform, as shown below

``` shell
$ ../cloud-init/generate_yaml.sh
```

Next, edit `variables.tf` to at least modify the `KEY_NAME` value to match your IAM key pair. You can also tweak the instance type and the region where to spawn it.
---

To deploy:
## Provision the infra

``` shell
terraform init
terraform plan
terraform apply
$ terraform init
$ terraform plan -var="key_name=your-key-name"
$ terraform apply -var="key_name=your-key-name"
```

The output should end with something like:
Expand All @@ -36,3 +30,36 @@ instance_public_ip_addr = "35.85.51.82"
```

In this case, your file will be accessible at http://35.85.51.82/path/to/your/file.png

---

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| terraform | >= 1.9.0 |
| aws | ~> 6.11 |

## Providers

| Name | Version |
|------|---------|
| aws | ~> 6.11 |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| ami\_owners | Varnish Software marketplace image | `list(string)` | <pre>[<br/> "679593333241"<br/>]</pre> | no |
| key\_name | Add your key in Key pairs in AWS | `string` | n/a | yes |
| region | n/a | `string` | `"us-west-2"` | no |
| ve6\_instance | n/a | `string` | `"t3.micro"` | no |

## Outputs

| Name | Description |
|------|-------------|
| instance\_private\_ip\_addr | n/a |
| instance\_public\_ip\_addr | n/a |
<!-- END_TF_DOCS -->
16 changes: 8 additions & 8 deletions s3-shield/terraform-aws/instance_ve6.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
data "aws_ami" "ubuntu-ve6" {
data "aws_ami" "ubuntu_ve6" {
most_recent = true

filter {
Expand All @@ -11,18 +11,18 @@ data "aws_ami" "ubuntu-ve6" {
values = ["hvm"]
}

owners = ["679593333241"] # Varnish Software marketplace image
owners = var.ami_owners
}

resource "aws_instance" "tf-ve6" {
ami = data.aws_ami.ubuntu-ve6.id
instance_type = "${var.VE6_INSTANCE}"
key_name = "${var.KEY_NAME}"
resource "aws_instance" "tf_ve6" {
ami = data.aws_ami.ubuntu_ve6.id
instance_type = var.ve6_instance
key_name = var.key_name
vpc_security_group_ids = [aws_security_group.s3shield_sec_22_80_443.id]
#user_data = data.template_file.user_data_ve6.rendered
user_data = "${file("../cloud-init/cloud-init-s3-shield.yaml")}"
user_data = file("../cloud-init/cloud-init-s3-shield.yaml")
tags = {
Project = "varnish-s3-shield"
Name = "varnish-s3-shield"
Name = "varnish-s3-shield"
}
}
6 changes: 3 additions & 3 deletions s3-shield/terraform-aws/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.16"
version = "~> 6.11"
}
}
required_version = ">= 1.2.0"
required_version = ">= 1.9.0"
}

provider "aws" {
region = var.REGION
region = var.region
}
22 changes: 13 additions & 9 deletions s3-shield/terraform-aws/variables.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
variable REGION {
type = string
variable "region" {
type = string
default = "us-west-2"
}

variable VE6_INSTANCE {
type = string
default = "t2.micro"
variable "ve6_instance" {
type = string
default = "t3.micro"
}

# Add your key in Key pairs in AWS and change the name under
variable KEY_NAME {
type = string
default = "your_key_pair_name"
variable "key_name" {
type = string
description = "Add your key in Key pairs in AWS"
}

variable "ami_owners" {
type = list(string)
default = ["679593333241"]
description = "Varnish Software marketplace image"
}