# Is it possible to share actions between tenants?

**URL:** <https://community.auth0.com/t/is-it-possible-to-share-actions-between-tenants/108985>\
**Category:** Get Help\
**Tags:** extensibility, actions-extensibility\
**Created:** [June 9, 2023, 8:23pm UTC](https://community.auth0.com/t/is-it-possible-to-share-actions-between-tenants/108985 "2023-06-09T20:23:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mactyr](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mactyr/32/47959_2.png) [@mactyr](https://community.auth0.com/u/mactyr)\
**Post date:** [June 9, 2023, 8:23pm UTC](https://community.auth0.com/t/is-it-possible-to-share-actions-between-tenants/108985/1 "2023-06-09T20:23:52Z")

</div>

I have developed a custom action which I would like to deploy to more than one tenant. So far, the only way I’ve found to do this is to cut and paste the code of the action and create a new custom action for each tenant with the same code, but that’s obviously not a very maintainable solution; if I need to change the action code, I have to go through the various tenants and make sure to apply the same change to all of them. Is there a more efficient way to do this?

As an aside for the moderators: there seems to be something wrong with the tagging for this new topic. I see there are existing topics with “actions” and “tenants” tags (which seem most appropriate for this question) but when I type those into the “select at least 2 tags…” box, it says “No matches found”. I guessed that maybe “extensibility” would be the closest thing on the list that is available to me… and then after that the option to choose “actions-extensibility” appeared, which wasn’t available before! This is all pretty confusing and unintuitive for a first-time poster!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [June 9, 2023, 10:45pm UTC](https://community.auth0.com/t/is-it-possible-to-share-actions-between-tenants/108985/2 "2023-06-09T22:45:55Z")

</div>

Hey there @mactyr welcome to the community!

> [@mactyr](#):
>
> I have developed a custom action which I would like to deploy to more than one tenant. So far, the only way I’ve found to do this is to cut and paste the code of the action and create a new custom action for each tenant with the same code, but that’s obviously not a very maintainable solution; if I need to change the action code, I have to go through the various tenants and make sure to apply the same change to all of them. Is there a more efficient way to do this?

Unfortunately, Actions are currently not able to be shared between tenants - I did a quick search in our [Feedback section](https://community.auth0.com/c/feedback/95) and don’t see a similar request, so I definitely recommend creating one as it’s an interesting use case I image other users would be interested in as well.

> [@mactyr](#):
>
> As an aside for the moderators: there seems to be something wrong with the tagging for this new topic. I see there are existing topics with “actions” and “tenants” tags (which seem most appropriate for this question) but when I type those into the “select at least 2 tags…” box, it says “No matches found”. I guessed that maybe “extensibility” would be the closest thing on the list that is available to me… and then after that the option to choose “actions-extensibility” appeared, which wasn’t available before! This is all pretty confusing and unintuitive for a first-time poster!

We’re always looking to improve the community experience so thanks for the feedback 🙂

---

<div class="post-metadata">

**Author:** ![mactyr](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mactyr/32/47959_2.png) [@mactyr](https://community.auth0.com/u/mactyr)\
**Post date:** [June 12, 2023, 5:49pm UTC](https://community.auth0.com/t/is-it-possible-to-share-actions-between-tenants/108985/3 "2023-06-12T17:49:11Z")

</div>

@ty.frith thanks for the response. I’ve filed a [feedback request](https://community.auth0.com/t/share-custom-actions-across-tenants/109087) for this feature.

---

<div class="post-metadata">

**Author:** ![richard.sanigar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/richard.sanigar/32/23147_2.png) [@richard.sanigar](https://community.auth0.com/u/richard.sanigar)\
**Post date:** [June 19, 2023, 9:29am UTC](https://community.auth0.com/t/is-it-possible-to-share-actions-between-tenants/108985/4 "2023-06-19T09:29:13Z")

</div>

Hi [mactyr](https://community.auth0.com/u/mactyr)

One option to rid yourself of cutting and pasting is to use the Auth0 Terraform Provider to create your Auth0 configuration from a script, or in our case a Gitlab Pipeline.

The Terraform Provider has an [auth0\_action](https://registry.terraform.io/providers/auth0/auth0/latest/docs) resource, which would allow you to deploy your action into the tenants.

The trick is to create a machine to machine application in both tenants and call it Terraform Client. Then link the Application to the Auth0 Management API. (Behind the scenes the Terraform Auth0 Provider is calling the Auth0 Management API to create the Auth0 resources). In your terraform resource file, you use the client\_id and client\_secret of the Machine to Machine Terraform Client you’ve created to link Auth0 to the Terraform Provider.

provider “auth0” {  
domain = “”  
client\_id = “\<client\_id of the M2M application\>”  
client\_secret = “\<client\_secret of the M2M application\>”  
debug = true  
}

If you’re only going to create less than 500 resource per month, Terraform is free. You can download the executable from the [HashiCorp](https://developer.hashicorp.com/terraform/downloads) site

Terraform (Infrastructure as code) and the Terraform Auth0 Provider may help you out.

Regards

Richard

---

<div class="post-metadata">

**Author:** ![mactyr](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mactyr/32/47959_2.png) [@mactyr](https://community.auth0.com/u/mactyr)\
**Post date:** [June 23, 2023, 4:59pm UTC](https://community.auth0.com/t/is-it-possible-to-share-actions-between-tenants/108985/5 "2023-06-23T16:59:39Z")

</div>

Thanks @richard.sanigar, that’s a helpful tip for me as we are actually in the process of migrating some other infrastructure setup to Terraform but it hadn’t occurred to me that it could help with this. I will add it to our list.

---

<div class="post-metadata">

**Author:** ![richard.sanigar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/richard.sanigar/32/23147_2.png) [@richard.sanigar](https://community.auth0.com/u/richard.sanigar)\
**Post date:** [June 27, 2023, 1:06pm UTC](https://community.auth0.com/t/is-it-possible-to-share-actions-between-tenants/108985/6 "2023-06-27T13:06:48Z")

</div>

Hi Mactyr

I forgot to mention you can put your code in a separate file and include it using either **file** or **templatefile** , to prevent cutting and pasting.

```auto
resource "auth0_action" "add_custom_claims_to_access_token" {
  name = "add-custom-claims-to-access-token${var.service_name_postfix}"
  runtime = "node16"
  deploy = true
  code = file("files/script/login-flow-action-script.js")

  supported_triggers {
    id = "post-login"
    version = "v3"
  }
}

resource "auth0_action" "add_custom_claims_to_m2m_token" {
  name = "add-custom-claims-to-m2m-token${var.service_name_postfix}"
  runtime = "node16"
  deploy = true
  code = file("files/script/m2m-flow-action-script.js")

  supported_triggers {
    id = "credentials-exchange"
    version = "v2"
  }
}

```

If you have subtle differences between tenants, then use the terraform template function. Terraform will parse the template file first, substituting any changes e.g.

```auto
resource "auth0_action" "add_custom_claims_to_m2m_token" {
  name = "add-custom-claims-to-m2m-token${var.service_name_postfix}"
  runtime = "node16"
  deploy = true
  code = templatefile("files/script/m2m-flow-action-script-template.js",
      { app_name = var.tenant_app_name
      })

  supported_triggers {
    id = "credentials-exchange"
    version = "v2"
  }
}

```

So if you had something like this in your action script template file:

```auto
        if (event.client.name === ${app_name}) {
          ....
        }

```

Terraform will replace the ${app\_name} with the value of the var.tenant\_app\_name, and then assign the whole contents of the file to the code variable of the resource.

Hope your terraforming goes well

Regards

Richard

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 11, 2023, 1:07pm UTC](https://community.auth0.com/t/is-it-possible-to-share-actions-between-tenants/108985/7 "2023-07-11T13:07:09Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
