I have a terraform repo that contains multiple modules as below.
root
|-modules
| |-module1
| | |- main.tf
| | |- variables
| | |- dev.tfvars
| | |- test.tfvars
| | |- prod.tfvars
| |-module2
| | |- main.tf
| | |- variables
| | |- dev.tfvars
| | |- test.tfvars
| | |- prod.tfvars
|-main.tf
root's main.tf includes modules as below
module "module1"{
source = ./modules/module1
}
module "module1"{
source = ./modules/module1
}
Now for this structure, I need to add environment specific tfvars file to provide variables needed for that module. I am able to override variables if it's a single module. But not able to figure out overrides in this case. Any advice is helpful.
You have to pass all those overwritten variables explicitly to your modules, start from the root.
I would restructure the project to take the environment specifics out of the modules. Modules should be environment agnostic.
root
|-modules
| |-module1
| | |- main.tf
| | |- variables
| |-module2
| | |- main.tf
| | |- variables
|-main.tf
|- dev.tfvars
|- test.tfvars
|- prod.tfvars
pass the required vars to the module invocation
module "module1"{
source = ./modules/module1
myvar1 = var.myvar1
myvar2 = var.myvar2
}
module "module2"{
source = ./modules/module2
myvar1 = var.myvar1
myvar2 = var.myvar2
}
then select the tfvars file for the environment you are deploying to
terraform plan -var-file=dev.tfvars
Related
I have created EKS cluster using terraform-aws-modules/vpc/aws with Terraform, I use one VPC with 3 private subnets on each AZs in Frankfurt. I've created two services (tomcat and psql) and deployment which are exposed via LoadBalancer and accessible via internet. It looks fine so far.
but the problem is that it's only one environment (DEV). I would like to create multiple environments like stage,test and more inside one VPC and inside one cluster, how to do it using terraform? should I create new files per environment? It would not make sense but nothing comes to my mind... I was considering also workspaces but the problem is that new workspace requires new state - it means that I need to create new VPC with new cluster per one workspace! maybe I should divide my terraform files to have something like "general" workspace and there would be a configuration to VPC and cluster, and create new workspaces for each of the environments? do you have any ideas or better solutions?
VPC - 172.26.0.0/16
+----------------------+----------------------------------+
| |
| |
| KUBERNETES CLUSTER |
| +-------------------------------------------------+ |
| | | |
| | | |
| | | |
| | +------------------+ +-----------------+ | |
| | | | | | | |
| | | TEST ENV | | DEV ENV | | |
| | | +------+ +-----+ | | +-----+ +-----+ | | |
| | | |tomcat| |psql | | | |tomcat |psql | | | |
| | | +------+ +-----+ | | +-----+ +-----+ | | |
| | | | | | | |
| | +------------------+ +-----------------+ | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| +-------------------------------------------------+ |
| |
+---------------------------------------------------------+
It is possible to create multiple environments in a single K8s cluster. You could use namespace for this. To access the different environments from outside the cluster, you can use a different domain name for each environment.
For example dev.abc.com to access the development environment and test.abc.com to access the test environment.
You can "separate the vpc" in its own state file. And then have a workspace for each EKS cluster. For the EKS you can pull the VPC info one of two ways, either from AWS data source by tag or from the state file.
Your tree structure would look something like this:
├── vpc
│ ├── main.tf
│ └── outputs.tf
└── eks
└── main.tf
Add the following to the backend settings in vpc/main.tf:
terraform {
backend "s3" {
...
key = "vpc/terraform.tfstate"
workspace_key_prefix = "vpc"
...
}
}
and eks/main.tf:
terraform {
backend "s3" {
...
key = "eks/terraform.tfstate"
workspace_key_prefix = "eks"
...
}
}
Passing the VPC to the EKS section:
Option 1 (pull from aws data source by name, ref https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc):
data "aws_vpc" "selected" {
filter {
...
}
}
Option 2 (pull from state file):
data "terraform_remote_state" "vpc" {
backend = "s3"
config = {
...
key = "vpc/terraform.tfstate"
workspace_key_prefix = "vpc"
...
}
}
It's not a good practice to manage your applications inside terraform, you can use terraform just to create your cluster (infra) EC2, EKS, VPC.... but what inside the cluster, you can use helm/kubectl.... to manage your pods, for example you can have two repositories, one for terraform iac and the other for projects, then you can manage your environments ( dev, staging, prod...) by namespaces...
I'm creating a github pages website with this tree in my repository:
|- pages
| |- 3.0.3
| | |- SUMMARY.md
| | |- core
| | | |- String.md
|- LICENSE.md
|- README.md
|- _config.yml
|- index.md
In index.md I wrote
* [0.3.0](pages/0.3.0/SUMMARY.md)
and in pages/0.3.0/SUMMARY.md
* [String](core/String.md)
My problem is this: I can correctly access the main page ('index.md') and pages/0.3.0/SUMMARY.md, but when I want to access String.md
generated page, github pages makes me download the file instead of loading the .html page.
What am I doing wrong?
Here is the website and here my repository
Your links are incorrect,
You should use [String](core/String.html) URL instead of [String](core/String.md)
Because, Jekyll renders .md files as .html
I want to create pdf file using pdfmake and store this pdf on the local root storage directory. new folder should be parallel to other folders like android ,bluetooth. I have given folder list below.
which method will work on this?
I have tried some method of file native like-externalDataDirectory,dataDirectory from http://ionicframework.com/docs/native/file/
Internal Storage
|- .IdeaDesktopHD
|- .lelauncher
|- .magic
|- .powercenterhd
|- Alarms
|- Android
|- Audio
|- Bluetooth
|- Contact
|- data
|- DCIM
|- Document
|- Download
|- googleota
|- legc
|- LenovoReaper
|- LesyncDownload
|- Movies
|- MyFavorite
|- Notifications
|- Others
|- Pictures
|- Podcasts
|- powercenterhd
|- Ringtones
|- SHAREit
Any idea which method or function i should use ?
try out this
downloadImage(url: string) {
this.fileTransfer.download(encodeURI(url),"file:///storage/emulated/0/folderName/file.pdf")
.then((
console.log('
}, (error) => {
console.log('error occured');
});
}
I have a large directory structure, typical of most apps.
For example, like this:
theprojectroot
|- src
| |- app
| | |- index.html
| | |- index.js
| | |- userhome
| | | |- userhome.html
| | | |- userhome.js
| | |- management
| | | |- management.html
| | | |- management.js
| | |- social
| | | |- social.html
| | | |- social.js
| |- assets
|- vendor
|- package.json
I would like to copy all the HTML files - and ONLY the HTML files - in all the directories into another folder.
I'm currently using Grunt copy to copy all files, but now I'd like to do so just for the HTML. In the docs, there doesn't seem to be any option to select a file type.
Does anyone have a hack they could suggest to do this?
The following code will work
copy: {
files: {
cwd: 'path/to/files', // set working folder / root to copy
src: '**/*.html', // copy all files and subfolders **with ending .html**
dest: 'dist/files', // destination folder
expand: true // required when using cwd
}
}
The flatten: true option as in this answer might work for some cases, but it seems to me that the more common requirement (as in my case) is to copy a folder and its sub-folder structure, as-is, to dest. It seems that in most cases if you have sub-folders, they are probably being referenced that way in code. The key to doing this is the cwd option, which will preserve folder structure relative to the specified working directory:
copy: {
files: {
cwd: 'path/to/files', // set working folder / root to copy
src: '**/*.html', // copy only html files
dest: 'dist/files', // destination folder
expand: true // required when using cwd
}
}
I'm currently working on developing a personal Django site that will consist of various technologies / subdomains. My main page(s) will be Django, with a blog.blah.com subdomain that runs wordpress, and several other subdomains for projects (project1.blah.com, project2.blah.com), that are static HTML files (created with Sphinx).
I'm having a lot of trouble organizing my file hierarchy and web server configurations. I'm currently running Apache on port 8080 which serves the Django stuff via mod_wsgi, and I use NGINX on port 80 to handle requests and proxying.
Here's my current filesystem layout. NOTE: I run ALL websites under a single user account.
blah#blah:~$ tree
.
`-- sites
|-- blah.org
| |-- logs
| |-- blah
| | |-- apache
| | | |-- blah.conf
| | | `-- blah.wsgi
| | |-- INSTALL
| | |-- nginx
| | | `-- blah.conf
| | |-- blah
| | | |-- app1
| | | | `-- models.py
| | | |-- app2
| | | | `-- models.py
| | | |-- manage.py
| | | |-- settings.py
| | | `-- urls.py
| | `-- README
| `-- private
`-- blah2.org
Can anyone help me figure out where to place files for a best-practices type of deployment? The structure above ONLY contains my Django code. I've got no idea where to put my static content files (eg: html subdomain sites), and my other services (eg: wordpress stuff).
Any help would be greatly appreciated! Bonus points if you show off your directory structure.
I put my stuff in /srv/www/blah.org/ like this:
-- blah.org
| -- media
| -- amedia
| -- templates
| -- blah
| django app
...
| -- settings.py
| -- config
| -- crontab
| -- blag.org.conf (nginx)
| -- manage.py
Then I confiugure static /media/ and /amedia/ with nginx and proxy everything else to gunicorn serving django.