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

Issue 1769 add aws shield protection feature ( Part II ) #7721

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2b9f301
add the provider for shield protection
parabolic Feb 22, 2019
a7a08ce
add the aws_shield_protection resource
parabolic Feb 25, 2019
e203a83
add the testing for the shield protection
parabolic Feb 25, 2019
6d33837
add the shield resource nav bar
parabolic Feb 25, 2019
44b9a07
add the documentation file
parabolic Feb 25, 2019
024a01e
Merge remote-tracking branch 'upstream/master' into Issue_1769_AWS_Sh…
parabolic Feb 25, 2019
453e80f
add a missing return
parabolic Feb 25, 2019
1692897
add spaces between functions for consistency.
parabolic Feb 26, 2019
8a63828
Merge remote-tracking branch 'upstream/master' into Issue_1769_AWS_Sh…
parabolic Feb 28, 2019
da53142
add the provider for shield protection
parabolic Feb 22, 2019
8fa945b
add the aws_shield_protection resource
parabolic Feb 25, 2019
d7b8cbe
add the testing for the shield protection
parabolic Feb 25, 2019
7e58ec5
add the shield resource nav bar
parabolic Feb 25, 2019
cde6586
add the documentation file
parabolic Feb 25, 2019
8fcb758
add a missing return
parabolic Feb 25, 2019
e4ca542
add spaces between functions for consistency.
parabolic Feb 26, 2019
521a9b8
provider: Hardcode Global Accelerator SDK Region to us-west-2 and Shi…
bflad May 14, 2019
b553421
tests/resource/aws_shield_protection: Syntax and style adjustments
bflad May 14, 2019
0c7a09f
Merge branch 'Issue_1769_AWS_Shield_Protection_feature' of github.com…
parabolic May 15, 2019
6ee7bad
Update the provider with the suggestions:
parabolic May 15, 2019
c78d5fd
Update website/docs/r/shield_protection.html.markdown
parabolic May 15, 2019
70cb118
Update website/docs/r/shield_protection.html.markdown
parabolic May 15, 2019
e34cee9
Update website/docs/r/shield_protection.html.markdown
parabolic May 15, 2019
6a53956
Update the documentation from the proposals:
parabolic May 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (c *Config) Client() (interface{}, error) {
fsxconn: fsx.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["fsx"])})),
gameliftconn: gamelift.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["gamelift"])})),
glacierconn: glacier.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["glacier"])})),
globalacceleratorconn: globalaccelerator.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["globalaccelerator"])})),
globalacceleratorconn: globalaccelerator.New(sess.Copy(&aws.Config{Region: aws.String("us-west-2"), Endpoint: aws.String(c.Endpoints["globalaccelerator"])})),
glueconn: glue.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["glue"])})),
guarddutyconn: guardduty.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["guardduty"])})),
iamconn: iam.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["iam"])})),
Expand Down Expand Up @@ -439,7 +439,7 @@ func (c *Config) Client() (interface{}, error) {
serverlessapplicationrepositoryconn: serverlessapplicationrepository.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["serverlessrepo"])})),
sesConn: ses.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["ses"])})),
sfnconn: sfn.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["stepfunctions"])})),
shieldconn: shield.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["shield"])})),
shieldconn: shield.New(sess.Copy(&aws.Config{Region: aws.String("us-east-1"), Endpoint: aws.String(c.Endpoints["shield"])})),
simpledbconn: simpledb.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["sdb"])})),
snsconn: sns.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["sns"])})),
sqsconn: sqs.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints["sqs"])})),
Expand Down
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ func Provider() terraform.ResourceProvider {
"aws_service_discovery_private_dns_namespace": resourceAwsServiceDiscoveryPrivateDnsNamespace(),
"aws_service_discovery_public_dns_namespace": resourceAwsServiceDiscoveryPublicDnsNamespace(),
"aws_service_discovery_service": resourceAwsServiceDiscoveryService(),
"aws_shield_protection": resourceAwsShieldProtection(),
"aws_simpledb_domain": resourceAwsSimpleDBDomain(),
"aws_ssm_activation": resourceAwsSsmActivation(),
"aws_ssm_association": resourceAwsSsmAssociation(),
Expand Down
85 changes: 85 additions & 0 deletions aws/resource_aws_shield_protection.go
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
}
Loading