Skip to content

Commit

Permalink
Merge pull request #67 from opzkit/fix-image-defaults
Browse files Browse the repository at this point in the history
fix: use null as default since that's what we check
  • Loading branch information
argoyle authored Dec 4, 2023
2 parents 10ca696 + a61db15 commit 4510961
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Validate examples terraform v${{ matrix.tf-version }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: make examples
build:
needs: [examples]
Expand Down
25 changes: 25 additions & 0 deletions ami.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
data "aws_ami" "default_image" {
most_recent = true
name_regex = "^ubuntu/.*focal-20.04-amd64-server-\\d+(\\.\\d+)?$"
owners = ["099720109477"]

filter {
name = "name"
values = ["ubuntu/*focal*"]
}

filter {
name = "architecture"
values = ["x86_64"]
}

filter {
name = "root-device-type"
values = ["ebs"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}
}
9 changes: 2 additions & 7 deletions examples/additional_nodes/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ provider "kops" {
}

provider "aws" {
skip_requesting_account_id = true
skip_credentials_validation = true
skip_metadata_api_check = true
s3_use_path_style = true
region = "eu-west-1"
access_key = "mock_access_key"
secret_key = "mock_secret_key"
s3_use_path_style = true
region = "eu-west-1"
}

terraform {
Expand Down
9 changes: 2 additions & 7 deletions examples/basic/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ provider "kops" {
}

provider "aws" {
skip_requesting_account_id = true
skip_credentials_validation = true
skip_metadata_api_check = true
s3_use_path_style = true
region = "eu-west-1"
access_key = "mock_access_key"
secret_key = "mock_secret_key"
s3_use_path_style = true
region = "eu-west-1"
}

terraform {
Expand Down
9 changes: 2 additions & 7 deletions examples/policies/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ provider "kops" {
}

provider "aws" {
skip_requesting_account_id = true
skip_credentials_validation = true
skip_metadata_api_check = true
s3_use_path_style = true
region = "eu-west-1"
access_key = "mock_access_key"
secret_key = "mock_secret_key"
s3_use_path_style = true
region = "eu-west-1"
}

terraform {
Expand Down
6 changes: 3 additions & 3 deletions k8s.tf
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ resource "kops_instance_group" "masters" {
cluster_name = kops_cluster.k8s.id
name = "${var.control_plane_prefix}-${var.region}${each.key}"
role = "ControlPlane"
image = var.master_image != null ? var.master_image : var.image
image = coalesce(var.master_image, var.image, "${data.aws_ami.default_image.owner_id}/${data.aws_ami.default_image.name}")
min_size = 1
max_size = 1
machine_type = var.master_types[0]
Expand Down Expand Up @@ -272,7 +272,7 @@ resource "kops_instance_group" "nodes" {
cluster_name = kops_cluster.k8s.id
name = "nodes-${each.key}"
role = "Node"
image = var.node_image != null ? var.node_image : var.image
image = coalesce(var.node_image, var.image, "${data.aws_ami.default_image.owner_id}/${data.aws_ami.default_image.name}")
min_size = lookup(local.min_nodes, each.key)
max_size = lookup(local.max_nodes, each.key)
machine_type = var.node_types[0]
Expand Down Expand Up @@ -311,7 +311,7 @@ resource "kops_instance_group" "additional_nodes" {
cluster_name = kops_cluster.k8s.id
name = "nodes-${each.key}"
role = "Node"
image = each.value.image != null ? each.value.image : var.image
image = coalesce(each.value.image, var.image, "${data.aws_ami.default_image.owner_id}/${data.aws_ami.default_image.name}")
min_size = each.value.min_size
max_size = each.value.max_size
machine_type = each.value.types[0]
Expand Down
6 changes: 3 additions & 3 deletions vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ variable "dns_zone" {
variable "image" {
type = string
description = "The image to use for instances (can be overridden by master_image, node_image and image in additional_nodes)"
default = ""
default = null
}

variable "master_types" {
Expand Down Expand Up @@ -87,7 +87,7 @@ variable "master_max_instance_lifetime_hours" {
variable "master_image" {
type = string
description = "The image to use for master instances"
default = ""
default = null
}

variable "node_types" {
Expand Down Expand Up @@ -126,7 +126,7 @@ variable "node_max_instance_lifetime_hours" {
variable "node_image" {
type = string
description = "The image to use for node instances"
default = ""
default = null
}

variable "additional_nodes" {
Expand Down

0 comments on commit 4510961

Please sign in to comment.