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

Allow use of resource_type and resource_type_list #17418

Merged
merged 3 commits into from
Feb 12, 2021
Merged

Conversation

bill-rich
Copy link
Contributor

AWS::CloudFront::Distribution is only allowed in resource_type. Originally fms_policy put all resource types into resource_type_list. This PR allows the use of both.

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Output from acceptance testing:

==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSFmsPolicy_ -timeout 120m
=== RUN   TestAccAWSFmsPolicy_basic
=== PAUSE TestAccAWSFmsPolicy_basic
=== RUN   TestAccAWSFmsPolicy_cloudfrontDistribution
=== PAUSE TestAccAWSFmsPolicy_cloudfrontDistribution
=== RUN   TestAccAWSFmsPolicy_includeMap
=== PAUSE TestAccAWSFmsPolicy_includeMap
=== RUN   TestAccAWSFmsPolicy_update
=== PAUSE TestAccAWSFmsPolicy_update
=== RUN   TestAccAWSFmsPolicy_tags
=== PAUSE TestAccAWSFmsPolicy_tags
=== CONT  TestAccAWSFmsPolicy_basic
=== CONT  TestAccAWSFmsPolicy_update
=== CONT  TestAccAWSFmsPolicy_tags
=== CONT  TestAccAWSFmsPolicy_includeMap
=== CONT  TestAccAWSFmsPolicy_cloudfrontDistribution
--- PASS: TestAccAWSFmsPolicy_basic (31.81s)
--- PASS: TestAccAWSFmsPolicy_includeMap (33.09s)
--- PASS: TestAccAWSFmsPolicy_tags (34.23s)
--- PASS: TestAccAWSFmsPolicy_update (51.61s)
--- PASS: TestAccAWSFmsPolicy_cloudfrontDistribution (106.17s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	106.214s

@bill-rich bill-rich requested a review from a team as a code owner February 3, 2021 00:17
@ghost ghost added size/M Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. service/fms Issues and PRs that pertain to the fms service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Feb 3, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Feb 3, 2021
@bill-rich bill-rich removed the needs-triage Waiting for first response or review from a maintainer. label Feb 4, 2021
return err
}
if aws.StringValue(resp.Policy.ResourceType) != "ResourceTypeList" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid logic like this, we can mark the resource_type attribute as Computed as it is generally preferable to always set the value to simplify resource logic. 👍

if v, ok := d.GetOk("exclude_map"); ok {
fmsPolicy.ExcludeMap = expandFMSPolicyMap(v.([]interface{}))
}
fmsPolicy := resourceAwsFmsPolicyExpandPolicy(d)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is breaking creation because the resource ID and PolicyUpdateToken are not yet available:

=== CONT  TestAccAWSFmsPolicy_tags
    resource_aws_fms_policy_test.go:129: Step 1/2 error: Error running apply:
        Error: Creating Policy Failed: InvalidParameter: 2 validation error(s) found.
        - minimum field size of 36, PutPolicyInput.Policy.PolicyId.
        - minimum field size of 1, PutPolicyInput.Policy.PolicyUpdateToken.



=== CONT  TestAccAWSFmsPolicy_cloudfrontDistribution
    resource_aws_fms_policy_test.go:47: Step 1/2 error: Error running apply:
        Error: Creating Policy Failed: InvalidParameter: 2 validation error(s) found.
        - minimum field size of 36, PutPolicyInput.Policy.PolicyId.
        - minimum field size of 1, PutPolicyInput.Policy.PolicyUpdateToken.



=== CONT  TestAccAWSFmsPolicy_basic
    resource_aws_fms_policy_test.go:19: Step 1/2 error: Error running apply:
        Error: Creating Policy Failed: InvalidParameter: 2 validation error(s) found.
        - minimum field size of 36, PutPolicyInput.Policy.PolicyId.
        - minimum field size of 1, PutPolicyInput.Policy.PolicyUpdateToken.



=== CONT  TestAccAWSFmsPolicy_includeMap
    resource_aws_fms_policy_test.go:75: Step 1/2 error: Error running apply:
        Error: Creating Policy Failed: InvalidParameter: 2 validation error(s) found.
        - minimum field size of 36, PutPolicyInput.Policy.PolicyId.
        - minimum field size of 1, PutPolicyInput.Policy.PolicyUpdateToken.



