Skip to content

Commit

Permalink
GATE-1848: Adds support for teams rule api
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Borkenstein committed Sep 2, 2021
1 parent d633db0 commit acd87ee
Show file tree
Hide file tree
Showing 5 changed files with 498 additions and 16 deletions.
3 changes: 2 additions & 1 deletion cloudflare/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ func Provider() terraform.ResourceProvider {
"cloudflare_static_route": resourceCloudflareStaticRoute(),
"cloudflare_teams_list": resourceCloudflareTeamsList(),
"cloudflare_teams_location": resourceCloudflareTeamsLocation(),
"cloudflare_teams_account": resourceCloudflareTeamsAccountConfiguration(),
"cloudflare_teams_account": resourceCloudflareTeamsAccount(),
"cloudflare_teams_rule": resourceCloudflareTeamsRule(),
"cloudflare_waf_group": resourceCloudflareWAFGroup(),
"cloudflare_waf_package": resourceCloudflareWAFPackage(),
"cloudflare_waf_rule": resourceCloudflareWAFRule(),
Expand Down
18 changes: 9 additions & 9 deletions cloudflare/resource_cloudflare_teams_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"github.com/pkg/errors"
)

func resourceCloudflareTeamsAccountConfiguration() *schema.Resource {
func resourceCloudflareTeamsAccount() *schema.Resource {
return &schema.Resource{
Read: resourceCloudflareTeamsAccountConfigurationRead,
Update: resourceCloudflareTeamsAccountConfigurationUpdate,
Create: resourceCloudflareTeamsAccountConfigurationUpdate,
Read: resourceCloudflareTeamsAccountRead,
Update: resourceCloudflareTeamsAccountUpdate,
Create: resourceCloudflareTeamsAccountUpdate,
// This resource is a top-level account configuration and cant be "deleted"
Delete: func(_ *schema.ResourceData, _ interface{}) error { return nil },
Importer: &schema.ResourceImporter{
Expand Down Expand Up @@ -97,14 +97,14 @@ var antivirusSchema = map[string]*schema.Schema{
},
}

func resourceCloudflareTeamsAccountConfigurationRead(d *schema.ResourceData, meta interface{}) error {
func resourceCloudflareTeamsAccountRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
accountID := d.Get("account_id").(string)

configuration, err := client.TeamsAccountConfiguration(context.Background(), accountID)
if err != nil {
if strings.Contains(err.Error(), "HTTP status 400") {
log.Printf("[INFO] Teams Account config %s doesnt exists", d.Id())
log.Printf("[INFO] Teams Account config %s does not exists", d.Id())
d.SetId("")
return nil
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func resourceCloudflareTeamsAccountConfigurationRead(d *schema.ResourceData, met
return nil
}

func resourceCloudflareTeamsAccountConfigurationUpdate(d *schema.ResourceData, meta interface{}) error {
func resourceCloudflareTeamsAccountUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
accountID := d.Get("account_id").(string)
blockPageConfig := inflateBlockPageConfig(d.Get("block_page"))
Expand Down Expand Up @@ -165,7 +165,7 @@ func resourceCloudflareTeamsAccountConfigurationUpdate(d *schema.ResourceData, m
}

d.SetId(accountID)
return resourceCloudflareTeamsAccountConfigurationRead(d, meta)
return resourceCloudflareTeamsAccountRead(d, meta)
}

func resourceCloudflareTeamsAccountImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
Expand All @@ -179,7 +179,7 @@ func resourceCloudflareTeamsAccountImport(d *schema.ResourceData, meta interface
log.Printf("[DEBUG] Importing Cloudflare Teams Account configuration for account %s", accountID)

d.Set("account_id", accountID)
err := resourceCloudflareTeamsAccountConfigurationRead(d, meta)
err := resourceCloudflareTeamsAccountRead(d, meta)
return []*schema.ResourceData{d}, err
}

Expand Down
10 changes: 4 additions & 6 deletions cloudflare/resource_cloudflare_teams_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,33 @@ func TestAccCloudflareTeamsAccountConfigurationBasic(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCloudflareTeamsAccountConfigBasic(rnd, accountID),
Config: testAccCloudflareTeamsAccountBasic(rnd, accountID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "account_id", accountID),
resource.TestCheckResourceAttr(name, "tls_decrypt_enabled", "true"),
resource.TestCheckResourceAttr(name, "activity_log_enabled", "true"),
resource.TestCheckResourceAttr(name, "block_page.0.name", rnd),
resource.TestCheckResourceAttr(name, "block_page.0.enabled", "true"),
resource.TestCheckResourceAttr(name, "block_page.0.footer_text", "hello"),
resource.TestCheckResourceAttr(name, "block_page.0.header_text", "hello"),
resource.TestCheckResourceAttr(name, "block_page.0.background_color", "#000000"),
resource.TestCheckResourceAttr(name, "block_page.0.logo_path", "https://google.com"),
resource.TestCheckResourceAttr(name, "block_page.0.logo_path", "https://example.com"),
),
},
},
})
}

func testAccCloudflareTeamsAccountConfigBasic(rnd, accountID string) string {
func testAccCloudflareTeamsAccountBasic(rnd, accountID string) string {
return fmt.Sprintf(`
resource "cloudflare_teams_account" "%[1]s" {
account_id = "%[2]s"
tls_decrypt_enabled = true
activity_log_enabled = true
block_page {
name="%[1]s"
enabled=true
footer_text="hello"
header_text="hello"
logo_path="https://google.com"
logo_path="https://example.com"
background_color="#000000"
}
antivirus {
Expand Down
Loading

0 comments on commit acd87ee

Please sign in to comment.