title: Terraform: call null_resource (local-exec) BEFORE the other modules
body: <p>I have a python script that generates custom cloud-init scripts for each AWS EC2 instance that I'm creating with terraform. But right now I'm unable to make a single call to <code>terraform apply</code> since the files for cloud-init don't exist at that moment, and I get an error. So for now I'm doing <code>terraform apply -target=null_resource.pynit_lite</code> to generate the files, then <code>terraform apply</code> to create the infrastructure.</p>
  <p>What I'd like is to have the null_resource execute first, then the rest so that the cloud-init files exist at the moment of the ec2 resource creation, so that I can do a single call to <code>terraform apply</code>.</p>
  <p>I guess I'd need to implement some sort of &quot;depends_on&quot; so that the EC2 module waits for the null_resource to finish, but this is not a feature in terraform.</p>
  <p>My code looks like this:</p>
  <pre><code>provider &quot;aws&quot; {
    region = var.region
    profile = var.profile
  }
  
  resource &quot;null_resource&quot; &quot;pynit_lite&quot; {
    provisioner &quot;local-exec&quot; {
      command = &quot;python3 pynit_lite.py&quot;
    }
  }
  
  data &quot;aws_vpc&quot; &quot;devvpc&quot; {
    id = var.vpc_id
  }
  
  data &quot;aws_subnet_ids&quot; &quot;devsubs&quot; {
    vpc_id = var.vpc_id
  }
  
  module &quot;EC2&quot; {
    source = &quot;../../../Modules/EC2&quot;
  
    name = var.instanceNames
    DSKsize = var.DSKsize
    root_volume_size = var.root_volume_size
    ami = var.ami
    instance_count = length(var.instanceNames)
    instance_type = var.instance_type
    key_name = var.key_name
    ec2_security_group_ids = var.ec2_security_group_ids
    script = var.scripts
  
    subnet = var.subnet
    vpc = var.vpc_id
  }
  
  output &quot;EIP-public&quot; {
    value = module.EC2.EIPAddress
  }
  output &quot;EIP-internal&quot; {
    value = module.EC2.InternalIps
  }
  </code></pre>
  <p>I've looked this question but it does not provide a solution for this: <a href="https://stackoverflow.com/questions/56714815/unable-to-make-terraform-module-dependent-on-resource">Unable to make Terraform module dependent on resource</a></p>
  <p>This is non-blocking but certainly annoying, so any help would be greatly appreciated.</p>
  <p>Thanks.</p>