Skip to content

Commit

Permalink
Upgraded to TF 0.14 and issues fixes (#22)
Browse files Browse the repository at this point in the history
* updated vpc version and vpc config accordingly and updated to TF 0.14, both examples work

* fixed some issues

* removed line comment on examples/default/init/main.tf

* terraform fmt on example/default/init/main.tf

* set fmt recursive to true in taskfile
  • Loading branch information
SadriG91 committed Apr 6, 2021
1 parent f026f09 commit 494bb18
Show file tree
Hide file tree
Showing 20 changed files with 234 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.* text eol=lf
7 changes: 3 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: workflow

on: [push]
on: [push, pull_request]

jobs:
test:
Expand All @@ -11,9 +11,8 @@ jobs:
uses: actions/setup-go@v1
with: { go-version: 1.13 }
- name: Install Terraform
run: |
curl -sL https://releases.hashicorp.com/terraform/0.12.8/terraform_0.12.8_linux_amd64.zip -o terraform.zip
sudo unzip terraform.zip -d /usr/bin && rm -f terraform.zip
uses: hashicorp/setup-terraform@v1
with: { terraform_version: 0.14.9 }
- name: Install Taskfile
run: curl -sL https://taskfile.dev/install.sh | sh
- name: Run tests
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ To get a working Sonarqube installation up and running complete the following st
replace the value for route53_zone with the name of your route53 hosted zone
4. create the following ssm parameters in your AWS account and encrypt them using the key create above.

| ssm parameter name| description |
| ssm parameter name| description of value |
|--- |--- |
| \<name_prefix\>/github-auth-enabled |set to true|
| \<name_prefix\>/github-client-id | obtained from github|
| \<name_prefix\>/github-client-secret |obtained from github|
| \<name_prefix\>/github-organizations |github organisation for ouath|
| \<name_prefix\>/admin-username |may only contain url safe chars|
| \<name_prefix\>/admin-password |may only contain url safe chars|
| /<name_prefix\>/github-auth-enabled |set to true|
| /<name_prefix\>/github-client-id | obtained from github|
| /<name_prefix\>/github-client-secret |obtained from github|
| /<name_prefix\>/github-organizations |github organisation for ouath|
| /<name_prefix\>/admin-username |may only contain url safe chars|
| /<name_prefix\>/admin-password |may only contain url safe chars|

5. run terraform apply

Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tasks:
cd $d
echo "${BOLD}$PWD:${NORM}"
if ! terraform fmt -check=true -list=false -recursive=false; then
if ! terraform fmt -check=true -list=false -recursive=true; then
echo " ✗ terraform fmt" && exit $?
else
echo " √ terraform fmt"
Expand Down
57 changes: 57 additions & 0 deletions examples/default/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions examples/default/init/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions examples/default/init/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 0.12"
required_version = ">= 0.14"

backend "s3" {
key = "terraform-modules/development/terraform-aws-sonarqube/default-init.tfstate"
Expand All @@ -13,7 +13,6 @@ terraform {
}

provider "aws" {
version = ">= 2.17"
region = "eu-west-1"
allowed_account_ids = ["<test-account-id>"]
}
Expand Down Expand Up @@ -93,3 +92,6 @@ output "parameters_key_arn" {
value = module.sonarqube-init.parameters_key_arn
}

output "parameters_key_alias" {
value = module.sonarqube-init.parameters_key_alias
}
12 changes: 12 additions & 0 deletions examples/default/init/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0"
}
random = {
source = "hashicorp/random"
}
}
required_version = ">= 0.14"
}
8 changes: 3 additions & 5 deletions examples/default/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 0.12"
required_version = ">= 0.14"