--- FAIL: TestAccAWSFmsPolicy_tags (11.14s)
--- FAIL: TestAccAWSFmsPolicy_cloudfrontDistribution (13.52s)
=== CONT  TestAccAWSFmsPolicy_update
    resource_aws_fms_policy_test.go:104: Step 1/2 error: Error running apply:
        Error: Creating Policy Failed: InvalidParameter: 2 validation error(s) found.
        - minimum field size of 36, PutPolicyInput.Policy.PolicyId.
        - minimum field size of 1, PutPolicyInput.Policy.PolicyUpdateToken.



--- FAIL: TestAccAWSFmsPolicy_basic (14.61s)
--- FAIL: TestAccAWSFmsPolicy_includeMap (15.72s)
--- FAIL: TestAccAWSFmsPolicy_update (16.84s)

@bflad bflad self-assigned this Feb 4, 2021
@bflad bflad added the enhancement Requests to existing resources that expand the functionality or scope. label Feb 11, 2021
@bill-rich
Copy link
Contributor Author

I got this fixed up, so it should be ready for another look.

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking better now. 👍 Just one documentation thing and missing changelog entry

Output from acceptance testing in AWS Commercial (us-east-1):

--- PASS: TestAccAWSFmsPolicy_tags (16.55s)
--- PASS: TestAccAWSFmsPolicy_includeMap (17.11s)
--- PASS: TestAccAWSFmsPolicy_basic (20.22s)
--- PASS: TestAccAWSFmsPolicy_update (28.45s)
--- PASS: TestAccAWSFmsPolicy_cloudfrontDistribution (79.45s)

We will need to setup special handling for the new CloudFormation test as it currently fails in the default us-west-2 region:

=== CONT  TestAccAWSFmsPolicy_cloudfrontDistribution
    resource_aws_fms_policy_test.go:47: Step 1/2 error: Error running apply:
        Error: Creating Policy Failed: InvalidInputException: Resource ["AWS::CloudFront::Distribution"] can not be used in region: us-west-2.

@@ -59,7 +59,8 @@ The following arguments are supported:
* `include_map` - (Optional) A map of lists, with a single key named 'account' with a list of AWS Account IDs to include for this policy.
* `remediation_enabled` - (Required) A boolean value, indicates if the policy should automatically applied to resources that already exist in the account.
* `resource_tags` - (Optional) A map of resource tags, that if present will filter protections on resources based on the exclude_resource_tags.
* `resource_type_list` - (Required, Forces new resource) A list of resource types to protect, valid values are: `AWS::ElasticLoadBalancingV2::LoadBalancer`, `AWS::ApiGateway::Stage`, `AWS::CloudFront::Distribution`.
* `resource_type` - (Optional) A resource type to protect, valid values are: `AWS::ElasticLoadBalancingV2::LoadBalancer`, `AWS::ApiGateway::Stage`, `AWS::CloudFront::Distribution`. Conflicts with `resource_type_list`.
* `resource_type_list` - (Optional) A list of resource types to protect, valid values are: `AWS::ElasticLoadBalancingV2::LoadBalancer`, `AWS::ApiGateway::Stage`, `AWS::CloudFront::Distribution`. Conflicts with `resource_type`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema validation also includes: "AWS::EC2::NetworkInterface", "AWS::EC2::Instance", "AWS::EC2::SecurityGroup"

Suggested change
* `resource_type_list` - (Optional) A list of resource types to protect, valid values are: `AWS::ElasticLoadBalancingV2::LoadBalancer`, `AWS::ApiGateway::Stage`, `AWS::CloudFront::Distribution`. Conflicts with `resource_type`.
* `resource_type_list` - (Optional) A list of resource types to protect, valid values are: `AWS::ElasticLoadBalancingV2::LoadBalancer`, `AWS::ApiGateway::Stage`, `AWS::CloudFront::Distribution`, `AWS::EC2::Instance`, `AWS::EC2::NetworkInterface`, `AWS::EC2::SecurityGroup`. Conflicts with `resource_type`.

@bill-rich bill-rich merged commit 22a3875 into main Feb 12, 2021
@bill-rich bill-rich deleted the b_fms_distribution branch February 12, 2021 00:49
@github-actions github-actions bot added this to the v3.28.0 milestone Feb 12, 2021
github-actions bot pushed a commit that referenced this pull request Feb 12, 2021
@ghost
Copy link

ghost commented Feb 12, 2021

This has been released in version 3.28.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Mar 14, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Mar 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. enhancement Requests to existing resources that expand the functionality or scope. service/fms Issues and PRs that pertain to the fms service. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants