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

Add elasticache user and group support #1044

Merged

Conversation

swhite-oreilly
Copy link
Contributor

This PR includes two new modules for Elasticache Users and User Groups.

Also including a filter update to ignore the default subnet for elasticache.

Testing

Elasticache users and users groups were created. using the setup code mentioned below, and then AWS Nuke was used to clean these resources up, specifying ElasticacheUser and ElasticacheUserGroup. The resources were handle as expected:

...
us-east-1 - ElasticacheUserGroup - myusergroup - would remove
...
us-east-1 - ElasticacheSubnetGroup - default - Cannot delete default subnet group
us-east-1 - ElasticacheSubnetGroup - mygroup - would remove
...
us-east-1 - ElasticacheUser - default - Cannot delete default user
us-east-1 - ElasticacheUser - user1 - would remove

Setup code

# Create a Redis cluster
echo "Creating Redis cluster"
aws elasticache create-cache-cluster \
--cache-cluster-id my-cluster \
--cache-node-type cache.t4g.micro \
--engine redis \
--num-cache-nodes 1 \
--cache-parameter-group default.redis7

# Create a Memcached cluster
echo "Creating Memcached cluster"
aws elasticache create-cache-cluster \
--cache-cluster-id my-memcached-cluster \
--cache-node-type cache.r4.large \
--engine memcached \
--engine-version 1.4.24 \
--cache-parameter-group default.memcached1.4 \
--num-cache-nodes 3

echo "Getting a subnet from the default VPC"
DEFAULT_VPC_ID=$(aws ec2 describe-vpcs --filters "Name=isDefault,Values=true" --query 'Vpcs[0].VpcId' --output text)

SUBNET_ID=$(aws ec2 describe-subnets --filters "Name=vpc-id,Values=$DEFAULT_VPC_ID" "Name=availability-zone,Values=us-east-1*" --query 'Subnets[0].SubnetId' --output text)
echo "Using subnet $SUBNET_ID"

# Create an elasticache subnet group (Note: This command will fail if the subnet does not exist)
echo "Creating elasticache subnet group"
aws elasticache create-cache-subnet-group \
    --cache-subnet-group-name "mygroup" \
    --cache-subnet-group-description "my subnet group" \
    --subnet-ids "$SUBNET_ID"

# Create a elasticache parameter group
echo "Creating elasticache parameter group"
aws elasticache create-cache-parameter-group \
    --cache-parameter-group-family "redis5.0" \
    --cache-parameter-group-name "mygroup" \
    --description "mygroup"

# Create a elasticache user
echo "Creating elasticache user"
aws elasticache create-user \
    --user-id user1 \
    --user-name myUser \
    --passwords PASSWORD_STRING \
    --engine redis \
    --access-string "on ~app::* -@all +@read"

# Create a elasticache user group
echo "Creating elasticache user group"
aws elasticache create-user-group \
    --user-group-id myusergroup \
    --engine redis \
    --user-ids default

Adding go modules for elasticache users and groups.  Adding filtering for subnet groups to ignore the default elasticache subnet group.
Adding working code for packages cleanup.
Moving opensearch changes to separate branch.
@swhite-oreilly swhite-oreilly requested a review from a team as a code owner July 19, 2023 15:36
func ListElasticacheUsers(sess *session.Session) ([]Resource, error) {
svc := elasticache.New(sess)

params := &elasticache.DescribeUsersInput{MaxRecords: aws.Int64(100)}
Copy link
Member

Choose a reason for hiding this comment

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

This properly needs paging as well, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bjoernhaeuser paging added.

func ListElasticacheUserGroups(sess *session.Session) ([]Resource, error) {
svc := elasticache.New(sess)

params := &elasticache.DescribeUserGroupsInput{MaxRecords: aws.Int64(100)}
Copy link
Member

Choose a reason for hiding this comment

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

This properly needs paging as well, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bjoernhaeuser paging added.

Comment on lines +65 to +67
func (i *ElasticacheUserGroup) String() string {
return *i.groupId
}
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the late reply - would you mind adding properties for both resources as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@der-eismann I have added properties to both resources. Are these sufficient or are there additional properties you would like to see?

Copy link
Member

Choose a reason for hiding this comment

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

No these are fine, thanks!

@der-eismann der-eismann merged commit 9874f48 into rebuy-de:main Aug 24, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants