Terraform, providers miss inherits on module - module

Terraform v0.14.8
Got this probleme when I try to launch terraform init, the provider registry.terraform.io/hashicorp/aci is not found
I want to use my provider : registry.terraform.io/ciscodevnet/aci
$ terraform providers
Providers required by configuration:
.
├── provider[registry.terraform.io/ciscodevnet/aci] 0.5.4
└── module.bride_domain_2001
└── provider[registry.terraform.io/hashicorp/aci]
My question : How to force registry.terraform.io/ciscodevnet/aci on module ?
How i call my module :
module "bride_domain_2001" {
source = "./modules/bride_domain_2001"
aci_vrf_vrf_training_id= aci_vrf.vrf_training.id
aci_tenant_tenant_training_id= aci_tenant.tenant_training.id
}
Expected Behavior
The in-house provider should be inherited from the parent and used
Actual Behavior
Terraform doesn't use inheritance from parent module
Thanks

It seems that your child module bride_domain_2001 is missing a required_providers entry to specify that it depends on ciscodevnet/aci, which is causing Terraform's backward compatibility behavior to assume you meant hashicorp/aci.
To fix it, add a required_providers entry to your child module:
terraform {
required_providers {
aci = {
source = "ciscodevnet/aci"
# (possibly also a >= version constraint)
}
}
}
Once you add this, Terraform will see that the root module and the child module both depend on this same provider ciscodevnet/aci, and so your configuration for the provider should then be inherited by resources belonging to that provider in the child module.

Related

How to use terraform to ignore previous execution(state) [duplicate]

I'm a bit of a newbie with Terraform and still working my way through the documentation, have not yet been able to find a way to accomodate the set up I need to achieve for a specific solution and hoping that some kind soul may be able to give me a push in the right direction.
I'm trying to manage a single set of paramaterised templates which deploy everything needed to support a new application we are working on in GCP. What I am trying to achieve is being able to deploy those templates to three different environments, each environment being in a distinct GCP project, by itself.
The plan is, as per recommendations, run terraform and pass in
a) The specific .tfvars file depending on the environment/project being deployed to (dev/test/prod).
b) Use the -chdir parameter to tell Terraform to pick up all the templates from 'infra-common' folder.
The tricky part is that we want each environment (gcp project) to host it's own state file in gcs/storage.
I had been looking at workspaces but it appears that workspaces will just create state subfolders on a single backend.
Question: Can this be done or is there a better way to do it?
Thanks!
You can use --backend-config for this. Here's how you can achieve the desired behavior:
Create a .config file for each environment (dev.config, test.config, prod.config) which contain the name of the gcs bucket (which must already exist) for the respective environment
Specify the common backend in a single remote_state.tf file
Here's how it would look:
config/dev.config:
bucket = "tf-state-dev"
config/test.config:
bucket = "tf-state-test"
config/prod.config:
bucket = "tf-state-prod"
remote_state.tf:
terraform {
backend "gcs" {
prefix = "terraform/state"
}
}
then, you can run the init. So for example, for dev this would look like:
$ terraform init --backend-config=config/dev.config
then, you can create a workspace for the environment:
$ terraform workspace new dev
With this approach, you can use a single set of templates (you can in fact configure dynamic variables based on the current workspace).
What you could do (we have a project with a similar setup with a different cloud provider), is:
use infra-common as a module
instead of working with .tfvar files per environment, use a separate root module per environment which invokes infra-common as sub-module.
Your folder structure could look like:
project
|-- dev
| `-- main.tf
|-- modules
| `-- infra-common
| |-- main.tf
| `-- variables.tf
|-- test
| `-- main.tf
`-- prod
`-- main.tf
dev/main.tf
terraform {
backend "gcs" {
bucket = "tf-state-dev"
prefix = "terraform/state"
}
}
module "stage" {
source = "../modules/infra-common"
env = "dev"
some_var = "value"
}
prod/main.tf
terraform {
backend "gcs" {
bucket = "tf-state-prod"
prefix = "terraform/state"
}
}
module "stage" {
source = "../modules/infra-common"
env = "prod"
some_var = "value"
}

TomEE Microprofile: microprofile-config.properties ignored

