product1.conf
data {
key1 {
some-field = "some-value"
product1 {
path = ${some-path}
}
}
}
product2.conf
data {
key1 {
some-field = "some-value"
product2 {
path = ${some-path}
}
}
}
Desired Conf that needs to be Loaded -
data {
key1 {
some-field = "some-value"
product1 {
path = ${some-path}
}
product2 {
path = ${some-path}
}
}
}
In the example shown above, I have multiple conf files and all of them are required to be loaded. Previously I have tried having one single conf file instead of multiple and with the above-desired structure did help me load the configurations using -
val config = ConfigFactory.load(ConfigFactory.parseFile(new File(<path>)).resolve())
args.withFallback(config)
.
I would need help to load multiple config files. Thanks in Advance
Assuming that the conf files are statically knowable, you can have an application.conf like this
include "product1"
include "product2"
which will effectively merge the two configurations.
Related
I am trying to import already existing resources, these cannot be recreated, and there are many.
There is configuration that is basic to all resources and for some there are small changes.
I would like to import all the resources with a single command, doing it one by one is tedious and prone to mistakes.
Currently importing single resources with:
terraform import 'github_repository.repo_config["repo2"]' repo2
What would the import command look like if it were to import all of the resources?
The configuration is as follows:
terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 5.0"
}
}
}
provider "github" {
owner = "medecau"
}
variable "repo_config" {
type = map(object({
description = string
homepage_url = string
topics = list(string)
}))
default = {
"repo1" = {
description = "Repo 1"
homepage_url = "https://medecau.github.io/repo1/"
topics = ["topic1", "topic2", "topic3"]
}
"repo2" = {
description = "Repo 2"
homepage_url = null
topics = null
}
}
}
variable "default_repo_config" {
type = object({
description = string
homepage_url = string
topics = list(string)
})
default = {
description = ""
homepage_url = ""
topics = []
}
}
data "github_repositories" "medecau_repos" {
query = "user:medecau"
include_repo_id = true
}
resource "github_repository" "repo_config" {
# cast to set to remove duplicates
for_each = toset(data.github_repositories.medecau_repos.names)
name = each.value
description = lookup(var.repo_config, each.value, var.default_repo_config).description
homepage_url = lookup(var.repo_config, each.value, var.default_repo_config).homepage_url
topics = lookup(var.repo_config, each.value, var.default_repo_config).topics
has_issues = true
has_projects = false
has_wiki = false
vulnerability_alerts = true
security_and_analysis {
advanced_security {
status = "enabled"
}
secret_scanning {
status = "enabled"
}
secret_scanning_push_protection {
status = "enabled"
}
}
}
Importing multiple resources with single terraform import .. call is not supported natively as of now by terraform.
However terraformer could be something which can reduce your effort. Please go through the Terraformer Github documentation to verify if this works for you.
Note: Supports only organizational resources.
I am trying to fetch all the entity names using data source vault_identity_entity, however unable to fetch the name of entity located under aliases.
Sample code:
'''
data “vault_identity_group” “group” {
group_name = “vaultadmin”
}
data “vault_identity_entity” “entity” {
for_each = toset(data.vault_identity_group.group.member_entity_ids)
entity_id = each.value
}
data “null_data_source” “values” {
for_each = data.vault_identity_entity.entity
inputs = {
ssh_user_details = lookup(jsondecode(data.vault_identity_entity.entity[each.key].data_json),“name”,{})
}
}
"data_json": "{\"aliases\":[{\"canonical_id\":\"37b4c764-a4ec-dcb7-c3c7-31cf9c51e456\",\"creation_time\":\"2022-07-20T08:53:36.553988277Z\",\"custom_metadata\":null,\"id\":\"59fb8a9c-1c0c-0591-0f6e-1a153233e456\",\"last_update_time\":\"2022-07-20T08:53:36.553988277Z\",\"local\":false,\"merged_from_canonical_ids\":null,\"metadata\":null,\"mount_accessor\":\"auth_approle_12d1d8af\",\"mount_path\":\"auth/approle/\",\"mount_type\":\"approle\",\"name\":\"name.user#test.com\"}],\"creation_time\":\"2022-07-20T08:53:36.553982983Z\",\"direct_group_ids\":[\"e456cb46-2b51-737c-3277-64082352f47e\"],\"disabled\":false,\"group_ids\":[\"e456cb46-2b51-737c-3277-64082352f47e\"],\"id\":\"37b4c764-a4ec-dcb7-c3c7-31cf9c51e456\",\"inherited_group_ids\":[],\"last_update_time\":\"2022-07-20T08:53:36.553982983Z\",\"merged_entity_ids\":null,\"metadata\":null,\"name\":\"entity_ec5c123\",\"namespace_id\":\"root\",\"policies\":[]}",
Above scripts returns entity id entity_ec5c123. Any suggestions to retrieve the name field under aliases, which has users email id.
Maybe something like this?
data “vault_identity_group” “group” {
group_name = “vaultadmin”
}
data “vault_identity_entity” “entity” {
for_each = toset(data.vault_identity_group.group.member_entity_ids)
entity_id = each.value
}
locals {
mount_accessor = "auth_approle_12d1d8af"
# mount_path = "auth/approle/"
aliases = {for k,v in data.vault_identity_entity.entity : k => jsondecode(v.data_json, "aliases") }
}
data “null_data_source” “values” {
for_each = data.vault_identity_entity.entity
inputs = {
ssh_user_details = lookup({for alias in lookup(local.aliases, each.key, "ent_missing") : alias.mount_accessor => alias.name}, local.mount_accessor, "ent_no_alias_on_auth_method")
}
}
Basically you want to do a couple lookups here, you can simplify this if you can guarantee that each entity will only have a single alias, but otherwise you should probably be looking up the alias for a specific mount_accessor and discarding the other entries.
Haven't really done a bunch of testing with this code, but you should be able to run terraform console after doing an init on your workspace and figure out what the data structs look like if you have issues.
I'm trying to create an aws_ami data source that fetches the latest AMI based on a few tags.
The catch is that I want to do it with a map of tags and their values, not by defining filters for each specific tag in the data source.
Example:
module-vars.tf
variable "filter-tags" {
type = "map"
default = {
"java_vendor" = "oracle"
}
}
module.tf
data "aws_ami" "aws-ami" {
most_recent = true
owners = ["self"]
// Filter code here
// e.g. FICTIONAL CODE, DON'T USE
filter {
name = "tags:${var.filter-tags}"
}
}
So obviously this filter-tags variable should be able to change and the filtered AMI should have all the tags matching.
Any ideas?
Found a way to do it with dynamic blocks
data "aws_ami" "aws-ami" {
most_recent = true
owners = ["self"]
dynamic "filter" {
for_each = var.filter-tags
iterator = tag
content {
name = "tag:${tag.key}"
values = ["${tag.value}"]
}
}
}
So i am changing my project from core PHP to Codeigniter. I have a edit for in which their are 3 input type file. Now i want to run my query according to these inout file. like if input file 1 is empty than don't update value else update. I did it in core PHP like this:
The name of input type file are: image1, image2, image3
mysqli query in core PHP:
if(!empty($photo1))
{
$p1=str_replace("-","",time().$photo1);
move_uploaded_file($_FILES['photo1']['tmp_name'], $folder.$p1);
$query .=",`image1`='$p1'";
}
if(!empty($photo2))
{
$p2=str_replace("-","",time().$photo2);
move_uploaded_file($_FILES['photo2']['tmp_name'], $folder.$p2);
$query .=",`image2`='$p2'";
}
if(!empty($photo3))
{
$p3=str_replace("-","",time().$photo3);
move_uploaded_file($_FILES['photo3']['tmp_name'], $folder.$p3);
$query .=",`image3`='$p3'";
}
Now how to do this in codeigniter model:
controller
public function store_ad()
{
$id=$this->input->post('id');
$d_email=$this->session->userdata('dealer_email');
$p_type=$this->input->post('property_type');
$p_subtype=$this->input->post('property_subtype');
$p_for=$this->input->post('p_for');
$p_name=$this->input->post('p_name');
$p_price=$this->input->post('p_price');
$state=$this->input->post('state');
$city=$this->input->post('city');
$loc=$this->input->post('location');
$pincode=$this->input->post('pincode');
$about=$this->input->post('p_about');
$stat=$this->input->post('status');
$config['upload_path'] = './images/properties';
$config['allowed_types']='gif|png|jpeg|jpg';
$this->load->library('upload',$config);
if($this->upload->do_upload('image1'))
{
$data1=$this->upload->data();
$img1=$data1['raw_name'].$data1['file_ext'];
}
if($this->upload->do_upload('image2'))
{
$data2=$this->upload->data();
$img2=$data2['raw_name'].$data2['file_ext'];
}
if($this->upload->do_upload('image3'))
{
$data3=$this->upload->data();
$img3=$data3['raw_name'].$data3['file_ext'];
}
}
How to crearte model according to the non empty input file. I am storing the name of the file in database
Inside your method in the model class check if the files you want to upload is empty or not e.g
public function update($data_array, $img1, $img2, $img3){
if(!empty($img1)){
$data_array['img_column1'] = $img1;
}
if(!empty($img2)){
$data_array['img_column2'] = $img2;
}
if(!empty($img3)){
$data_array['img_column3'] = $img3;
}
return $this->db->insert('YOUR_TABLE_NAME', $data_array);
}
Hope this helps....
In scala-lift v2.6, src/main/resources/app/confg/parameters.conf looks very much like a json:
env_type {
dev {
greeting = "greeting: dev"
lift {
runMode = "development"
}
dryRun = true
etlPrune = false
testMode = true
}
}
Is there any way to specify a list of values for a certain key in such config format?
The format is a JSON superset called HOCON ("Human-Optimized Config Object Notation"), which is what the Typesafe Config library uses.
To specify multiple values for a key, use square brackets and commas. For example:
env_type {
dev {
names = ["dev", "sandbox", "alt-prod"]
}
}
To get names in your application code:
val conf = ConfigFactory.load
val devNames = conf.getStringList("env_type.dev.names") // java.util.List[String]