-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7721 from parabolic/Issue_1769_AWS_Shield_Protect…
…ion_feature Issue 1769 add aws shield protection feature ( Part II )
- Loading branch information
Showing
6 changed files
with
689 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/shield" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceAwsShieldProtection() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAwsShieldProtectionCreate, | ||
Read: resourceAwsShieldProtectionRead, | ||
Delete: resourceAwsShieldProtectionDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"resource_arn": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validateArn, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsShieldProtectionCreate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).shieldconn | ||
|
||
input := &shield.CreateProtectionInput{ | ||
Name: aws.String(d.Get("name").(string)), | ||
ResourceArn: aws.String(d.Get("resource_arn").(string)), | ||
} | ||
|
||
resp, err := conn.CreateProtection(input) | ||
if err != nil { | ||
return fmt.Errorf("error creating Shield Protection: %s", err) | ||
} | ||
d.SetId(*resp.ProtectionId) | ||
return resourceAwsShieldProtectionRead(d, meta) | ||
} | ||
|
||
func resourceAwsShieldProtectionRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).shieldconn | ||
|
||
input := &shield.DescribeProtectionInput{ | ||
ProtectionId: aws.String(d.Id()), | ||
} | ||
|
||
resp, err := conn.DescribeProtection(input) | ||
if err != nil { | ||
return fmt.Errorf("error reading Shield Protection (%s): %s", d.Id(), err) | ||
} | ||
d.Set("name", resp.Protection.Name) | ||
d.Set("resource_arn", resp.Protection.ResourceArn) | ||
return nil | ||
} | ||
|
||
func resourceAwsShieldProtectionDelete(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).shieldconn | ||
|
||
input := &shield.DeleteProtectionInput{ | ||
ProtectionId: aws.String(d.Id()), | ||
} | ||
|
||
_, err := conn.DeleteProtection(input) | ||
|
||
if isAWSErr(err, shield.ErrCodeResourceNotFoundException, "") { | ||
return nil | ||
} | ||
|
||
if err != nil { | ||
return fmt.Errorf("error deleting Shield Protection (%s): %s", d.Id(), err) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.