Skip to content

Commit e2b8171

Browse files
authored
Merge pull request #12 from ryanmcafee/feature/terraform-workspace-support
Feature/terraform workspace support
2 parents 29475b6 + a8cac51 commit e2b8171

37 files changed

+1399
-2713
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ credentials
77
terraform.tfvars
88
terraform.tfstate.d
99
backend.hcl
10-
customizations
10+
customizations
11+
terraform.tfstate

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Flavorize aims to make it easy to setup and provision a fully working Kubernetes
66

77
To setup/provision a Kubernetes cluster, follow the documentation for the appropriate provider. The following guides make it possible to setup a Kubernetes cluster in under 1 hr, on your pick of cloud provider. Your mileage will vary based on your knowledge and experience, but I have aimed to make the setup as streamlined as possible to help encourage the adoption and usage of Kubernetes and other cloud native technologies. Flavorize is now baked into my workflow and can't imagine using Kubernetes without it. I have built kubernetes "flavors" for Azure as well as Digital Ocean of which you may find quick starts on how to use below.
88

9-
[Azure](docs/providers/Azure.md)
9+
[Azure](flavors/azure/readme.md)
1010

11-
[Digital Ocean](docs/providers/DigitalOcean.md)
11+
[Digital Ocean](flavors/digitalocean/readme.md)
1212

1313
# Contributing
1414

destroy.ps1

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#! /usr/bin/pwsh
2+
3+
[CmdletBinding()]
4+
Param(
5+
[string]$flavor = "azure",
6+
[string]$tf_workspace = (Invoke-Expression -Command "terraform workspace show").Trim(),
7+
[string]$kube_config_dir = "credentials/workspaces/${tf_workspace}/.kube",
8+
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
9+
[string[]]$Args
10+
)
11+
12+
#Initialize terraform
13+
terraform init flavors/${flavor}
14+
15+
$provider_specific_variable_file=If (Test-Path "customizations/workspaces/${tf_workspace}/provider.tfvars" -PathType Leaf) {"customizations/workspaces/${tf_workspace}/provider.tfvars"} Else {"customizations/provider.tfvars"}
16+
$flavor_variable_file=If (Test-Path "customizations/workspaces/${tf_workspace}/flavorize.tfvars" -PathType Leaf) {"customizations/workspaces/${tf_workspace}/flavorize.tfvars"} Else {"customizations/flavorize.tfvars"}
17+
18+
#Create the terraform plan
19+
terraform destroy -var-file="${provider_specific_variable_file}" -var-file="${flavor_variable_file}" flavors/${flavor}

docs/Contributing.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
In order to add support for an additional cloud provider you'll want to do the following:
66

7-
1) Add your new Terraform cloud provider resource plugin to providers.tf and make sure that you set the correct version number for it to work reliably for others.
7+
1) Create an issue for the provider you are adding support for
88

9-
2) Create additional directory under modules/k8s/{cloudProviderName} and place 3 files there: k8s.tf, variables.tf and output.tf
9+
2) Clone the repo locally
1010

11-
3) Consult documentation for your cloud provider that you are adding support for and update k8s.tf in your directory accordingly. Please also ensure that the provider's resources will only attempt provisioning when the value for your cloud_provider is set to your new provider. You can accomplish this by using a ternary statement and the count property. Look at the azure provider for an example of this.
11+
3) Create a feature branch from master
1212

13-
4) Ensure that the available output variables conform to the same output variables used in: modules/k8s/azure/output.tf so we can continue to interchangably provision common resources across cloud providers (certmanager, ingress controller, externaldns, etc..).
13+
4) Navigate to the "flavors" directory and expand it.
1414

15-
5) Add any additional provider specific variables to: modules/k8s/{cloudProviderName}/variables.tf.
15+
5) Copy the "flavors/azure" folder into "flavors/yournewflavor"
1616

17-
6) Add your new provider to main.tf in the directory root with the same module name of "k8s". After doing so and testing it out to make sure it works, please comment out the additional provider. To my knowledge, Terraform currently doesn't offer a way to disable a module at the module level, so for now this is the best work around I can think of. Please open an issue, if you have a better recommendation.
17+
6) Update the following files in the new flavor folder: k8s.tf (provider specific kubernetes cluster provisioning and calls the flavorize module), output.tf (store the kubernetes cluster info in tf state), providers.tf (terraform provider setup), variables.tf (variables specific to your new provider)
1818

1919
7) Lastly, ensure that any additional variables specific to your provider have been added to terraform.tfvars.example
2020

0 commit comments

Comments
 (0)