question
stringlengths
11
28.2k
answer
stringlengths
26
27.7k
tag
stringclasses
130 values
question_id
int64
935
78.4M
score
int64
10
5.49k
I'm going to edit the Opera Mini v6.5 server because it is blocked in our country. Now I have unpacked the ‍‍‍‍‍‍‍.apk file extracted classes.Dex then converted it via dex2jar.bat, now modified the server. My problem is I want to repack the .jar or .class to classes.Dex. How do I do it?
Here is a solution that was helpful in my case... Suppose .jar file sits in "c:\temp\in.jar". In command prompt window cd to ..\android-sdk\platform-tools. To get .apk execute: dx --dex --output="c:\temp\app.apk" "c:\temp\in.jar" To get .dex file execute: dx --dex --output="c:\temp\dx.dex" "c:\temp\in.jar"
Dex
8,348,144
19
I initially thought it was exclusively for official libraries like the support library. However any time I add a custom JAR using the "Add to build path" menu item, it automatically shows up in both "Referenced Libraries" and "Android Private Libraries". One of these is redundant since there is no point in exporting bo...
In my case i always add libraries to libs folder. According to my understanding thats the way its suppose to be. Android Private Library folder references these jars in libs folder. The Android Private Library is used during the creation of apk (probably during the conversion of your java code into dex file).
Dex
20,604,193
19
I have a working android application. of which i dont have a source code. I would like to debug a functionality of this application. I could successfully reverse engineer this application apk file using apktool - https://code.google.com/p/android-apktool/ This tool generates class files in smali format. My requiremen...
1. Debug log in smali Debug log in smali. Say for example inside method test() you want to print "Inside Test()" debug log. At the start of method in smali add following instructions : sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream; const-string v1, "Inside Test()" invoke-virtual {v0, v1}, Ljava/io/Prin...
Dex
20,879,950
19
So I am wondering why I encounter the 64k dex method limit when trying to run my app on android versions older than lollipop, when it runs just fine on the more recent versions. Could it be, because the support libraries are actually being referenced when running on the older versions? This is my gradle: apply pl...
To answer your specific question is: This method count limitation is on the DEX (Dalvik Executable) file. A common workaround for this limitation is to have multiple DEX files. Older versions of Android does not natively support multiple DEX files. Starting from Lollipop the system supports it natively. So that's why...
Dex
36,559,835
19
I have 2 app versions - pro and lite. They are both already on the market at v1.01. I am trying to release v1.1 for both. This update includes SwawrmConnect integration in order to use their global leaderboards. I should start off by saying I know I am not maintaining my code correctly. I have 2 completely separate...
Coincidentally I ran into the same issue just day before yesterday. Here's what I suggest you to do. First and foremost make sure that you have a backup of all the jars presently residing in the 'Android Dependencies'/'libs' folder. Now, lets fix the lite version first by following these steps. Remove all jar files e...
Dex
16,087,341
18
I got this error when we run apk file of our application. In build.gradle we set multidex and compile multidex is existed in Gradle file . We changed the version of Firebase versions to above and below but that's did not work for us . This is our full log in Run console : D/AndroidRuntime: Shutting down VM E/Android...
In your build.gradle, upgrade play-services-gcm and play-services-location to 15.0.1: com.google.android.gms:play-services-gcm:15.0.1 com.google.android.gms:play-services-location:15.0.1
Dex
51,388,073
18
Why should (or shouldnt) I include a gradle dependency as @aar, What are the benefits/drawbacks if any? As you can see I added @aar to the libraries below that supported it. But everything seemed to work before doing that as well... dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.a...
Libraries can be uploaded in multiple formats, most of the time you'll be using .jar or .aar. When you don't specify the @ suffix, you'll be downloading the library in it's default format (defined by its author, if not then .jar) along with all its dependencies. compile 'com.android.support:appcompat-v7:22.1.1' When y...
Dex
30,157,575
17
Maybe is too soon to ask, but as Jack and Jill was announced today I get very excited with it. I really want to go for it, but they also state: Various tools that read .class files (such as JaCoCo, Mockito, and some lint checks) are currently not compatible with the Jack compiler. There is already an mockito alternativ...
Mockito doesn't generate any byte code at compile time and hence is not affected by the used compiler. Same holds true for dexmaker. (they don't have any hooks into Gradle during build) So you can simply continue to use Mockito, even with Jack compiler. Note that I have a test project which confirms this.
Dex
35,917,993
17
After adding Google Guava r09 to our Android project the build time increased significantly, especially the DEX generation phase. I understand that DEX generation takes all our classes + all jars we depend on and translates them to DEX format. Guava is a pretty big jar around 1.1MB Can it be the cause for the build s...
For what it's worth, my gut is that this isn't the cause. It's hard to take a long time doing anything with a mere 1.1MB of bytecode; I've never noticed dex taking any significant time. But let's assume it is the issue for sake of argument. If it matters enough, you could probably slice up the Guava .jar to remove whol...
Dex
7,548,038
16
I'm compiling my (fairly simple, just 5 files with few hundred LOC) app from command line on OSX using: ant debug It works. But it works slowly: BUILD SUCCESSFUL Total time: 26 seconds Why is that? It takes this much time even if I change only one line in one java file. Most of this time is spent in dex stage (about 20...
I finally found a solution for this! It's a bit of a hack, but it works. First, go to your ANDROID-SDK/platform-tools directory, then rename dx app to something else, like dextool, and finally create new dx file with contents: #!/bin/sh shift dextool --dex --incremental --no-optimize $@ Replace "dextool" with the name...
Dex
12,088,375
16
I have hit the magic dex limit because my application uses a lot of jars (drive API, greendao, text to pdf, support.. ). My current solution was that I literally created a second apk just for google drive which I called from the main apk. But now I found out that android finally supports this with this library. My prob...
The Blog was the old solution. With Android Studio 0.9.2 & Gradle Plugin 0.14.1, you only need to: Add to AndroidManifest.xml: . android:name="android.support.multidex.MultiDexApplication" or Add MultiDex.install(this); in your custom Application's attachBaseContext method or your custom Application extend Multi...
Dex
26,925,264
16
With the release of Android Studio 3.0 Beta release, the android studio provides next-generation dex compiler, D8 to compile code and build android APK. Currently, D8 is available for preview. Check more details: https://android-developers.googleblog.com/2017/08/next-generation-dex-compiler-now-in.html How to enable bu...
To enable D8 for your Android Studio 3.0 Beta, you can add following line in your project's gradle.properties file: android.enableD8=true
Dex
45,648,215
16
I found that after my app reached a fair size (e.g. by adding multiple libraries), running the app threw java.lang.SecurityException: writable dex file '.../code_cache/.overlay/base.apk/classes2.dex' is not allowed. If I then remove most of the libraries leaving only those that were added by default, and run again, it ...
I was also having this problem, so I took a look at this documentation DexClassLoader, and decided to do this. package com.example import android.app.Application class BaseApp : Application() { override fun onCreate() { super.onCreate() val dexOutputDir: File = codeCacheDir dexOutputDir....
Dex
76,498,531
16
If you find yourself writing a big Android application that depends on many different libraries (which I would recommend instead of reinventing the wheel) it is very likely that you have already come across the 65k method limit of the Dalvik executable file classes.dex. Furthermore, if you depend on large libraries lik...
The biggest change for developers that came with the 6.5 release of the Google Play Services was probably the Granular Dependency Management. Google managed to split up it's library to allow developers to depend only on certain components which they really need for their apps. Since version 6.5 developers are no longer...
Dex
27,589,560
14
I'm using Android Studio for the first time and I got the following error after importing the project (previously it was an eclipse project where I had issues too.) Here is the information given: Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.internal.LoggedErrorException: Failed to run comma...
cd android/ && ./gradlew clean && cd .. && react-native run-android
Dex
27,787,747
14
We found an issue on Amazon market that IAP doesn't work if it's receivers located not in main DEX file. The question is how to force gradle to put specific classes (receivers) into main DEX file. Here are the gradle DEX settings: afterEvaluate { tasks.matching { it.name.startsWith('dex') }.each { dx ->...
With Android Plugin for Gradle, Revision 2.2.0 (Released in September 2016) you can use multiDexKeepFile api android { buildTypes { debug { ... multiDexEnabled true multiDexKeepFile file('multidex_keep_file.txt') } } } Where multidex_keep_file.txt is file wit...
Dex
30,081,386
14
With the advent of ASMDEX (ASM for dex files) and dexmaker, shouldn't it be possible to port Groovy to Android? Both frameworks allow the generation of dex bytecode at runtime. As I understand it, it is impossible to modify dex classes from the APK in memory. But wouldn't it be possible to copy those classes to writab...
The original porting project is named discobot then some guys made a new project called discobot2 Afaik the first project had no runtime transformation of classes, but was able to run first Groovy programs on Android, with a very slow startup time. As for the second project the last to me known state is that they solve...
Dex
10,777,560
13
I use ant release and got this error: [dx] UNEXPECTED TOP-LEVEL EXCEPTION: [dx] com.android.dx.util.DexException: Multiple dex files define Lcom/android/vending/billing/IMarketBillingService; [dx] at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:580) [dx] at com.android.dx.merge.De...
Please check if the package includes com/android/vending/billing/IMarketBillingService is reference twice or more in your project settings.
Dex
15,869,893
12
I am working on a project that is quickly approaching the 64K method limit for dex files. This Android Developer blog post (from July 2011) explains how to get dynamic class loading working with a command-line build driven by Ant, but does not explore how to get it working from within IDEs (besides saying it won't work...
Try using ProGuard to strip out unused classes and methods from your project and you should (hopefully) find you don't need multiple dex files. That said if you do: IntelliJ and Eclipse are just IDEs -- they don't directly build your code -- so you will need to identify how your project is being built -- most likely An...
Dex
21,146,959
12
Currently working on my android application after including play services and firebase library in my project I'm getting this error and unable to run my code :app:prePackageMarkerForDebug :app:transformClassesWithDexForDebug To run dex in process, the Gradle daemon needs a larger heap. It currently has approxima...
You need to enable multidex in the android default config then: android { compileSdkVersion 23 buildToolsVersion '23.0.3' defaultConfig { applicationId "com.example.case" minSdkVersion 16 targetSdkVersion 23 versionCode 43 versionName "4.0.13" // Enabling mu...
Dex
37,430,331
12
I got an error in the build server when sending an Android build during the dex phase. Googling a bit I learned that there is a hard limit of 64K functions (including all libs, the heaviest is google play services), or you can use the multiple dex mechanism. How do I activate this for Codename One? I understand Codena...
I had a very similar issue and corresponded with Codename One's pro support on this. Gradle support was something they just recently announced so its not as documented but should be available in the next update. You need to add the following build hints to your project: android.gradle=true android.multidex=true I und...
Dex
34,260,220
11
I think there must be a bug with the 27.1.0 v7 support lib, just released. After updating my project to use it (from 26.1.0), I keep getting this compilation error: Task :app:transformDexArchiveWithDexMergerForRegularDebug FAILED D8 is used to merge dex. Program type already present: android.support.v7.recyclervie...
Figured it out! Turns out the android.arch.paging:runtime-1.0.0-alpha4-1 dependency also had ListAdapter declared. After updating the paging lib to alpha6, the problem was resolved. EDIT For some reason, this question is getting a lot of attention! So, I thought I'd add this comment as a "teach a person to fish" sort o...
Dex
49,038,630
11
Since this morning I cannot build my Android app because I get this error What went wrong: Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'. com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/measurem...
Please update the google-service plugin to: classpath 'com.google.gms:google-services:3.3.0' to be able to use the latest version of Firebase and to avoid the errors. Read the following for more information: https://android-developers.googleblog.com/2018/05/announcing-new-sdk-versioning.html Compilation failed to comp...
Dex
50,182,756
11
So I've just hit the maximum method count limit for my android project, which fails to build with the following error message: Error: null, Cannot fit requested classes in a single dex file (# methods: 117407 > 65536) I understand what the message means, and how to resolve it (running proguard, enabling multidex etc)...
Simple add this to your gradle (Module: app) >> multiDexEnabled true android { defaultConfig { ... minSdkVersion 21 targetSdkVersion 28 multiDexEnabled true } ... } then Rebuild Project in Menu click => Build>Rebuild Project.
Dex
54,911,906
11
I am having trouble with intellij idea ide. It was working fine , but suddenly it started showing error: Android Dex: [untitled3] Error: Could not create the Java Virtual Machine. Android Dex: [untitled3] Error: A fatal exception has occurred. Program will exit. I have checked my sdk, jdk path. i have done re-installi...
The problem was caused by the too high heap size for the DX compiler, it can be changed here (File | Settings | Compiler | Android DX Compiler). Check this document that explains why it happens when 32-bit JDK is used.
Dex
18,095,117
10
What is the dex in Gradle or in Android? In Gradle, what's the meaning of dexoptions? Sometimes my project does not compile because of some dexerrors. I need to activate ProGuard to compile my Android app.
In the standard java world: When you compile standard java code : the compiler produce *.class file. A *class file contains standard java bytecode that can be executed on a standard JVM. In the Android world: It is different. You use the java language to write your code, but the compiler don't produce *.class files, it...
Dex
24,224,186
10
I want to use Android L compat libs. after adding the relevant code to gradle, I get the error: Error Code: 2 Output: objc[36290]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Hom...
Gradle plugin v0.14.0 for Android adds full multidex support. Remove all the build.gradle changes you made (for multidex), and simply add the following: android { defaultConfig { ... multiDexEnabled = true } }
Dex
26,633,591
10
I have several projects which I build to create an .aar. I then import this .aar into into Android Studio under /libs. The build.gradle file for this dependency looks as follows: repositories{ flatDir{ dirs 'libs' } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com...
I run into the same issue. The fix is firstly to deploy the AAR file to a local maven (I utilized the plugin at https://github.com/dcendents/android-maven-gradle-plugin). Then I referenced to the local maven as described at https://stackoverflow.com/a/23045791/2563009. And eventually I declared the dependencies with a ...
Dex
29,857,141
10
I have multiple library projects and they all have dependency to Support Library. My application has dependency to these multiple library projects. Every library project contains references to support library's resources in their R.java file. This inflates the field ID count because of redundancy. My app gets DexInde...
DexIndexOverflowException: field ID not in [0, 0xffff]: 65536 Android has pre-defined upper limit of Methods of 65536. When? The size of the DEX file’s method index is 16 bit, so it means that 65536 represents the total number of references that can be invoked by the code within a single DEX file. If overcome ...
Dex
46,805,025
10
I have succeeded in dynamically loading classes from a dex file in the following way enter code here File file = getDir("dex", 0); DexClassLoader dexClassLoader = new DexClassLoader("/data/data/com.example.callerapp/files/test.dex", file.getAbsolutePath(), null, getClassLoader()); try { Class<Object> _class = (Clas...
You can not load aar file at runtime because aar file contains resources and classes.jar file and does not conatain a dex file. But you can use injector gradle plugin to get dex from your aar and merge all your aar resources into your project and after that you can use injector-android lib to load that dex files at r...
Dex
48,716,303
10
I am trying to understand the difference between google_service_account_iam_binding and google_service_account_iam_member in the GCP terraform provider at https://www.terraform.io/docs/providers/google/r/google_service_account_iam.html. I understand that google_service_account_iam_binding is for granting a role to a li...
"Authoritative" means to change all related privileges, on the other hand, "non-authoritative" means not to change related privileges, only to change ones you specified. Otherwise, you can interpret authoritative as the single source of truth, and non-authoritative as a piece of truth.
Terraform
63,915,353
28
How can this S3 bucket IAM policy, which has multiple conditions, be re-written as aws_iam_policy_document data block, please? "Condition": { "StringEquals": { "s3:x-amz-acl": "bucket-owner-full-control", "aws:SourceAccount": "xxxxxxxxxxxx" }, "ArnLike": { "aws:Source...
The aws_iam_policy_document supports multiple condition directives. The following Terraform configuration should help: data "aws_iam_policy_document" "test" { statement { effect = "Deny" actions = ["backup:*"] resources = ["*"] condition { test = "StringEquals" values = ["bucket-own...
Terraform
62,831,874
28
I am trying to use a certificate issued in eu-central-1 for my apigateway which is regional and works in the same region. My terraform code is as follows: //ACM Certificate provider "aws" { region = "eu-central-1" alias = "eu-central-1" } resource "aws_acm_certificate" "certificate" { provider = "aws.eu-centra...
Change certificate_arn to regional_certificate_arn. From documentation (emphasis mine): When referencing an AWS-managed certificate, the following arguments are supported: certificate_arn - (Optional) The ARN for an AWS-managed certificate. AWS Certificate Manager is the only supported source. Used when an edge-optim...
Terraform
57,231,202
28
I am sitting with a situation where I need to provision EC2 instances with some packages on startup. There are a couple of (enterprise/corporate) constraints that exist: I need to provision on top of a specific AMI, which adds enterprisey stuff such as LDAP/AD access and so on These changes are intended to be used for...
Using Packer to create finished (or very nearly finished) images drastically shortens the time it takes to deploy new instances and also allows you to use autoscaling groups. If you have Terraform run a provisioner such as Chef or Ansible on every EC2 instance creation you add a chunk of time for the provisioner to run...
Terraform
49,314,752
28
I am getting this error when I try to do any operation: Error locking state: Error acquiring the state lock: state blob is already locked How can I list the people currently have a lock and how long the lock has been acquired for?
The easiest fix for this issue is to: (1) navigate to the storage account, (2) then to the container in the Azure portal that holds the state file. (3) The blob will show as ‘Leased’ under the leased state column. (4) Select the state file, and hit the ‘break lease’ button. *FYI: You need PIM (Privileged Identity Mana...
Terraform
64,690,427
27
I am writing a small script that takes a small file from my local machine and puts it into an AWS S3 bucket. My terraform.tf: provider "aws" { region = "us-east-1" version = "~> 1.6" } terraform { backend "s3" { bucket = "${var.bucket_testing}" kms_key_id = "arn:aws:kms:us-east-1:12345678900:key...
This error means that you have run the command in the wrong place. You have to be in the directory that contains your configuration files, so before running init or apply you have to cd to your Terraform project folder.
Terraform
52,351,809
27
When starting of I was using the default workspace. Due to increased complexity I would like to use multiple workspaces. I want to move what is in default workspace into its own workspace or rename the default workspace as another workspace. How can I do this?
Yes it is possible to migrate state between workspaces. I'm assuming that you are using S3 remote backend and terraform version >= 0.13 Let's see how this state surgery looks like: Sample resource config that needs to be migrated between workspaces: provider "local" { version = "2.1.0" } resource "local_file" "foo" ...
Terraform
66,979,732
26
AWS supports IAM Roles for Service Accounts (IRSA) that allows cluster operators to map AWS IAM Roles to Kubernetes Service Accounts. To do so, one has to create an iamserviceaccount in an EKS cluster: eksctl create iamserviceaccount \ --name <AUTOSCALER_NAME> \ --namespace kube-system \ --cluster <CLUSTER_...
I am adding my answer here because I stumble upon the same issue, and accepted answer (and other answers above), do not provide full resolution to the issue - no code examples. They are just guidelines which I had to use to research much deeper. There are some issues which is really easy to miss - and without code exam...
Terraform
65,934,606
26
I am trying to work out how to iterate over nested variables from a complex object given in the following tfvars file using Terraform 0.12.10: example.tfvars virtual_network_data = { 1 = { product_instance_id = 1 location = "somewhere" address_space ...
The technique in this situation is to use other Terraform language features to transform your collection to be a suitable shape for the for_each argument: one element per resource instance. For nested data structures, you can use flatten in conjunction with two or more for expressions to produce a flat data structure w...
Terraform
58,343,258
26
Im trying to iterate through a variable type map and i'm not sure how to This is what i have so far In my main.tf: resource "aws_route_53_record" "proxy_dns" { count = "${length(var.account_name)}" zone_id = "${infrastructure.zone_id}" name = "proxy-${element(split(",", var.account_name), count.index)}-dns type...
If you are using Terraform 0.12.6 or later then you can use for_each instead of count to produce one instance for each element in your map: resource "aws_route53_record" "proxy_dns" { for_each = var.account_name zone_id = infrastructure.zone_id name = "proxy-${each.value}-dns" # ... etc ... } The primary a...
Terraform
57,503,110
26
I am currently working through the beta book "Terraform Up & Running, 2nd Edition". In chapter 2, I created an auto scaling group and a load balancer in AWS. Now I made my backend server HTTP ports configurable. By default they listen on port 8080. variable "server_port" { … default = 8080 } resource "aws_laun...
From the issue link in the comment on Cannot rename ALB Target Group if Listener present: Add a lifecycle rule to your target group so it becomes: resource "aws_lb_target_group" "asg" { name = "terraform-asg-example" port = var.server_port protocol = "HTTP" vpc_id = data.aws_vpc.default.id ...
Terraform
57,183,814
26
I'm using terraform to provision some resources in azure and I can't seem to get helm to install nginx-ingress because it timeouts waiting for condition helm_release.nginx_ingress: 1 error(s) occurred: helm_release.nginx_ingress: rpc error: code = Unknown desc = release nginx-ingress failed: timed out waiting for the...
To install the nginx-ingress in AKS cluster through helm in Terraform, here I show one way that available here. In this way, you need to install the helm in the machine which you want to run the terraform script. And then you also need to configure the helm to your AKS cluster. The steps in Configure the helm to AKS. Y...
Terraform
57,019,284
26
In the documentation or in their bug database, both authors seem to prefer to write out the expression this way: var.a != "" ? var.a : "default-a" The value is explicitly tested to be not equal to empty string, then binary choice is made accordingly. However, does this work too? var.a ? var.a : "default-a" I have not...
Handling of type conversions like these is always a tradeoff in language design, and different languages make different compromises here. For Terraform's language in particular, the philosophy is "explicit is better than implicit": the idea is that ideally someone who is unfamiliar with a configuration and possibly unf...
Terraform
56,967,975
26
Is there any way to get local variables within Terraform console? > local.name unknown values referenced, can't compute value Seems like Terraform console allows only to check input variables and module output variables. > var.in 2 > module.abc.out 3 Configuration file examples: # main.tf locals { name = 1 } var...
This should work in recent Terraform releases. $ terraform version Terraform v1.0.5 $ terraform console > local.name 1 > var.in 2 And it can be scripted (non-interactive) using Bash here string, for example. $ terraform console <<<local.name 1 This is might be really useful for custom tooling, and can even be quite ...
Terraform
53,158,080
26
Is there a way to conditionally add statement blocks in aws_iam_policy_document? I'm looking for something like: data "aws_iam_policy_document" "policy" { statement { sid = "PolicyAlways" ... } if (var.enable_optional_policy) { statement { sid = "PolicySometimes" ... } } }
Yes. You can use a dynamic block with a boolean to optionally include the block. data "aws_iam_policy_document" "policy" { statement { sid = "PolicyAlways" ... } dynamic "statement" { # The contents of the list below are arbitrary, but must be of length one. # It is only used to determine wheth...
Terraform
62,029,196
25
We store our latest approved AMIs in AWS parameter store. When creating new instances with Terraform I would like to programatically get this AMI ID. I have a command to pull the AMI ID but I'm not sure how to use it with Terraform. Here is the command I use to pull the AMI ID: $(aws ssm get-parameter --name /path/to/a...
You can use the aws_ssm_parameter data source to fetch the value of a parameter at runtime: data "aws_ssm_parameter" "ami" { name = "/path/to/ami" } resource "aws_instance" "nginx" { ami = data.aws_ssm_parameter.ami.value # pull value from parameter store instance_type = "t2.micro" provisioner "remo...
Terraform
57,776,524
25
I am working with Terraform provisionar. and in one scenario I need to execute a 'local-exec' provisionar and use the output [This is array of IP addesses] of the command into next 'remote-exec' provisionar. And i am not able to store the 'local-exec' provisionar output in local variable to use later. I can store it i...
Unfortunately you can't. The solution I have found is to instead use an external data source block. You can run a command from there and retrieve the output(s), the only catch is that the command needs to produce json to standard output (stdout). See documentation here. I hope this is some help to others trying to solv...
Terraform
56,474,709
25
I need to upload a folder to S3 Bucket. But when I apply for the first time. It just uploads. But I have two problems here: uploaded version outputs as null. I would expect some version_id like 1, 2, 3 When running terraform apply again, it says Apply complete! Resources: 0 added, 0 changed, 0 destroyed. I would expec...
Terraform only makes changes to the remote objects when it detects a difference between the configuration and the remote object attributes. In the configuration as you've written it so far, the configuration includes only the filename. It includes nothing about the content of the file, so Terraform can't react to the f...
Terraform
56,107,258
25
I am trying to deploy a Cloudfront distribution with Terraform and getting an error while specifying the origin_id Cloudfront is pointing at a load balancer via a Route53 lookup. resource "aws_cloudfront_distribution" "my-app" { origin { custom_origin_config { http_port = 443 https_port ...
The error relates to the cache behaviour. You need to make sure that the target_origin_id relates to an origin_id within a cache behaviour. Like so: resource "aws_cloudfront_distribution" "my-app" { origin { custom_origin_config { http_port = 443 https_port = 443 origin...
Terraform
55,972,204
25
I have seen many examples on how to use Terraform to launch AWS resources. I have also seen many claims that Terraform is cloud agnostic. What I have not seen is an example of how I can launch a VPC with some subnets, some instances, some ELB's, and a few databases in either AWS or Azure using a single tf file. Does a...
While Terraform as a tool is cloud agnostic (in that it will support anything that exposes its API and has enough developer support to create a "provider" for it), Terraform itself will not natively abstract this at all and I'd seriously consider whether this is a good idea at all unless you have a really good use case...
Terraform
42,789,247
25
Im trying to use EC2 Container service. Im using terraform for creating it. I have defined a ecs cluster, autoscaling group, launch configuration. All seems to work. Except one thing. The ec2 instances are creating, but they are not register in the cluster, cluster just says no instances available. In ecs agent log on ...
It was a problem with trust relationships in the role as the role should include ec2. Unfortunately the error message was not all that helpful. Example of trust relationship: { "Version": "2008-10-17", "Statement": [ { "Action": "sts:AssumeRole", "Principal": { "Service": ["ecs.amazonaws.com...
Terraform
34,582,908
25
In an attempt to create a route key named $disconnect for an API Gateway, I'm running the snippet below, while var.route_name should receive the string "disconnect": resource "aws_apigatewayv2_route" "route" { api_id = var.apigw_api.id route_key = "$${var.route_name}" # more stuff... } But it's not escaping i...
In Terraform's template language, the sequence $${ is the escape sequence for literal ${, and so unfortunately in your example Terraform will understand $${var.route_name} as literally ${var.route_name}, and not as a string interpolation at all. To avoid this, you can use any strategy that causes the initial $ to be se...
Terraform
66,953,938
24
I am using terraform to gnerate certificates. Looking for information on how to dump pem and cert values to disk file using terrafrom. here is the output variable. i want to dump them to variable. any reference code snippet ?? output "private_key" { description = "The venafi private key" value = venafi_cert...
One way would be to use local_file. For example: resource "local_file" "private_key" { content = venafi_certificate.this.private_key_pem filename = "private_key.pem" }
Terraform
63,845,957
24
I was using terraform in cloud build, but it fails at this step steps: # Terraform - id: 'configure_terraform' name: node:10.16.3 entrypoint: "node" args: ["./create_terraform_config.js", "../terraform/override.tf", "${_TERRAFORM_BUCKET_NAME}", "${_TERRAFORM_BUCKET_PAT...
This might fix the issue terraform init -reconfigure reference: https://github.com/hashicorp/terraform/issues/23532#issuecomment-560493391
Terraform
59,053,993
24
On terraform/cloudformation documentation there are two different resources to create an ElastiCache Redis instance: aws_elasticache_cluster (https://www.terraform.io/docs/providers/aws/r/elasticache_cluster.html) aws_elasticache_replication_group (https://www.terraform.io/docs/providers/aws/r/elasticache_replication...
Simply, the replication group is for the Redis cluster and the cache cluster is for the Memcache. You cannot apply the command to the others, i.e. cache cluster for Redis cluster and vice versa. The redis also can use aws_elasticache_cluster but only if when redis has node 1, that is not a cluster mode. num_cache_node...
Terraform
58,356,938
24
What is the best way to make REST API calls from Terraform? I'm currently using a null_resource with the local-exec provisioner to make a cURL call: resource "null_resource" "cloudability-setup" { provisioner "local-exec" { command = <<EOT curl -s -X POST https://api.cloudability.com/v3/vendors/aws/acc...
This question has been viewed over 10,000 times and I realized I never posted my solution to the problem. I ended up writing a Python script to handle the various API responses and controlling the return codes to Terraform. Terraform resource: resource "null_resource" "cloudability-setup" { provisioner "local-exec" ...
Terraform
51,197,781
24
While running terraform init when using Terraform 0.11.3 we are getting the following error: Initializing provider plugins... - Checking for available provider plugins on https://releases.hashicorp.com... Error installing provider "template": Get https://releases.hashicorp.com/terraform-provider-template/: read tc...
You can use pre-installed plugins by either putting the plugins in the same directory as the terraform binary or by setting the -plugin-dir flag. It's also possible to build a bundle of every provider you need automatically using the terraform-bundle tool. I run Terraform in our CI pipeline in a Docker container so hav...
Terraform
50,944,395
24
I am trying to create an sg with Terraform. I want all instances of a particular SG to have all communication allowed among them, so I am adding the SG itself to the ingress rules as follows: resource "aws_security_group" "rancher-server-sg" { vpc_id = "${aws_vpc.rancher-vpc.id}" name = "rancher-server-sg" descri...
Citing the manual: self - (Optional) If true, the security group itself will be added as a source to this ingress rule. ingress { from_port = 0 to_port = 0 protocol = -1 self = true }
Terraform
49,995,417
24
I'd like to create and deploy a cluster using terraform ecs_service, but am unable to do so. My terraform applys always fail around IAM roles, which I don't clearly understand. Specifically, the error message is: InvalidParametersException: Unable to assume role and validate the specified targetGroupArn. Please verif...
I was seeing an identical error message and I was doing something else wrong: I had specified the loadbalancer's ARN and not the loadbalancer's target_group ARN.
Terraform
56,742,157
23
Question If there a way to get the assigned IP address of an aws_lb resource at the time aws_lb is created by Terraform? As in AWS documentation - NLB - To find the private IP addresses to whitelist, we can find out the IP address associated to ELB. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/. I...
More elegent solution using only HCL in Terraform : data "aws_network_interface" "lb" { for_each = var.subnets filter { name = "description" values = ["ELB ${aws_lb.example_lb.arn_suffix}"] } filter { name = "subnet-id" values = [each.value] } } resource "aws_security_group" "lb_sg" { ...
Terraform
56,713,493
23
I have the following code in my main.tf file: provider "aws" { access_key = "${var.aws_access_key}" secret_key = "${var.aws_secret_key}" region = "us-east-1" alias = "us-east-1" } provider "aws" { access_key = "${var.aws_access_key}" secret_key = "${var.aws_secret_key}" region = "us-west-1" ...
I was looking for the same answer for a different problem. I wanted to get the region for a name of a role, I was able to get the info by doing this: 1.- Create a file like data.tf and add this info: data "aws_region" "current" {} 2.- Get the info from the data by calling this variable in any TF file: name = "${var.vp...
Terraform
51,619,602
23
I create an AMI in EC2 with terraform with this resource: resource "aws_instance" "devops-demo" { ami = "jnkdjsndjsnfsdj" instance_type = "t2.micro" key_name = "demo-devops" user_data = "${file("ops_setup.sh")}" } The user data executes a shell script that install Java JRE: sudo yum remove...
Using the export command only sets those variables for the current shell and all processes that start from that shell. It is not a persistent setting. Anything you wish to make permanent should be set in /etc/environment. For example in userdata: echo "JAVA_HOME=/jdk1.8.0_172" >> /etc/environment This would add the JA...
Terraform
50,668,315
23
Is there any way to avoid resource deletion when reorganizing/renaming resources? Example: when I first implemented CloudFront Terraform it was an independent sub directory in my project, later I switched to using it as a module in. my root Terraform config but this caused Terraform to want to delete the old CloudFront...
Unfortunately Terraform doesn't know that you've renamed/moved the resource around but you could tell it where the resource should be stored in the state by using terraform state mv. In your case if you ran: terraform state mv aws_cloudfront_distribution.main_site_distribution module.cloudfront.aws_cloudfront_distribut...
Terraform
49,112,142
23
I am using AWS CodeBuild along with Terraform for automated deployment of a Lambda based service. I have a very simple buildscript.yml that accomplishes the following: Get dependencies Run Tests Get AWS credentials and save to file (detailed below) Source the creds file Run Terraform The step "source the creds file" ...
Try using . instead of source. source is not POSIX compliant. ss64.com/bash/source.html
Terraform
44,810,237
23
I'm using packer with ansible provisioner to build an ami, and terraform to setup the infrastructure with that ami as a source - somewhat similar to this article: http://www.paulstack.co.uk/blog/2016/01/02/building-an-elasticsearch-cluster-in-aws-with-packer-and-terraform When command packer build pack.json completes s...
You should consider using Terraform's Data Source for aws_ami. With this, you can rely on custom tags that you set on the AMI when it is created (for example a version number or timestamp). Then, in the Terraform configuration, you can simply filter the available AMIs for this account and region to get the AMI ID tha...
Terraform
37,357,618
23
Any pointers how to setup Terraform v0.14.0 on a Apple M1 , as tfenv doesn't support v0.14.0 on Apple M1 tfenv install v0.14.0 Installing Terraform v0.14.0 Downloading release tarball from https://releases.hashicorp.com/terraform/0.14.0/terraform_0.14.0_darwin_arm64.zip curl: (22) The requested URL returned error: 403 ...
You can set the env var TFENV_ARCH and use tfenv TFENV_ARCH=amd64 tfenv install 0.14.0
Terraform
71,606,880
22
I am working on terraform tasks and trying to understand how state files work. I have created main.tf file which has vpc,firewall,subnet,compute_instance which has to be create in GCP. So i have applied this to GCP environment and a file name terraform.tfstate file got created and i did backup of this file into folde...
There is no way to roll back to a previous state as described in a state file in Terraform today. Terraform always plans changes with the goal of moving from the prior state (the latest state snapshot) to the goal state represented by the configuration. Terraform also uses the configuration for information that is not ...
Terraform
57,821,319
22
I have a list of maps like this - [ { "outer_key_1" = [ { "ip_cidr" = "172.16.6.0/24" "range_name" = "range1" }, { "ip_cidr" = "172.16.7.0/24" "range_name" = "range2" }, { "ip_cidr" = "172.17.6.0/24" "range_name" = "range3" }, ...
You can actually pass a list of maps to the merge() function: The Terraform language has a general feature for turning lists/tuples into multiple arguments, by using the special symbol ... after the last argument expression So, in your example above, you could do: locals { result = merge(module.module_name.module_o...
Terraform
57,392,101
22
I have 6 subnets, I want to filter 3 subnets from them matching substring internal and use in rds. Tag name has internal word and want to filter based on that. Could anyone please help me? data "aws_vpc" "vpc_nonprod-sctransportationops-vpc" { tags { Name = "vpc_nonprod-sctransportationops-vpc" } } data "a...
aws_subnet_ids has this feature, however, different way. Here, it solved my problem: data "aws_subnet_ids" "all" { vpc_id = "${data.aws_vpc.vpc_nonprod-sctransportationops-vpc.id}" tags = { Name = "*internal*" } } Thanks for reviewing :D
Terraform
48,817,967
22
I deploy lambda using Terraform as follows but have following questions: 1) I want null_resource.lambda to be called always or when stop_ec2.py is changed so that stop_ec2_upload.zip is not out-of-date. What should I write in triggers{}? 2) how to make aws_lambda_function.stop_ec2 update the new stop_ec2_upload.zip to ...
I read the link provided by Chandan and figured out. Here is my code and it works perfectly. In fact, with "archive_file", and source_code_hash, I do not need trigger. whenever I create a new file stop_ec2.py or modify it. when I run terraform, the file will be re-zipped and uploaded to cloud. data "archive_file" "stop...
Terraform
48,577,727
22
I am trying to use Terraform to be able to stand up a simple API Proxy in API Gateway on AWS. Basically, I want to wrap root and proxy the requests back to another end point. Its probably the simplest setup and I can't seem to get it to work in Terraform. Below you will find the script. At this point I am able to ...
This is the relevant module which shows a working solution. It doesn't stand alone since it relies on some variables defined elsewhere but it should be enough to help anyone struggling to get a AWS Proxy setup and also shows Lambda authorizer integration as a bonus. provider "aws" { region = "${var.region}" profi...
Terraform
42,070,187
22
Is there a way in Terraform to check if a resource in Google Cloud exists prior to trying to create it? I want to check if the following resources below exist in my CircleCI CI/CD pipeline during a job. I have access to terminal commands, bash, and gcloud commands. If the resources do exist, I want to use them. If they...
TF does not have any build in tools for checking if there are pre-existing resources, as this is not what TF is meant to do. However, you can create your own custom data source. Using the custom data source you can program any logic you want, including checking for pre-existing resources and return that information to ...
Terraform
70,689,512
21
So azurerm updated to 2.0 a few hours ago.... My main code is version locked for safety, but I'm doing some testing to see what's changed from the public beta of 1.44 and now I'm getting this error on any TF command apart from terraform init. has anybody else come upon this?
OK, running terraform in debug mode showed it was at the provider level that the error was being thrown. It's not listed in the 2.0 upgrade guide but if you look at the provider docs it now shows a features{} block. So at a minimum the provider now needs to look like: provider "azurerm" { features {} }
Terraform
60,384,689
21
I have a terraform config which creates an AWS IAM user with an access key, and I assign both id and secret to output variables: ... resource "aws_iam_access_key" "brand_new_user" { user = aws_iam_user.brand_new_user.name } output "brand_new_user_id" { value = aws_iam_access_key.brand_new_user.id } output "brand...
I had some hopes to avoid it, but so far I did not find a better way than parse terraform state: terraform state pull | jq '.resources[] | select(.type == "aws_iam_access_key") | .instances[0].attributes' which would result in a structure similar to: { "encrypted_secret": null, "id": "....", "key_fingerprint": n...
Terraform
59,473,690
21
According to the documentation, to use s3 and not a local terraform.tfstate file for state storage, one should configure a backend more or less as follows: terraform { backend "s3" { bucket = "my-bucket-name" key = "my-key-name" region = "my-region" } } I was using a local (terraform.tfstate) ...
terraform_remote_state isn't for storage of your state its for retrieval in another terraform plan if you have outputs. It is a data source. For example if you output your Elastic IP Address in one state: resource "aws_eip" "default" { vpc = true } output "eip_id" { value = "${aws_eip.default.id}" } Then wan...
Terraform
50,820,850
21
I have an existing resource group on Azure with a VM running on it and have been playing around with Terraform to try and import the resource to my state file. I have set up a skeleton file, and as far as my understanding is once I import TF should populate this with the values on my resource group in Azure resource "...
It looks like you need to fix your script file first - azurerm isn't a valid resource name, did you mean: resource "azurerm_resource_group" "example" { # ...instance configuration... name = "MyResourceGroup" } As seen in the output, import is expecting two parameters, ADDR and ID - you're only passing (wh...
Terraform
47,439,848
21
Is there any way to get the value of a secret from Azure Key Vault? Doesn't look like value gets exposed in the key vault secret object here.
Now you can do it with azurerm_key_vault_secret data source. I'm enjoying without any scripting. data "azurerm_key_vault" "example" { name = "mykeyvault" resource_group_name = "some-resource-group" } data "azurerm_key_vault_secret" "test" { name = "secret-sauce" key_vault_id = data.azurerm_...
Terraform
46,751,391
21
I have noticed that terraform will only run "file", "remote-exec" or "local-exec" on resources once. Once a resource is provisioned if the commands in a "remote-exec" are changed or a file from the provisioner "file" is changed then terraform will not make any changes to the instance. So how to I get terraform to run...
Came across this thread in my searches and eventually found a solution: resource "null_resource" "ansible" { triggers { key = "${uuid()}" } provisioner "local-exec" { command = "ansible-playbook -i /usr/local/bin/terraform-inventory -u ubuntu playbook.yml --private-key=/home/user/.ssh/aws_user.pem -u ubu...
Terraform
39,069,311
21
In reading the docs over at Terraform it says there are 3 options for finding AWS credientials: Static Credentials( embedded in the source file ) Environment variables. From the AWS credentials file I am trying to have my setup just use the credential file. I've checked that the environment variables are cleared and ...
I tested with Terraform v0.6.15 and its working fine. Issue must be with the profile. Check the following. 1. Remove 2 profile tags from your provider. provider "aws" { region = "${var.region}" shared_credentials_file = "/Users/david/.aws/credentials" profile = "testing" } 2. Make sure your credentials fil...
Terraform
36,990,299
21
Using Terraform, I am declaring an s3 bucket and associated policy document, along with an iam_role and iam_role_policy. The s3 bucket is creating fine in AWS however the bucket is listed as "Access: Objects can be public", and want the objects to be private. How can I explicitly make the objects private? resource "...
The easiest way to block all objects in a bucket from ever being public is to attach an aws_s3_bucket_public_access_block resource to the bucket. It would look like this: resource "aws_s3_bucket_public_access_block" "app" { bucket = aws_s3_bucket.app.id block_public_acls = true block_public_policy = tr...
Terraform
67,389,192
20
Going through terraform tutorial I stumbled upon this error. Error: Error launching source instance: InvalidAMIID.NotFound: The image id '[ami-830c94e3]' does not exist status code: 400, request id: 4c3e0252-c3a5-471e-8b57-3f6e349628af This is my code. The only change that I did was was region change from us-west-...
It was simple. Apparently, AMI for Amazon Images of each region is different. I had to copy the AMI of the image that was present in my region. For example ami-07dfba995513840b5 is the id for Red Hat Enterprise Linux 8 (HVM), SSD Volume Type in eu-central-1 region. Go to AWS console, click EC2 from all services list, n...
Terraform
63,633,785
20
Is there a way of implementing the below logic variable "environment" { description = "The environment this will be run in can only be set to [preprod|test|prod]" type = string default = "test" validation { condition = can(regex("^(prod|preprod|test)$", var.environment)) error_message = "...
Update for Terraform 1.9.0 Input variable validation rules can refer to other objects : Previously input variable validation rules could refer only to the variable being validated. Now they are general expressions, similar to those elsewhere in a module, which can refer to other input variables and to other objects su...
Terraform
63,629,916
20
Terraform v0.12.12 + provider.aws v3.0.0 + provider.template v2.1.2 Before I was doing this: resource "aws_route53_record" "derps" { name = aws_acm_certificate.mycert[0].resource_record_name type = aws_acm_certificate.mycert[0].resource_record_type zone_id = var.my_zone_id records = aws_acm_certificate.m...
The AWS Terraform provider was recently upgraded to version 3.0. This version comes with a list of breaking changes. I recommend consulting the AWS provider 3.0 upgrade guide. The issue you are encountering is because the domain_validation_options attribute is now a set instead of a list. From that guide: Since the do...
Terraform
63,235,321
20
I'm unsure what I'm doing wrong. I have terraform as such: resource "aws_apigatewayv2_domain_name" "web" { domain_name = var.web_url count = var.web_url != "" ? 1 : 0 domain_name_configuration { certificate_arn = var.web_acm_arn endpoint_type = "REGIONAL" security_policy = "TLS_1_2" } } re...
As the error message suggest, since you've used count in your aws_apigatewayv2_domain_name, you should use index now when you refer to it. For example: domain_name = aws_apigatewayv2_domain_name.web[0].id
Terraform
63,147,590
20
I have some Terraform code with an aws_instance and a null_resource: resource "aws_instance" "example" { ami = data.aws_ami.server.id instance_type = "t2.medium" key_name = aws_key_pair.deployer.key_name tags = { name = "example" } vpc_security_group_ids = [aws_security_group.main.id] }...
The null_resource is currently only going to wait until the aws_instance resource has completed which in turn only waits until the AWS API returns that it is in the Running state. There's a long gap from there to the instance starting the OS and then being able to accept SSH connections before your local-exec provision...
Terraform
62,403,030
20
I have a lot of Terraform modules written in Terraform 0.11 using gcp-provider of Terraform and want to upgrade the same to Terraform 0.12. For this purpose, I need to keep both the versions installed on my system and use the version according to the version the module is written in. I will go one by one in every modul...
I use Ubuntu 18.04 and I achieved this safely following the below steps. Similar steps can be followed to do the same on any Linux distro (making sure you are downloading the compatible binary. Confirm here) NOTE Running the following commands as root or sudo user Create directories to keep the Terraform binaries $ mkd...
Terraform
60,113,774
20
I have created an EC2 instance using terraform (I do not have the .pem keys). Can I establish an SSH connection between my local system and the EC2 instance?
Assuming you provisioned an instance using Terraform v0.12.+ with this structure: resource "aws_instance" "instance" { ami = "${var.ami}" instance_type = "t2.micro" count = 1 associate_public_ip_address = true } You can make some additional settings: Configure the public ip output: ...
Terraform
59,708,577
20
I am using terraform v0.12.6 and I run into many errors like: Error: Error creating Security Group: InvalidGroup.Duplicate: The security group 'security-search-populate' already exists for VPC 'vpc-003e06e33a87c22f5' status code: 400, request id: 82acdc81-c324-4672-b9fe-531eb8283ed3 Error: Error creating IAM Role ...
If the existing resources are already in terraform in another module or workspace, then I would not import any of those resources since resources should be managed by a single state, not multiple. If the existing resources are not managed anywhere else in terraform, then it should be imported into terraform. You'll nee...
Terraform
57,903,408
20
I'm looking to set up some alerts from gcloud -> slack, and so far have a test up and running having followed these instructions: https://cloud.google.com/monitoring/support/notification-options?_ga=2.190773474.-879257953.1550134526#slack However, ideally I'd store the config for these notifications in a terraform scri...
Visit https://app.google.stackdriver.com/settings/accounts/notifications/slack?project=YOUR_PROJECT_NAME Select "Add Slack Channel" Select "Authorize Stackdriver" Select "Install" You will be redirected back to a URL of the form: https://app.google.stackdriver.com/settings/accounts/notifications/slack/add?project=YOUR...
Terraform
54,884,815
20
I'm having a terrible time getting Terraform to assume an IAM role with another account with MFA required. Here's my setup AWS Config [default] region = us-west-2 output = json [profile GEHC-000] region = us-west-2 output = json .... [profile GEHC-056] source_profile = GEHC-000 role_arn = arn:aws:iam::~069:role/hc/h...
Terraform doesn't currently support prompting for the MFA token when being ran as it is intended to be ran in a less interactive fashion as much as possible and it would apparently require significant rework of the provider structure to support this interactive provider configuration. There's more discussion about this...
Terraform
52,432,717
20
My idea is to have elements of a list modified by appending to each of them a string. How could this be achieved? I haven't find any function that allow me to do that.
Have you tried formatlist()? For example: my_list_var = ["a", "b", "c"] my_new_list = formatlist("%s-foo", var.mylist) my_new_list will be: ["a-foo", "b-foo", "c-foo"] Yo can also pass another list of the same length as parameter to append different strings to each element.
Terraform
51,821,961
20
I am getting the following error when running terraform: * aws_iam_role_policy.rds_policy: Error putting IAM role policy my-rds-policy: MalformedPolicyDocument: The policy failed legacy parsing Here is my definition of the resource: resource "aws_iam_role_policy" "rds_policy" { name = "my-rds-policy" role = "${aws...
You need to make sure that you don't have any indentation at the start of your EOF heredoc because your JSON policy should not start with an indented brace. So you should be fine with this small change: resource "aws_iam_role_policy" "rds_policy" { name = "my-rds-policy" role = "${aws_iam_role.rds_role.id}" polic...
Terraform
42,652,528
20
I am trying to create a Linux VM, with Terraform, in the West Europe Azure region, with a Ubuntu Server 20.04 LTS image. I can do this just fine from within the Azure Portal, but Terraform complains that the image doesn't exist: The platform image 'Canonical:UbuntuServer:20.04-LTS:latest' is not available. Indeed, az...
I too was confused at first when I found out that it is available but under a different name, it is indeed kind of hidden. offer = "0001-com-ubuntu-server-focal" publisher = "Canonical" sku = "20_04-lts-gen2" I used this inside packer so I am guessing it is the same in ter...
Terraform
71,253,468
19
I am using terraform to create a web-acl in aws and want to associate that web-acl with CloudFront distribution. So, here's how my code looks like: provider "aws" { alias = "east1" region = "us-east-1" } # ------------------------------------------- # ------------------------------------------- # Cloud Front modu...
When using WAFv2, you need to specify the the ARN not the ID to web_acl_id in aws_cloudfront_distribution. See the note here https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_distribution#web_acl_id or this GitHub issue https://github.com/hashicorp/terraform-provider-aws/issues/1390...
Terraform
66,476,009
19
I am going through a terraform guide, where the author is spinning up a docker setup using the docker_image and docker_container resources. In the sample code the main.tf file includes both the required_providers and the provider blocks, as follows: terraform { required_providers { docker = { source = "kreu...
When considering Terraform providers there are two related notions to think about: the provider itself, and a configuration for the provider. As an analogy, the provider kreuzwerker/docker here is a bit like a class you're importing from another library, giving it the local name docker. I'll use a pseudo-JavaScript syn...
Terraform
66,080,706
19
I tried terraform versions v0.12.26 and v0.13.3. Both failed. terraform plan Acquiring state lock. This may take a few moments... Error: Error locking state: Error acquiring the state lock: 2 errors occurred: * ResourceNotFoundException: Requested resource not found * ResourceNotFoundException: Requested resource not f...
The error is ResourceNotFoundException, which suggests that your dev-lock-table does not exist. Terraform does not create it. Instead it must exist before you will use it. From docs: dynamodb_table field to an existing DynamoDB table name.
Terraform
64,149,876
19
I have a terraform configuration which needs to: Create a lambda Invoke the lambda Iterate on the lambda's json result which returns an array and create a CloudWatch event rule per entry in the array The relevant code looks like: Create lambda code... data "aws_lambda_invocation" "run_lambda" { function_name = "${...
One possibility is to reconsider for_each and use count instead, if appropriate. for_each has some major limitations. I ran into something similar (seems like a major bug to me, but they say it is a feature) Consider I am deploying three vms, and want to bind them to a load balancer: resource "aws_instance" "xxx-IIS-00...
Terraform
63,768,921
19
I am having a hard time figuring out how to make an output for each target group resource that this code creates. I'd like to be able to reference each one individually in other modules. It sounds like for_each stores it as a map, so my question is how would I get the arn for targetgroup1 and targetgroup2? Terraform n...
The aws_lb_target_group.target-group generated will be a map, with key values of targetgroup2 and targetgroup1. Therefore, to get the individual target group details you can do: output "target-group1-arn" { value = aws_lb_target_group.target-group["targetgroup1"].arn } To return both as a map: output "target-groups-...
Terraform
63,627,282
19
I'm writing sort of wrapper module for azurerm_storage_account. azurerm_storage_account has optional block static_website { index_document = string error_404_document = string } I want to set it based on variable and I'm not really sure how can I do that? Conditional operators don't really work for blocks (e.g. st...
I think you can use dynamic block for that. Basically, when the disable is true, no static_website will be created. Otherwise, one static_website block is going to be constructed. For example, the modified code could be: dynamic "static_website" { for_each = var.disable == true ? toset([]) : toset([1]) con...
Terraform
63,592,602
19
I want to assign multiple IAM roles to a single service account through terraform. I prepared a TF file to do that, but it has an error. With a single role it can be successfully assigned but with multiple IAM roles, it gave an error. data "google_iam_policy" "auth1" { binding { role = "roles/cloudsql.admin" ...
I did something like this resource "google_project_iam_member" "member-role" { for_each = toset([ "roles/cloudsql.admin", "roles/secretmanager.secretAccessor", "roles/datastore.owner", "roles/storage.admin", ]) role = each.key member = "serviceAccount:${google_service_account.service_account_1.e...
Terraform
61,661,116
19