backend "s3" {
key = "terraform-modules/development/terraform-aws-sonarqube/default.tfstate"
Expand All @@ -13,7 +13,6 @@ terraform {
}

provider "aws" {
version = ">= 2.17"
region = "eu-west-1"
allowed_account_ids = ["<test-account-id>"]
}
Expand All @@ -29,12 +28,11 @@ locals {
module "sonarqube" {
source = "../../"
name_prefix = "sonarqube-default-test"
private_subnet_count = "2"
cluster_instance_type = "t2.small"
cluster_instance_count = "1"
tags = local.tags
parameters_key_arn = "<parameters-key-arn>"
route53_zone_name = "<route53-zone-name>"
parameters_key_arn = "<parameters_key_arn>"
route53_zone_name = "<route53_zone_name>"
}

output "sonarqube_URL" {
Expand Down
9 changes: 9 additions & 0 deletions examples/default/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0"
}
}
required_version = ">= 0.14"
}
39 changes: 39 additions & 0 deletions examples/sonarqube-service/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 18 additions & 12 deletions examples/sonarqube-service/example.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
provider "aws" {
version = ">= 2.17"
region = "eu-west-1"
region = "eu-west-1"
}

data "aws_vpc" "main" {
Expand All @@ -13,8 +12,8 @@ data "aws_subnet_ids" "main" {

locals {
name_prefix = "sonarqube-example"
route53_zone = "example.com"
certificate_arn = "<ssl-certificate-arn>"
route53_zone = "<route53_zone>"
certificate_arn = "<certificate_arn>"

tags = {
terraform = "true"
Expand All @@ -25,26 +24,26 @@ locals {

module "ecs_cluster" {
source = "telia-oss/ecs/aws//modules/cluster"
version = "2.0.0"
version = "3.0.0-alpha.3"

instance_ami = "ami-0af844a965e5738db"
instance_ami = "ami-0ffea00000f287d30"
instance_type = "t2.small"
name_prefix = local.name_prefix
vpc_id = data.aws_vpc.main.id
subnet_ids = [data.aws_subnet_ids.main.ids]
subnet_ids = data.aws_subnet_ids.main.ids
tags = local.tags
load_balancers = [module.loadbalancer.security_group_id]
load_balancer_count = 1
}

module "loadbalancer" {
source = "telia-oss/loadbalancer/aws"
version = "3.0.0"
version = "4.0.0"

name_prefix = local.name_prefix
type = "application"
vpc_id = data.aws_vpc.main.id
subnet_ids = [data.aws_subnet_ids.main.ids]
subnet_ids = data.aws_subnet_ids.main.ids
tags = local.tags
}

Expand All @@ -60,6 +59,13 @@ module "sonarqube" {
cluster_security_group_id = module.ecs_cluster.security_group_id
loadbalancer_dns_name = module.loadbalancer.dns_name
route53_zone_name = local.route53_zone

##This is added to force Terraform to create the parameters before deploying Sonarqube
##This is for the example only don't do this in production
depends_on = [
aws_ssm_parameter.sonarqube_rds_username,
aws_ssm_parameter.sonarqube_rds_password
]
}

resource "aws_lb_listener" "main" {
Expand Down Expand Up @@ -95,14 +101,14 @@ resource "aws_kms_alias" "key-alias" {
}

#Passwords set and storted in repo for example only (don't do it this way!)
resource "aws_ssm_parameter" "rds_username" {
resource "aws_ssm_parameter" "sonarqube_rds_username" {
name = "/${local.name_prefix}/rds-username"
type = "SecureString"
value = "username"
key_id = aws_kms_key.sonarqube-parameters.key_id
}

resource "aws_ssm_parameter" "rds_password" {
resource "aws_ssm_parameter" "sonarqube_rds_password" {
name = "/${local.name_prefix}/rds-password"
type = "SecureString"
value = "notsogoodpassword"
Expand All @@ -117,7 +123,7 @@ resource "aws_ssm_parameter" "admin_username" {
}

resource "aws_ssm_parameter" "admin_password" {
name = "/${local.name_prefix}/admin-username"
name = "/${local.name_prefix}/admin-password"
type = "SecureString"
value = "anotherbadpassword"
key_id = aws_kms_key.sonarqube-parameters.key_id
Expand Down
11 changes: 8 additions & 3 deletions examples/sonarqube-service/versions.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

terraform {
required_version = ">= 0.12"
}
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0"
}
}
required_version = ">= 0.14"
}
Loading

0 comments on commit 494bb18

Please sign in to comment.