Skip to content

Commit

Permalink
Fixes issues with config-as-code resources caused by renaming them.
Browse files Browse the repository at this point in the history
  • Loading branch information
micahlmartin committed Oct 20, 2021
1 parent bfb4d3e commit f604b72
Show file tree
Hide file tree
Showing 40 changed files with 158 additions and 55 deletions.
4 changes: 2 additions & 2 deletions docs/resources/cloudprovider_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_cloudprovider_aws Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating an AWS cloud provider
Resource for creating an AWS cloud provider. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_cloudprovider_aws (Resource)

Resource for creating an AWS cloud provider
Resource for creating an AWS cloud provider. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/cloudprovider_azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_cloudprovider_azure Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating an Azure cloud provider
Resource for creating an Azure cloud provider. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_cloudprovider_azure (Resource)

Resource for creating an Azure cloud provider
Resource for creating an Azure cloud provider. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/cloudprovider_datacenter.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_cloudprovider_datacenter Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating a physical data center cloud provider
Resource for creating a physical data center cloud provider. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_cloudprovider_datacenter (Resource)

Resource for creating a physical data center cloud provider
Resource for creating a physical data center cloud provider. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/cloudprovider_gcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_cloudprovider_gcp Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating a GCP cloud provider
Resource for creating a GCP cloud provider. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_cloudprovider_gcp (Resource)

Resource for creating a GCP cloud provider
Resource for creating a GCP cloud provider. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.



Expand Down
8 changes: 6 additions & 2 deletions docs/resources/cloudprovider_kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_cloudprovider_kubernetes Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating a Kubernetes cloud provider
Resource for creating a Kubernetes cloud provider. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_cloudprovider_kubernetes (Resource)

Resource for creating a Kubernetes cloud provider
Resource for creating a Kubernetes cloud provider. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down Expand Up @@ -40,6 +40,10 @@ resource "harness_cloudprovider_kubernetes" "example" {
password_secret_name = harness_encrypted_text.password.name
}
}
lifecycle {
create_before_destroy = true
}
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/cloudprovider_spot.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_cloudprovider_spot Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating a Spot cloud provider
Resource for creating a Spot cloud provider. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_cloudprovider_spot (Resource)

Resource for creating a Spot cloud provider
Resource for creating a Spot cloud provider. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/cloudprovider_tanzu.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_cloudprovider_tanzu Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating a Tanzu cloud provider
Resource for creating a Tanzu cloud provider. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_cloudprovider_tanzu (Resource)

Resource for creating a Tanzu cloud provider
Resource for creating a Tanzu cloud provider. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/infrastructure_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_infrastructure_definition Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating am infrastructure definition
Resource for creating am infrastructure definition. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_infrastructure_definition (Resource)

Resource for creating am infrastructure definition
Resource for creating am infrastructure definition. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/service_ami.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_service_ami Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating an AMI service
Resource for creating an AMI service. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_service_ami (Resource)

Resource for creating an AMI service
Resource for creating an AMI service. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/service_aws_codedeploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_service_aws_codedeploy Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating an AWS CodeDeploy service
Resource for creating an AWS CodeDeploy service. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_service_aws_codedeploy (Resource)

Resource for creating an AWS CodeDeploy service
Resource for creating an AWS CodeDeploy service. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/service_aws_lambda.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_service_aws_lambda Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating an AWS Lambda service
Resource for creating an AWS Lambda service. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_service_aws_lambda (Resource)

Resource for creating an AWS Lambda service
Resource for creating an AWS Lambda service. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/service_ecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_service_ecs Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating an AWS ECS service
Resource for creating an AWS ECS service. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_service_ecs (Resource)

Resource for creating an AWS ECS service
Resource for creating an AWS ECS service. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/service_helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_service_helm Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating a Kubernetes Helm service
Resource for creating a Kubernetes Helm service. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_service_helm (Resource)

Resource for creating a Kubernetes Helm service
Resource for creating a Kubernetes Helm service. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/service_kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_service_kubernetes Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating a Kubernetes service
Resource for creating a Kubernetes service. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_service_kubernetes (Resource)

Resource for creating a Kubernetes service
Resource for creating a Kubernetes service. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/service_ssh.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_service_ssh Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating an SSH service
Resource for creating an SSH service. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_service_ssh (Resource)

Resource for creating an SSH service
Resource for creating an SSH service. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/service_tanzu.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_service_tanzu Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating a Tanzu (PCF) service
Resource for creating a Tanzu (PCF) service. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_service_tanzu (Resource)

Resource for creating a Tanzu (PCF) service
Resource for creating a Tanzu (PCF) service. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/service_winrm.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_service_winrm Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating an WinRM service
Resource for creating an WinRM service. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_service_winrm (Resource)

Resource for creating an WinRM service
Resource for creating an WinRM service. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/yaml_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "harness_yaml_config Resource - terraform-provider-harness"
subcategory: ""
description: |-
Resource for creating a raw YAML configuration in Harness. Note: This works for all objects EXCEPT application objects.
Resource for creating a raw YAML configuration in Harness. Note: This works for all objects EXCEPT application objects. This object uses the config-as-code API's. When updating the name or path of this resource you should typically also set the create_before_destroy = true lifecycle setting.
---

# harness_yaml_config (Resource)

Resource for creating a raw YAML configuration in Harness. Note: This works for all objects EXCEPT application objects.
Resource for creating a raw YAML configuration in Harness. Note: This works for all objects EXCEPT application objects. This object uses the config-as-code API's. When updating the `name` or `path` of this resource you should typically also set the `create_before_destroy = true` lifecycle setting.

