diff --git a/port/integration/resource_test.go b/port/integration/resource_test.go index f564cc9a..6caddb1a 100644 --- a/port/integration/resource_test.go +++ b/port/integration/resource_test.go @@ -11,10 +11,10 @@ import ( "github.com/port-labs/terraform-provider-port-labs/v2/internal/utils" ) -func createBlueprint(identifier string) string { +func createIntegration(identifier string) string { return fmt.Sprintf(` -resource "port_blueprint" "microservice" { +resource "port_integration" "microservice" { identifier = "%s" title = "TF Provider Test" icon = "Terraform" @@ -23,10 +23,10 @@ resource "port_blueprint" "microservice" { `, identifier) } -func createBlueprintWithProperties(identifier string) string { +func createIntegrationWithProperties(identifier string) string { return fmt.Sprintf(` -resource "port_blueprint" "microservice" { +resource "port_integration" "microservice" { identifier = "%s" title = "TF Provider Test" icon = "Terraform" @@ -55,18 +55,18 @@ resource "port_blueprint" "microservice" { `, identifier) } -func TestAccPortBlueprintPermissionsBasic(t *testing.T) { - blueprintIdentifier := utils.GenID() +func TestAccPortIntegrationPermissionsBasic(t *testing.T) { + integrationIdentifier := utils.GenID() err := os.Setenv("PORT_BETA_FEATURES_ENABLED", "true") if err != nil { t.Fatal(err) } - var testAccPortBlueprintResourceBasic = createBlueprint(blueprintIdentifier) + var testAccPortIntegrationResourceBasic = createIntegration(integrationIdentifier) - var testAccBaseBlueprintPermissionsConfigUpdate = ` + var testAccBaseIntegrationPermissionsConfigUpdate = ` - resource "port_blueprint_permissions" "microservice_permissions" { - blueprint_identifier = port_blueprint.microservice.identifier + resource "port_integration_permissions" "microservice_permissions" { + integration_identifier = port_integration.microservice.identifier entities = { "register" = { "roles": [ @@ -127,45 +127,45 @@ func TestAccPortBlueprintPermissionsBasic(t *testing.T) { ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccPortBlueprintResourceBasic, + Config: testAccPortIntegrationResourceBasic, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_blueprint.microservice", "identifier", blueprintIdentifier), - resource.TestCheckResourceAttr("port_blueprint.microservice", "title", "TF Provider Test"), - resource.TestCheckResourceAttr("port_blueprint.microservice", "icon", "Terraform"), + resource.TestCheckResourceAttr("port_integration.microservice", "identifier", integrationIdentifier), + resource.TestCheckResourceAttr("port_integration.microservice", "title", "TF Provider Test"), + resource.TestCheckResourceAttr("port_integration.microservice", "icon", "Terraform"), ), }, { - Config: testAccPortBlueprintResourceBasic + testAccBaseBlueprintPermissionsConfigUpdate, + Config: testAccPortIntegrationResourceBasic + testAccBaseIntegrationPermissionsConfigUpdate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_blueprint.microservice", "identifier", blueprintIdentifier), - resource.TestCheckResourceAttr("port_blueprint.microservice", "title", "TF Provider Test"), - resource.TestCheckResourceAttr("port_blueprint.microservice", "icon", "Terraform"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "blueprint_identifier", blueprintIdentifier), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "id", blueprintIdentifier), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.roles.#", "1"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.roles.0", "Member"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.users.#", "0"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.teams.#", "0"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.update_metadata_properties.icon.roles.#", "1"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.update_metadata_properties.icon.roles.0", "Member"), + resource.TestCheckResourceAttr("port_integration.microservice", "identifier", integrationIdentifier), + resource.TestCheckResourceAttr("port_integration.microservice", "title", "TF Provider Test"), + resource.TestCheckResourceAttr("port_integration.microservice", "icon", "Terraform"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "integration_identifier", integrationIdentifier), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "id", integrationIdentifier), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.roles.#", "1"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.roles.0", "Member"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.users.#", "0"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.teams.#", "0"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.update_metadata_properties.icon.roles.#", "1"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.update_metadata_properties.icon.roles.0", "Member"), ), }, }, }) } -func TestAccPortBlueprintPermissionsWithProperties(t *testing.T) { - blueprintIdentifier := utils.GenID() +func TestAccPortIntegrationPermissionsWithProperties(t *testing.T) { + integrationIdentifier := utils.GenID() err := os.Setenv("PORT_BETA_FEATURES_ENABLED", "true") if err != nil { t.Fatal(err) } - var testAccPortBlueprintResourceBasic = createBlueprintWithProperties(blueprintIdentifier) + var testAccPortIntegrationResourceBasic = createIntegrationWithProperties(integrationIdentifier) - var testAccBaseBlueprintPermissionsConfigUpdate = ` + var testAccBaseIntegrationPermissionsConfigUpdate = ` - resource "port_blueprint_permissions" "microservice_permissions" { - blueprint_identifier = port_blueprint.microservice.identifier + resource "port_integration_permissions" "microservice_permissions" { + integration_identifier = port_integration.microservice.identifier entities = { "register" = { "roles": [ @@ -233,41 +233,41 @@ func TestAccPortBlueprintPermissionsWithProperties(t *testing.T) { ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccPortBlueprintResourceBasic, + Config: testAccPortIntegrationResourceBasic, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_blueprint.microservice", "identifier", blueprintIdentifier), - resource.TestCheckResourceAttr("port_blueprint.microservice", "title", "TF Provider Test"), - resource.TestCheckResourceAttr("port_blueprint.microservice", "icon", "Terraform"), + resource.TestCheckResourceAttr("port_integration.microservice", "identifier", integrationIdentifier), + resource.TestCheckResourceAttr("port_integration.microservice", "title", "TF Provider Test"), + resource.TestCheckResourceAttr("port_integration.microservice", "icon", "Terraform"), ), }, { - Config: testAccPortBlueprintResourceBasic + testAccBaseBlueprintPermissionsConfigUpdate, + Config: testAccPortIntegrationResourceBasic + testAccBaseIntegrationPermissionsConfigUpdate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_blueprint.microservice", "identifier", blueprintIdentifier), - resource.TestCheckResourceAttr("port_blueprint.microservice", "title", "TF Provider Test"), - resource.TestCheckResourceAttr("port_blueprint.microservice", "icon", "Terraform"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "blueprint_identifier", blueprintIdentifier), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "id", blueprintIdentifier), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.roles.#", "1"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.roles.0", "Member"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.users.#", "0"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.teams.#", "0"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.update_properties.myStringIdentifier.roles.#", "1"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.update_properties.myStringIdentifier.roles.0", "Member"), + resource.TestCheckResourceAttr("port_integration.microservice", "identifier", integrationIdentifier), + resource.TestCheckResourceAttr("port_integration.microservice", "title", "TF Provider Test"), + resource.TestCheckResourceAttr("port_integration.microservice", "icon", "Terraform"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "integration_identifier", integrationIdentifier), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "id", integrationIdentifier), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.roles.#", "1"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.roles.0", "Member"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.users.#", "0"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.teams.#", "0"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.update_properties.myStringIdentifier.roles.#", "1"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.update_properties.myStringIdentifier.roles.0", "Member"), )}, }, }) } -func TestAccPortBlueprintPermissionsWithRelations(t *testing.T) { - blueprintMicroserviceIdentifier := utils.GenID() - blueprintEnvIdentifier := utils.GenID() +func TestAccPortIntegrationPermissionsWithRelations(t *testing.T) { + integrationMicroserviceIdentifier := utils.GenID() + integrationEnvIdentifier := utils.GenID() err := os.Setenv("PORT_BETA_FEATURES_ENABLED", "true") if err != nil { t.Fatal(err) } - var testAccPortBlueprintResourceBasic = fmt.Sprintf(` -resource "port_blueprint" "environment" { + var testAccPortIntegrationResourceBasic = fmt.Sprintf(` +resource "port_integration" "environment" { title = "Environment" icon = "Environment" identifier = "%s" @@ -286,7 +286,7 @@ resource "port_blueprint" "environment" { } -resource "port_blueprint" "microservice" { +resource "port_integration" "microservice" { identifier = "%s" title = "TF Provider Test" icon = "Terraform" @@ -295,14 +295,14 @@ resource "port_blueprint" "microservice" { "environment" = { title = "Test Relation" required = "true" - target = port_blueprint.environment.identifier + target = port_integration.environment.identifier } } } -`, blueprintEnvIdentifier, blueprintMicroserviceIdentifier) +`, integrationEnvIdentifier, integrationMicroserviceIdentifier) teamName := utils.GenID() - var testAccBaseBlueprintPermissionsConfigUpdate = fmt.Sprintf(` + var testAccBaseIntegrationPermissionsConfigUpdate = fmt.Sprintf(` resource "port_team" "team" { name = "%s" @@ -310,8 +310,8 @@ resource "port_blueprint" "microservice" { users = [] } - resource "port_blueprint_permissions" "microservice_permissions" { - blueprint_identifier = port_blueprint.microservice.identifier + resource "port_integration_permissions" "microservice_permissions" { + integration_identifier = port_integration.microservice.identifier entities = { "register" = { "roles": [ @@ -381,45 +381,45 @@ resource "port_blueprint" "microservice" { ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccPortBlueprintResourceBasic, + Config: testAccPortIntegrationResourceBasic, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_blueprint.environment", "identifier", blueprintEnvIdentifier), - resource.TestCheckResourceAttr("port_blueprint.microservice", "identifier", blueprintMicroserviceIdentifier), - resource.TestCheckResourceAttr("port_blueprint.microservice", "title", "TF Provider Test"), - resource.TestCheckResourceAttr("port_blueprint.microservice", "icon", "Terraform"), + resource.TestCheckResourceAttr("port_integration.environment", "identifier", integrationEnvIdentifier), + resource.TestCheckResourceAttr("port_integration.microservice", "identifier", integrationMicroserviceIdentifier), + resource.TestCheckResourceAttr("port_integration.microservice", "title", "TF Provider Test"), + resource.TestCheckResourceAttr("port_integration.microservice", "icon", "Terraform"), ), }, { - Config: testAccPortBlueprintResourceBasic + testAccBaseBlueprintPermissionsConfigUpdate, + Config: testAccPortIntegrationResourceBasic + testAccBaseIntegrationPermissionsConfigUpdate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port_blueprint.microservice", "identifier", blueprintMicroserviceIdentifier), - resource.TestCheckResourceAttr("port_blueprint.environment", "identifier", blueprintEnvIdentifier), - resource.TestCheckResourceAttr("port_blueprint.microservice", "title", "TF Provider Test"), - resource.TestCheckResourceAttr("port_blueprint.microservice", "icon", "Terraform"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "blueprint_identifier", blueprintMicroserviceIdentifier), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "id", blueprintMicroserviceIdentifier), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.roles.#", "1"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.roles.0", "Member"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.teams.#", "1"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.teams.0", teamName), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.register.users.#", "0"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.update_relations.environment.roles.#", "1"), - resource.TestCheckResourceAttr("port_blueprint_permissions.microservice_permissions", "entities.update_relations.environment.roles.0", "Member"), + resource.TestCheckResourceAttr("port_integration.microservice", "identifier", integrationMicroserviceIdentifier), + resource.TestCheckResourceAttr("port_integration.environment", "identifier", integrationEnvIdentifier), + resource.TestCheckResourceAttr("port_integration.microservice", "title", "TF Provider Test"), + resource.TestCheckResourceAttr("port_integration.microservice", "icon", "Terraform"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "integration_identifier", integrationMicroserviceIdentifier), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "id", integrationMicroserviceIdentifier), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.roles.#", "1"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.roles.0", "Member"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.teams.#", "1"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.teams.0", teamName), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.register.users.#", "0"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.update_relations.environment.roles.#", "1"), + resource.TestCheckResourceAttr("port_integration_permissions.microservice_permissions", "entities.update_relations.environment.roles.0", "Member"), )}, }, }) } -func TestAccPortBlueprintPermissionsWithInvalidProperties(t *testing.T) { - blueprintIdentifier := utils.GenID() +func TestAccPortIntegrationPermissionsWithInvalidProperties(t *testing.T) { + integrationIdentifier := utils.GenID() err := os.Setenv("PORT_BETA_FEATURES_ENABLED", "true") if err != nil { t.Fatal(err) } - var testAccPortBlueprintResourceBasic = createBlueprintWithProperties(blueprintIdentifier) + var testAccPortIntegrationResourceBasic = createIntegrationWithProperties(integrationIdentifier) teamName := utils.GenID() - var testAccBaseBlueprintPermissionsConfigUpdate = fmt.Sprintf(` + var testAccBaseIntegrationPermissionsConfigUpdate = fmt.Sprintf(` resource "port_team" "team" { name = "%s" @@ -427,8 +427,8 @@ func TestAccPortBlueprintPermissionsWithInvalidProperties(t *testing.T) { users = [] } - resource "port_blueprint_permissions" "microservice_permissions" { - blueprint_identifier = port_blueprint.microservice.identifier + resource "port_integration_permissions" "microservice_permissions" { + integration_identifier = port_integration.microservice.identifier entities = { "register" = { "roles": [ @@ -496,7 +496,7 @@ func TestAccPortBlueprintPermissionsWithInvalidProperties(t *testing.T) { ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccPortBlueprintResourceBasic + testAccBaseBlueprintPermissionsConfigUpdate, + Config: testAccPortIntegrationResourceBasic + testAccBaseIntegrationPermissionsConfigUpdate, ExpectError: regexp.MustCompile("Invalid Attribute Value Match"), }, }, diff --git a/port/integration/schema.go b/port/integration/schema.go index ef38ecc6..bff6096c 100644 --- a/port/integration/schema.go +++ b/port/integration/schema.go @@ -4,32 +4,14 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" ) func IntegrationSchema() map[string]schema.Attribute { - var entityMapping = map[string]schema.Attribute{ - "blueprint": schema.StringAttribute{ - Required: true, - }, - "identifier": schema.StringAttribute{ - Required: true, - }, - "title": schema.StringAttribute{ - Required: true, - }, - "properties": schema.MapAttribute{ - ElementType: types.StringType, - }, - "relations": schema.MapAttribute{ - ElementType: types.StringType, - }, - } return map[string]schema.Attribute{ "id": schema.StringAttribute{ Computed: true, @@ -46,6 +28,25 @@ func IntegrationSchema() map[string]schema.Attribute { MarkdownDescription: "Integration Config Raw JSON string (use jsonenconde)", Optional: true, }, + "webhook_changelog_destination": schema.SingleNestedAttribute{ + MarkdownDescription: "The webhook changelog destination of the blueprint", + Optional: true, + Attributes: map[string]schema.Attribute{ + "url": schema.StringAttribute{ + MarkdownDescription: "The url of the webhook changelog destination", + Required: true, + }, + "agent": schema.BoolAttribute{ + MarkdownDescription: "The agent of the webhook changelog destination", + Optional: true, + }, + }, + }, + "kafka_changelog_destination": schema.ObjectAttribute{ + MarkdownDescription: "The changelog destination of the blueprint", + Optional: true, + AttributeTypes: map[string]attr.Type{}, + }, } }