diff --git a/docs/resources/integration.md b/docs/resources/integration.md index 4632e927..73ba6457 100644 --- a/docs/resources/integration.md +++ b/docs/resources/integration.md @@ -68,9 +68,9 @@ resource "juju_integration" "this" { Optional: -- `endpoint` (String) The endpoint name. -- `name` (String) The name of the application. -- `offer_url` (String) The URL of a remote application. +- `endpoint` (String) The endpoint name. This attribute may not be used at the same time as the offer_url. +- `name` (String) The name of the application. This attribute may not be used at the same time as the offer_url. +- `offer_url` (String) The URL of a remote application. This attribute may not be used at the same time as name and endpoint. ### Notes diff --git a/docs/resources/offer.md b/docs/resources/offer.md index a145fefd..02c94610 100644 --- a/docs/resources/offer.md +++ b/docs/resources/offer.md @@ -13,23 +13,22 @@ A resource that represent a Juju Offer. ## Example Usage ```terraform -resource "juju_offer" "this" { +resource "juju_offer" "myoffer" { model = juju_model.development.name application_name = juju_application.percona-cluster.name endpoint = server } -// an offer can then be used in an integration as below: -resource "juju_integration" "this" { +// an offer can then be used in an cross model integration as below: +resource "juju_integration" "myintegration" { model = juju_model.development-destination.name application { name = juju_application.wordpress.name endpoint = "db" } - application { - offer_url = juju_offer.this.url + offer_url = juju_offer.myoffer.url } } ``` diff --git a/examples/resources/juju_offer/resource.tf b/examples/resources/juju_offer/resource.tf index 84e714a5..a7be5728 100644 --- a/examples/resources/juju_offer/resource.tf +++ b/examples/resources/juju_offer/resource.tf @@ -1,19 +1,18 @@ -resource "juju_offer" "this" { +resource "juju_offer" "myoffer" { model = juju_model.development.name application_name = juju_application.percona-cluster.name endpoint = server } -// an offer can then be used in an integration as below: -resource "juju_integration" "this" { +// an offer can then be used in an cross model integration as below: +resource "juju_integration" "myintegration" { model = juju_model.development-destination.name application { name = juju_application.wordpress.name endpoint = "db" } - application { - offer_url = juju_offer.this.url + offer_url = juju_offer.myoffer.url } } diff --git a/internal/provider/resource_integration.go b/internal/provider/resource_integration.go index 99e23881..70587a23 100644 --- a/internal/provider/resource_integration.go +++ b/internal/provider/resource_integration.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -138,20 +139,39 @@ func (r *integrationResource) Schema(_ context.Context, _ resource.SchemaRequest NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ "name": schema.StringAttribute{ - Description: "The name of the application.", - Optional: true, + Description: "The name of the application. This attribute may not be used at the" + + " same time as the offer_url.", + Optional: true, + Validators: []validator.String{ + stringvalidator.ConflictsWith(path.Expressions{ + path.MatchRelative().AtParent().AtName("offer_url"), + }...), + }, }, "endpoint": schema.StringAttribute{ - Description: "The endpoint name.", - Optional: true, - Computed: true, + Description: "The endpoint name. This attribute may not be used at the" + + " same time as the offer_url.", + Optional: true, + Computed: true, + Validators: []validator.String{ + stringvalidator.ConflictsWith(path.Expressions{ + path.MatchRelative().AtParent().AtName("offer_url"), + }...), + }, }, "offer_url": schema.StringAttribute{ - Description: "The URL of a remote application.", - Optional: true, + Description: "The URL of a remote application. This attribute may not be used at the" + + " same time as name and endpoint.", + Optional: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), }, + Validators: []validator.String{ + stringvalidator.ConflictsWith(path.Expressions{ + path.MatchRelative().AtParent().AtName("name"), + path.MatchRelative().AtParent().AtName("endpoint"), + }...), + }, }, }, },