Coder Social home page Coder Social logo

terraform-aws-modules / terraform-aws-sns Goto Github PK

View Code? Open in Web Editor NEW
94.0 9.0 155.0 80 KB

Terraform module to create AWS SNS resources πŸ‡ΊπŸ‡¦

Home Page: https://registry.terraform.io/modules/terraform-aws-modules/sns/aws

License: Apache License 2.0

HCL 100.00%
sns sns-topic terraform-module

terraform-aws-sns's Issues

Cannot reference module.<name>.topic_arn inside aws_iam_policy_document as value for topic_policy

Description

When creating a totally custom SNS policy using a terraform aws_iam_policy_document as the topic_policy value, terraform throws a Error: Cycle Error if the module output of the module the policy is being attached to is referenced in the SNS topics policy.

The policy works fine if I remove the module reference and hardcode the ARN, however since this behaviour works in other Terraform modules for example https://github.com/terraform-aws-modules/terraform-aws-s3-bucket I figured it would work in this one

Versions

  • Module version [Required]: 6.0.1

  • Terraform version: v1.5.7

  • Provider version(s):
    • registry.terraform.io/hashicorp/aws v5.43.0

Reproduction Code [Required]

data "aws_iam_policy_document" "sns_policy" {

  statement {
    sid       = "sub"
    effect    = "Allow"
    resources = [
      "${module.sns.topic_arn}/*",
    ]

    actions = [
      "sns:Subscribe"
    ]
    principals {
      type        = "AWS"
      identifiers = ["*"]

    }
  }
}

module "sns" {

  source = "terraform-aws-modules/sns/aws"

  name = "bug-report-sns-topic"

  create_topic_policy     = false
  topic_policy            = data.aws_iam_policy_document.sns_policy.json
}

Steps to reproduce the behaviour:

  1. run terraform init
  2. run terraform validate

Expected behavior

The validation should pass with no errors.

Actual behavior

The validation fails with the following error:

β•·
β”‚ Error: Cycle: module.sns.output.topic_arn (expand), data.aws_iam_policy_document.sns_policy, module.sns.var.topic_policy (expand), module.sns.aws_sns_topic.this
β”‚ 
β”‚ 
β•΅

Terminal Output Screenshot(s)

image

Additional context

I've done similar things with terraform modules for example https://github.com/terraform-aws-modules/terraform-aws-s3-bucket where doing the following:

data "aws_iam_policy_document" "bucket_policy" {

  statement {
    sid    = "AllowReadWriteAccess"
    effect = "Allow"
    resources = [
      module.s3.s3_bucket_arn,
      "${module.s3.s3_bucket_arn}/*"
    ]
    principals {
      type        = "AWS"
      identifiers = ["*"]
    }
    actions = [
      "s3:List*",
      "s3:Get*",
      "s3:DeleteObject"
    ]
  }
}



module "s3" {
  source = "terraform-aws-modules/s3-bucket/aws"

  bucket        = "s3-bucket"
  attach_policy = true
  policy        = data.aws_iam_policy_document.bucket_policy.json

}

Policy Deletes and Recreate on its own

When creating a multiple statements policy Terraform deletes or creates the second policy every time.

When running first apply the policy created successfully (as it should be):
image

when running the second apply command (without any code changes) the result is the second statement will be deleted:
image

The required outcome should be that the second statement won't deleted in the second apply command and there will be no changes to apply.

count = "true" for teraform011 branch

For the master branch you'e changed the "count" line to evaluate to a number, but for the teraform11 branch, this evaluates by default to a string value of "true".

`Error: invalid topic name` when creating a FIFO Topic

Description

When enabling FIFO SNS topic by using:

  fifo_topic                  = true
  content_based_deduplication = true

If I don't append the .fifo suffix in my topic name it throws an error: Error: invalid topic name: my-topic.

In terraform-aws-sqs module the .fifo suffix is appended automatically when creating a FIFO queue.

Let me know if I can open a PR with the change in case you think it would be better to do something similar for this module too.

Missing property on module

Hi there
I was testing this module and noticed that the "firehose_success_feedback_sample_rate" property is missing from the "aws_sns_topic" resource.

Add wrapper module generated with pre-commit

Is your request related to a problem? Please describe.

Describe the solution you'd like.

Add wrapper module same as in SQS module

Describe alternatives you've considered.

Additional context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.