# Azure Terrafrom iSsues with the API Publisher

**URL:** <https://discuss.hashicorp.com/t/azure-terrafrom-issues-with-the-api-publisher/19741>\
**Category:** Terraform\
**Tags:** azure\
**Created:** [January 14, 2021, 6:09pm UTC](https://discuss.hashicorp.com/t/azure-terrafrom-issues-with-the-api-publisher/19741 "2021-01-14T18:09:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsudabathula](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/bsudabathula/32/16451_2.png) [@bsudabathula](https://discuss.hashicorp.com/u/bsudabathula)\
**Post date:** [January 14, 2021, 6:09pm UTC](https://discuss.hashicorp.com/t/azure-terrafrom-issues-with-the-api-publisher/19741/1 "2021-01-14T18:09:01Z")

</div>

Team,

I am working as a senior software engineer in Delta Dental Of California and we recently migrated to Azure Cloud. We are planning to use Terraform as Infrastructure as a code and started learning the terraform .

We are publishing the API’s in Azure APi manager using the terrform code and we are able to do that. If we are deploying another set of api’s , the terraform is deleting the previously created API’s.

is there any chance in terraform to maintain the previous states of the API’s with out destroying every deployment.

We are currently blocked and i need your support on this.

Below is the issue I am facing:

1. Published our first API (demo-api) using resource . - Successful
2. We are able to test this API from API Manager
3. Publishing our second API (demo2-api) - Second API is published and it dot destroyed the First API

We have created a Pipeline which using Terrafrom and creating the resources based on our tf files. We are using a single pipeline for deploying all the API’s but we are passing the API details at RunTime.

Is there any chance to maintain all the previous version with out deleting it. Appreciate your help on this.

pool:

```
name: Azure Pipelines

vmImage: windows-latest

workspace:

    clean: all  

```

trigger:

- master

stages:

- stage: Hub\_SBOX\_Middleware\_ITS\_Demo\_API

---

<div class="post-metadata">

**Author:** ![tbugfinder](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tbugfinder/32/12689_2.png) [@tbugfinder](https://discuss.hashicorp.com/u/tbugfinder)\
**Post date:** [January 14, 2021, 6:33pm UTC](https://discuss.hashicorp.com/t/azure-terrafrom-issues-with-the-api-publisher/19741/2 "2021-01-14T18:33:13Z")

</div>

Hi @bsudabathula,  
do you have different code repositories while deploying API1 and API2 or do you use different parameters for the same code?

It looks like you have different deployments however reuse a single state.

---

<div class="post-metadata">

**Author:** ![bsudabathula](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/bsudabathula/32/16451_2.png) [@bsudabathula](https://discuss.hashicorp.com/u/bsudabathula)\
**Post date:** [January 14, 2021, 6:47pm UTC](https://discuss.hashicorp.com/t/azure-terrafrom-issues-with-the-api-publisher/19741/3 "2021-01-14T18:47:16Z")

</div>

Hi,

We are using the different parameters for the same code and we are passing those at runtime through pipeline.

---

<div class="post-metadata">

**Author:** ![tbugfinder](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tbugfinder/32/12689_2.png) [@tbugfinder](https://discuss.hashicorp.com/u/tbugfinder)\
**Post date:** [January 14, 2021, 7:05pm UTC](https://discuss.hashicorp.com/t/azure-terrafrom-issues-with-the-api-publisher/19741/4 "2021-01-14T19:05:06Z")

</div>

Without using different state-file locations or properly have all resource definitions within the same code-base, you’re basically applying changes to your current deployment which includes deleting previous deployments.

---

<div class="post-metadata">

**Author:** ![bsudabathula](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/bsudabathula/32/16451_2.png) [@bsudabathula](https://discuss.hashicorp.com/u/bsudabathula)\
**Post date:** [January 14, 2021, 7:31pm UTC](https://discuss.hashicorp.com/t/azure-terrafrom-issues-with-the-api-publisher/19741/5 "2021-01-14T19:31:48Z")

</div>

Thanks for the quick response. You mean to say that don’t destroy the previous state file locations and create a new state file location for each and every deployment. Am i correct?

---

<div class="post-metadata">

**Author:** ![tbugfinder](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tbugfinder/32/12689_2.png) [@tbugfinder](https://discuss.hashicorp.com/u/tbugfinder)\
**Post date:** [January 14, 2021, 8:06pm UTC](https://discuss.hashicorp.com/t/azure-terrafrom-issues-with-the-api-publisher/19741/6 "2021-01-14T20:06:16Z")

</div>

IMHO, there are two options.  
a) Add all your resource configurations to the code-base and still use a single state file.  
b) For each deployment use a distinct state-file. In case a specific deployment has to be destroyed or updated use the proper state-file.

Ref: [State - Terraform by HashiCorp](https://www.terraform.io/docs/state/index.html)
