Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AUTH-4232 add saas app remove bookmark specific app resource #1647

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions internal/provider/resource_cloudflare_access_application.go
Expand Up @@ -60,6 +60,14 @@ func resourceCloudflareAccessApplicationCreate(ctx context.Context, d *schema.Re
newAccessApplication.CorsHeaders = CORSConfig
}

if _, ok := d.GetOk("saas_app"); ok {
SaasConfig, err := convertSaasSchemaToStruct(d)
if err != nil {
return diag.FromErr(err)
}
newAccessApplication.SaasApplication = SaasConfig
}

tflog.Debug(ctx, fmt.Sprintf("Creating Cloudflare Access Application from struct: %+v", newAccessApplication))

identifier, err := initIdentifier(d)
Expand Down
Expand Up @@ -674,6 +674,89 @@ func TestAccCloudflareAccessApplicationMisconfiguredCORSCredentialsAllowingAllOr
})
}

func testAccessApplicationSaasApp(resourceID, zone, zoneID string) string {
return fmt.Sprintf(`
resource "cloudflare_access_application" "%[1]s" {
name = "%[1]s-updated"
zone_id = "%[3]s"
domain = "%[1]s.%[2]s"
type = "saas"

saas_app {
consumer_service_url = "https://dashtest.cloudflare.com/api/v4/saml/acs"
sp_entity_id = "dash.cloudflare.com"
name_id_format = "id"
custom_attributes {

}
}
}
`, resourceID, zone, zoneID)
}

func TestAccCloudflareAccessApplicationWithSaasApp(t *testing.T) {
rnd := generateRandomResourceName()
name := "cloudflare_access_application." + rnd
zone := os.Getenv("CLOUDFLARE_DOMAIN")
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
updatedName := fmt.Sprintf("%s-updated", rnd)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccessAccPreCheck(t)
testAccPreCheckAccount(t)
},
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccessApplicationSaasApp(rnd, zone, zoneID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "saas_app.consumer_service_url", "https://dashtest.cloudflare.com/api/v4/saml/acs"),
resource.TestCheckResourceAttr(name, "saas_app.sp_entity_id", "dash.cloudflare.com"),
resource.TestCheckResourceAttr(name, "saas_app.name_id_format", "id"),
),
},
{
Config: testAccessApplicationSaasApp(rnd, zone, zoneID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "name", updatedName),
resource.TestCheckResourceAttr(name, "zone_id", zoneID),
),
},
},
})
}

func TestAccCloudflareAccessApplicationBookmark(t *testing.T) {
rnd := generateRandomResourceName()
name := "cloudflare_access_application." + rnd
zone := os.Getenv("CLOUDFLARE_DOMAIN")
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
updatedName := fmt.Sprintf("%s-updated", rnd)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccessAccPreCheck(t)
testAccPreCheckAccount(t)
},
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccessApplicationBookmark(rnd, zone, zoneID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "type", "bookmark"),
),
},
{
Config: testAccessApplicationBookmark(rnd, zone, zoneID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "name", updatedName),
resource.TestCheckResourceAttr(name, "zone_id", zoneID),
),
},
},
})
}
func TestAccCloudflareAccessApplicationMisconfiguredCORSCredentialsAllowingWildcardOrigins(t *testing.T) {
rnd := generateRandomResourceName()
zone := os.Getenv("CLOUDFLARE_DOMAIN")
Expand All @@ -694,6 +777,18 @@ func TestAccCloudflareAccessApplicationMisconfiguredCORSCredentialsAllowingWildc
})
}

func testAccessApplicationBookmark(resourceID, zone, zoneID string) string {
return fmt.Sprintf(`
resource "cloudflare_access_application" "%[1]s" {
name = "%[1]s-updated"
zone_id = "%[3]s"
domain = "%[1]s.%[2]s"
type = "bookmark"

}
`, resourceID, zone, zoneID)
}

func testAccessApplicationWithZoneID(resourceID, zone, zoneID string) string {
return fmt.Sprintf(`
resource "cloudflare_access_application" "%[1]s" {
Expand Down
175 changes: 0 additions & 175 deletions internal/provider/resource_cloudflare_access_bookmark.go

This file was deleted.