terraform: Error while adding "secret_environment_variables" in google_cloudfunctions_function resource - google-cloud-functions

I've tried the below tf code for cloudFunction.
resource "google_cloudfunctions_function" "dbex-function" {
name = "function-test"
description = "My function"
runtime = "python39"
....
entry_point = "dbex_conn"
environment_variables = {
TARGET = "test.com"
}
secret_environment_variables {
key = "KEY"
secret = key
version = "latest"
}
}
But, I'm getting the below error in terraform validate.
Error: Unsupported block type
on cloudFunction.tf line 133, in resource "google_cloudfunctions_function" "dbex-function":
133: secret_environment_variables {
Blocks of type "secret_environment_variables" are not expected here.
validate failed, post status
Don't know why it's giving such an error.
Please note:
The terraform version for me is : 0.14.11 and google provider version is : v3.90.1
I've checked the similar problem here: terraform: how to add a block of secret_environment_variables in google_cloudfunctions_function
But this is not working for my case.

This is happening because of the provider version you are using, there is no block with secret_environment_variables in v3.90.1.
Upgrade your provider version to atleast 4.2 to access secret_environment_variables block.
Below is the document you can refer to:
https://registry.terraform.io/providers/hashicorp/google/4.20.0/docs/resources/cloudfunctions_function

Related

Porting a cloudformation template to terraform

I am following a direction on Hashicorp's site regarding wrapping a CF Template in Terraform. There's a fair amount to the whole code, but the CF Template works, so the issue is with the "wrapping"...
Terraform plan gives me this error output:
terraform plan
Error: aws_cloudformation_stack.Momma: "template_body" contains an invalid JSON: invalid character 'A' looking for beginning of object key string
Error: aws_cloudformation_stack.Momma: : invalid or unknown key: source
So it seems that the "AWSTemplateFormatVersion" line is what it does not like. Hence the'A' it is picking up, I guess.
This is the Hashicorp page I am following, I'm wondering if there are any escape characters that are appropriate or, if anyone can see any immediate formatting issues with my JSON?
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudformation_stack
terraform {}
provider "aws" {
version = "= 2.61"
region = "ap-southeast-2"
}
resource "aws_cloudformation_stack" "Momma" {
source = "../../aws_modules/aws-db-event-subscription"
name = "Momma-Stack"
template_body = <<STACK
{
AWSTemplateFormatVersion: 2010-09-09
Description: Team Server
Metadata:
'AWS::CloudFormation::Interface':
ParameterGroups:
- Label:
default: Deployment Options
Parameters:
- Environment
- KeyPairName
- VPCID
- Subnet1ID
- RemoteAccessCIDR
- Owner
ParameterLabels:
KeyPairName:
Default: Key Pair Name
RemoteAccessCIDR:
Default: External Access CIDR
VPCID:
Default: VPC ID
Owner:
Default: MommaTeam....
Thank you for any guidance offered.
There are at least two issues that are apparent:
source = "../../aws_modules/aws-db-event-subscription" is invalid. There is no attribute called source in aws_cloudformation_stack. You can remove it.
Your template_body should not begin with { in:
template_body = <<STACK
{
This is because you are using YAML for your template, not JSON.

When using terraform with heroku, is there a way to refresh app state after an addon is attached?

I'm using terraform to set up an app on heroku. The app needs a mysql database and I'm using ClearDB addon for that. When ClearDB is attached to the app, it sets a CLEARDB_DATABASE_URL config variable. The app requires the database url to be in a DATABASE_URL config variable.
So what I'm trying to do is to use resource heroku_app_config_association to copy the
value from CLEARDB_DATABASE_URL to DATABASE_URL. The problem is that after heroku_app resource is created, its state does not yet contain CLEARDB_DATABASE_URL, and after heroku_addon is created, the state of heroku_app is not updated.
This is the content of my main.tf file:
provider "heroku" {}
resource "heroku_app" "main" {
name = var.app_name
region = "eu"
}
resource "heroku_addon" "database" {
app = heroku_app.main.name
plan = "cleardb:punch"
}
resource "heroku_app_config_association" "main" {
app_id = heroku_app.main.id
sensitive_vars = {
DATABASE_URL = heroku_app.main.all_config_vars.CLEARDB_DATABASE_URL
}
depends_on = [
heroku_addon.database
]
}
This is the error that I get:
Error: Missing map element
on main.tf line 22, in resource "heroku_app_config_association" "main":
22: DATABASE_URL = heroku_app.main.all_config_vars.CLEARDB_DATABASE_URL
|----------------
| heroku_app.main.all_config_vars is empty map of string
This map does not have an element with the key "CLEARDB_DATABASE_URL".
The configuration variable is copied successfully when terraform apply is executed second time. Is there a way to make it work on the first run?
To get up-to-date state of the heroku_app resource I used the data source:
data "heroku_app" "main" {
name = heroku_app.main.name
depends_on = [
heroku_addon.database
]
}
I could then access the value in heroku_app_config_association resource:
resource "heroku_app_config_association" "main" {
app_id = heroku_app.main.id
sensitive_vars = {
DATABASE_URL = data.heroku_app.main.config_vars.CLEARDB_DATABASE_URL
}
}

Drools REST CannotResolveClassException

Using Drools 5.5.0.Final with Guvnor 5.5.0.Final with the sample mortgages package.
When submitting REST json request with the following Batch Execution Command:
{
"batch-execution": {
"lookup":"ksession1",
"commands":[
{
"insert":{
"out-identifier":"outApplicant",
"return-object":"true",
"object": {
"Applicant":{
"age":17
}
}
}
},
{
"fire-all-rules":""
}
]
}
}
returns: 500 Internal Server Error
com.thoughtworks.xstream.converters.ConversionException: Applicant : Applicant
---- Debugging information ----
message : Applicant
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : Applicant
class : org.drools.command.runtime.rule.InsertObjectCommand
required-type : org.drools.command.runtime.rule.InsertObjectCommand
converter-type : org.drools.runtime.help.impl.XStreamJson$JsonInsertConverter
line number : -1
class[1] : org.drools.command.runtime.BatchExecutionCommandImpl
converter-type[1] : org.drools.runtime.help..XSt...$JsonBatchExecutionCommandConverter
version : null
The Applicant class is defined in the mortgages package within an XSD like so:
age:Whole number (integer)
applicationDate:Date
creditRating:Text
name:Text
approved:True or False
How can I tell drools where to find the Applicant class? ( which is defined in the mortgage sample as an XSD file)
knowledge-services.xml currently looks like this:
<drools:grid-node id="node1"/>
<drools:kbase id="kbase1" node="node1">
<drools:resources>
<drools:resource type="PKG" source="http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/packages/mortgages"/>
</drools:resources>
</drools:kbase>
I suspect that changing the REST json request to fully specify the package name for Applicant class might work.
...
"object": {
"something.somethingelse.Applicant":{
"age":17
}
}
...
But can't seem to find where the fully qualified package name for Applicant is declared?
Acceptable answer must show an example which works without having to write java code, since the whole point of the REST interface is to access drools through a web service interface.
Is there a spring configuration , or some other way to write the json request that will work?
Since no one replied, I am posting the answer that worked for me along with the root cause and step-by-step procedure I used to debug the problem. Please do comment if there is a better way.
First, here is the complete and correct format for the REST Json request to insert an Applicant instance to the rules engine using drools-server when the model been defined in drools-guvnor GUI interface and not uploaded as a POJO model.
{
"batch-execution": {
"lookup":"ksession1",
"commands":[
{
"insert":{
"out-identifier":"outApplicant",
"return-object":"true",
"object": {
"mortgages.Applicant":{
"age":17
}
}
}
},
{
"fire-all-rules":""
}
]
}
}
Root cause: $TOMCAT_HOME/webapps/drools-server/WEB-INF/classes/knowledge-services.xml had incorrect resource.
The relevant parts of my corrected knowledge-services.xml:
<drools:grid-node id="node1"/>
<drools:kbase id="kbase1" node="node1">
<drools:resources>
<drools:resource
type="PKG"
source="http://localhost:8080/drools-guvnor/rest/packages/mortgages/binary"
basic-authentication="enabled"
username="admin"
password="admin"
/>
</drools:resources>
</drools:kbase>
Secondary issue: The authentication credentials were not specified in knowledge-services.xml
which resulted in this error:
Exception: java.io.IOException: Servier returned HTTP response code: 401 for URL: http://localhost:8080/drools-guvnor/rest/packages/mortgages/binary
Third issue: The example mortgage package was not built as a binary package in Guvnor.
ERROR: java.io.lang.RunTimeException: jav.io.StreamCorruptionException: Invalid Stream Header
To fix:
In Guvnor... Packages.. mortgages..Edit..build package
Additional note: INFO level logging is not enabled by default in drools-server.
To enable extra logging, so that you can see detailed debug messages in $TOMCAT_HOME/logs/catalina.log follow these steps:
Go to $TOMCAT_HOME/webapps/drools-server/WEB_INF/classes
create a file logging.properties
add these lines:
org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = java.util.logging.ConsoleHandler
HTH

Drupal 7 Solr Indexing Error showing "EntityMalformedException: Missing bundle property on entity of type taxonomy_term"

In Drupal 7.14, when i Index my Whole Site, Solr is showing following error:
AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows.
Path: /batch?id=1938&op=do StatusText: Service unavailable (with message)
ResponseText: EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7539 of /project/path/includes/common.inc).
So when i look into the lines in /includes/common.inc (around lines: 7537):
// Explicitly fail for malformed entities missing the bundle property.
if (!isset($entity->{$info['entity keys']['bundle']}) || $entity->{$info['entity keys']['bundle']} === '') {
throw new EntityMalformedException(t('Missing bundle property on entity of type #entity_type.', array('#entity_type' => $entity_type)));
}
What is that chunk of code (in common.inc) is doing actually please?
How can i overcome that error?
Please, try this module https://drupal.org/project/taxonomy_orphanage it will delete all empty bundles.

How do you pass a JSON object to Enyo through a web service?

I’m trying to pass a JSON object to Enyo using a web server.
The file being loaded from the service in Enyo:
{ "Comments" : ["NewComment 1", "NewComment 2", "NewComment 3" ]}
The following callback for the service generates an error saying
gotComments: function(inSender, inResponse) {
this.serverReply = InResponse; // error uncaught reference error: inResponse not defined
this.$.list.render();
},
When I click on inReply on my chrome debugger it says
Object:
Comments: Array[3]
How can it say it is not define, if the watch window shows it as
Object:
Comments: Array[3]
The code in your question mixes InResponse (capital I) and inResponse (lowercase i). Assuming this is what your real code looks like, change
this.serverReply = InResponse;
to
this.serverReply = inResponse;