Skip to content

Commit

Permalink
Merge pull request #2843 from jroyal/jroyal/auth-5562
Browse files Browse the repository at this point in the history
Fix import of cloudflare_access_application not reading saas_app config
  • Loading branch information
jacobbednarz authored Oct 17, 2023
2 parents 5088d09 + 247ea6f commit a93baf6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/2843.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_access_application: fix import of cloudflare_access_application not reading saas_app config
```
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,54 @@ func TestAccCloudflareAccessApplication_WithSaas(t *testing.T) {
})
}

func TestAccCloudflareAccessApplication_WithSaas_Import(t *testing.T) {
t.Parallel()
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
rnd := generateRandomResourceName()
name := "cloudflare_access_application." + rnd

checkFn := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, consts.AccountIDSchemaKey, accountID),
resource.TestCheckResourceAttr(name, "name", rnd),
resource.TestCheckResourceAttr(name, "type", "saas"),
resource.TestCheckResourceAttr(name, "session_duration", "24h"),
resource.TestCheckResourceAttr(name, "saas_app.#", "1"),
resource.TestCheckResourceAttr(name, "saas_app.0.sp_entity_id", "saas-app.example"),
resource.TestCheckResourceAttr(name, "saas_app.0.consumer_service_url", "https://saas-app.example/sso/saml/consume"),
resource.TestCheckResourceAttr(name, "saas_app.0.name_id_format", "email"),

resource.TestCheckResourceAttr(name, "saas_app.0.custom_attribute.#", "2"),
resource.TestCheckResourceAttr(name, "saas_app.0.custom_attribute.0.name", "email"),
resource.TestCheckResourceAttr(name, "saas_app.0.custom_attribute.0.name_format", "urn:oasis:names:tc:SAML:2.0:attrname-format:basic"),
resource.TestCheckResourceAttr(name, "saas_app.0.custom_attribute.0.source.0.name", "user_email"),
resource.TestCheckResourceAttr(name, "saas_app.0.custom_attribute.1.name", "rank"),
resource.TestCheckResourceAttr(name, "saas_app.0.custom_attribute.1.source.0.name", "rank"),
resource.TestCheckResourceAttr(name, "saas_app.0.custom_attribute.1.friendly_name", "Rank"),
resource.TestCheckResourceAttr(name, "saas_app.0.custom_attribute.1.required", "true"),
)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckAccount(t)
},
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccCloudflareAccessApplicationConfigWithSaas(rnd, accountID),
Check: checkFn,
},
{
ImportState: true,
ImportStateVerify: true,
ResourceName: name,
ImportStateIdPrefix: fmt.Sprintf("%s/", accountID),
Check: checkFn,
},
},
})
}

func TestAccCloudflareAccessApplication_WithAutoRedirectToIdentity(t *testing.T) {
rnd := generateRandomResourceName()
name := fmt.Sprintf("cloudflare_access_application.%s", rnd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,9 @@ func convertSAMLAttributeStructToSchema(attr cloudflare.SAMLAttributeConfig) map
}

func convertSaasStructToSchema(d *schema.ResourceData, app *cloudflare.SaasApplication) []interface{} {
if _, ok := d.GetOk("saas_app"); !ok {
if app == nil {
return []interface{}{}
}

m := map[string]interface{}{
"sp_entity_id": app.SPEntityID,
"consumer_service_url": app.ConsumerServiceUrl,
Expand Down

0 comments on commit a93baf6

Please sign in to comment.