diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..86877f0 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,13 @@ +{ + "name": "gitlab-runner", + "image": "mcr.microsoft.com/vscode/devcontainers/base:ubuntu-22.04", + "features": { + "ghcr.io/devcontainers/features/terraform:1.3.5": { + "version": "1.6.1", + "terragrunt": "0.52.1" + }, + "ghcr.io/devcontainers-contrib/features/pre-commit:2.0.9": { + "version": "3.4.0" + } + } +} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ce318ab --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,29 @@ +--- +default_language_version: + python: python3 + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + args: + - --markdown-linebreak-ext=md + - id: check-merge-conflict + - id: no-commit-to-branch + args: + - "--branch" + - "main" + - id: check-symlinks + - id: check-added-large-files + - id: check-json + - id: check-yaml + - repo: https://github.com/markdownlint/markdownlint + rev: v0.13.0 + hooks: + - id: markdownlint + - repo: https://github.com/maxbrunet/pre-commit-renovate + rev: 37.31.1 + hooks: + - id: renovate-config-validator diff --git a/backend.tf b/backend.tf new file mode 100644 index 0000000..cde57e0 --- /dev/null +++ b/backend.tf @@ -0,0 +1,4 @@ +terraform { + backend "s3" { + } +} diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..7459dc0 --- /dev/null +++ b/main.tf @@ -0,0 +1,18 @@ +module "ec2-instance" { + source = "terraform-aws-modules/ec2-instance/aws" + version = "5.5.0" + + name = "runner-instance" + + instance_type = var.instance_type + key_name = var.key_name + monitoring = true + vpc_security_group_ids = ["sg-12345678"] + subnet_id = "subnet-eddcdzz4" + + tags = { + Project = var.project + User = var.user + Environment = var.environment + } +} diff --git a/providers.tf b/providers.tf new file mode 100644 index 0000000..f164d60 --- /dev/null +++ b/providers.tf @@ -0,0 +1,10 @@ +provider "gitlab" { + token = var.token + base_url = var.base_url + insecure = var.insecure +} + +provider "aws" { + region = var.aws_region + profile = var.aws_profile +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..37df34d --- /dev/null +++ b/renovate.json @@ -0,0 +1,80 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "github>platform-engineering-org/.github" + ], + "customManagers": [ + { + "customType": "regex", + "matchStringsStrategy": "combination", + "fileMatch": [ + "variables.tf" + ], + "matchStrings": [ + "variable\\s*\"runner_version\"", + "description", + "type", + "default\\s*=\\s*\"(?.*)\"" + ], + "depNameTemplate": "gitlab-org/gitlab-runner", + "datasourceTemplate": "gitlab-releases", + "extractVersionTemplate": "^v?(?.*)$" + }, + { + "customType": "regex", + "fileMatch": [".devcontainer/devcontainer.json"], + "matchStrings": [ + "\"image\": \"(?mcr.microsoft.com/vscode/devcontainers/base):(?.*)\"" + ], + "datasourceTemplate": "docker" + }, + { + "customType": "regex", + "fileMatch": [".devcontainer/devcontainer.json"], + "matchStrings": [ + "\"(?ghcr.io/devcontainers/features/terraform):(?.*)\"" + ], + "datasourceTemplate": "docker" + }, + { + "customType": "regex", + "matchStringsStrategy": "combination", + "fileMatch": [".devcontainer/devcontainer.json"], + "matchStrings": [ + "\"ghcr.io/devcontainers/features/terraform\"", + "\"version\":\\s*\"(?.*)\"" + ], + "depNameTemplate": "hashicorp/terraform", + "datasourceTemplate": "github-releases" + }, + { + "customType": "regex", + "fileMatch": [".devcontainer/devcontainer.json"], + "matchStrings": [ + "\"(?terragrunt)\":\\s*\"(?.*)\"" + ], + "depNameTemplate": "gruntwork-io/terragrunt", + "datasourceTemplate": "github-releases", + "extractVersionTemplate": "^v?(?.*)$" + }, + { + "customType": "regex", + "fileMatch": [".devcontainer/devcontainer.json"], + "matchStrings": [ + "\"(?ghcr.io/devcontainers-contrib/features/pre-commit):(?.*)\"" + ], + "datasourceTemplate": "docker" + }, + { + "customType": "regex", + "matchStringsStrategy": "combination", + "fileMatch": [".devcontainer/devcontainer.json"], + "matchStrings": [ + "\"ghcr.io/devcontainers-contrib/features/pre-commit\"", + "\"version\":\\s*\"(?.*)\"" + ], + "depNameTemplate": "pre-commit/pre-commit", + "datasourceTemplate": "github-releases" + } + ] +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..545d691 --- /dev/null +++ b/variables.tf @@ -0,0 +1,87 @@ +variable "aws_region" { + description = "AWS region." + type = string +} + +variable "aws_profile" { + description = "AWS profile." + type = string + default = "default" +} + +variable "token" { + type = string + description = "Gitlab token" + sensitive = true +} + +variable "insecure" { + type = string + description = "Do not verify certifcate if true" + default = true +} + +variable "base_url" { + type = string + description = "gitlab api end point" + default = "https://gitlab.com/api/v4/" +} + +variable "environment" { + description = "A name that identifies the environment, will used as prefix and for tagging." + type = string + default = "dev" +} + +variable "runner_name" { + description = "Name of the runner, will be used in the runner config.toml" + type = string + default = "pe-runner" +} + +variable "gitlab_url" { + description = "URL of the gitlab instance to connect to." + type = string + default = "https://gitlab.com" +} + +variable "registration_token_runner" { + description = "Registration token for the runner." + type = string + sensitive = true +} + +variable "timezone" { + description = "Name of the timezone that the runner will be used in." + type = string + default = "Europe/Amsterdam" +} + +variable "project" { + description = "Project Name" + type = string + default = "Platform Engineering" +} + +variable "user" { + description = "User name" + type = string +} + +variable "runner_version" { + description = "Gitlab runner version" + type = string + default = "16.4.1" +} + +variable "instance_type" { + description = "AWS instance type" + type = string + default = "t3.micro" +} + +variable "key_name" { + description = "AWS instance type" + type = string + default = "t3.micro" +} diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..1d0636a --- /dev/null +++ b/versions.tf @@ -0,0 +1,28 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "5.22.0" + } + gitlab = { + source = "gitlabhq/gitlab" + version = "16.4.1" + } + local = { + source = "hashicorp/local" + version = "2.4.0" + } + null = { + source = "hashicorp/null" + version = "3.2.1" + } + tls = { + source = "hashicorp/tls" + version = "4.0.4" + } + random = { + source = "hashicorp/random" + version = "3.5.1" + } + } +}