Skip to content

Commit

Permalink
Change the public ip resource conflict warning message order (#600)
Browse files Browse the repository at this point in the history
* change the warning message order

* change the warning message

* Update stackit/internal/services/iaas/publicipassociate/resource.go

Co-authored-by: João Palet <[email protected]>

* adapt warning in schema and docs

---------

Co-authored-by: João Palet <[email protected]>
  • Loading branch information
GokceGK and joaopalet authored Nov 25, 2024
1 parent 2a2d62a commit 1051995
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions docs/resources/public_ip_associate.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ page_title: "stackit_public_ip_associate Resource - stackit"
subcategory: ""
description: |-
Associates an existing public IP to a network interface. This is useful for situations where you have a pre-allocated public IP or unable to use the stackit_public_ip resource to create a new public IP. Must have a region specified in the provider configuration.
!> The stackit_public_ip_associate resource should not be used together with the stackit_public_ip resource for the same network interface, as they both have control of the network interface association and this will lead to conflicts.
!> The stackit_public_ip_associate resource should not be used together with the stackit_public_ip resource for the same public IP or for the same network interface.
Using both resources together for the same public IP or network interface WILL lead to conflicts, as they both have control of the public IP and network interface association.
~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our guide https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources for how to opt-in to use beta resources.
---

# stackit_public_ip_associate (Resource)

Associates an existing public IP to a network interface. This is useful for situations where you have a pre-allocated public IP or unable to use the `stackit_public_ip` resource to create a new public IP. Must have a `region` specified in the provider configuration.

!> The `stackit_public_ip_associate` resource should not be used together with the `stackit_public_ip` resource for the same network interface, as they both have control of the network interface association and this will lead to conflicts.
!> The `stackit_public_ip_associate` resource should not be used together with the `stackit_public_ip` resource for the same public IP or for the same network interface.
Using both resources together for the same public IP or network interface WILL lead to conflicts, as they both have control of the public IP and network interface association.

~> This resource is in beta and may be subject to breaking changes in the future. Use with caution. See our [guide](https://registry.terraform.io/providers/stackitcloud/stackit/latest/docs/guides/opting_into_beta_resources) for how to opt-in to use beta resources.

Expand Down
9 changes: 5 additions & 4 deletions stackit/internal/services/iaas/publicipassociate/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func (r *publicIpAssociateResource) Configure(ctx context.Context, req resource.
return
}

core.LogAndAddWarning(ctx, &resp.Diagnostics, "The `stackit_public_ip_associate` resource should not be used together with the `stackit_public_ip` resource for the same public IP or for the same network interface.",
"Using both resources together for the same public IP or network interface WILL lead to conflicts, as they both have control of the public IP and network interface association.")

r.client = apiClient
tflog.Info(ctx, "iaas client configured")
}
Expand All @@ -109,7 +112,8 @@ func (r *publicIpAssociateResource) Schema(_ context.Context, _ resource.SchemaR
"main": "Associates an existing public IP to a network interface. " +
"This is useful for situations where you have a pre-allocated public IP or unable to use the `stackit_public_ip` resource to create a new public IP. " +
"Must have a `region` specified in the provider configuration.",
"warning_message": "The `stackit_public_ip_associate` resource should not be used together with the `stackit_public_ip` resource for the same network interface, as they both have control of the network interface association and this will lead to conflicts.",
"warning_message": "The `stackit_public_ip_associate` resource should not be used together with the `stackit_public_ip` resource for the same public IP or for the same network interface. \n" +
"Using both resources together for the same public IP or network interface WILL lead to conflicts, as they both have control of the public IP and network interface association.",
}
resp.Schema = schema.Schema{
MarkdownDescription: features.AddBetaDescription(fmt.Sprintf("%s\n\n!> %s", descriptions["main"], descriptions["warning_message"])),
Expand Down Expand Up @@ -185,9 +189,6 @@ func (r *publicIpAssociateResource) Create(ctx context.Context, req resource.Cre
ctx = tflog.SetField(ctx, "public_ip_id", publicIpId)
ctx = tflog.SetField(ctx, "network_interface_id", networkInterfaceId)

core.LogAndAddWarning(ctx, &resp.Diagnostics, "The `stackit_public_ip_associate` resource should not be used together with the `stackit_public_ip` resource for the same network interface.",
"The `stackit_public_ip_associate` resource should not be used together with the `stackit_public_ip` resource for the same network interface, as they both have control of the network interface association and this will lead to conflicts.")

// Generate API request body from model
payload, err := toCreatePayload(&model)
if err != nil {
Expand Down

0 comments on commit 1051995

Please sign in to comment.