i'm having problems getting config values into my microprofile app. I have created a META-INF/microprofile-config.properties file like this:
configEntry=HelloWorld
I've got a simple test class like this:
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Initialized;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.inject.ConfigProperty;
#ApplicationScoped
public class ConfigTest {
#Inject
#ConfigProperty(name = "configEntry", defaultValue = "missing")
private String configValue;
#Inject
Config conf;
public void init(#Observes #Initialized(ApplicationScoped.class) final Object init) {
System.out.println("configEntry = " + configValue);
}
}
I run this on TomEE MP 8.0.10 (downloaded standalone binaries). But whatever I do, configEntry is always 'missing' and when I debug-inspect the Config instance, I can see that there are 3 ConfigSources loaded (SystemPropertyConfigSource, SystemEnvConfigSource,TomEEConfigSource) but none is containing any entry for configValue.
I have also tried to create my own ConfigSource via META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource. Same problem here: My test ConfigSource never gets included in the list of ConfigSoruces.
Is there any kind of secret (TomEE flag) to make this work? Did I miss something crucial, or is TomEE simply not supporting microprofile-config.properties (any longer)?
I found the problem:
This was due to an incompatible maven build configuration. All guides and tutorials I found usually specify the pre-build location of the file, not the location they must end up in the war file/dir. I did put them into the correct pre-build location, but maven placed them 'wron' (inside /META-INF/ not WEB-INF/classes/META-INF).
So, here for all with a similar confusion, after the build this is where the files must reside to be found:
microprofile-config.properties: /WEB-INF/classes/META-INF/
spi services directory: /WEB-INF/classes/META-INF/
spi custom ConfigSource text file: /WEB-INF/classes/META-INF/services/

How to change the path for local backend state when using workspaces in terraform?

What is the expected configuration for using terraform workspaces with the local backend?
The local backend supports workspacing, but it does not appear you have much control over where the actual state is stored.
When you are not using workspaces you can supply a path parameter to the local backend to control where the state files are stored.
# Either in main.tf
terraform {
backend "local" {
path = "/path/to/terraform.tfstate
}
}
# Or as a flag
terraform init -backend-config="path=/path/to/terraform.tfstate"
I expected analogous functionality when using workspaces in that you would supply a directory for path and the workspaces would get created under that directory
For example:
terraform new workspace first
terraform init -backend-config="path=/path/to/terraform.tfstate.d"
terraform apply
terraform new workspace second
terraform init -backend-config="path=/path/to/terraform.tfstate.d"
terraform apply
would result in the state
/path/to/terraform.tfstate.d/first/terraform.tfstate
/path/to/terraform.tfstate.d/second/terraform.tfstate
This does not appear to be the case however. It looks like the local backend ignores the path parameter and puts the workspace configuration in the working directory.
Am I missing something or are you unable to control local backend workspace state?
There is an undocumented flag for the local backend workspace_dir that solves this issue.
The documentation task is tracked here
terraform {
backend "local" {
workspace_dir = "/path/to/terraform.tfstate.d"
}
}

Instant app with multivariant base module

I've started to implement instant app feature in my application. I managed to transition to base module and properly build an installable app. The base module has 3 build types:
buildTypes {
release {...}
acceptance {...}
debug {...}
When I try to build instant app as a separate module that has build.gradle file:
apply plugin: 'com.android.instantapp'
dependencies {
implementation project(':base')
}
I'm getting below error message:
Cannot choose between the following variants of project :app:
- inchargeAcceptanceBundleElements
- inchargeAcceptanceRuntime
- inchargeAcceptanceUnitTestCompile
...
(much much longer I can give full stacktrace if needed)
I tried to change instantapp/build.gradle:
implementation project(path: ':base', configuration: 'default')
but then I get:
Unable to resolve dependency for ':instantapp#debug/compileClasspath': Failed to transform file 'base-release.aar' to match attributes {artifactType=processed-aar} using transform IdentityTransform
Then the app module itself has 4 product flavors but it shouldn't matter I believe.
Any advice how to run instantapp module ?

how to invoke a play application without hitting the URL (http request)?

I'm using play application (using Play version 2.1.0) with RabbitMQ and do not have any view component.
So i would like to invoke this play application without hitting the execution URL (http://localhost:9000/<routing_info>) on server startup.
Would also like to know if there is any way in Play 2.1.0 version to run the application on server startup, i mean bootstrapping. Is this option available in play 2.1.0.
As i've read through the documentation its mentioned only for 1.2 version.
Please help!!
Play allows you to define a 'global' object which will be instantiated automatically by Play when the application starts.
In application.conf you should find the following:
# Global object class
# ~~~~~
# Define the Global object class for this application.
# Default to Global in the root package.
application.global=global.Global
On a new play application, this line is commented out. I've uncommented it and made it point to an object called Global in the global package. You can make it what ever you want.
Your global object should extend GlobalSettings.
In my applications, I use a static initialiser block to run code when that class is loaded:
public class Global extends GlobalSettings
{
static
{
...
}
}