Skip to content

Instantly share code, notes, and snippets.

@valtermartins1301
Last active September 9, 2019 20:16
Show Gist options
  • Save valtermartins1301/c3e86640aef7692a89c178c939eaa835 to your computer and use it in GitHub Desktop.
Save valtermartins1301/c3e86640aef7692a89c178c939eaa835 to your computer and use it in GitHub Desktop.

Revisions

  1. valtermartins1301 revised this gist Sep 9, 2019. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -1,4 +0,0 @@
    .terraform
    *.tfplan
    *.tfstate
    *.tfstate.backup
  2. valtermartins1301 revised this gist Sep 9, 2019. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions .README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    # Terraform to create Netlify environment with Github + Route53 (AWS)

    ## Providers
    - (Netlify)[https://github.com/terraform-providers/terraform-provider-netlify]
    - (AWS)[https://github.com/terraform-providers/terraform-provider-aws]
    - (Github)[https://github.com/terraform-providers/terraform-provider-github]
  3. valtermartins1301 revised this gist Sep 9, 2019. No changes.
  4. valtermartins1301 renamed this gist Sep 9, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. valtermartins1301 revised this gist Sep 9, 2019. No changes.
  6. valtermartins1301 renamed this gist Sep 9, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. valtermartins1301 created this gist Sep 9, 2019.
    4 changes: 4 additions & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    .terraform
    *.tfplan
    *.tfstate
    *.tfstate.backup
    11 changes: 11 additions & 0 deletions backend.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    terraform {
    required_version = "~> 0.11.14"
    backend "s3" {}
    }

    # Setting AWS region
    provider "aws" {
    region = "${var.region}"

    version = "~> 2.20"
    }
    4 changes: 4 additions & 0 deletions data_source.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    data "aws_route53_zone" "route53_zone" {
    name = "${var.route53_record_alias_zone}"
    private_zone = false
    }
    23 changes: 23 additions & 0 deletions github.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    provider "github" {
    token = "${var.github_token}"
    organization = "your-organization"
    }

    resource "github_repository_deploy_key" "key" {
    title = "Netlify"
    repository = "your-repository-name"
    key = "${netlify_deploy_key.key.public_key}"
    read_only = false
    }

    resource "github_repository_webhook" "main" {
    repository = "your-repository-name"
    events = ["delete", "push", "pull_request"]

    configuration {
    content_type = "json"
    url = "https://api.netlify.com/hooks/github"
    }

    depends_on = ["netlify_site.main"]
    }
    23 changes: 23 additions & 0 deletions netlify.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    # Configure the Netlify Provider
    provider "netlify" {
    token = "${var.netlify_token}"
    }

    # Create a new deploy key for this specific website
    resource "netlify_deploy_key" "key" {}

    # Define your site
    resource "netlify_site" "main" {
    name = "${var.name}-${var.environment}"

    custom_domain = "${aws_route53_record.www.name}"

    repo {
    repo_branch = "master"
    command = "${var.build_command}"
    deploy_key_id = "${netlify_deploy_key.key.id}"
    dir = "build"
    provider = "github"
    repo_path = "your-repo/path"
    }
    }
    8 changes: 8 additions & 0 deletions route53.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    resource "aws_route53_record" "www" {
    zone_id = "${data.aws_route53_zone.route53_zone.zone_id}"
    name = "${var.name}.${var.environment}.your-domain.com"
    type = "CNAME"
    ttl = "300"

    records = ["${var.name}-${var.environment}.netlify.com."]
    }
    15 changes: 15 additions & 0 deletions variables.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    variable "profile" {
    default = "default"
    }

    variable "region" {}
    variable "name" {}

    variable "build_command" {
    default = "yarn build"
    }

    variable "github_token" {}
    variable "netlify_token" {}
    variable "route53_record_alias_zone" {}
    variable "environment" {}