## Example Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ resource "harness_cloudprovider_kubernetes" "example" {
password_secret_name = harness_encrypted_text.password.name
}
}

lifecycle {
create_before_destroy = true
}
}
2 changes: 2 additions & 0 deletions internal/provider/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"
"log"

"github.com/harness-io/harness-go-sdk/harness/api"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand All @@ -26,6 +27,7 @@ func commonCloudProviderSchema() map[string]*schema.Schema {
}

func resourceCloudProviderDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
log.Printf("[DEBUG] Deleting cloud provider %s", d.Get("name"))
c := meta.(*api.Client)

id := d.Get("id").(string)
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_cloudprovider_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func resourceCloudProviderAws() *schema.Resource {
helpers.MergeSchemas(commonSchema, providerSchema)

return &schema.Resource{
Description: "Resource for creating an AWS cloud provider",
Description: configAsCodeDescription("Resource for creating an AWS cloud provider."),
CreateContext: resourceCloudProviderAwsCreateOrUpdate,
ReadContext: resourceCloudProviderAwsRead,
UpdateContext: resourceCloudProviderAwsCreateOrUpdate,
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_cloudprovider_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func resourceCloudProviderAzure() *schema.Resource {
helpers.MergeSchemas(commonSchema, providerSchema)

return &schema.Resource{
Description: "Resource for creating an Azure cloud provider",
Description: configAsCodeDescription("Resource for creating an Azure cloud provider."),
CreateContext: resourceCloudProviderAzureCreateOrUpdate,
ReadContext: resourceCloudProviderAzureRead,
UpdateContext: resourceCloudProviderAzureCreateOrUpdate,
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_cloudprovider_datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func resourceCloudProviderDataCenter() *schema.Resource {
providerSchema := commonCloudProviderSchema()

return &schema.Resource{
Description: "Resource for creating a physical data center cloud provider",
Description: configAsCodeDescription("Resource for creating a physical data center cloud provider."),
CreateContext: resourceCloudProviderDataCenterCreateOrUpdate,
ReadContext: resourceCloudProviderDataCenterRead,
UpdateContext: resourceCloudProviderDataCenterCreateOrUpdate,
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_cloudprovider_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func resourceCloudProviderGcp() *schema.Resource {
helpers.MergeSchemas(commonCloudProviderSchema(), providerSchema)

return &schema.Resource{
Description: "Resource for creating a GCP cloud provider",
Description: configAsCodeDescription("Resource for creating a GCP cloud provider."),
CreateContext: resourceCloudProviderGcpCreateOrUpdate,
ReadContext: resourceCloudProviderGcpRead,
UpdateContext: resourceCloudProviderGcpCreateOrUpdate,
Expand Down
12 changes: 10 additions & 2 deletions internal/provider/resource_cloudprovider_kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"
"log"
"strings"

"github.com/harness-io/harness-go-sdk/harness/api"
Expand Down Expand Up @@ -231,7 +232,7 @@ func resourceCloudProviderK8s() *schema.Resource {
helpers.MergeSchemas(commonCloudProviderSchema(), providerSchema)

return &schema.Resource{
Description: "Resource for creating a Kubernetes cloud provider",
Description: configAsCodeDescription("Resource for creating a Kubernetes cloud provider."),
CreateContext: resourceCloudProviderK8sCreateOrUpdate,
ReadContext: resourceCloudProviderK8sRead,
UpdateContext: resourceCloudProviderK8sCreateOrUpdate,
Expand All @@ -249,9 +250,13 @@ func resourceCloudProviderK8sRead(ctx context.Context, d *schema.ResourceData, m
c := meta.(*api.Client)

cp := &cac.KubernetesCloudProvider{}
if err := c.ConfigAsCode().GetCloudProviderById(d.Id(), cp); err != nil {
id := d.Id()

log.Printf("[DEBUG] Terraform: Reading Kubernetes cloud provider %s", id)
if err := c.ConfigAsCode().GetCloudProviderById(id, cp); err != nil {
return diag.FromErr(err)
} else if cp.IsEmpty() {
log.Printf("[DEBUG] Terraform: Could not find cloud provider %s. Marking as new resource", id)
d.SetId("")
d.MarkNewResource()
return nil
Expand Down Expand Up @@ -282,12 +287,15 @@ func resourceCloudProviderK8sCreateOrUpdate(ctx context.Context, d *schema.Resou
var err error

if d.IsNewResource() {
log.Printf("[DEBUG] Terraform: Creating Kubernetes cloud provider %s", d.Get("name"))
input = cac.NewEntity(cac.ObjectTypes.KubernetesCloudProvider).(*cac.KubernetesCloudProvider)
} else {
log.Printf("[DEBUG] Terraform: Updating Kubernetes cloud provider %s", d.Get("name"))
input = &cac.KubernetesCloudProvider{}
if err = c.ConfigAsCode().GetCloudProviderById(d.Id(), input); err != nil {
return diag.FromErr(err)
} else if input.IsEmpty() {
log.Printf("[DEBUG] Terraform: Could not find cloud provider. Marking as new resource.")
d.SetId("")
d.MarkNewResource()
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_cloudprovider_spot.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func resourceCloudProviderSpot() *schema.Resource {
helpers.MergeSchemas(commonSchema, providerSchema)

return &schema.Resource{
Description: "Resource for creating a Spot cloud provider",
Description: configAsCodeDescription("Resource for creating a Spot cloud provider."),
CreateContext: resourceCloudProviderSpotCreateOrUpdate,
ReadContext: resourceCloudProviderSpotRead,
UpdateContext: resourceCloudProviderSpotCreateOrUpdate,
Expand Down
Loading

0 comments on commit f604b72

Please sign in to comment.